porffor 0.48.3 → 0.48.5
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/assemble.js +105 -132
- package/compiler/builtins/__internal_object.ts +2 -5
- package/compiler/builtins/array.ts +2 -2
- package/compiler/builtins/date.ts +1 -2
- package/compiler/builtins/error.js +7 -11
- package/compiler/builtins/function.ts +2 -6
- package/compiler/builtins/json.ts +11 -14
- package/compiler/builtins/object.ts +10 -27
- package/compiler/builtins/promise.ts +4 -17
- package/compiler/builtins/set.ts +1 -5
- package/compiler/builtins/weakref.ts +1 -5
- package/compiler/builtins/z_map.ts +1 -5
- package/compiler/builtins/z_weakmap.ts +1 -5
- package/compiler/builtins/z_weakset.ts +1 -5
- package/compiler/builtins.js +2 -15
- package/compiler/builtins_precompiled.js +103 -97
- package/compiler/codegen.js +138 -130
- package/compiler/precompile.js +1 -1
- package/compiler/types.js +1 -1
- package/compiler/wasmSpec.js +1 -2
- package/compiler/wrap.js +2 -4
- package/package.json +1 -1
- package/runner/index.js +1 -13
package/compiler/assemble.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Valtype, FuncType, ExportDesc, Section, Magic,
|
1
|
+
import { Valtype, FuncType, ExportDesc, Section, Magic, Opcodes, PageSize, Reftype } from './wasmSpec.js';
|
2
2
|
import { encodeVector, encodeString, encodeLocal, unsignedLEB128, signedLEB128, unsignedLEB128_into, signedLEB128_into, ieee754_binary64, ieee754_binary64_into } from './encoding.js';
|
3
3
|
import { importedFuncs } from './builtins.js';
|
4
4
|
import { log } from './log.js';
|
@@ -9,17 +9,10 @@ const createSection = (type, data) => [
|
|
9
9
|
...encodeVector(data)
|
10
10
|
];
|
11
11
|
|
12
|
-
const customSection = (name, data) =>
|
12
|
+
const customSection = (name, data) => createSection(
|
13
13
|
Section.custom,
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
const chHint = (topTier, baselineTier, strategy) => {
|
18
|
-
// 1 byte of 4 2 bit components: spare, top tier, baseline tier, compilation strategy
|
19
|
-
// tiers: 0x00 = default, 0x01 = baseline (liftoff), 0x02 = optimized (turbofan)
|
20
|
-
// strategy: 0x00 = default, 0x01 = lazy, 0x02 = eager, 0x03 = lazy baseline, eager top tier
|
21
|
-
return (strategy | (baselineTier << 2) | (topTier << 4));
|
22
|
-
};
|
14
|
+
[ ...encodeString(name), ...data ]
|
15
|
+
);
|
23
16
|
|
24
17
|
const encodeNames = funcs => {
|
25
18
|
const encodeSection = (id, section) => [
|
@@ -50,11 +43,6 @@ const encodeNames = funcs => {
|
|
50
43
|
export default (funcs, globals, tags, pages, data, noTreeshake = false) => {
|
51
44
|
const types = [], typeCache = {};
|
52
45
|
|
53
|
-
const optLevel = parseInt(process.argv.find(x => x.startsWith('-O'))?.[2] ?? 1);
|
54
|
-
|
55
|
-
const compileHints = Prefs.compileHints;
|
56
|
-
if (compileHints) log.warning('assemble', 'compile hints is V8 only w/ experimental arg! (you used -compile-hints)');
|
57
|
-
|
58
46
|
const getType = (params, returns) => {
|
59
47
|
const hash = `${params.join(',')}_${returns.join(',')}`;
|
60
48
|
if (Prefs.optLog) log('assemble', `getType(${JSON.stringify(params)}, ${JSON.stringify(returns)}) -> ${hash} | cache: ${typeCache[hash]}`);
|
@@ -77,15 +65,15 @@ export default (funcs, globals, tags, pages, data, noTreeshake = false) => {
|
|
77
65
|
};
|
78
66
|
|
79
67
|
let importFuncs = [], importDelta = 0;
|
80
|
-
if (
|
68
|
+
if (!Prefs.treeshakeWasmImports || noTreeshake) {
|
81
69
|
importFuncs = importedFuncs;
|
82
70
|
} else {
|
83
71
|
let imports = new Map();
|
84
72
|
|
85
73
|
// tree shake imports
|
86
74
|
for (const f of funcs) {
|
87
|
-
for (const inst of f.wasm) {
|
88
|
-
if (
|
75
|
+
if (f.usesImports) for (const inst of f.wasm) {
|
76
|
+
if (inst[0] === Opcodes.call && inst[1] < importedFuncs.length) {
|
89
77
|
const idx = inst[1];
|
90
78
|
const func = importedFuncs[idx];
|
91
79
|
|
@@ -103,8 +91,6 @@ export default (funcs, globals, tags, pages, data, noTreeshake = false) => {
|
|
103
91
|
f.asmIndex = f.index - importDelta;
|
104
92
|
}
|
105
93
|
|
106
|
-
time('treeshake import funcs');
|
107
|
-
|
108
94
|
if (Prefs.optLog) log('assemble', `treeshake: using ${importFuncs.length}/${importedFuncs.length} imports`);
|
109
95
|
|
110
96
|
const importSection = importFuncs.length === 0 ? [] : createSection(
|
@@ -261,101 +247,103 @@ export default (funcs, globals, tags, pages, data, noTreeshake = false) => {
|
|
261
247
|
);
|
262
248
|
time('export section');
|
263
249
|
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
lastType = local.type;
|
250
|
+
let codeSection = [];
|
251
|
+
for (let i = 0; i < funcs.length; i++) {
|
252
|
+
const x = funcs[i];
|
253
|
+
// time(x.name);
|
254
|
+
const locals = Object.values(x.locals).sort((a, b) => a.idx - b.idx);
|
255
|
+
// time(' locals gen');
|
256
|
+
|
257
|
+
const paramCount = x.params.length;
|
258
|
+
let localDecl = [], typeCount = 0, lastType, declCount = 0;
|
259
|
+
for (let i = paramCount; i <= locals.length; i++) {
|
260
|
+
const local = locals[i];
|
261
|
+
if (i !== paramCount && local?.type !== lastType) {
|
262
|
+
unsignedLEB128_into(typeCount, localDecl);
|
263
|
+
localDecl.push(lastType);
|
264
|
+
typeCount = 0;
|
265
|
+
declCount++;
|
281
266
|
}
|
282
267
|
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
const makeAssembled = Prefs.d;
|
287
|
-
let wasm = [], wasmNonFlat = [];
|
288
|
-
for (let i = 0; i < x.wasm.length; i++) {
|
289
|
-
let o = x.wasm[i];
|
290
|
-
|
291
|
-
// encode local/global ops as unsigned leb128 from raw number
|
292
|
-
if (
|
293
|
-
// (o[0] === Opcodes.local_get || o[0] === Opcodes.local_set || o[0] === Opcodes.local_tee || o[0] === Opcodes.global_get || o[0] === Opcodes.global_set) &&
|
294
|
-
(o[0] >= Opcodes.local_get && o[0] <= Opcodes.global_set) &&
|
295
|
-
o[1] > 127
|
296
|
-
) {
|
297
|
-
const n = o[1];
|
298
|
-
o = [ o[0] ];
|
299
|
-
unsignedLEB128_into(n, o);
|
300
|
-
}
|
268
|
+
typeCount++;
|
269
|
+
lastType = local?.type;
|
270
|
+
}
|
301
271
|
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
272
|
+
// time(' localDecl gen');
|
273
|
+
|
274
|
+
const makeAssembled = Prefs.d;
|
275
|
+
let wasm = [], wasmNonFlat = [];
|
276
|
+
for (let i = 0; i < x.wasm.length; i++) {
|
277
|
+
let o = x.wasm[i];
|
278
|
+
|
279
|
+
// encode local/global ops as unsigned leb128 from raw number
|
280
|
+
if (
|
281
|
+
(o[0] >= Opcodes.local_get && o[0] <= Opcodes.global_set) &&
|
282
|
+
o[1] > 127
|
283
|
+
) {
|
284
|
+
const n = o[1];
|
285
|
+
o = [ o[0] ];
|
286
|
+
unsignedLEB128_into(n, o);
|
287
|
+
}
|
310
288
|
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
289
|
+
// encode f64.const ops as ieee754 from raw number
|
290
|
+
if (o[0] === Opcodes.f64_const) {
|
291
|
+
const n = o[1];
|
292
|
+
o = ieee754_binary64(n);
|
293
|
+
if (o.length === 8) o.unshift(Opcodes.f64_const);
|
294
|
+
}
|
295
|
+
|
296
|
+
// encode call ops as unsigned leb128 from raw number
|
297
|
+
if ((o[0] === Opcodes.call /* || o[0] === Opcodes.return_call */) && o[1] >= importedFuncs.length) {
|
298
|
+
const n = o[1] - importDelta;
|
299
|
+
o = [ Opcodes.call ];
|
300
|
+
unsignedLEB128_into(n, o);
|
301
|
+
}
|
318
302
|
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
}
|
326
|
-
|
327
|
-
let returns = [ valtypeBinary, Valtype.i32 ];
|
328
|
-
if (o.at(-1) === 'no_type_return') {
|
329
|
-
o.pop();
|
330
|
-
returns = [ valtypeBinary ];
|
331
|
-
}
|
332
|
-
|
333
|
-
o[1] = getType(params, returns);
|
303
|
+
// encode call indirect ops as types from info
|
304
|
+
if (o[0] === Opcodes.call_indirect) {
|
305
|
+
o = [...o];
|
306
|
+
const params = [];
|
307
|
+
for (let i = 0; i < o[1]; i++) {
|
308
|
+
params.push(valtypeBinary, Valtype.i32);
|
334
309
|
}
|
335
310
|
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
311
|
+
let returns = [ valtypeBinary, Valtype.i32 ];
|
312
|
+
if (o.at(-1) === 'no_type_return') {
|
313
|
+
o.pop();
|
314
|
+
returns = [ valtypeBinary ];
|
340
315
|
}
|
341
316
|
|
342
|
-
|
317
|
+
o[1] = getType(params, returns);
|
343
318
|
}
|
344
|
-
// time(' wasm transform');
|
345
319
|
|
346
|
-
|
347
|
-
x
|
320
|
+
for (let j = 0; j < o.length; j++) {
|
321
|
+
const x = o[j];
|
322
|
+
if (x == null || !(x <= 0xff)) continue;
|
323
|
+
wasm.push(x);
|
348
324
|
}
|
349
325
|
|
350
|
-
|
351
|
-
|
326
|
+
if (makeAssembled) wasmNonFlat.push(o);
|
327
|
+
}
|
328
|
+
// time(' wasm transform');
|
352
329
|
|
353
|
-
|
330
|
+
if (makeAssembled) {
|
331
|
+
x.assembled = { localDecl, wasm, wasmNonFlat };
|
332
|
+
}
|
354
333
|
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
334
|
+
let out = unsignedLEB128(declCount)
|
335
|
+
.concat(localDecl, wasm, Opcodes.end);
|
336
|
+
|
337
|
+
codeSection.push(
|
338
|
+
...unsignedLEB128(out.length),
|
339
|
+
...out
|
340
|
+
);
|
341
|
+
|
342
|
+
// time(' finish');
|
343
|
+
}
|
344
|
+
|
345
|
+
codeSection.unshift(...unsignedLEB128(funcs.length, codeSection));
|
346
|
+
codeSection.unshift(Section.code, ...unsignedLEB128(codeSection.length));
|
359
347
|
time('code section');
|
360
348
|
|
361
349
|
const typeSection = createSection(
|
@@ -364,58 +352,43 @@ export default (funcs, globals, tags, pages, data, noTreeshake = false) => {
|
|
364
352
|
);
|
365
353
|
time('type section');
|
366
354
|
|
367
|
-
|
368
|
-
|
369
|
-
|
355
|
+
let dataSection = [];
|
356
|
+
if (data.length > 0) {
|
357
|
+
for (let i = 0; i < data.length; i++) {
|
358
|
+
const x = data[i];
|
370
359
|
if (Prefs.d && x.bytes.length > PageSize) log.warning('assemble', `data (${x.page}) has more bytes than Wasm page size! (${x.bytes.length})`);
|
371
360
|
|
372
|
-
const bytes = unsignedLEB128(x.bytes.length).concat(x.bytes);
|
373
361
|
if (x.page != null) {
|
374
362
|
// type: active
|
375
363
|
let offset = pages.allocs.get(x.page) ?? (pages.get(x.page) * pageSize);
|
376
364
|
if (offset === 0) offset = 16;
|
377
|
-
|
365
|
+
dataSection.push(0x00, Opcodes.i32_const, ...signedLEB128(offset), Opcodes.end);
|
378
366
|
} else {
|
379
367
|
// type: passive
|
380
|
-
|
368
|
+
dataSection.push(0x01);
|
381
369
|
}
|
382
370
|
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
371
|
+
dataSection.push(
|
372
|
+
...unsignedLEB128(x.bytes.length),
|
373
|
+
...x.bytes
|
374
|
+
);
|
375
|
+
}
|
376
|
+
|
377
|
+
dataSection.unshift(...unsignedLEB128(data.length, dataSection));
|
378
|
+
dataSection.unshift(Section.data, ...unsignedLEB128(dataSection.length));
|
379
|
+
}
|
387
380
|
|
388
381
|
const dataCountSection = data.length === 0 ? [] : createSection(
|
389
382
|
Section.data_count,
|
390
383
|
unsignedLEB128(data.length)
|
391
384
|
);
|
392
|
-
time('
|
393
|
-
|
394
|
-
if (Prefs.sections) console.log({
|
395
|
-
typeSection: typeSection.map(x => x.toString(16)),
|
396
|
-
importSection: importSection.map(x => x.toString(16)),
|
397
|
-
funcSection: funcSection.map(x => x.toString(16)),
|
398
|
-
globalSection: globalSection.map(x => x.toString(16)),
|
399
|
-
exportSection: exportSection.map(x => x.toString(16)),
|
400
|
-
codeSection: codeSection.map(x => x.toString(16)),
|
401
|
-
dataSection: dataSection.map(x => x.toString(16)),
|
402
|
-
});
|
403
|
-
|
404
|
-
// compilation hints section - unspecd, v8 only
|
405
|
-
// https://github.com/WebAssembly/design/issues/1473#issuecomment-1431274746
|
406
|
-
const chSection = !compileHints ? [] : customSection(
|
407
|
-
'compilationHints',
|
408
|
-
// for now just do everything as optimize eager
|
409
|
-
encodeVector(funcs.map(_ => chHint(0x02, 0x02, 0x02)))
|
410
|
-
);
|
385
|
+
time('data section');
|
411
386
|
|
412
387
|
return Uint8Array.from([
|
413
388
|
...Magic,
|
414
|
-
...ModuleVersion,
|
415
389
|
...typeSection,
|
416
390
|
...importSection,
|
417
391
|
...funcSection,
|
418
|
-
...chSection,
|
419
392
|
...tableSection,
|
420
393
|
...memorySection,
|
421
394
|
...tagSection,
|
@@ -6,17 +6,14 @@ export const __Porffor_object_underlying = (obj: any): any => {
|
|
6
6
|
|
7
7
|
if (Porffor.fastAnd(
|
8
8
|
t >= Porffor.TYPES.error,
|
9
|
-
t <= Porffor.TYPES.
|
9
|
+
t <= Porffor.TYPES.todoerror
|
10
10
|
)) {
|
11
11
|
const remap: object = obj;
|
12
12
|
return remap;
|
13
13
|
}
|
14
14
|
|
15
15
|
if (Porffor.fastAnd(t > 0x05, t != Porffor.TYPES.undefined)) {
|
16
|
-
|
17
|
-
// let idx: i32 = Porffor.array.fastIndexOf(underlyingKeys, obj);
|
18
|
-
|
19
|
-
let idx: i32 = underlyingKeys.indexOf(obj);
|
16
|
+
let idx: i32 = Porffor.array.fastIndexOf(underlyingKeys, obj);
|
20
17
|
if (idx == -1) {
|
21
18
|
const underlying: object = {};
|
22
19
|
|
@@ -892,10 +892,10 @@ export const __Porffor_array_fastPush = (arr: any[], el: any): i32 => {
|
|
892
892
|
return len;
|
893
893
|
};
|
894
894
|
|
895
|
-
export const __Porffor_array_fastIndexOf = (arr: any[], el:
|
895
|
+
export const __Porffor_array_fastIndexOf = (arr: any[], el: number): i32 => {
|
896
896
|
const len: i32 = arr.length;
|
897
897
|
for (let i: i32 = 0; i < len; i++) {
|
898
|
-
if (arr[i]
|
898
|
+
if (arr[i] == el) return i;
|
899
899
|
}
|
900
900
|
|
901
901
|
return -1;
|
@@ -1744,8 +1744,7 @@ export const __ecma262_DateString = (tv: number): bytestring => {
|
|
1744
1744
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-timezonestring
|
1745
1745
|
export const __ecma262_TimeZoneString = (tv: number) => {
|
1746
1746
|
// todo: time zone support
|
1747
|
-
|
1748
|
-
return out;
|
1747
|
+
return '+0000 (UTC)';
|
1749
1748
|
};
|
1750
1749
|
|
1751
1750
|
// 21.4.4.41.4 ToDateString (tv)
|
@@ -2,15 +2,12 @@ export default () => {
|
|
2
2
|
let out = '';
|
3
3
|
|
4
4
|
const error = name => out += `export const ${name} = function (message: any) {
|
5
|
-
|
6
|
-
|
7
|
-
else message = ecma262.ToString(message);
|
5
|
+
if (message === undefined) message = '';
|
6
|
+
// else message = ecma262.ToString(message);
|
8
7
|
|
9
|
-
const obj: object = Porffor.
|
8
|
+
const obj: object = Porffor.allocateBytes(128);
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
obj.name = _name;
|
10
|
+
obj.name = '${name}';
|
14
11
|
obj.message = message;
|
15
12
|
obj.constructor = ${name};
|
16
13
|
|
@@ -18,7 +15,7 @@ export default () => {
|
|
18
15
|
return out;
|
19
16
|
};
|
20
17
|
|
21
|
-
export const __${name
|
18
|
+
export const __${name}_prototype_toString = (_this: ${name}) => {
|
22
19
|
const obj: object = _this;
|
23
20
|
|
24
21
|
const message: any = obj.message;
|
@@ -26,8 +23,7 @@ export const __${name.startsWith('__') ? name.slice(2) : name}_prototype_toStrin
|
|
26
23
|
return obj.name;
|
27
24
|
}
|
28
25
|
|
29
|
-
|
30
|
-
return obj.name + bridge + message;
|
26
|
+
return obj.name + ': ' + message;
|
31
27
|
};`;
|
32
28
|
|
33
29
|
error('Error');
|
@@ -40,7 +36,7 @@ export const __${name.startsWith('__') ? name.slice(2) : name}_prototype_toStrin
|
|
40
36
|
error('URIError');
|
41
37
|
|
42
38
|
error('Test262Error');
|
43
|
-
error('
|
39
|
+
error('TodoError');
|
44
40
|
|
45
41
|
out += `\nexport const __Test262Error_thrower = message => { throw new Test262Error(message); };`;
|
46
42
|
|
@@ -3,13 +3,9 @@ import type {} from './porffor.d.ts';
|
|
3
3
|
export const __Function_prototype_toString = (_this: Function) => {
|
4
4
|
const out: bytestring = Porffor.allocate();
|
5
5
|
|
6
|
-
|
7
|
-
Porffor.bytestring.appendStr(out, prefix);
|
8
|
-
|
6
|
+
Porffor.bytestring.appendStr(out, 'function ');
|
9
7
|
Porffor.bytestring.appendStr(out, _this.name);
|
10
|
-
|
11
|
-
const postfix: bytestring = '() { [native code] }';
|
12
|
-
Porffor.bytestring.appendStr(out, postfix);
|
8
|
+
Porffor.bytestring.appendStr(out, '() { [native code] }');
|
13
9
|
return out;
|
14
10
|
};
|
15
11
|
|
@@ -2,19 +2,16 @@ import type {} from './porffor.d.ts';
|
|
2
2
|
|
3
3
|
export const __Porffor_json_serialize = (value: any, depth: i32, space: bytestring|undefined): bytestring|undefined => {
|
4
4
|
// somewhat modelled after 25.5.2.2 SerializeJSONProperty: https://tc39.es/ecma262/#sec-serializejsonproperty
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
if (value === null) return nullString;
|
10
|
-
if (value === true) return out = 'true';
|
11
|
-
if (value === false) return out = 'false';
|
5
|
+
if (value === null) return 'null';
|
6
|
+
if (value === true) return 'true';
|
7
|
+
if (value === false) return 'false';
|
12
8
|
|
13
9
|
const t: i32 = Porffor.rawType(value);
|
14
10
|
if (Porffor.fastOr(
|
15
11
|
(t | 0b10000000) == Porffor.TYPES.bytestring,
|
16
12
|
t == Porffor.TYPES.stringobject
|
17
13
|
)) { // string
|
14
|
+
const out: bytestring = Porffor.allocate();
|
18
15
|
Porffor.bytestring.appendChar(out, 34); // start "
|
19
16
|
|
20
17
|
const len: i32 = value.length;
|
@@ -77,11 +74,12 @@ export const __Porffor_json_serialize = (value: any, depth: i32, space: bytestri
|
|
77
74
|
t == Porffor.TYPES.number,
|
78
75
|
t == Porffor.TYPES.numberobject
|
79
76
|
)) { // number
|
80
|
-
if (Number.isFinite(value)) return
|
81
|
-
return
|
77
|
+
if (Number.isFinite(value)) return __Number_prototype_toString(value, 10);
|
78
|
+
return 'null';
|
82
79
|
}
|
83
80
|
|
84
81
|
if (t == Porffor.TYPES.array) {
|
82
|
+
const out: bytestring = Porffor.allocate();
|
85
83
|
Porffor.bytestring.appendChar(out, 91); // [
|
86
84
|
|
87
85
|
const hasSpace: boolean = space !== undefined;
|
@@ -94,7 +92,7 @@ export const __Porffor_json_serialize = (value: any, depth: i32, space: bytestri
|
|
94
92
|
for (let i: i32 = 0; i < depth; i++) Porffor.bytestring.appendStr(out, space);
|
95
93
|
}
|
96
94
|
|
97
|
-
Porffor.bytestring.appendStr(out, __Porffor_json_serialize(x, depth, space) ??
|
95
|
+
Porffor.bytestring.appendStr(out, __Porffor_json_serialize(x, depth, space) ?? 'null');
|
98
96
|
|
99
97
|
Porffor.bytestring.appendChar(out, 44); // ,
|
100
98
|
}
|
@@ -120,7 +118,7 @@ export const __Porffor_json_serialize = (value: any, depth: i32, space: bytestri
|
|
120
118
|
|
121
119
|
if (t > 0x06) {
|
122
120
|
// non-function object
|
123
|
-
|
121
|
+
const out: bytestring = Porffor.allocate();
|
124
122
|
Porffor.bytestring.appendChar(out, 123); // {
|
125
123
|
|
126
124
|
const hasSpace: boolean = space !== undefined;
|
@@ -188,10 +186,9 @@ export const __JSON_stringify = (value: any, replacer: any, space: any) => {
|
|
188
186
|
if (space < 1) {
|
189
187
|
space = undefined;
|
190
188
|
} else {
|
191
|
-
const spaceStr: bytestring =
|
192
|
-
spaceStr.length = 0;
|
193
|
-
|
189
|
+
const spaceStr: bytestring = Porffor.allocate();
|
194
190
|
for (let i: i32 = 0; i < space; i++) Porffor.bytestring.appendChar(spaceStr, 32);
|
191
|
+
|
195
192
|
space = spaceStr;
|
196
193
|
}
|
197
194
|
} else if (Porffor.fastOr(
|
@@ -520,9 +520,7 @@ export const __Object_defineProperty = (target: any, prop: any, desc: any) => {
|
|
520
520
|
if (!Porffor.object.isObject(desc)) throw new TypeError('Descriptor is a non-object');
|
521
521
|
|
522
522
|
if (Porffor.rawType(target) == Porffor.TYPES.array) {
|
523
|
-
|
524
|
-
const tmp2: bytestring = 'value';
|
525
|
-
if (prop === tmp1 && __Object_hasOwn(desc, tmp2)) {
|
523
|
+
if (prop === 'length' && __Object_hasOwn(desc, 'value')) {
|
526
524
|
const v: any = desc.value;
|
527
525
|
const n: number = ecma262.ToNumber(v);
|
528
526
|
if (Porffor.fastOr(
|
@@ -566,33 +564,20 @@ export const __Object_defineProperty = (target: any, prop: any, desc: any) => {
|
|
566
564
|
accessor = true;
|
567
565
|
} else if (existingDesc && value === undefined && writable === undefined) {
|
568
566
|
// all undefined, check if past accessor
|
569
|
-
|
570
|
-
const _set: bytestring = 'set';
|
571
|
-
if (_get in existingDesc || _set in existingDesc) accessor = true;
|
567
|
+
if ('get' in existingDesc || 'set' in existingDesc) accessor = true;
|
572
568
|
}
|
573
569
|
|
574
570
|
if (existingDesc) {
|
575
|
-
let inKey: bytestring = '';
|
576
|
-
|
577
571
|
// probably slow due to excessive in's but needs to have them to be spec compliant handling explicit undefined vs non-existent
|
578
|
-
|
579
|
-
if (
|
580
|
-
|
581
|
-
inKey = 'enumerable';
|
582
|
-
if (enumerable == null && !(inKey in desc)) enumerable = existingDesc.enumerable;
|
572
|
+
if (configurable == null && !('configurable' in desc)) configurable = existingDesc.configurable;
|
573
|
+
if (enumerable == null && !('enumerable' in desc)) enumerable = existingDesc.enumerable;
|
583
574
|
|
584
575
|
if (accessor) {
|
585
|
-
|
586
|
-
if (
|
587
|
-
|
588
|
-
inKey = 'set';
|
589
|
-
if (set == null && !(inKey in desc)) set = existingDesc.set;
|
576
|
+
if (get == null && !('get' in desc)) get = existingDesc.get;
|
577
|
+
if (set == null && !('set' in desc)) set = existingDesc.set;
|
590
578
|
} else {
|
591
|
-
|
592
|
-
if (
|
593
|
-
|
594
|
-
inKey = 'writable';
|
595
|
-
if (writable == null && !(inKey in desc)) writable = existingDesc.writable;
|
579
|
+
if (value == null && !('value' in desc)) value = existingDesc.value;
|
580
|
+
if (writable == null && !('writable' in desc)) writable = existingDesc.writable;
|
596
581
|
}
|
597
582
|
}
|
598
583
|
|
@@ -688,8 +673,7 @@ export const __Object_prototype_toString = (_this: any) => {
|
|
688
673
|
let ovr: any = obj.toString;
|
689
674
|
if (Porffor.rawType(ovr) == Porffor.TYPES.function && ovr != __Object_prototype_toString) return ovr.call(_this);
|
690
675
|
|
691
|
-
const
|
692
|
-
const entryPtr: i32 = Porffor.object.lookup(obj, key);
|
676
|
+
const entryPtr: i32 = Porffor.object.lookup(obj, 'toString');
|
693
677
|
if (entryPtr != -1) {
|
694
678
|
ovr = Porffor.object.readValue(entryPtr);
|
695
679
|
if (Porffor.rawType(ovr) == Porffor.TYPES.function) return ovr.call(_this);
|
@@ -736,8 +720,7 @@ export const __Object_prototype_valueOf = (_this: any) => {
|
|
736
720
|
let ovr: any = obj.valueOf;
|
737
721
|
if (Porffor.rawType(ovr) == Porffor.TYPES.function && ovr != __Object_prototype_valueOf) return ovr.call(_this);
|
738
722
|
|
739
|
-
const
|
740
|
-
const entryPtr: i32 = Porffor.object.lookup(obj, key);
|
723
|
+
const entryPtr: i32 = Porffor.object.lookup(obj, 'valueOf');
|
741
724
|
if (entryPtr != -1) {
|
742
725
|
ovr = Porffor.object.readValue(entryPtr);
|
743
726
|
if (Porffor.rawType(ovr) == Porffor.TYPES.function) return ovr.call(_this);
|
@@ -393,27 +393,18 @@ export const __Promise_allSettled = (promises: any): Promise => {
|
|
393
393
|
if (__ecma262_IsPromise(x)) {
|
394
394
|
x.then(r => {
|
395
395
|
const o = {};
|
396
|
-
|
397
|
-
status = 'fulfilled';
|
398
|
-
o.status = status;
|
399
|
-
|
396
|
+
o.status = 'fulfilled';
|
400
397
|
o.value = r;
|
401
398
|
if (Porffor.array.fastPush(_allOut, o) == _allLen) _allRes(_allOut);
|
402
399
|
}, r => {
|
403
400
|
const o = {};
|
404
|
-
|
405
|
-
status = 'rejected';
|
406
|
-
o.status = status;
|
407
|
-
|
401
|
+
o.status = 'rejected';
|
408
402
|
o.reason = r;
|
409
403
|
if (Porffor.array.fastPush(_allOut, o) == _allLen) _allRes(_allOut);
|
410
404
|
});
|
411
405
|
} else {
|
412
406
|
const o = {};
|
413
|
-
|
414
|
-
status = 'fulfilled';
|
415
|
-
o.status = status;
|
416
|
-
|
407
|
+
o.status = 'fulfilled';
|
417
408
|
o.value = x;
|
418
409
|
Porffor.array.fastPush(_allOut, o);
|
419
410
|
}
|
@@ -483,11 +474,7 @@ export const __Promise_race = (promises: any): Promise => {
|
|
483
474
|
};
|
484
475
|
|
485
476
|
|
486
|
-
export const __Promise_prototype_toString = (_this: any) =>
|
487
|
-
const str: bytestring = '[object Promise]';
|
488
|
-
return str;
|
489
|
-
};
|
490
|
-
|
477
|
+
export const __Promise_prototype_toString = (_this: any) => '[object Promise]';
|
491
478
|
export const __Promise_prototype_toLocaleString = (_this: any) => __Promise_prototype_toString(_this);
|
492
479
|
|
493
480
|
|
package/compiler/builtins/set.ts
CHANGED
@@ -246,9 +246,5 @@ export const __Set_prototype_isDisjointFrom = (_this: Set, other: any) => {
|
|
246
246
|
return true;
|
247
247
|
};
|
248
248
|
|
249
|
-
export const __Set_prototype_toString = (_this: Set) =>
|
250
|
-
const out: bytestring = '[object Set]';
|
251
|
-
return out;
|
252
|
-
};
|
253
|
-
|
249
|
+
export const __Set_prototype_toString = (_this: Set) => '[object Set]';
|
254
250
|
export const __Set_prototype_toLocaleString = (_this: Set) => __Set_prototype_toString(_this);
|
@@ -31,9 +31,5 @@ i32.load8_u 0 8
|
|
31
31
|
return`;
|
32
32
|
};
|
33
33
|
|
34
|
-
export const __WeakRef_prototype_toString = (_this: WeakRef) =>
|
35
|
-
const out: bytestring = '[object WeakRef]';
|
36
|
-
return out;
|
37
|
-
};
|
38
|
-
|
34
|
+
export const __WeakRef_prototype_toString = (_this: WeakRef) => '[object WeakRef]';
|
39
35
|
export const __WeakRef_prototype_toLocaleString = (_this: WeakRef) => __WeakRef_prototype_toString(_this);
|
@@ -128,9 +128,5 @@ export const __Map_prototype_values = (_this: Map) => {
|
|
128
128
|
return out;
|
129
129
|
};
|
130
130
|
|
131
|
-
export const __Map_prototype_toString = (_this: Map) =>
|
132
|
-
const str: bytestring = '[object Map]';
|
133
|
-
return str;
|
134
|
-
}
|
135
|
-
|
131
|
+
export const __Map_prototype_toString = (_this: Map) => '[object Map]';
|
136
132
|
export const __Map_prototype_toLocaleString = (_this: Map) => __Map_prototype_toString(_this);
|