porffor 0.57.18 → 0.57.20
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 +382 -324
- package/compiler/builtins/annexb_string.js +10 -14
- package/compiler/builtins/string.ts +4 -4
- package/compiler/builtins_precompiled.js +118 -82
- package/compiler/codegen.js +55 -49
- package/compiler/encoding.js +22 -0
- package/compiler/wrap.js +5 -41
- package/foo.js +17 -1
- package/package.json +1 -1
- package/r.js +243 -0
- package/runtime/index.js +1 -1
package/compiler/codegen.js
CHANGED
@@ -466,9 +466,22 @@ const lookup = (scope, name, failEarly = false) => {
|
|
466
466
|
}
|
467
467
|
}
|
468
468
|
|
469
|
-
return
|
470
|
-
|
471
|
-
|
469
|
+
return [
|
470
|
+
[ Opcodes.local_get, localTmp(scope, '#arguments') ],
|
471
|
+
...Opcodes.eqz,
|
472
|
+
[ Opcodes.if, Blocktype.void ],
|
473
|
+
...generateObject(scope, {
|
474
|
+
properties: names.map((x, i) => ({
|
475
|
+
key: { type: 'Literal', value: i },
|
476
|
+
value: { type: 'Identifier', name: x },
|
477
|
+
kind: 'init'
|
478
|
+
}))
|
479
|
+
}, '#arguments', false),
|
480
|
+
[ Opcodes.local_set, localTmp(scope, '#arguments') ],
|
481
|
+
[ Opcodes.end ],
|
482
|
+
|
483
|
+
[ Opcodes.local_get, localTmp(scope, '#arguments') ]
|
484
|
+
];
|
472
485
|
}
|
473
486
|
|
474
487
|
// no local var with name
|
@@ -1245,7 +1258,7 @@ const asmFuncToAsm = (scope, func, extra) => func(scope, {
|
|
1245
1258
|
getNodeType, generate, generateIdent,
|
1246
1259
|
builtin: (n, offset = false) => {
|
1247
1260
|
let idx = importedFuncs[n] ?? funcIndex[n];
|
1248
|
-
if (idx == null && builtinFuncs
|
1261
|
+
if (idx == null && Object.hasOwn(builtinFuncs, n)) {
|
1249
1262
|
includeBuiltin(scope, n);
|
1250
1263
|
idx = funcIndex[n];
|
1251
1264
|
}
|
@@ -1260,7 +1273,7 @@ const asmFuncToAsm = (scope, func, extra) => func(scope, {
|
|
1260
1273
|
},
|
1261
1274
|
hasFunc: x => funcIndex[x] != null,
|
1262
1275
|
funcRef: name => {
|
1263
|
-
if (funcIndex[name] == null && builtinFuncs
|
1276
|
+
if (funcIndex[name] == null && Object.hasOwn(builtinFuncs, name)) {
|
1264
1277
|
includeBuiltin(scope, name);
|
1265
1278
|
}
|
1266
1279
|
|
@@ -1269,7 +1282,7 @@ const asmFuncToAsm = (scope, func, extra) => func(scope, {
|
|
1269
1282
|
},
|
1270
1283
|
glbl: (opcode, name, type) => {
|
1271
1284
|
const globalName = '#porf#' + name; // avoid potential name clashing with user js
|
1272
|
-
if (!globals
|
1285
|
+
if (!Object.hasOwn(globals, globalName)) {
|
1273
1286
|
const idx = globals['#ind']++;
|
1274
1287
|
globals[globalName] = { idx, type };
|
1275
1288
|
|
@@ -1298,7 +1311,7 @@ const asmFuncToAsm = (scope, func, extra) => func(scope, {
|
|
1298
1311
|
return out;
|
1299
1312
|
},
|
1300
1313
|
loc: (name, type) => {
|
1301
|
-
if (!scope.locals
|
1314
|
+
if (!Object.hasOwn(scope.locals, name)) {
|
1302
1315
|
const idx = scope.localInd++;
|
1303
1316
|
scope.locals[name] = { idx, type };
|
1304
1317
|
}
|
@@ -1401,8 +1414,8 @@ const generateLogicExp = (scope, decl) =>
|
|
1401
1414
|
performLogicOp(scope, decl.operator, generate(scope, decl.left), generate(scope, decl.right), getNodeType(scope, decl.left), getNodeType(scope, decl.right));
|
1402
1415
|
|
1403
1416
|
const isExistingProtoFunc = name => {
|
1404
|
-
if (name.startsWith('__Array_prototype')) return
|
1405
|
-
if (name.startsWith('__String_prototype_')) return
|
1417
|
+
if (name.startsWith('__Array_prototype')) return Object.hasOwn(prototypeFuncs[TYPES.array], name.slice(18));
|
1418
|
+
if (name.startsWith('__String_prototype_')) return Object.hasOwn(prototypeFuncs[TYPES.string], name.slice(19));
|
1406
1419
|
|
1407
1420
|
return false;
|
1408
1421
|
};
|
@@ -1461,7 +1474,7 @@ const getType = (scope, name, failEarly = false) => {
|
|
1461
1474
|
}
|
1462
1475
|
|
1463
1476
|
if (global !== false && name === 'arguments' && !scope.arrow) {
|
1464
|
-
return [ number(TYPES.
|
1477
|
+
return [ number(TYPES.object, Valtype.i32) ];
|
1465
1478
|
}
|
1466
1479
|
|
1467
1480
|
if (metadata?.type != null) {
|
@@ -1475,12 +1488,10 @@ const getType = (scope, name, failEarly = false) => {
|
|
1475
1488
|
[ global ? Opcodes.global_get : Opcodes.local_get, typeLocal.idx ]
|
1476
1489
|
];
|
1477
1490
|
|
1478
|
-
if (hasFuncWithName(name)) {
|
1491
|
+
if (hasFuncWithName(name) || isExistingProtoFunc(name)) {
|
1479
1492
|
return [ number(TYPES.function, Valtype.i32) ];
|
1480
1493
|
}
|
1481
1494
|
|
1482
|
-
if (isExistingProtoFunc(name)) return [ number(TYPES.function, Valtype.i32) ];
|
1483
|
-
|
1484
1495
|
return fallback;
|
1485
1496
|
};
|
1486
1497
|
|
@@ -2119,7 +2130,7 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
2119
2130
|
target.name = spl.slice(0, -1).join('_');
|
2120
2131
|
|
2121
2132
|
if (builtinFuncs['__' + target.name + '_' + protoName]) protoName = null;
|
2122
|
-
else if (lookupName(scope, target.name)[0] == null && !builtinFuncs
|
2133
|
+
else if (lookupName(scope, target.name)[0] == null && !Object.hasOwn(builtinFuncs, target.name)) {
|
2123
2134
|
if (lookupName(scope, '__' + target.name)[0] != null || builtinFuncs['__' + target.name]) target.name = '__' + target.name;
|
2124
2135
|
else protoName = null;
|
2125
2136
|
}
|
@@ -2177,38 +2188,14 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
2177
2188
|
...generate(scope, decl.arguments[0] ?? DEFAULT_VALUE()),
|
2178
2189
|
[ Opcodes.local_tee, valTmp ],
|
2179
2190
|
...getNodeType(scope, decl.arguments[0] ?? DEFAULT_VALUE()),
|
2180
|
-
[ Opcodes.local_tee, typeTmp ]
|
2181
|
-
|
2182
|
-
// check not undefined or null if not in precompile
|
2183
|
-
// todo: technically this should be allowed sometimes but for now, never
|
2184
|
-
...(globalThis.precompile ? [] : [
|
2185
|
-
...nullish(scope,
|
2186
|
-
[ [ Opcodes.local_get, valTmp ] ],
|
2187
|
-
[ [ Opcodes.local_get, typeTmp ] ],
|
2188
|
-
false, true),
|
2189
|
-
[ Opcodes.if, Blocktype.void ],
|
2190
|
-
...internalThrow(scope, 'TypeError', `Cannot use undefined or null as 'this'`),
|
2191
|
-
[ Opcodes.end ]
|
2192
|
-
])
|
2191
|
+
[ Opcodes.local_tee, typeTmp ]
|
2193
2192
|
],
|
2194
2193
|
_thisWasmComponents: {
|
2195
2194
|
_callValue: [
|
2196
2195
|
...generate(scope, decl.arguments[0] ?? DEFAULT_VALUE()),
|
2197
2196
|
[ Opcodes.local_tee, valTmp ],
|
2198
2197
|
...getNodeType(scope, decl.arguments[0] ?? DEFAULT_VALUE()),
|
2199
|
-
[ Opcodes.local_set, typeTmp ]
|
2200
|
-
|
2201
|
-
// check not undefined or null if not in precompile
|
2202
|
-
// todo: technically this should be allowed sometimes but for now, never
|
2203
|
-
...(globalThis.precompile ? [] : [
|
2204
|
-
...nullish(scope,
|
2205
|
-
[ [ Opcodes.local_get, valTmp ] ],
|
2206
|
-
[ [ Opcodes.local_get, typeTmp ] ],
|
2207
|
-
false, true),
|
2208
|
-
[ Opcodes.if, Blocktype.void ],
|
2209
|
-
...internalThrow(scope, 'TypeError', `Cannot use undefined or null as 'this'`),
|
2210
|
-
[ Opcodes.end ]
|
2211
|
-
])
|
2198
|
+
[ Opcodes.local_set, typeTmp ]
|
2212
2199
|
],
|
2213
2200
|
_callType: [ [ Opcodes.local_get, typeTmp ] ]
|
2214
2201
|
}
|
@@ -2529,6 +2516,7 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
2529
2516
|
const wrapperArgc = Prefs.indirectWrapperArgc ?? 10;
|
2530
2517
|
const underflow = wrapperArgc - args.length;
|
2531
2518
|
for (let i = 0; i < underflow; i++) args.push(DEFAULT_VALUE());
|
2519
|
+
if (args.length > wrapperArgc) args = args.slice(0, wrapperArgc);
|
2532
2520
|
|
2533
2521
|
for (let i = 0; i < args.length; i++) {
|
2534
2522
|
const arg = args[i];
|
@@ -2728,9 +2716,7 @@ const generateThis = (scope, decl) => {
|
|
2728
2716
|
|
2729
2717
|
if (!scope.constr && !scope.method) {
|
2730
2718
|
// this in a non-constructor context is a reference to globalThis
|
2731
|
-
return
|
2732
|
-
...generate(scope, { type: 'Identifier', name: 'globalThis' })
|
2733
|
-
];
|
2719
|
+
return generate(scope, { type: 'Identifier', name: 'globalThis' });
|
2734
2720
|
}
|
2735
2721
|
|
2736
2722
|
// opt: do not check for pure constructors or strict mode
|
@@ -3282,7 +3268,7 @@ const generateVarDstr = (scope, kind, pattern, init, defaultValue, global) => {
|
|
3282
3268
|
const [ _func, out ] = generateFunc(scope, init, true);
|
3283
3269
|
|
3284
3270
|
const funcName = init.id?.name;
|
3285
|
-
if (name !== funcName && funcIndex
|
3271
|
+
if (name !== funcName && Object.hasOwn(funcIndex, funcName)) {
|
3286
3272
|
funcIndex[name] = funcIndex[funcName];
|
3287
3273
|
delete funcIndex[funcName];
|
3288
3274
|
}
|
@@ -5657,7 +5643,6 @@ const generateObject = (scope, decl, global = false, name = '$undeclared') => {
|
|
5657
5643
|
}
|
5658
5644
|
|
5659
5645
|
out.push(Opcodes.i32_from_u);
|
5660
|
-
|
5661
5646
|
return out;
|
5662
5647
|
};
|
5663
5648
|
|
@@ -6402,7 +6387,7 @@ const generateTaggedTemplate = (scope, decl, global = false, name = undefined, v
|
|
6402
6387
|
const immediates = asm.slice(1).map(x => {
|
6403
6388
|
const n = parseFloat(x);
|
6404
6389
|
if (Number.isNaN(n) && x !== 'NaN') {
|
6405
|
-
if (builtinFuncs
|
6390
|
+
if (Object.hasOwn(builtinFuncs, x)) {
|
6406
6391
|
if (funcIndex[x] == null) includeBuiltin(scope, x);
|
6407
6392
|
return funcIndex[x];
|
6408
6393
|
}
|
@@ -6441,7 +6426,7 @@ const generateTaggedTemplate = (scope, decl, global = false, name = undefined, v
|
|
6441
6426
|
};
|
6442
6427
|
|
6443
6428
|
const { quasis, expressions } = decl.quasi;
|
6444
|
-
if (intrinsics
|
6429
|
+
if (Object.hasOwn(intrinsics, decl.tag.name)) {
|
6445
6430
|
let str = quasis[0].value.raw;
|
6446
6431
|
|
6447
6432
|
for (let i = 0; i < expressions.length; i++) {
|
@@ -6653,19 +6638,40 @@ const generateFunc = (scope, decl, forceNoExpr = false) => {
|
|
6653
6638
|
number(TYPES.string, Valtype.i32),
|
6654
6639
|
[ Opcodes.i32_ne ],
|
6655
6640
|
[ Opcodes.if, Blocktype.void ],
|
6641
|
+
[ Opcodes.local_get, func.locals[name].idx + 1 ],
|
6642
|
+
number(TYPE_FLAGS.parity, Valtype.i32),
|
6643
|
+
[ Opcodes.i32_or ],
|
6644
|
+
number(TYPES.undefined, Valtype.i32),
|
6645
|
+
[ Opcodes.i32_eq ],
|
6646
|
+
|
6647
|
+
[ Opcodes.local_get, func.locals[name].idx + 1 ],
|
6648
|
+
number(TYPES.object, Valtype.i32),
|
6649
|
+
[ Opcodes.i32_eq ],
|
6656
6650
|
[ Opcodes.local_get, func.locals[name].idx ],
|
6657
|
-
|
6651
|
+
...Opcodes.eqz,
|
6652
|
+
[ Opcodes.i32_and ],
|
6653
|
+
|
6654
|
+
[ Opcodes.i32_or ],
|
6655
|
+
[ Opcodes.if, Blocktype.void ],
|
6656
|
+
...internalThrow(func, 'TypeError', `${unhackName(func.name)} expects 'this' to be non-nullish`),
|
6657
|
+
[ Opcodes.end ],
|
6658
|
+
|
6659
|
+
[ Opcodes.local_get, func.locals[name].idx ],
|
6660
|
+
...(valtypeBinary === Valtype.i32 ? [ [ Opcodes.f64_convert_i32_s ] ] : []),
|
6658
6661
|
[ Opcodes.local_get, func.locals[name].idx + 1 ],
|
6659
6662
|
[ Opcodes.call, includeBuiltin(scope, '__ecma262_ToString').index ],
|
6660
6663
|
[ Opcodes.local_set, func.locals[name].idx + 1 ],
|
6661
|
-
Opcodes.i32_trunc_sat_f64_s,
|
6664
|
+
...(valtypeBinary === Valtype.i32 ? [ Opcodes.i32_trunc_sat_f64_s ] : []),
|
6662
6665
|
[ Opcodes.local_set, func.locals[name].idx ],
|
6666
|
+
|
6663
6667
|
[ Opcodes.local_get, func.locals[name].idx + 1 ],
|
6664
6668
|
number(TYPES.bytestring, Valtype.i32),
|
6665
6669
|
[ Opcodes.i32_eq ],
|
6666
6670
|
[ Opcodes.if, Blocktype.void ],
|
6667
6671
|
[ Opcodes.local_get, func.locals[name].idx ],
|
6672
|
+
Opcodes.i32_to_u,
|
6668
6673
|
[ Opcodes.call, includeBuiltin(scope, '__Porffor_bytestringToString').index ],
|
6674
|
+
Opcodes.i32_from_u,
|
6669
6675
|
[ Opcodes.local_set, func.locals[name].idx ],
|
6670
6676
|
[ Opcodes.end ],
|
6671
6677
|
[ Opcodes.end ]
|
package/compiler/encoding.js
CHANGED
@@ -84,6 +84,28 @@ export const unsignedLEB128_length = n => {
|
|
84
84
|
return length;
|
85
85
|
};
|
86
86
|
|
87
|
+
export const signedLEB128_length = n => {
|
88
|
+
if (n >= -64 && n <= 63) return 1;
|
89
|
+
if (n >= -8192 && n <= 8191) return 2;
|
90
|
+
if (n >= -1048576 && n <= 1048575) return 3;
|
91
|
+
if (n >= -134217728 && n <= 134217727) return 4;
|
92
|
+
|
93
|
+
let length = 0;
|
94
|
+
while (true) {
|
95
|
+
let byte = n & 0x7f;
|
96
|
+
n >>= 7;
|
97
|
+
|
98
|
+
if ((n === 0 && (byte & 0x40) === 0) || (n === -1 && (byte & 0x40) !== 0)) {
|
99
|
+
length++;
|
100
|
+
break;
|
101
|
+
} else {
|
102
|
+
length++;
|
103
|
+
}
|
104
|
+
}
|
105
|
+
|
106
|
+
return length;
|
107
|
+
};
|
108
|
+
|
87
109
|
export const big_signedLEB128 = n => {
|
88
110
|
// just input for small numbers (for perf as common)
|
89
111
|
if (n >= 0n && n <= 63n) return [ Number(n) ];
|
package/compiler/wrap.js
CHANGED
@@ -401,7 +401,7 @@ export default (source, module = undefined, customImports = {}, print = str => p
|
|
401
401
|
const surrounding = Prefs.backtraceSurrounding ?? 10;
|
402
402
|
let min = middleIndex - surrounding;
|
403
403
|
let max = middleIndex + surrounding + 1;
|
404
|
-
if (Prefs.backtraceFunc || middleIndex
|
404
|
+
if (Prefs.backtraceFunc || middleIndex === -1) {
|
405
405
|
min = 0;
|
406
406
|
max = func.wasm.length;
|
407
407
|
}
|
@@ -415,7 +415,7 @@ export default (source, module = undefined, customImports = {}, print = str => p
|
|
415
415
|
longest = Math.max(longest, noAnsi(disasm[j])?.length ?? 0);
|
416
416
|
}
|
417
417
|
|
418
|
-
if (middleIndex
|
418
|
+
if (middleIndex !== -1) {
|
419
419
|
const middle = Math.floor(disasm.length / 2);
|
420
420
|
disasm[middle] = `\x1B[47m\x1B[30m${noAnsi(disasm[middle])}${'\u00a0'.repeat(longest - noAnsi(disasm[middle]).length)}\x1B[0m`;
|
421
421
|
}
|
@@ -429,47 +429,11 @@ export default (source, module = undefined, customImports = {}, print = str => p
|
|
429
429
|
if (funcInd == null || blobOffset == null ||
|
430
430
|
Number.isNaN(funcInd) || Number.isNaN(blobOffset) || Prefs.backtrace === false) return false;
|
431
431
|
|
432
|
-
|
433
|
-
const func = funcs.find(x => x.asmIndex === funcInd);
|
432
|
+
const func = funcs.find(x => (x.index - importDelta) === funcInd);
|
434
433
|
if (!func) return false;
|
435
434
|
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
let i = 0;
|
440
|
-
for (; i < wasm.length; i++) {
|
441
|
-
let mismatch = false;
|
442
|
-
for (let j = 0; j < toFind.length; j++) {
|
443
|
-
if (wasm[i + j] !== toFind[j]) {
|
444
|
-
mismatch = true;
|
445
|
-
break;
|
446
|
-
}
|
447
|
-
}
|
448
|
-
|
449
|
-
if (!mismatch) break;
|
450
|
-
}
|
451
|
-
|
452
|
-
if (i === wasm.length) {
|
453
|
-
printBacktrace(-1, func, funcs, globals, exceptions);
|
454
|
-
return false;
|
455
|
-
}
|
456
|
-
|
457
|
-
const offset = (blobOffset - i) - encodeVector(localDecl).length;
|
458
|
-
|
459
|
-
let cumLen = 0;
|
460
|
-
i = 0;
|
461
|
-
for (; i < assembledWasmOps.length; i++) {
|
462
|
-
cumLen += assembledWasmOps[i].filter(x => x != null && x <= 0xff).length;
|
463
|
-
if (cumLen === offset) break;
|
464
|
-
}
|
465
|
-
|
466
|
-
if (cumLen !== offset) {
|
467
|
-
printBacktrace(-1, func, funcs, globals, exceptions);
|
468
|
-
return false;
|
469
|
-
}
|
470
|
-
|
471
|
-
printBacktrace(i + 1, func, funcs, globals, exceptions);
|
472
|
-
return true;
|
435
|
+
printBacktrace(-1, func, funcs, globals, exceptions);
|
436
|
+
return false;
|
473
437
|
};
|
474
438
|
|
475
439
|
const t2 = performance.now();
|
package/foo.js
CHANGED
@@ -1 +1,17 @@
|
|
1
|
-
|
1
|
+
import compile from './compiler/wrap.js';
|
2
|
+
import { Worker, isMainThread } from 'node:worker_threads';
|
3
|
+
|
4
|
+
import { join } from 'node:path';
|
5
|
+
const __dirname = import.meta.dirname;
|
6
|
+
const __filename = join(__dirname, 'foo.js');
|
7
|
+
|
8
|
+
if (isMainThread) {
|
9
|
+
const worker = new Worker(__filename);
|
10
|
+
} else {
|
11
|
+
for (let i = 0; i < 500; i++) {
|
12
|
+
const js = `console.log(globalThis);`;
|
13
|
+
const out = compile(js);
|
14
|
+
out.exports.main();
|
15
|
+
console.log(i);
|
16
|
+
}
|
17
|
+
}
|
package/package.json
CHANGED
package/r.js
ADDED
@@ -0,0 +1,243 @@
|
|
1
|
+
function isConfigurable(obj, name) {
|
2
|
+
if (Object.hasOwn(obj, name)) return Object.getOwnPropertyDescriptor(obj, name).configurable;
|
3
|
+
return true;
|
4
|
+
}
|
5
|
+
|
6
|
+
function isEnumerable(obj, name) {
|
7
|
+
return Object.hasOwn(obj, name) && Object.getOwnPropertyDescriptor(obj, name).enumerable;
|
8
|
+
}
|
9
|
+
|
10
|
+
function isSameValue(a, b) {
|
11
|
+
if (a === 0 && b === 0) return 1 / a === 1 / b;
|
12
|
+
if (a !== a && b !== b) return true;
|
13
|
+
|
14
|
+
return a === b;
|
15
|
+
}
|
16
|
+
|
17
|
+
function isWritable(obj, name, verifyProp, value) {
|
18
|
+
if (Object.hasOwn(obj, name) && Object.getOwnPropertyDescriptor(obj, name).writable != null) return Object.getOwnPropertyDescriptor(obj, name).writable;
|
19
|
+
if (!Object.hasOwn(obj, name) && Object.isExtensible(obj)) return true;
|
20
|
+
|
21
|
+
var unlikelyValue = Array.isArray(obj) && name === "length" ?
|
22
|
+
Math.pow(2, 32) - 1 :
|
23
|
+
"unlikelyValue";
|
24
|
+
var newValue = value || unlikelyValue;
|
25
|
+
var hadValue = Object.hasOwn(obj, name);
|
26
|
+
var oldValue = obj[name];
|
27
|
+
var writeSucceeded;
|
28
|
+
|
29
|
+
try {
|
30
|
+
obj[name] = newValue;
|
31
|
+
} catch {}
|
32
|
+
|
33
|
+
writeSucceeded = isSameValue(obj[verifyProp || name], newValue);
|
34
|
+
|
35
|
+
if (writeSucceeded) {
|
36
|
+
if (hadValue) {
|
37
|
+
obj[name] = oldValue;
|
38
|
+
} else {
|
39
|
+
delete obj[name];
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
return writeSucceeded;
|
44
|
+
}
|
45
|
+
|
46
|
+
function verifyProperty(obj, name, desc, options) {
|
47
|
+
var originalDesc = Object.getOwnPropertyDescriptor(obj, name);
|
48
|
+
|
49
|
+
if (desc === undefined) {
|
50
|
+
if (originalDesc !== undefined) {
|
51
|
+
throw new Test262Error('verifyProperty: expected undefined descriptor');
|
52
|
+
}
|
53
|
+
|
54
|
+
return true;
|
55
|
+
}
|
56
|
+
|
57
|
+
if (!Object.hasOwn(obj, name)) throw new Test262Error('verifyProperty: obj should have own property');
|
58
|
+
|
59
|
+
if (Object.hasOwn(desc, 'value')) {
|
60
|
+
const v = desc.value;
|
61
|
+
if (!isSameValue(originalDesc.value, v)) throw new Test262Error('verifyProperty: descriptor value mismatch');
|
62
|
+
// if (!isSameValue(obj[name], v)) throw new Test262Error('verifyProperty: object value mismatch');
|
63
|
+
}
|
64
|
+
|
65
|
+
if (Object.hasOwn(desc, 'enumerable')) {
|
66
|
+
if (desc.enumerable !== originalDesc.enumerable ||
|
67
|
+
desc.enumerable !== isEnumerable(obj, name)) {
|
68
|
+
throw new Test262Error('enumerable fail');
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
if (Object.hasOwn(desc, 'writable')) {
|
73
|
+
if (desc.writable !== originalDesc.writable ||
|
74
|
+
desc.writable !== isWritable(obj, name)) {
|
75
|
+
throw new Test262Error('writable fail');
|
76
|
+
}
|
77
|
+
}
|
78
|
+
|
79
|
+
if (Object.hasOwn(desc, 'configurable')) {
|
80
|
+
if (desc.configurable !== originalDesc.configurable ||
|
81
|
+
desc.configurable !== isConfigurable(obj, name)) {
|
82
|
+
throw new Test262Error('configurable fail');
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
86
|
+
if (options && options.restore) {
|
87
|
+
Object.defineProperty(obj, name, originalDesc);
|
88
|
+
}
|
89
|
+
|
90
|
+
return true;
|
91
|
+
}
|
92
|
+
|
93
|
+
function verifyEqualTo(obj, name, value) {
|
94
|
+
if (!isSameValue(obj[name], value)) {
|
95
|
+
throw new Test262Error('propertyHelper verifyEqualTo failed');
|
96
|
+
}
|
97
|
+
}
|
98
|
+
|
99
|
+
function verifyWritable(obj, name, verifyProp, value) {
|
100
|
+
if (!verifyProp) {
|
101
|
+
if (!Object.getOwnPropertyDescriptor(obj, name).writable)
|
102
|
+
throw new Test262Error('propertyHelper verifyWritable failed');
|
103
|
+
}
|
104
|
+
|
105
|
+
if (!isWritable(obj, name, verifyProp, value)) {
|
106
|
+
throw new Test262Error('propertyHelper verifyWritable failed');
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
function verifyNotWritable(obj, name, verifyProp, value) {
|
111
|
+
if (!verifyProp) {
|
112
|
+
if (Object.getOwnPropertyDescriptor(obj, name).writable)
|
113
|
+
throw new Test262Error('propertyHelper verifyNotWritable failed');
|
114
|
+
}
|
115
|
+
|
116
|
+
if (isWritable(obj, name, verifyProp)) {
|
117
|
+
throw new Test262Error('propertyHelper verifyNotWritable failed');
|
118
|
+
}
|
119
|
+
}
|
120
|
+
|
121
|
+
function verifyEnumerable(obj, name) {
|
122
|
+
if (!isEnumerable(obj, name)) {
|
123
|
+
throw new Test262Error('propertyHelper verifyEnumerable failed');
|
124
|
+
}
|
125
|
+
}
|
126
|
+
|
127
|
+
function verifyNotEnumerable(obj, name) {
|
128
|
+
if (isEnumerable(obj, name)) {
|
129
|
+
throw new Test262Error('propertyHelper verifyNotEnumerable failed');
|
130
|
+
}
|
131
|
+
}
|
132
|
+
|
133
|
+
function verifyConfigurable(obj, name) {
|
134
|
+
if (!isConfigurable(obj, name)) {
|
135
|
+
throw new Test262Error('propertyHelper verifyConfigurable failed');
|
136
|
+
}
|
137
|
+
}
|
138
|
+
|
139
|
+
function verifyNotConfigurable(obj, name) {
|
140
|
+
if (isConfigurable(obj, name)) {
|
141
|
+
throw new Test262Error('propertyHelper verifyNotConfigurable failed');
|
142
|
+
}
|
143
|
+
}
|
144
|
+
var assert = mustBeTrue => {
|
145
|
+
if (mustBeTrue === true) {
|
146
|
+
return;
|
147
|
+
}
|
148
|
+
|
149
|
+
throw new Test262Error('assert failed');
|
150
|
+
};
|
151
|
+
assert; // idk why exactly but this fixes many tests by forcing indirect ref
|
152
|
+
|
153
|
+
var __assert_throws = (expectedErrorConstructor, func) => {
|
154
|
+
if (typeof func !== 'function') {
|
155
|
+
throw new Test262Error('assert.throws invoked with a non-function value');
|
156
|
+
}
|
157
|
+
|
158
|
+
try {
|
159
|
+
func();
|
160
|
+
} catch {
|
161
|
+
return;
|
162
|
+
}
|
163
|
+
|
164
|
+
throw new Test262Error('assert.throws failed');
|
165
|
+
};
|
166
|
+
|
167
|
+
var __assert__isSameValue = (a, b) => {
|
168
|
+
if (a === b) {
|
169
|
+
// Handle +/-0 vs. -/+0
|
170
|
+
return a !== 0 || 1 / a === 1 / b;
|
171
|
+
}
|
172
|
+
|
173
|
+
// Handle NaN vs. NaN
|
174
|
+
return a !== a && b !== b;
|
175
|
+
};
|
176
|
+
|
177
|
+
var __assert_sameValue = (actual, expected) => {
|
178
|
+
if (assert._isSameValue(actual, expected)) {
|
179
|
+
return;
|
180
|
+
}
|
181
|
+
|
182
|
+
throw new Test262Error('assert.sameValue failed');
|
183
|
+
};
|
184
|
+
|
185
|
+
var __assert_notSameValue = (actual, unexpected) => {
|
186
|
+
if (!assert._isSameValue(actual, unexpected)) {
|
187
|
+
return;
|
188
|
+
}
|
189
|
+
|
190
|
+
throw new Test262Error('assert.notSameValue failed');
|
191
|
+
};
|
192
|
+
// define our $262 here too
|
193
|
+
// var $262 = {
|
194
|
+
// global: globalThis,
|
195
|
+
// gc() { /* noop */ },
|
196
|
+
// detachArrayBuffer(buffer) {
|
197
|
+
// return Porffor.arraybuffer.detach(buffer);
|
198
|
+
// },
|
199
|
+
// getGlobal(name) {
|
200
|
+
// return globalThis[name];
|
201
|
+
// },
|
202
|
+
// // todo: setGlobal
|
203
|
+
// destroy() { /* noop */ },
|
204
|
+
// agent: {}
|
205
|
+
// };
|
206
|
+
|
207
|
+
// function Test262Error(message) {
|
208
|
+
// this.message = message;
|
209
|
+
// this.name = 'Test262Error';
|
210
|
+
// }
|
211
|
+
|
212
|
+
// var __Test262Error_thrower = message => {
|
213
|
+
// throw new Test262Error(message);
|
214
|
+
// };
|
215
|
+
|
216
|
+
var $DONOTEVALUATE = () => {
|
217
|
+
throw 'Test262: This statement should not be evaluated.';
|
218
|
+
};
|
219
|
+
// Copyright (C) 2019 Aleksey Shvayka. All rights reserved.
|
220
|
+
// This code is governed by the BSD license found in the LICENSE file.
|
221
|
+
/*---
|
222
|
+
esid: sec-array-constructor
|
223
|
+
description: >
|
224
|
+
Property descriptor of Array
|
225
|
+
info: |
|
226
|
+
22.1.1 The Array Constructor
|
227
|
+
|
228
|
+
* is the initial value of the Array property of the global object.
|
229
|
+
|
230
|
+
17 ECMAScript Standard Built-in Objects
|
231
|
+
|
232
|
+
Every other data property described in clauses 18 through 26 and in Annex B.2
|
233
|
+
has the attributes { [[Writable]]: true, [[Enumerable]]: false,
|
234
|
+
[[Configurable]]: true } unless otherwise specified.
|
235
|
+
includes: [propertyHelper.js]
|
236
|
+
---*/
|
237
|
+
|
238
|
+
verifyProperty(this, 'Array', {
|
239
|
+
value: Array,
|
240
|
+
writable: true,
|
241
|
+
enumerable: false,
|
242
|
+
configurable: true,
|
243
|
+
});
|