porffor 0.55.17 → 0.55.18
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 +7 -11
- package/compiler/builtins/__internal_string.ts +0 -6
- package/compiler/builtins/_internal_object.ts +8 -15
- package/compiler/builtins/_internal_string.ts +1 -1
- package/compiler/builtins/array.ts +2 -4
- package/compiler/builtins/boolean.ts +1 -2
- package/compiler/builtins/generator.ts +10 -14
- package/compiler/builtins/json.ts +3 -5
- package/compiler/builtins/number.ts +1 -2
- package/compiler/builtins/object.ts +15 -14
- package/compiler/builtins/promise.ts +18 -29
- package/compiler/builtins/string_f64.ts +1 -2
- package/compiler/builtins/symbol.ts +1 -3
- package/compiler/builtins/z_ecma262.ts +2 -4
- package/compiler/builtins.js +2 -2
- package/compiler/builtins_objects.js +1 -3
- package/compiler/builtins_precompiled.js +1867 -1963
- package/compiler/codegen.js +60 -55
- package/compiler/precompile.js +3 -4
- package/compiler/wrap.js +2 -16
- package/package.json +1 -1
- package/r.cjs +2 -0
- package/runner/index.js +1 -1
- package/compiler/builtins/bigint.ts +0 -233
@@ -8,8 +8,7 @@ export const __Porffor_object_underlying = (obj: any): any => {
|
|
8
8
|
t >= Porffor.TYPES.error,
|
9
9
|
t <= Porffor.TYPES.todoerror
|
10
10
|
)) {
|
11
|
-
|
12
|
-
return remap;
|
11
|
+
return obj as object;
|
13
12
|
}
|
14
13
|
|
15
14
|
if (Porffor.fastAnd(t > 0x05, t != Porffor.TYPES.undefined)) {
|
@@ -36,41 +35,38 @@ export const __Porffor_object_underlying = (obj: any): any => {
|
|
36
35
|
}
|
37
36
|
|
38
37
|
if (t == Porffor.TYPES.array) {
|
39
|
-
const
|
40
|
-
const len: i32 = arr.length;
|
38
|
+
const len: i32 = (obj as any[]).length;
|
41
39
|
|
42
40
|
const key5: bytestring = 'length';
|
43
41
|
__Porffor_object_expr_initWithFlags(underlying, key5, len, 0b1000);
|
44
42
|
|
45
43
|
// todo: this should somehow be kept in sync?
|
46
44
|
for (let i: i32 = 0; i < len; i++) {
|
47
|
-
__Porffor_object_expr_initWithFlags(underlying, __Number_prototype_toString(i),
|
45
|
+
__Porffor_object_expr_initWithFlags(underlying, __Number_prototype_toString(i), (obj as any[])[i], 0b1110);
|
48
46
|
}
|
49
47
|
}
|
50
48
|
|
51
49
|
if (Porffor.fastOr(t == Porffor.TYPES.string, t == Porffor.TYPES.stringobject)) {
|
52
|
-
const
|
53
|
-
const len: i32 = str.length;
|
50
|
+
const len: i32 = (obj as string).length;
|
54
51
|
|
55
52
|
const key6: bytestring = 'length';
|
56
53
|
__Porffor_object_expr_initWithFlags(underlying, key6, len, 0b0000);
|
57
54
|
|
58
55
|
for (let i: i32 = 0; i < len; i++) {
|
59
|
-
__Porffor_object_expr_initWithFlags(underlying, __Number_prototype_toString(i),
|
56
|
+
__Porffor_object_expr_initWithFlags(underlying, __Number_prototype_toString(i), (obj as string)[i], 0b0100);
|
60
57
|
}
|
61
58
|
|
62
59
|
if (t == Porffor.TYPES.string) Porffor.object.preventExtensions(underlying);
|
63
60
|
}
|
64
61
|
|
65
62
|
if (t == Porffor.TYPES.bytestring) {
|
66
|
-
const
|
67
|
-
const len: i32 = str.length;
|
63
|
+
const len: i32 = (obj as bytestring).length;
|
68
64
|
|
69
65
|
const key7: bytestring = 'length';
|
70
66
|
__Porffor_object_expr_initWithFlags(underlying, key7, len, 0b0000);
|
71
67
|
|
72
68
|
for (let i: i32 = 0; i < len; i++) {
|
73
|
-
__Porffor_object_expr_initWithFlags(underlying, __Number_prototype_toString(i),
|
69
|
+
__Porffor_object_expr_initWithFlags(underlying, __Number_prototype_toString(i), (obj as bytestring)[i], 0b0100);
|
74
70
|
}
|
75
71
|
|
76
72
|
Porffor.object.preventExtensions(underlying);
|
@@ -54,7 +54,6 @@ if 64
|
|
54
54
|
v128.any_true
|
55
55
|
if 64
|
56
56
|
i32.const 0
|
57
|
-
i32.const 2
|
58
57
|
return
|
59
58
|
end
|
60
59
|
|
@@ -87,7 +86,6 @@ if 64
|
|
87
86
|
i64.ne
|
88
87
|
if 64
|
89
88
|
i32.const 0
|
90
|
-
i32.const 2
|
91
89
|
return
|
92
90
|
end
|
93
91
|
|
@@ -120,7 +118,6 @@ if 64
|
|
120
118
|
i32.ne
|
121
119
|
if 64
|
122
120
|
i32.const 0
|
123
|
-
i32.const 2
|
124
121
|
return
|
125
122
|
end
|
126
123
|
|
@@ -200,7 +197,6 @@ if 64
|
|
200
197
|
v128.any_true
|
201
198
|
if 64
|
202
199
|
i32.const 0
|
203
|
-
i32.const 2
|
204
200
|
return
|
205
201
|
end
|
206
202
|
|
@@ -233,7 +229,6 @@ if 64
|
|
233
229
|
i64.ne
|
234
230
|
if 64
|
235
231
|
i32.const 0
|
236
|
-
i32.const 2
|
237
232
|
return
|
238
233
|
end
|
239
234
|
|
@@ -266,7 +261,6 @@ if 64
|
|
266
261
|
i32.ne
|
267
262
|
if 64
|
268
263
|
i32.const 0
|
269
|
-
i32.const 2
|
270
264
|
return
|
271
265
|
end
|
272
266
|
|
@@ -92,13 +92,11 @@ i64.shl
|
|
92
92
|
local.get ${get}
|
93
93
|
i64.extend_i32_u
|
94
94
|
i64.or
|
95
|
-
|
96
95
|
f64.reinterpret_i64
|
97
|
-
i32.const 1
|
98
96
|
return`;
|
99
97
|
};
|
100
98
|
|
101
|
-
export const __Porffor_object_accessorGet = (entryPtr: i32): Function => {
|
99
|
+
export const __Porffor_object_accessorGet = (entryPtr: i32): Function|undefined => {
|
102
100
|
const out: Function = Porffor.wasm.i32.load(entryPtr, 0, 4);
|
103
101
|
|
104
102
|
// no getter, return undefined
|
@@ -109,7 +107,7 @@ export const __Porffor_object_accessorGet = (entryPtr: i32): Function => {
|
|
109
107
|
return out;
|
110
108
|
};
|
111
109
|
|
112
|
-
export const __Porffor_object_accessorSet = (entryPtr: i32): Function => {
|
110
|
+
export const __Porffor_object_accessorSet = (entryPtr: i32): Function|undefined => {
|
113
111
|
const out: Function = Porffor.wasm.i32.load(entryPtr, 0, 8);
|
114
112
|
|
115
113
|
// no setter, return undefined
|
@@ -137,7 +135,6 @@ export const __Porffor_object_lookup = (obj: any, target: any): i32 => {
|
|
137
135
|
|
138
136
|
let out: boolean = false;
|
139
137
|
if (targetType == Porffor.TYPES.symbol) {
|
140
|
-
const targetSym: symbol = target;
|
141
138
|
for (; ptr < endPtr; ptr += 14) {
|
142
139
|
const keyRaw: i32 = Porffor.wasm.i32.load(ptr, 0, 0);
|
143
140
|
if (keyRaw == 0) {
|
@@ -145,9 +142,9 @@ export const __Porffor_object_lookup = (obj: any, target: any): i32 => {
|
|
145
142
|
out = true;
|
146
143
|
}
|
147
144
|
|
148
|
-
if (keyRaw >>> 30 == 3) { // MSB 1 and 2 set, symbol
|
149
|
-
|
150
|
-
if (
|
145
|
+
if (keyRaw >>> 30 == 3) { // MSB 1 and 2 set, symbol (unset MSB x2)
|
146
|
+
// todo: remove casts once weird bug which breaks unrelated things is fixed (https://github.com/CanadaHonk/porffor/commit/5747f0c1f3a4af95283ebef175cdacb21e332a52)
|
147
|
+
if ((keyRaw & 0x3FFFFFFF) as symbol == target as symbol) return ptr;
|
151
148
|
}
|
152
149
|
}
|
153
150
|
} else {
|
@@ -161,12 +158,10 @@ export const __Porffor_object_lookup = (obj: any, target: any): i32 => {
|
|
161
158
|
const msb: i32 = keyRaw >>> 30;
|
162
159
|
if (msb == 0) {
|
163
160
|
// bytestring
|
164
|
-
|
165
|
-
if (Porffor.strcmp(keyStr, target)) return ptr;
|
161
|
+
if (Porffor.strcmp(keyRaw as bytestring, target)) return ptr;
|
166
162
|
} else if (msb == 2) {
|
167
|
-
// string
|
168
|
-
|
169
|
-
if (Porffor.strcmp(keyStr, target)) return ptr;
|
163
|
+
// string (unset MSB)
|
164
|
+
if (Porffor.strcmp((keyRaw & 0x7FFFFFFF) as string, target)) return ptr;
|
170
165
|
}
|
171
166
|
}
|
172
167
|
}
|
@@ -497,8 +492,6 @@ local.get ${value}
|
|
497
492
|
local.get ${value+1}
|
498
493
|
|
499
494
|
call __Object_is
|
500
|
-
drop
|
501
|
-
|
502
495
|
i32.trunc_sat_f64_u
|
503
496
|
i32.eqz
|
504
497
|
local.set ${err}`;
|
@@ -35,7 +35,7 @@ export const __Porffor_compareStrings = (a: any, b: any): boolean => {
|
|
35
35
|
return Porffor.strcmp(a, b);
|
36
36
|
};
|
37
37
|
|
38
|
-
export const __Porffor_concatStrings = (a: any, b: any):
|
38
|
+
export const __Porffor_concatStrings = (a: any, b: any): any => {
|
39
39
|
let at: i32 = Porffor.rawType(a);
|
40
40
|
let bt: i32 = Porffor.rawType(b);
|
41
41
|
|
@@ -66,15 +66,13 @@ export const __Array_from = (arg: any, mapFn: any): any[] => {
|
|
66
66
|
}
|
67
67
|
|
68
68
|
if (type == Porffor.TYPES.object) {
|
69
|
-
const obj: object = arg;
|
70
|
-
|
71
69
|
const lengthKey: bytestring = 'length';
|
72
|
-
len = ecma262.ToIntegerOrInfinity(
|
70
|
+
len = ecma262.ToIntegerOrInfinity((arg as object)[lengthKey]);
|
73
71
|
if (len > 4294967295) throw new RangeError('Invalid array length');
|
74
72
|
if (len < 0) len = 0;
|
75
73
|
|
76
74
|
for (let i: i32 = 0; i < len; i++) {
|
77
|
-
out[i] =
|
75
|
+
out[i] = (arg as object)[i];
|
78
76
|
}
|
79
77
|
}
|
80
78
|
|
@@ -9,8 +9,7 @@ export const Boolean = function (value: any): boolean|BooleanObject {
|
|
9
9
|
// 2. If NewTarget is undefined, return b.
|
10
10
|
if (!new.target) return b;
|
11
11
|
|
12
|
-
|
13
|
-
return O;
|
12
|
+
return b as BooleanObject;
|
14
13
|
};
|
15
14
|
|
16
15
|
// 20.3.3.2 Boolean.prototype.toString ()
|
@@ -1,8 +1,7 @@
|
|
1
1
|
import type {} from './porffor.d.ts';
|
2
2
|
|
3
3
|
export const __Porffor_Generator = (values: any[]): __Porffor_Generator => {
|
4
|
-
|
5
|
-
return gen;
|
4
|
+
return values as __Porffor_Generator;
|
6
5
|
};
|
7
6
|
|
8
7
|
export const __Porffor_Generator_yield = (vals: any[], value: any): void => {
|
@@ -16,11 +15,10 @@ export const __Porffor_Generator_return = (vals: any[], value: any): __Porffor_G
|
|
16
15
|
vals.length = 1;
|
17
16
|
vals[0] = value;
|
18
17
|
|
19
|
-
|
20
|
-
return gen;
|
18
|
+
return vals as __Porffor_Generator;
|
21
19
|
};
|
22
20
|
|
23
|
-
export const __Porffor_Generator_prototype_next = (vals: any[])
|
21
|
+
export const __Porffor_Generator_prototype_next = (vals: any[]) => {
|
24
22
|
const obj: object = {};
|
25
23
|
obj.value = vals.shift();
|
26
24
|
obj.done = vals.length == 0;
|
@@ -28,22 +26,21 @@ export const __Porffor_Generator_prototype_next = (vals: any[]): object => {
|
|
28
26
|
return obj;
|
29
27
|
};
|
30
28
|
|
31
|
-
export const __Porffor_Generator_prototype_return = (vals: any[], value: any)
|
29
|
+
export const __Porffor_Generator_prototype_return = (vals: any[], value: any) => {
|
32
30
|
vals.length = 1;
|
33
31
|
vals[0] = value;
|
34
32
|
|
35
33
|
return __Porffor_Generator_prototype_next(vals);
|
36
34
|
};
|
37
35
|
|
38
|
-
export const __Porffor_Generator_prototype_throw = (vals: any[], value: any)
|
36
|
+
export const __Porffor_Generator_prototype_throw = (vals: any[], value: any) => {
|
39
37
|
vals.length = 0;
|
40
38
|
throw value;
|
41
39
|
};
|
42
40
|
|
43
41
|
|
44
42
|
export const __Porffor_AsyncGenerator = (values: any[]): __Porffor_AsyncGenerator => {
|
45
|
-
|
46
|
-
return gen;
|
43
|
+
return values as __Porffor_AsyncGenerator;
|
47
44
|
};
|
48
45
|
|
49
46
|
export const __Porffor_AsyncGenerator_yield = (vals: any[], value: any): void => {
|
@@ -57,11 +54,10 @@ export const __Porffor_AsyncGenerator_return = (vals: any[], value: any): __Porf
|
|
57
54
|
vals.length = 1;
|
58
55
|
vals[0] = value;
|
59
56
|
|
60
|
-
|
61
|
-
return gen;
|
57
|
+
return vals as __Porffor_AsyncGenerator;
|
62
58
|
};
|
63
59
|
|
64
|
-
export const __Porffor_AsyncGenerator_prototype_next = async (vals: any[])
|
60
|
+
export const __Porffor_AsyncGenerator_prototype_next = async (vals: any[]) => {
|
65
61
|
const obj: object = {};
|
66
62
|
obj.value = await vals.shift();
|
67
63
|
obj.done = vals.length == 0;
|
@@ -69,14 +65,14 @@ export const __Porffor_AsyncGenerator_prototype_next = async (vals: any[]): obje
|
|
69
65
|
return obj;
|
70
66
|
};
|
71
67
|
|
72
|
-
export const __Porffor_AsyncGenerator_prototype_return = async (vals: any[], value: any)
|
68
|
+
export const __Porffor_AsyncGenerator_prototype_return = async (vals: any[], value: any) => {
|
73
69
|
vals.length = 1;
|
74
70
|
vals[0] = await value;
|
75
71
|
|
76
72
|
return await __Porffor_AsyncGenerator_prototype_next(vals);
|
77
73
|
};
|
78
74
|
|
79
|
-
export const __Porffor_AsyncGenerator_prototype_throw = async (vals: any[], value: any)
|
75
|
+
export const __Porffor_AsyncGenerator_prototype_throw = async (vals: any[], value: any) => {
|
80
76
|
vals.length = 0;
|
81
77
|
throw await value;
|
82
78
|
};
|
@@ -85,8 +85,7 @@ export const __Porffor_json_serialize = (value: any, depth: i32, space: bytestri
|
|
85
85
|
const hasSpace: boolean = space !== undefined;
|
86
86
|
depth += 1;
|
87
87
|
|
88
|
-
const
|
89
|
-
for (const x of arr) {
|
88
|
+
for (const x of (value as any[])) {
|
90
89
|
if (hasSpace) {
|
91
90
|
Porffor.bytestring.appendChar(out, 10); // \n
|
92
91
|
for (let i: i32 = 0; i < depth; i++) Porffor.bytestring.appendStr(out, space);
|
@@ -124,13 +123,12 @@ export const __Porffor_json_serialize = (value: any, depth: i32, space: bytestri
|
|
124
123
|
const hasSpace: boolean = space !== undefined;
|
125
124
|
depth += 1;
|
126
125
|
|
127
|
-
const
|
128
|
-
for (const key in obj) {
|
126
|
+
for (const key in (value as object)) {
|
129
127
|
// skip symbol keys
|
130
128
|
if (Porffor.rawType(key) == Porffor.TYPES.symbol) continue;
|
131
129
|
|
132
130
|
// skip non-serializable values (functions, etc)
|
133
|
-
const val: bytestring|undefined = __Porffor_json_serialize(
|
131
|
+
const val: bytestring|undefined = __Porffor_json_serialize((value as object)[key], depth, space);
|
134
132
|
if (val == null) continue;
|
135
133
|
|
136
134
|
if (hasSpace) {
|
@@ -25,8 +25,7 @@ export const Number = function (value: any): number|NumberObject {
|
|
25
25
|
// 4. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%Number.prototype%", « [[NumberData]] »).
|
26
26
|
// 5. Set O.[[NumberData]] to n.
|
27
27
|
// 6. Return O.
|
28
|
-
|
29
|
-
return O;
|
28
|
+
return n as NumberObject;
|
30
29
|
};
|
31
30
|
|
32
31
|
// radix: number|any for rawType check
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import type {} from './porffor.d.ts';
|
2
2
|
|
3
|
-
export const Object = function (value: any):
|
3
|
+
export const Object = function (value: any): any {
|
4
4
|
if (value == null) {
|
5
5
|
// if nullish, return new empty object
|
6
6
|
const obj: object = Porffor.allocate();
|
@@ -8,6 +8,7 @@ export const Object = function (value: any): object {
|
|
8
8
|
}
|
9
9
|
|
10
10
|
// primitives into primitive objects
|
11
|
+
if ((Porffor.rawType(value) | 0b10000000) == Porffor.TYPES.bytestring) return new String(value);
|
11
12
|
if (Porffor.rawType(value) == Porffor.TYPES.number) return new Number(value);
|
12
13
|
if (Porffor.rawType(value) == Porffor.TYPES.boolean) return new Boolean(value);
|
13
14
|
|
@@ -159,11 +160,11 @@ export const __Object_prototype_hasOwnProperty = (_this: any, prop: any) => {
|
|
159
160
|
return __Array_prototype_includes(keys, p);
|
160
161
|
};
|
161
162
|
|
162
|
-
export const __Object_hasOwn = (obj: any, prop: any) => {
|
163
|
+
export const __Object_hasOwn = (obj: any, prop: any): boolean => {
|
163
164
|
return __Object_prototype_hasOwnProperty(obj, prop);
|
164
165
|
};
|
165
166
|
|
166
|
-
export const __Porffor_object_in = (obj: any, prop: any) => {
|
167
|
+
export const __Porffor_object_in = (obj: any, prop: any): boolean => {
|
167
168
|
if (__Object_prototype_hasOwnProperty(obj, prop)) {
|
168
169
|
return true;
|
169
170
|
}
|
@@ -180,7 +181,7 @@ export const __Porffor_object_in = (obj: any, prop: any) => {
|
|
180
181
|
return false;
|
181
182
|
};
|
182
183
|
|
183
|
-
export const __Porffor_object_instanceof = (obj: any, constr: any, checkProto: any) => {
|
184
|
+
export const __Porffor_object_instanceof = (obj: any, constr: any, checkProto: any): boolean => {
|
184
185
|
if (Porffor.rawType(constr) != Porffor.TYPES.function) {
|
185
186
|
throw new TypeError('instanceof right-hand side is not a function');
|
186
187
|
}
|
@@ -202,7 +203,7 @@ export const __Porffor_object_instanceof = (obj: any, constr: any, checkProto: a
|
|
202
203
|
};
|
203
204
|
|
204
205
|
|
205
|
-
export const __Object_assign = (target: any, ...sources: any[]) => {
|
206
|
+
export const __Object_assign = (target: any, ...sources: any[]): any => {
|
206
207
|
if (target == null) throw new TypeError('Argument is nullish, expected object');
|
207
208
|
|
208
209
|
for (const x of sources) {
|
@@ -220,7 +221,7 @@ export const __Object_assign = (target: any, ...sources: any[]) => {
|
|
220
221
|
};
|
221
222
|
|
222
223
|
// Object.assign but also non enumerable properties and 1 source
|
223
|
-
export const __Porffor_object_assignAll = (target: any, source: any) => {
|
224
|
+
export const __Porffor_object_assignAll = (target: any, source: any): any => {
|
224
225
|
if (target == null) throw new TypeError('Argument is nullish, expected object');
|
225
226
|
|
226
227
|
const keys: any[] = Reflect.ownKeys(source);
|
@@ -337,7 +338,7 @@ export const __Object_isSealed = (obj: any): any => {
|
|
337
338
|
};
|
338
339
|
|
339
340
|
|
340
|
-
export const __Object_getOwnPropertyDescriptor = (obj: any, prop: any):
|
341
|
+
export const __Object_getOwnPropertyDescriptor = (obj: any, prop: any): object|undefined => {
|
341
342
|
const p: any = ecma262.ToPropertyKey(prop);
|
342
343
|
|
343
344
|
const entryPtr: i32 = Porffor.object.lookup(obj, p);
|
@@ -387,7 +388,7 @@ local.set ${value+1}`;
|
|
387
388
|
return out;
|
388
389
|
};
|
389
390
|
|
390
|
-
export const __Object_getOwnPropertyDescriptors = (obj: any):
|
391
|
+
export const __Object_getOwnPropertyDescriptors = (obj: any): object => {
|
391
392
|
const out: object = {};
|
392
393
|
|
393
394
|
if (Porffor.rawType(obj) != Porffor.TYPES.object) {
|
@@ -515,7 +516,7 @@ local.set ${key}`;
|
|
515
516
|
};
|
516
517
|
|
517
518
|
|
518
|
-
export const __Object_defineProperty = (target: any, prop: any, desc: any) => {
|
519
|
+
export const __Object_defineProperty = (target: any, prop: any, desc: any): any => {
|
519
520
|
if (!Porffor.object.isObject(target)) throw new TypeError('Target is a non-object');
|
520
521
|
if (!Porffor.object.isObject(desc)) throw new TypeError('Descriptor is a non-object');
|
521
522
|
|
@@ -593,7 +594,7 @@ export const __Object_defineProperty = (target: any, prop: any, desc: any) => {
|
|
593
594
|
return target;
|
594
595
|
};
|
595
596
|
|
596
|
-
export const __Object_defineProperties = (target: any, props: any) => {
|
597
|
+
export const __Object_defineProperties = (target: any, props: any): any => {
|
597
598
|
if (!Porffor.object.isObject(target)) throw new TypeError('Target is a non-object');
|
598
599
|
if (!Porffor.object.isObjectOrSymbol(props)) throw new TypeError('Props needs to be an object or symbol');
|
599
600
|
|
@@ -604,7 +605,7 @@ export const __Object_defineProperties = (target: any, props: any) => {
|
|
604
605
|
return target;
|
605
606
|
};
|
606
607
|
|
607
|
-
export const __Object_create = (proto: any, props: any) => {
|
608
|
+
export const __Object_create = (proto: any, props: any): object => {
|
608
609
|
if (!Porffor.object.isObjectOrNull(proto)) throw new TypeError('Prototype should be an object or null');
|
609
610
|
|
610
611
|
const out: object = {};
|
@@ -618,7 +619,7 @@ export const __Object_create = (proto: any, props: any) => {
|
|
618
619
|
};
|
619
620
|
|
620
621
|
|
621
|
-
export const __Object_groupBy = (items: any, callbackFn: any) => {
|
622
|
+
export const __Object_groupBy = (items: any, callbackFn: any): object => {
|
622
623
|
const out: object = {};
|
623
624
|
|
624
625
|
let i = 0;
|
@@ -636,13 +637,13 @@ export const __Object_groupBy = (items: any, callbackFn: any) => {
|
|
636
637
|
};
|
637
638
|
|
638
639
|
|
639
|
-
export const __Object_getPrototypeOf = (obj: any) => {
|
640
|
+
export const __Object_getPrototypeOf = (obj: any): any => {
|
640
641
|
if (obj == null) throw new TypeError('Object is nullish, expected object');
|
641
642
|
|
642
643
|
return obj.__proto__;
|
643
644
|
};
|
644
645
|
|
645
|
-
export const __Object_setPrototypeOf = (obj: any, proto: any) => {
|
646
|
+
export const __Object_setPrototypeOf = (obj: any, proto: any): any => {
|
646
647
|
if (obj == null) throw new TypeError('Object is nullish, expected object');
|
647
648
|
if (!Porffor.object.isObjectOrNull(proto)) throw new TypeError('Prototype should be an object or null');
|
648
649
|
|
@@ -144,7 +144,7 @@ export const __Porffor_then = (promise: any[], fulfillReaction: any[], rejectRea
|
|
144
144
|
}
|
145
145
|
};
|
146
146
|
|
147
|
-
export const __Porffor_promise_resolve = (value: any, promise: any):
|
147
|
+
export const __Porffor_promise_resolve = (value: any, promise: any): void => {
|
148
148
|
// if value is own promise, reject with typeerror
|
149
149
|
if (value === promise) throw new TypeError('cannot resolve promise with itself');
|
150
150
|
|
@@ -156,13 +156,10 @@ export const __Porffor_promise_resolve = (value: any, promise: any): any => {
|
|
156
156
|
} else {
|
157
157
|
__ecma262_FulfillPromise(promise, value);
|
158
158
|
}
|
159
|
-
|
160
|
-
return undefined;
|
161
159
|
};
|
162
160
|
|
163
|
-
export const __Porffor_promise_reject = (reason: any, promise: any):
|
161
|
+
export const __Porffor_promise_reject = (reason: any, promise: any): void => {
|
164
162
|
__ecma262_RejectPromise(promise, reason);
|
165
|
-
return undefined;
|
166
163
|
};
|
167
164
|
|
168
165
|
export const __Porffor_promise_create = (): any[] => {
|
@@ -187,12 +184,12 @@ export const __Porffor_promise_create = (): any[] => {
|
|
187
184
|
return obj;
|
188
185
|
};
|
189
186
|
|
190
|
-
export const __Porffor_promise_runNext = (func: Function) => {
|
187
|
+
export const __Porffor_promise_runNext = (func: Function): void => {
|
191
188
|
const reaction: any[] = __Porffor_promise_newReaction(func, undefined, 1);
|
192
189
|
__ecma262_HostEnqueuePromiseJob(__ecma262_NewPromiseReactionJob(reaction, undefined));
|
193
190
|
};
|
194
191
|
|
195
|
-
export const __Porffor_promise_runJobs = () => {
|
192
|
+
export const __Porffor_promise_runJobs = (): void => {
|
196
193
|
while (true) {
|
197
194
|
let x: any = jobQueue.shift();
|
198
195
|
if (x == null) break;
|
@@ -225,10 +222,10 @@ export const __Porffor_promise_runJobs = () => {
|
|
225
222
|
|
226
223
|
// hack: cannot share scope so use a global
|
227
224
|
let activePromise: any;
|
228
|
-
export const __Porffor_promise_resolveActive = (value: any) => __Porffor_promise_resolve(value, activePromise);
|
229
|
-
export const __Porffor_promise_rejectActive = (reason: any) => __Porffor_promise_reject(reason, activePromise);
|
225
|
+
export const __Porffor_promise_resolveActive = (value: any): void => __Porffor_promise_resolve(value, activePromise);
|
226
|
+
export const __Porffor_promise_rejectActive = (reason: any): void => __Porffor_promise_reject(reason, activePromise);
|
230
227
|
|
231
|
-
export const Promise = function (executor: any):
|
228
|
+
export const Promise = function (executor: any): Promise {
|
232
229
|
if (!new.target) throw new TypeError("Constructor Promise requires 'new'");
|
233
230
|
if (Porffor.rawType(executor) != Porffor.TYPES.function) throw new TypeError('Promise executor is not a function');
|
234
231
|
|
@@ -242,17 +239,15 @@ export const Promise = function (executor: any): void {
|
|
242
239
|
__ecma262_RejectPromise(obj, e);
|
243
240
|
}
|
244
241
|
|
245
|
-
|
246
|
-
return pro;
|
242
|
+
return obj as Promise;
|
247
243
|
};
|
248
244
|
|
249
245
|
export const __Promise_withResolvers = (): Promise => {
|
250
246
|
const obj: any[] = __Porffor_promise_create();
|
251
247
|
activePromise = obj;
|
252
248
|
|
253
|
-
const promise: Promise = obj;
|
254
249
|
const out: object = Porffor.allocate();
|
255
|
-
out.promise =
|
250
|
+
out.promise = obj as Promise;
|
256
251
|
|
257
252
|
out.resolve = __Porffor_promise_resolveActive;
|
258
253
|
out.reject = __Porffor_promise_rejectActive;
|
@@ -265,8 +260,7 @@ export const __Promise_resolve = (value: any): Promise => {
|
|
265
260
|
|
266
261
|
__Porffor_promise_resolve(value, obj);
|
267
262
|
|
268
|
-
|
269
|
-
return pro;
|
263
|
+
return obj as Promise;
|
270
264
|
};
|
271
265
|
|
272
266
|
export const __Promise_reject = (reason: any): Promise => {
|
@@ -274,8 +268,7 @@ export const __Promise_reject = (reason: any): Promise => {
|
|
274
268
|
|
275
269
|
__Porffor_promise_reject(reason, obj);
|
276
270
|
|
277
|
-
|
278
|
-
return pro;
|
271
|
+
return obj as Promise;
|
279
272
|
};
|
280
273
|
|
281
274
|
|
@@ -296,19 +289,18 @@ export const __Promise_prototype_then = (_this: any, onFulfilled: any, onRejecte
|
|
296
289
|
|
297
290
|
__Porffor_then(_this, fulfillReaction, rejectReaction);
|
298
291
|
|
299
|
-
|
300
|
-
return pro;
|
292
|
+
return outPromise as Promise;
|
301
293
|
};
|
302
294
|
|
303
295
|
// 27.2.5.1 Promise.prototype.catch (onRejected)
|
304
296
|
// https://tc39.es/ecma262/#sec-promise.prototype.catch
|
305
|
-
export const __Promise_prototype_catch = (_this: any, onRejected: any)
|
297
|
+
export const __Promise_prototype_catch = (_this: any, onRejected: any) => {
|
306
298
|
// 1. Let promise be the this value.
|
307
299
|
// 2. Return ? Invoke(promise, "then", « undefined, onRejected »).
|
308
300
|
return __Promise_prototype_then(_this, undefined, onRejected);
|
309
301
|
};
|
310
302
|
|
311
|
-
export const __Promise_prototype_finally = (_this: any, onFinally: any)
|
303
|
+
export const __Promise_prototype_finally = (_this: any, onFinally: any) => {
|
312
304
|
// custom impl based on then but also not (sorry)
|
313
305
|
if (!__ecma262_IsPromise(_this)) throw new TypeError('Promise.prototype.then called on non-Promise');
|
314
306
|
|
@@ -332,8 +324,7 @@ export const __Promise_prototype_finally = (_this: any, onFinally: any): Promise
|
|
332
324
|
__ecma262_HostEnqueuePromiseJob(__ecma262_NewPromiseReactionJob(finallyReaction, value));
|
333
325
|
}
|
334
326
|
|
335
|
-
|
336
|
-
return pro;
|
327
|
+
return outPromise as Promise;
|
337
328
|
};
|
338
329
|
|
339
330
|
|
@@ -480,18 +471,16 @@ export const __Promise_prototype_toString = (_this: any) => '[object Promise]';
|
|
480
471
|
export const __Promise_prototype_toLocaleString = (_this: any) => __Promise_prototype_toString(_this);
|
481
472
|
|
482
473
|
|
483
|
-
export const __Porffor_promise_await = (value: any) => {
|
474
|
+
export const __Porffor_promise_await = (value: any): any => {
|
484
475
|
if (Porffor.rawType(value) != Porffor.TYPES.promise) return value;
|
485
476
|
|
486
477
|
// hack: peek value instead of awaiting
|
487
|
-
const
|
488
|
-
|
489
|
-
const state: i32 = promise[1];
|
478
|
+
const state: i32 = (value as any[])[1];
|
490
479
|
|
491
480
|
// pending
|
492
481
|
if (state == 0) return value;
|
493
482
|
|
494
|
-
const result: any =
|
483
|
+
const result: any = (value as any[])[0];
|
495
484
|
|
496
485
|
// fulfilled
|
497
486
|
if (state == 1) return result;
|
@@ -28,8 +28,7 @@ export const String = function (...args: any[]): string|bytestring|StringObject
|
|
28
28
|
// force bytestrings to strings
|
29
29
|
if (Porffor.rawType(s) == Porffor.TYPES.bytestring) s = Porffor.bytestringToString(s, s.length);
|
30
30
|
|
31
|
-
|
32
|
-
return O;
|
31
|
+
return s as StringObject;
|
33
32
|
};
|
34
33
|
|
35
34
|
export const __String_fromCharCode = (...codes: any[]): bytestring|string => {
|
@@ -17,8 +17,7 @@ export const Symbol = (description: any): Symbol => {
|
|
17
17
|
}
|
18
18
|
|
19
19
|
// 4. Return a new Symbol whose [[Description]] is descString.
|
20
|
-
|
21
|
-
return sym;
|
20
|
+
return Porffor.array.fastPush(descStore, descString) as Symbol;
|
22
21
|
};
|
23
22
|
|
24
23
|
export const __Symbol_prototype_description$get = (_this: Symbol) => {
|
@@ -55,7 +54,6 @@ export const __Symbol_prototype_toString = (_this: Symbol) => {
|
|
55
54
|
Porffor.wasm.i32.store8(Porffor.wasm`local.get ${out}` + descLen, 41, 0, 11);
|
56
55
|
|
57
56
|
out.length = 8 + descLen;
|
58
|
-
|
59
57
|
return out;
|
60
58
|
};
|
61
59
|
|
@@ -154,8 +154,7 @@ export const __ecma262_ToString = (argument: unknown): any => {
|
|
154
154
|
|
155
155
|
// hack: StringObject -> String
|
156
156
|
if (type == Porffor.TYPES.stringobject) {
|
157
|
-
|
158
|
-
return remap;
|
157
|
+
return argument as string;
|
159
158
|
}
|
160
159
|
|
161
160
|
// 9. Assert: argument is an Object.
|
@@ -171,9 +170,8 @@ export const __ecma262_ToString = (argument: unknown): any => {
|
|
171
170
|
// https://tc39.es/ecma262/#sec-topropertykey
|
172
171
|
export const __ecma262_ToPropertyKey = (argument: any): any => {
|
173
172
|
// 1. Let key be ? ToPrimitive(argument, string).
|
174
|
-
let key: any = argument;
|
175
|
-
|
176
173
|
// only run ToPrimitive if pure object for perf
|
174
|
+
let key: any = argument;
|
177
175
|
if (Porffor.rawType(argument) == Porffor.TYPES.object && Porffor.wasm`local.get ${argument}` != 0)
|
178
176
|
key = __ecma262_ToPrimitive_String(argument);
|
179
177
|
|
package/compiler/builtins.js
CHANGED
@@ -131,8 +131,7 @@ export const BuiltinFuncs = function() {
|
|
131
131
|
number(TYPES.number, Valtype.i32),
|
132
132
|
[ Opcodes.local_get, 1 ],
|
133
133
|
number(TYPES.number, Valtype.i32),
|
134
|
-
[ Opcodes.call, builtin('__Math_pow') ]
|
135
|
-
[ Opcodes.drop ],
|
134
|
+
[ Opcodes.call, builtin('__Math_pow') ]
|
136
135
|
]
|
137
136
|
};
|
138
137
|
|
@@ -756,6 +755,7 @@ export const BuiltinFuncs = function() {
|
|
756
755
|
params: [ Valtype.i32, Valtype.i32 ],
|
757
756
|
locals: [],
|
758
757
|
returns: [],
|
758
|
+
returnType: TYPES.undefined,
|
759
759
|
wasm: [
|
760
760
|
// dst
|
761
761
|
[ Opcodes.local_get, 1 ],
|