porffor 0.55.32 → 0.55.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compiler/builtins/_internal_object.ts +317 -237
- package/compiler/builtins/_internal_string.ts +4 -4
- package/compiler/builtins/annexb_string.js +12 -11
- package/compiler/builtins/array.ts +21 -22
- package/compiler/builtins/arraybuffer.ts +4 -4
- package/compiler/builtins/bigint.ts +4 -4
- package/compiler/builtins/console.ts +9 -9
- package/compiler/builtins/dataview.ts +3 -3
- package/compiler/builtins/date.ts +46 -52
- package/compiler/builtins/error.js +1 -1
- package/compiler/builtins/json.ts +6 -6
- package/compiler/builtins/math.ts +1 -1
- package/compiler/builtins/number.ts +9 -9
- package/compiler/builtins/object.ts +32 -32
- package/compiler/builtins/object_prototypeWithHidden.js +1 -1
- package/compiler/builtins/porffor.d.ts +4 -3
- package/compiler/builtins/promise.ts +6 -6
- package/compiler/builtins/reflect.ts +1 -1
- package/compiler/builtins/set.ts +7 -7
- package/compiler/builtins/string_f64.ts +2 -2
- package/compiler/builtins/symbol.ts +2 -2
- package/compiler/builtins/typedarray.js +7 -7
- package/compiler/builtins/z_ecma262.ts +7 -7
- package/compiler/builtins.js +5 -6
- package/compiler/builtins_objects.js +27 -5
- package/compiler/builtins_precompiled.js +519 -520
- package/compiler/codegen.js +29 -39
- package/compiler/precompile.js +4 -3
- package/package.json +1 -1
- package/r.cjs +2 -9
- package/runner/index.js +1 -1
- package/compiler/builtins/__internal_object.ts +0 -83
@@ -6,7 +6,7 @@ export const __Porffor_json_serialize = (value: any, depth: i32, space: bytestri
|
|
6
6
|
if (value === true) return 'true';
|
7
7
|
if (value === false) return 'false';
|
8
8
|
|
9
|
-
const t: i32 = Porffor.
|
9
|
+
const t: i32 = Porffor.type(value);
|
10
10
|
if (Porffor.fastOr(
|
11
11
|
(t | 0b10000000) == Porffor.TYPES.bytestring,
|
12
12
|
t == Porffor.TYPES.stringobject
|
@@ -125,7 +125,7 @@ export const __Porffor_json_serialize = (value: any, depth: i32, space: bytestri
|
|
125
125
|
|
126
126
|
for (const key in (value as object)) {
|
127
127
|
// skip symbol keys
|
128
|
-
if (Porffor.
|
128
|
+
if (Porffor.type(key) == Porffor.TYPES.symbol) continue;
|
129
129
|
|
130
130
|
// skip non-serializable values (functions, etc)
|
131
131
|
const val: bytestring|undefined = __Porffor_json_serialize((value as object)[key], depth, space);
|
@@ -180,8 +180,8 @@ export const __JSON_stringify = (value: any, replacer: any, space: any) => {
|
|
180
180
|
|
181
181
|
if (space !== undefined) {
|
182
182
|
if (Porffor.fastOr(
|
183
|
-
Porffor.
|
184
|
-
Porffor.
|
183
|
+
Porffor.type(space) == Porffor.TYPES.number,
|
184
|
+
Porffor.type(space) == Porffor.TYPES.numberobject
|
185
185
|
)) {
|
186
186
|
space = Math.min(Math.trunc(space), 10);
|
187
187
|
Porffor.print(space); Porffor.printStatic('\n');
|
@@ -195,8 +195,8 @@ export const __JSON_stringify = (value: any, replacer: any, space: any) => {
|
|
195
195
|
space = spaceStr;
|
196
196
|
}
|
197
197
|
} else if (Porffor.fastOr(
|
198
|
-
(Porffor.
|
199
|
-
Porffor.
|
198
|
+
(Porffor.type(space) | 0b10000000) == Porffor.TYPES.bytestring,
|
199
|
+
Porffor.type(space) == Porffor.TYPES.stringobject
|
200
200
|
)) {
|
201
201
|
// if empty, make it undefined
|
202
202
|
const len: i32 = space.length;
|
@@ -480,7 +480,7 @@ export const __Math_sumPrecise = (values: any[]): number => {
|
|
480
480
|
const large: Float64Array = new Float64Array(LARGE_SLOTS);
|
481
481
|
|
482
482
|
for (const _ of values) {
|
483
|
-
if (Porffor.
|
483
|
+
if (Porffor.type(_) != Porffor.TYPES.number) throw new TypeError('Math.sumPrecise must have only numbers in values');
|
484
484
|
|
485
485
|
const v: number = _;
|
486
486
|
if (v == 0) continue;
|
@@ -7,13 +7,13 @@ export const Number = function (value: any): number|NumberObject {
|
|
7
7
|
|
8
8
|
// 1. If value is present, then
|
9
9
|
// todo: handle undefined (NaN) and not present (0) args differently
|
10
|
-
if (Porffor.
|
10
|
+
if (Porffor.type(value) != Porffor.TYPES.undefined) {
|
11
11
|
// a. Let prim be ? ToNumeric(value).
|
12
12
|
n = ecma262.ToNumeric(value);
|
13
13
|
|
14
14
|
// b. If prim is a BigInt, let n be 𝔽(ℝ(prim)).
|
15
15
|
if (Porffor.comptime.flag`hasType.bigint`) {
|
16
|
-
if (Porffor.
|
16
|
+
if (Porffor.type(n) == Porffor.TYPES.bigint)
|
17
17
|
n = Porffor.bigint.toNumber(n);
|
18
18
|
}
|
19
19
|
|
@@ -33,9 +33,9 @@ export const Number = function (value: any): number|NumberObject {
|
|
33
33
|
return n as NumberObject;
|
34
34
|
};
|
35
35
|
|
36
|
-
// radix: number|any for
|
36
|
+
// radix: number|any for type check
|
37
37
|
export const __Number_prototype_toString = (_this: number, radix: number|any) => {
|
38
|
-
if (Porffor.
|
38
|
+
if (Porffor.type(radix) != Porffor.TYPES.number) {
|
39
39
|
// todo: string to number
|
40
40
|
radix = 10;
|
41
41
|
}
|
@@ -355,7 +355,7 @@ export const __Number_prototype_toFixed = (_this: number, fractionDigits: number
|
|
355
355
|
|
356
356
|
export const __Number_prototype_toLocaleString = (_this: number) => __Number_prototype_toString(_this, 10);
|
357
357
|
|
358
|
-
// fractionDigits: number|any for
|
358
|
+
// fractionDigits: number|any for type check
|
359
359
|
export const __Number_prototype_toExponential = (_this: number, fractionDigits: number|any) => {
|
360
360
|
if (!Number.isFinite(_this)) {
|
361
361
|
if (Number.isNaN(_this)) return 'NaN';
|
@@ -363,7 +363,7 @@ export const __Number_prototype_toExponential = (_this: number, fractionDigits:
|
|
363
363
|
return '-Infinity';
|
364
364
|
}
|
365
365
|
|
366
|
-
if (Porffor.
|
366
|
+
if (Porffor.type(fractionDigits) != Porffor.TYPES.number) {
|
367
367
|
// todo: string to number
|
368
368
|
fractionDigits = undefined;
|
369
369
|
} else {
|
@@ -404,7 +404,7 @@ export const __Number_prototype_toExponential = (_this: number, fractionDigits:
|
|
404
404
|
Porffor.wasm.i32.store8(outPtr++, 43, 0, 4); // +
|
405
405
|
} else if (_this < 1) {
|
406
406
|
// small exponential
|
407
|
-
if (Porffor.
|
407
|
+
if (Porffor.type(fractionDigits) != Porffor.TYPES.number) {
|
408
408
|
e = 1;
|
409
409
|
while (true) {
|
410
410
|
i *= 10;
|
@@ -461,7 +461,7 @@ export const __Number_prototype_toExponential = (_this: number, fractionDigits:
|
|
461
461
|
e++;
|
462
462
|
}
|
463
463
|
|
464
|
-
if (Porffor.
|
464
|
+
if (Porffor.type(fractionDigits) != Porffor.TYPES.number) {
|
465
465
|
while (true) {
|
466
466
|
i *= 10;
|
467
467
|
|
@@ -582,7 +582,7 @@ export const parseInt = (input: any, radix: any): f64 => {
|
|
582
582
|
|
583
583
|
let negative: boolean = false;
|
584
584
|
|
585
|
-
if (Porffor.
|
585
|
+
if (Porffor.type(input) == Porffor.TYPES.bytestring) {
|
586
586
|
const endPtr: i32 = i + len;
|
587
587
|
|
588
588
|
// check start of string
|
@@ -7,9 +7,9 @@ export const Object = function (value: any): any {
|
|
7
7
|
}
|
8
8
|
|
9
9
|
// primitives into primitive objects
|
10
|
-
if ((Porffor.
|
11
|
-
if (Porffor.
|
12
|
-
if (Porffor.
|
10
|
+
if ((Porffor.type(value) | 0b10000000) == Porffor.TYPES.bytestring) return new String(value);
|
11
|
+
if (Porffor.type(value) == Porffor.TYPES.number) return new Number(value);
|
12
|
+
if (Porffor.type(value) == Porffor.TYPES.boolean) return new Boolean(value);
|
13
13
|
|
14
14
|
// return input
|
15
15
|
return value;
|
@@ -20,7 +20,7 @@ export const __Object_keys = (obj: any): any[] => {
|
|
20
20
|
const out: any[] = Porffor.allocate();
|
21
21
|
|
22
22
|
obj = __Porffor_object_underlying(obj);
|
23
|
-
const t: i32 = Porffor.
|
23
|
+
const t: i32 = Porffor.type(obj);
|
24
24
|
if (t == Porffor.TYPES.object) {
|
25
25
|
let ptr: i32 = Porffor.wasm`local.get ${obj}` + 8;
|
26
26
|
const endPtr: i32 = ptr + Porffor.wasm.i32.load16_u(obj, 0, 0) * 18;
|
@@ -76,7 +76,7 @@ export const __Object_values = (obj: any): any[] => {
|
|
76
76
|
const out: any[] = Porffor.allocate();
|
77
77
|
|
78
78
|
obj = __Porffor_object_underlying(obj);
|
79
|
-
const t: i32 = Porffor.
|
79
|
+
const t: i32 = Porffor.type(obj);
|
80
80
|
if (t == Porffor.TYPES.object) {
|
81
81
|
let ptr: i32 = Porffor.wasm`local.get ${obj}` + 8;
|
82
82
|
const endPtr: i32 = ptr + Porffor.wasm.i32.load16_u(obj, 0, 0) * 18;
|
@@ -146,13 +146,13 @@ export const __Object_prototype_hasOwnProperty = (_this: any, prop: any) => {
|
|
146
146
|
if (_this == null) throw new TypeError('Argument is nullish, expected object');
|
147
147
|
const p: any = ecma262.ToPropertyKey(prop);
|
148
148
|
|
149
|
-
const t: i32 = Porffor.
|
149
|
+
const t: i32 = Porffor.type(_this);
|
150
150
|
if (t == Porffor.TYPES.object) {
|
151
151
|
return Porffor.object.lookup(_this, p, __Porffor_object_hash(p)) != -1;
|
152
152
|
}
|
153
153
|
|
154
154
|
const obj: any = __Porffor_object_underlying(_this);
|
155
|
-
if (Porffor.
|
155
|
+
if (Porffor.type(obj) == Porffor.TYPES.object) {
|
156
156
|
if (Porffor.object.lookup(obj, p, __Porffor_object_hash(p)) != -1) return true;
|
157
157
|
}
|
158
158
|
|
@@ -173,7 +173,7 @@ export const __Porffor_object_in = (obj: any, prop: any): boolean => {
|
|
173
173
|
|
174
174
|
let lastProto = obj;
|
175
175
|
while (true) {
|
176
|
-
obj = Porffor.object.getPrototypeWithHidden(obj, Porffor.
|
176
|
+
obj = Porffor.object.getPrototypeWithHidden(obj, Porffor.type(obj));
|
177
177
|
if (Porffor.fastOr(obj == null, Porffor.wasm`local.get ${obj}` == Porffor.wasm`local.get ${lastProto}`)) break;
|
178
178
|
|
179
179
|
if (__Object_prototype_hasOwnProperty(obj, prop)) return true;
|
@@ -184,7 +184,7 @@ export const __Porffor_object_in = (obj: any, prop: any): boolean => {
|
|
184
184
|
};
|
185
185
|
|
186
186
|
export const __Porffor_object_instanceof = (obj: any, constr: any, checkProto: any): boolean => {
|
187
|
-
if (Porffor.
|
187
|
+
if (Porffor.type(constr) != Porffor.TYPES.function) {
|
188
188
|
throw new TypeError('instanceof right-hand side is not a function');
|
189
189
|
}
|
190
190
|
|
@@ -194,7 +194,7 @@ export const __Porffor_object_instanceof = (obj: any, constr: any, checkProto: a
|
|
194
194
|
|
195
195
|
let lastProto = obj;
|
196
196
|
while (true) {
|
197
|
-
obj = Porffor.object.getPrototypeWithHidden(obj, Porffor.
|
197
|
+
obj = Porffor.object.getPrototypeWithHidden(obj, Porffor.type(obj));
|
198
198
|
if (Porffor.fastOr(obj == null, Porffor.wasm`local.get ${obj}` == Porffor.wasm`local.get ${lastProto}`)) break;
|
199
199
|
|
200
200
|
if (obj === checkProto) return true;
|
@@ -240,7 +240,7 @@ export const __Object_prototype_propertyIsEnumerable = (_this: any, prop: any) =
|
|
240
240
|
|
241
241
|
const p: any = ecma262.ToPropertyKey(prop);
|
242
242
|
|
243
|
-
if (Porffor.
|
243
|
+
if (Porffor.type(_this) == Porffor.TYPES.object) {
|
244
244
|
const entryPtr: i32 = Porffor.object.lookup(_this, p, __Porffor_object_hash(p));
|
245
245
|
if (entryPtr == -1) return false;
|
246
246
|
|
@@ -248,7 +248,7 @@ export const __Object_prototype_propertyIsEnumerable = (_this: any, prop: any) =
|
|
248
248
|
}
|
249
249
|
|
250
250
|
const obj: any = __Porffor_object_underlying(_this);
|
251
|
-
if (Porffor.
|
251
|
+
if (Porffor.type(obj) == Porffor.TYPES.object) {
|
252
252
|
const entryPtr: i32 = Porffor.object.lookup(obj, p, __Porffor_object_hash(p));
|
253
253
|
if (entryPtr != -1) return Porffor.object.isEnumerable(entryPtr);
|
254
254
|
}
|
@@ -269,7 +269,7 @@ export const __Object_is = (x: any, y: any): boolean => {
|
|
269
269
|
}
|
270
270
|
|
271
271
|
// check NaN
|
272
|
-
if (Porffor.
|
272
|
+
if (Porffor.type(x) == Porffor.TYPES.number && Number.isNaN(x)) {
|
273
273
|
return Number.isNaN(y);
|
274
274
|
}
|
275
275
|
|
@@ -347,7 +347,7 @@ export const __Object_getOwnPropertyDescriptor = (obj: any, prop: any): object|u
|
|
347
347
|
|
348
348
|
const entryPtr: i32 = Porffor.object.lookup(obj, p, __Porffor_object_hash(p));
|
349
349
|
if (entryPtr == -1) {
|
350
|
-
if (Porffor.
|
350
|
+
if (Porffor.type(obj) == Porffor.TYPES.function) {
|
351
351
|
// hack: function .name and .length
|
352
352
|
const v = obj[p];
|
353
353
|
if (v != null) {
|
@@ -394,9 +394,9 @@ local.set ${value+1}`;
|
|
394
394
|
export const __Object_getOwnPropertyDescriptors = (obj: any): object => {
|
395
395
|
const out: object = {};
|
396
396
|
|
397
|
-
if (Porffor.
|
397
|
+
if (Porffor.type(obj) != Porffor.TYPES.object) {
|
398
398
|
obj = __Porffor_object_underlying(obj);
|
399
|
-
if (Porffor.
|
399
|
+
if (Porffor.type(obj) != Porffor.TYPES.object) return out;
|
400
400
|
}
|
401
401
|
|
402
402
|
const keys: any[] = Reflect.ownKeys(obj);
|
@@ -413,7 +413,7 @@ export const __Object_getOwnPropertyNames = (obj: any): any[] => {
|
|
413
413
|
const out: any[] = Porffor.allocate();
|
414
414
|
|
415
415
|
obj = __Porffor_object_underlying(obj);
|
416
|
-
const t: i32 = Porffor.
|
416
|
+
const t: i32 = Porffor.type(obj);
|
417
417
|
if (t == Porffor.TYPES.object) {
|
418
418
|
let ptr: i32 = Porffor.wasm`local.get ${obj}` + 8;
|
419
419
|
const endPtr: i32 = ptr + Porffor.wasm.i32.load16_u(obj, 0, 0) * 18;
|
@@ -453,7 +453,7 @@ end
|
|
453
453
|
i32.from_u
|
454
454
|
local.set ${key}`;
|
455
455
|
|
456
|
-
if (Porffor.
|
456
|
+
if (Porffor.type(key) == Porffor.TYPES.symbol) continue;
|
457
457
|
out[i++] = key;
|
458
458
|
}
|
459
459
|
|
@@ -468,7 +468,7 @@ export const __Object_getOwnPropertySymbols = (obj: any): any[] => {
|
|
468
468
|
const out: any[] = Porffor.allocate();
|
469
469
|
|
470
470
|
obj = __Porffor_object_underlying(obj);
|
471
|
-
const t: i32 = Porffor.
|
471
|
+
const t: i32 = Porffor.type(obj);
|
472
472
|
if (t == Porffor.TYPES.object) {
|
473
473
|
let ptr: i32 = Porffor.wasm`local.get ${obj}` + 8;
|
474
474
|
const endPtr: i32 = ptr + Porffor.wasm.i32.load16_u(obj, 0, 0) * 18;
|
@@ -508,7 +508,7 @@ end
|
|
508
508
|
i32.from_u
|
509
509
|
local.set ${key}`;
|
510
510
|
|
511
|
-
if (Porffor.
|
511
|
+
if (Porffor.type(key) != Porffor.TYPES.symbol) continue;
|
512
512
|
out[i++] = key;
|
513
513
|
}
|
514
514
|
|
@@ -523,7 +523,7 @@ export const __Object_defineProperty = (target: any, prop: any, desc: any): any
|
|
523
523
|
if (!Porffor.object.isObject(target)) throw new TypeError('Target is a non-object');
|
524
524
|
if (!Porffor.object.isObject(desc)) throw new TypeError('Descriptor is a non-object');
|
525
525
|
|
526
|
-
if (Porffor.
|
526
|
+
if (Porffor.type(target) == Porffor.TYPES.array) {
|
527
527
|
if (prop === 'length' && __Object_hasOwn(desc, 'value')) {
|
528
528
|
const v: any = desc.value;
|
529
529
|
const n: number = ecma262.ToNumber(v);
|
@@ -558,8 +558,8 @@ export const __Object_defineProperty = (target: any, prop: any, desc: any): any
|
|
558
558
|
|
559
559
|
// todo: should check if has attributes not if undefined
|
560
560
|
if (get !== undefined || set !== undefined) {
|
561
|
-
if (get !== undefined && Porffor.
|
562
|
-
if (set !== undefined && Porffor.
|
561
|
+
if (get !== undefined && Porffor.type(get) != Porffor.TYPES.function) throw new TypeError('Getter must be a function');
|
562
|
+
if (set !== undefined && Porffor.type(set) != Porffor.TYPES.function) throw new TypeError('Setter must be a function');
|
563
563
|
|
564
564
|
if (value !== undefined || writable !== undefined) {
|
565
565
|
throw new TypeError('Descriptor cannot define both accessor and data descriptor attributes');
|
@@ -640,7 +640,7 @@ export const __Object_groupBy = (items: any, callbackFn: any): object => {
|
|
640
640
|
|
641
641
|
export const __Object_getPrototypeOf = (obj: any): any => {
|
642
642
|
if (obj == null) throw new TypeError('Object is nullish, expected object');
|
643
|
-
return Porffor.object.getPrototypeWithHidden(obj, Porffor.
|
643
|
+
return Porffor.object.getPrototypeWithHidden(obj, Porffor.type(obj));
|
644
644
|
};
|
645
645
|
|
646
646
|
export const __Object_setPrototypeOf = (obj: any, proto: any): any => {
|
@@ -657,22 +657,22 @@ export const __Object_prototype_isPrototypeOf = (_this: any, obj: any) => {
|
|
657
657
|
if (_this == null) throw new TypeError('This is nullish, expected object');
|
658
658
|
|
659
659
|
if (!Porffor.object.isObject(obj)) return false;
|
660
|
-
return _this == Porffor.object.getPrototypeWithHidden(obj, Porffor.
|
660
|
+
return _this == Porffor.object.getPrototypeWithHidden(obj, Porffor.type(obj));
|
661
661
|
};
|
662
662
|
|
663
663
|
|
664
664
|
export const __Object_prototype_toString = (_this: any) => {
|
665
|
-
if (Porffor.
|
665
|
+
if (Porffor.type(_this) == Porffor.TYPES.object) {
|
666
666
|
// todo: breaks with Foo.prototype
|
667
667
|
const obj: object = _this;
|
668
668
|
if (obj != null) {
|
669
669
|
let ovr: any = obj.toString;
|
670
|
-
if (Porffor.
|
670
|
+
if (Porffor.type(ovr) == Porffor.TYPES.function && ovr != __Object_prototype_toString) return ovr.call(_this);
|
671
671
|
|
672
672
|
const entryPtr: i32 = Porffor.object.lookup(obj, 'toString', __Porffor_object_hash('toString')); // todo: comptime
|
673
673
|
if (entryPtr != -1) {
|
674
674
|
ovr = Porffor.object.readValue(entryPtr);
|
675
|
-
if (Porffor.
|
675
|
+
if (Porffor.type(ovr) == Porffor.TYPES.function) return ovr.call(_this);
|
676
676
|
else return undefined;
|
677
677
|
}
|
678
678
|
}
|
@@ -686,7 +686,7 @@ export const __Object_prototype_toString = (_this: any) => {
|
|
686
686
|
|
687
687
|
// todo: toStringTag support
|
688
688
|
|
689
|
-
const t: i32 = Porffor.
|
689
|
+
const t: i32 = Porffor.type(_this);
|
690
690
|
if (t == Porffor.TYPES.array) return '[object Array]';
|
691
691
|
if (t == Porffor.TYPES.function) return '[object Function]';
|
692
692
|
if (Porffor.fastOr(
|
@@ -709,17 +709,17 @@ export const __Object_prototype_toLocaleString = (_this: any) => __Object_protot
|
|
709
709
|
|
710
710
|
export const __Object_prototype_valueOf = (_this: any) => {
|
711
711
|
// todo: ToObject
|
712
|
-
if (Porffor.
|
712
|
+
if (Porffor.type(_this) == Porffor.TYPES.object) {
|
713
713
|
// todo: breaks with Foo.prototype
|
714
714
|
const obj: object = _this;
|
715
715
|
if (obj != null) {
|
716
716
|
let ovr: any = obj.valueOf;
|
717
|
-
if (Porffor.
|
717
|
+
if (Porffor.type(ovr) == Porffor.TYPES.function && ovr != __Object_prototype_valueOf) return ovr.call(_this);
|
718
718
|
|
719
719
|
const entryPtr: i32 = Porffor.object.lookup(obj, 'valueOf', __Porffor_object_hash('valueOf')); // todo: comptime
|
720
720
|
if (entryPtr != -1) {
|
721
721
|
ovr = Porffor.object.readValue(entryPtr);
|
722
|
-
if (Porffor.
|
722
|
+
if (Porffor.type(ovr) == Porffor.TYPES.function) return ovr.call(_this);
|
723
723
|
else return undefined;
|
724
724
|
}
|
725
725
|
}
|
@@ -2,7 +2,7 @@ export default ({ TYPES, TYPE_NAMES }) => {
|
|
2
2
|
let out = `// @porf --valtype=i32
|
3
3
|
export const __Porffor_object_getPrototypeWithHidden = (obj: any, trueType: i32): any => {
|
4
4
|
const objectProto: any = __Porffor_object_getPrototype(obj);
|
5
|
-
if (Porffor.
|
5
|
+
if (Porffor.type(objectProto) == Porffor.TYPES.empty) {
|
6
6
|
if (Porffor.comptime.flag\`hasFunc.#get___String_prototype\`) {
|
7
7
|
if (Porffor.fastOr(
|
8
8
|
trueType == Porffor.TYPES.string,
|
@@ -23,6 +23,7 @@ type PorfforGlobal = {
|
|
23
23
|
f64: {
|
24
24
|
load(pointer: any, align: i32, offset: i32): i32;
|
25
25
|
store(pointer: any, value: f64, align: i32, offset: i32): f64;
|
26
|
+
eq(a: f64, b: f64): boolean;
|
26
27
|
}
|
27
28
|
}
|
28
29
|
|
@@ -57,7 +58,7 @@ type PorfforGlobal = {
|
|
57
58
|
lookup(obj: object, target: any): i32;
|
58
59
|
get(obj: any, key: any): any;
|
59
60
|
|
60
|
-
writeKey(ptr: i32, key: any): void;
|
61
|
+
writeKey(ptr: i32, key: any, hash: i32): void;
|
61
62
|
set(obj: object, key: any, value: any): any;
|
62
63
|
define(obj: object, key: any, value: any, flags: i32): void;
|
63
64
|
delete(obj: object, key: any): boolean;
|
@@ -97,8 +98,8 @@ type PorfforGlobal = {
|
|
97
98
|
|
98
99
|
randomByte(): i32;
|
99
100
|
|
100
|
-
type(x: any):
|
101
|
-
|
101
|
+
type(x: any): i32;
|
102
|
+
typeName(type: i32): bytestring;
|
102
103
|
TYPES: {
|
103
104
|
number: i32;
|
104
105
|
boolean: i32;
|
@@ -31,7 +31,7 @@ export const __ecma262_TriggerPromiseReactions = (reactions: any[], argument: an
|
|
31
31
|
// https://tc39.es/ecma262/#sec-ispromise
|
32
32
|
export const __ecma262_IsPromise = (x: any): boolean => {
|
33
33
|
// custom impl
|
34
|
-
return Porffor.
|
34
|
+
return Porffor.type(x) == Porffor.TYPES.promise;
|
35
35
|
};
|
36
36
|
|
37
37
|
// 27.2.1.4 FulfillPromise (promise, value)
|
@@ -227,7 +227,7 @@ export const __Porffor_promise_rejectActive = (reason: any): void => __Porffor_p
|
|
227
227
|
|
228
228
|
export const Promise = function (executor: any): Promise {
|
229
229
|
if (!new.target) throw new TypeError("Constructor Promise requires 'new'");
|
230
|
-
if (Porffor.
|
230
|
+
if (Porffor.type(executor) != Porffor.TYPES.function) throw new TypeError('Promise executor is not a function');
|
231
231
|
|
232
232
|
const obj: any[] = __Porffor_promise_create();
|
233
233
|
activePromise = obj;
|
@@ -279,8 +279,8 @@ export const __Promise_prototype_then = (_this: any, onFulfilled: any, onRejecte
|
|
279
279
|
// 2. If IsPromise(promise) is false, throw a TypeError exception.
|
280
280
|
if (!__ecma262_IsPromise(_this)) throw new TypeError('Promise.prototype.then called on non-Promise');
|
281
281
|
|
282
|
-
if (Porffor.
|
283
|
-
if (Porffor.
|
282
|
+
if (Porffor.type(onFulfilled) != Porffor.TYPES.function) onFulfilled = __Porffor_promise_noop;
|
283
|
+
if (Porffor.type(onRejected) != Porffor.TYPES.function) onRejected = __Porffor_promise_noop;
|
284
284
|
|
285
285
|
const outPromise: any[] = __Porffor_promise_create();
|
286
286
|
|
@@ -304,7 +304,7 @@ export const __Promise_prototype_finally = (_this: any, onFinally: any) => {
|
|
304
304
|
// custom impl based on then but also not (sorry)
|
305
305
|
if (!__ecma262_IsPromise(_this)) throw new TypeError('Promise.prototype.then called on non-Promise');
|
306
306
|
|
307
|
-
if (Porffor.
|
307
|
+
if (Porffor.type(onFinally) != Porffor.TYPES.function) onFinally = __Porffor_promise_noop;
|
308
308
|
|
309
309
|
const promise: any[] = _this;
|
310
310
|
const state: i32 = promise[1];
|
@@ -472,7 +472,7 @@ export const __Promise_prototype_toLocaleString = (_this: any) => __Promise_prot
|
|
472
472
|
|
473
473
|
|
474
474
|
export const __Porffor_promise_await = (value: any): any => {
|
475
|
-
if (Porffor.
|
475
|
+
if (Porffor.type(value) != Porffor.TYPES.promise) return value;
|
476
476
|
|
477
477
|
// hack: peek value instead of awaiting
|
478
478
|
const state: i32 = (value as any[])[1];
|
@@ -89,7 +89,7 @@ export const __Reflect_ownKeys = (target: any) => {
|
|
89
89
|
const out: any[] = Porffor.allocate();
|
90
90
|
|
91
91
|
target = __Porffor_object_underlying(target);
|
92
|
-
const t: i32 = Porffor.
|
92
|
+
const t: i32 = Porffor.type(target);
|
93
93
|
if (t == Porffor.TYPES.object) {
|
94
94
|
let ptr: i32 = Porffor.wasm`local.get ${target}` + 8;
|
95
95
|
const endPtr: i32 = ptr + Porffor.wasm.i32.load16_u(target, 0, 0) * 18;
|
package/compiler/builtins/set.ts
CHANGED
@@ -172,7 +172,7 @@ export const Set = function (iterable: any): Set {
|
|
172
172
|
};
|
173
173
|
|
174
174
|
export const __Set_prototype_union = (_this: Set, other: any) => {
|
175
|
-
if (Porffor.
|
175
|
+
if (Porffor.type(other) != Porffor.TYPES.set) throw new TypeError('other argument must be a Set');
|
176
176
|
|
177
177
|
const out: Set = new Set(_this);
|
178
178
|
for (const x of other) {
|
@@ -183,7 +183,7 @@ export const __Set_prototype_union = (_this: Set, other: any) => {
|
|
183
183
|
};
|
184
184
|
|
185
185
|
export const __Set_prototype_intersection = (_this: Set, other: any) => {
|
186
|
-
if (Porffor.
|
186
|
+
if (Porffor.type(other) != Porffor.TYPES.set) throw new TypeError('other argument must be a Set');
|
187
187
|
|
188
188
|
const out: Set = new Set(_this);
|
189
189
|
for (const x of other) {
|
@@ -194,7 +194,7 @@ export const __Set_prototype_intersection = (_this: Set, other: any) => {
|
|
194
194
|
};
|
195
195
|
|
196
196
|
export const __Set_prototype_difference = (_this: Set, other: any) => {
|
197
|
-
if (Porffor.
|
197
|
+
if (Porffor.type(other) != Porffor.TYPES.set) throw new TypeError('other argument must be a Set');
|
198
198
|
|
199
199
|
const out: Set = new Set(_this);
|
200
200
|
for (const x of other) {
|
@@ -205,7 +205,7 @@ export const __Set_prototype_difference = (_this: Set, other: any) => {
|
|
205
205
|
};
|
206
206
|
|
207
207
|
export const __Set_prototype_symmetricDifference = (_this: Set, other: any) => {
|
208
|
-
if (Porffor.
|
208
|
+
if (Porffor.type(other) != Porffor.TYPES.set) throw new TypeError('other argument must be a Set');
|
209
209
|
|
210
210
|
const out: Set = new Set(_this);
|
211
211
|
for (const x of other) {
|
@@ -217,7 +217,7 @@ export const __Set_prototype_symmetricDifference = (_this: Set, other: any) => {
|
|
217
217
|
};
|
218
218
|
|
219
219
|
export const __Set_prototype_isSubsetOf = (_this: Set, other: any) => {
|
220
|
-
if (Porffor.
|
220
|
+
if (Porffor.type(other) != Porffor.TYPES.set) throw new TypeError('other argument must be a Set');
|
221
221
|
|
222
222
|
for (const x of _this) {
|
223
223
|
if (!other.has(x)) return false;
|
@@ -227,7 +227,7 @@ export const __Set_prototype_isSubsetOf = (_this: Set, other: any) => {
|
|
227
227
|
};
|
228
228
|
|
229
229
|
export const __Set_prototype_isSupersetOf = (_this: Set, other: any) => {
|
230
|
-
if (Porffor.
|
230
|
+
if (Porffor.type(other) != Porffor.TYPES.set) throw new TypeError('other argument must be a Set');
|
231
231
|
|
232
232
|
for (const x of other) {
|
233
233
|
if (!_this.has(x)) return false;
|
@@ -237,7 +237,7 @@ export const __Set_prototype_isSupersetOf = (_this: Set, other: any) => {
|
|
237
237
|
};
|
238
238
|
|
239
239
|
export const __Set_prototype_isDisjointFrom = (_this: Set, other: any) => {
|
240
|
-
if (Porffor.
|
240
|
+
if (Porffor.type(other) != Porffor.TYPES.set) throw new TypeError('other argument must be a Set');
|
241
241
|
|
242
242
|
for (const x of _this) {
|
243
243
|
if (other.has(x)) return false;
|
@@ -14,7 +14,7 @@ export const String = function (...args: any[]): string|bytestring|StringObject
|
|
14
14
|
const value: any = args[0];
|
15
15
|
|
16
16
|
// a. If NewTarget is undefined and value is a Symbol, return SymbolDescriptiveString(value).
|
17
|
-
if (!new.target && Porffor.
|
17
|
+
if (!new.target && Porffor.type(value) == Porffor.TYPES.symbol) return __Symbol_prototype_toString(value);
|
18
18
|
|
19
19
|
// b. Let s be ? ToString(value).
|
20
20
|
s = ecma262.ToString(value);
|
@@ -26,7 +26,7 @@ export const String = function (...args: any[]): string|bytestring|StringObject
|
|
26
26
|
// 4. Return StringCreate(s, ? GetPrototypeFromConstructor(NewTarget, "%String.prototype%")).
|
27
27
|
|
28
28
|
// force bytestrings to strings
|
29
|
-
if (Porffor.
|
29
|
+
if (Porffor.type(s) == Porffor.TYPES.bytestring) s = Porffor.bytestringToString(s, s.length);
|
30
30
|
|
31
31
|
return s as StringObject;
|
32
32
|
};
|
@@ -12,7 +12,7 @@ export const Symbol = (description: any): Symbol => {
|
|
12
12
|
let descString: any = undefined;
|
13
13
|
|
14
14
|
// 3. Else, let descString be ? ToString(description).
|
15
|
-
if (Porffor.
|
15
|
+
if (Porffor.type(description) != Porffor.TYPES.undefined) {
|
16
16
|
descString = ecma262.ToString(description);
|
17
17
|
}
|
18
18
|
|
@@ -74,7 +74,7 @@ export const __Symbol_for = (key: any): Symbol => {
|
|
74
74
|
};
|
75
75
|
|
76
76
|
export const __Symbol_keyFor = (arg: any): any => {
|
77
|
-
if (Porffor.
|
77
|
+
if (Porffor.type(arg) != Porffor.TYPES.symbol) throw new TypeError('Symbol.keyFor argument should be a Symbol');
|
78
78
|
|
79
79
|
const sym: Symbol = arg;
|
80
80
|
const desc: any = sym.description;
|
@@ -18,7 +18,7 @@ export default async () => {
|
|
18
18
|
let len: i32 = 0;
|
19
19
|
let bufferPtr: i32;
|
20
20
|
|
21
|
-
const type: i32 = Porffor.
|
21
|
+
const type: i32 = Porffor.type(arg);
|
22
22
|
if (Porffor.fastOr(
|
23
23
|
type == Porffor.TYPES.arraybuffer,
|
24
24
|
type == Porffor.TYPES.sharedarraybuffer
|
@@ -28,13 +28,13 @@ export default async () => {
|
|
28
28
|
if (arg.detached) throw new TypeError('Constructed ${name} with a detached ArrayBuffer');
|
29
29
|
|
30
30
|
let offset: i32 = 0;
|
31
|
-
if (Porffor.
|
31
|
+
if (Porffor.type(byteOffset) != Porffor.TYPES.undefined) offset = Math.trunc(byteOffset);
|
32
32
|
if (offset < 0) throw new RangeError('Invalid DataView byte offset (negative)');
|
33
33
|
|
34
34
|
Porffor.wasm.i32.store(outPtr, offset, 0, 8);
|
35
35
|
Porffor.wasm.i32.store(outPtr, bufferPtr + offset, 0, 4);
|
36
36
|
|
37
|
-
if (Porffor.
|
37
|
+
if (Porffor.type(length) == Porffor.TYPES.undefined) {
|
38
38
|
const bufferLen: i32 = Porffor.wasm.i32.load(bufferPtr, 0, 0);
|
39
39
|
len = (bufferLen - byteOffset) / ${name}.BYTES_PER_ELEMENT;
|
40
40
|
|
@@ -75,18 +75,18 @@ export const __${name}_from = (arg: any, mapFn: any): ${name} => {
|
|
75
75
|
const arr: any[] = Porffor.allocate();
|
76
76
|
let len: i32 = 0;
|
77
77
|
|
78
|
-
const type = Porffor.
|
78
|
+
const type = Porffor.type(arg);
|
79
79
|
if (Porffor.fastOr(
|
80
80
|
type == Porffor.TYPES.array,
|
81
81
|
type == Porffor.TYPES.string, type == Porffor.TYPES.bytestring,
|
82
82
|
type == Porffor.TYPES.set,
|
83
83
|
Porffor.fastAnd(type >= Porffor.TYPES.uint8array, type <= Porffor.TYPES.float64array)
|
84
84
|
)) {
|
85
|
-
const hasMapFn = Porffor.
|
85
|
+
const hasMapFn = Porffor.type(mapFn) != Porffor.TYPES.undefined;
|
86
86
|
|
87
87
|
let i: i32 = 0;
|
88
88
|
if (hasMapFn) {
|
89
|
-
if (Porffor.
|
89
|
+
if (Porffor.type(mapFn) != Porffor.TYPES.function) throw new TypeError('Called Array.from with a non-function mapFn');
|
90
90
|
|
91
91
|
for (const x of arg) {
|
92
92
|
arr[i] = mapFn(x, i);
|
@@ -132,7 +132,7 @@ export const __${name}_prototype_at = (_this: ${name}, index: number) => {
|
|
132
132
|
|
133
133
|
export const __${name}_prototype_slice = (_this: ${name}, start: number, end: number) => {
|
134
134
|
const len: i32 = _this.length;
|
135
|
-
if (Porffor.
|
135
|
+
if (Porffor.type(end) == Porffor.TYPES.undefined) end = len;
|
136
136
|
|
137
137
|
start |= 0;
|
138
138
|
end |= 0;
|
@@ -28,7 +28,7 @@ export const __ecma262_ToPrimitive_String = (input: any): any => {
|
|
28
28
|
// 7.1.4 ToNumber (argument)
|
29
29
|
// https://tc39.es/ecma262/#sec-tonumber
|
30
30
|
export const __ecma262_ToNumber = (argument: unknown): number => {
|
31
|
-
const t: i32 = Porffor.
|
31
|
+
const t: i32 = Porffor.type(argument);
|
32
32
|
|
33
33
|
// 1. If argument is a Number, return argument.
|
34
34
|
if (t == Porffor.TYPES.number) return argument;
|
@@ -73,12 +73,12 @@ export const __ecma262_ToNumeric = (value: unknown): number => {
|
|
73
73
|
// 1. Let primValue be ? ToPrimitive(value, number).
|
74
74
|
// only run ToPrimitive if pure object for perf
|
75
75
|
let primValue: any = value;
|
76
|
-
if (Porffor.
|
76
|
+
if (Porffor.type(value) == Porffor.TYPES.object && Porffor.wasm`local.get ${value}` != 0)
|
77
77
|
primValue = __ecma262_ToPrimitive_Number(value);
|
78
78
|
|
79
79
|
// 2. If primValue is a BigInt, return primValue.
|
80
80
|
if (Porffor.comptime.flag`hasType.bigint`) {
|
81
|
-
if (Porffor.
|
81
|
+
if (Porffor.type(primValue) == Porffor.TYPES.bigint) return primValue;
|
82
82
|
}
|
83
83
|
|
84
84
|
// 3. Return ? ToNumber(primValue).
|
@@ -124,7 +124,7 @@ export const __ecma262_ToIndex = (value: unknown): number => {
|
|
124
124
|
// 7.1.17 ToString (argument)
|
125
125
|
// https://tc39.es/ecma262/#sec-tostring
|
126
126
|
export const __ecma262_ToString = (argument: unknown): any => {
|
127
|
-
const type: i32 = Porffor.
|
127
|
+
const type: i32 = Porffor.type(argument);
|
128
128
|
|
129
129
|
// 1. If argument is a String, return argument.
|
130
130
|
if (Porffor.fastOr(
|
@@ -180,11 +180,11 @@ export const __ecma262_ToPropertyKey = (argument: any): any => {
|
|
180
180
|
// 1. Let key be ? ToPrimitive(argument, string).
|
181
181
|
// only run ToPrimitive if pure object for perf
|
182
182
|
let key: any = argument;
|
183
|
-
if (Porffor.
|
183
|
+
if (Porffor.type(argument) == Porffor.TYPES.object && Porffor.wasm`local.get ${argument}` != 0)
|
184
184
|
key = __ecma262_ToPrimitive_String(argument);
|
185
185
|
|
186
186
|
// 2. If key is a Symbol, then
|
187
|
-
if (Porffor.
|
187
|
+
if (Porffor.type(key) == Porffor.TYPES.symbol) {
|
188
188
|
// a. Return key.
|
189
189
|
return key;
|
190
190
|
}
|
@@ -194,6 +194,6 @@ export const __ecma262_ToPropertyKey = (argument: any): any => {
|
|
194
194
|
};
|
195
195
|
|
196
196
|
export const __ecma262_IsConstructor = (argument: any): boolean => {
|
197
|
-
if (Porffor.
|
197
|
+
if (Porffor.type(argument) != Porffor.TYPES.function) return false;
|
198
198
|
return (__Porffor_funcLut_flags(argument) & 0b10) == 2;
|
199
199
|
};
|