porffor 0.56.1 → 0.56.3
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/bun.lock +2 -2
- package/compiler/2c.js +1 -2
- package/compiler/allocator.js +2 -0
- package/compiler/builtins/_internal_object.ts +7 -4
- package/compiler/builtins/_internal_string.ts +8 -18
- package/compiler/builtins/object.ts +1 -0
- package/compiler/builtins/string_f64.ts +1 -1
- package/compiler/builtins.js +9 -47
- package/compiler/builtins_precompiled.js +39 -39
- package/compiler/codegen.js +117 -106
- package/foo +0 -0
- package/package.json +2 -2
- package/r.cjs +13 -295
- package/runner/index.js +1 -1
package/compiler/codegen.js
CHANGED
@@ -433,8 +433,6 @@ const lookup = (scope, name, failEarly = false) => {
|
|
433
433
|
let local = scope.locals[name];
|
434
434
|
|
435
435
|
if (Object.hasOwn(builtinVars, name)) {
|
436
|
-
if (builtinVars[name].floatOnly && valtype[0] === 'i') throw new Error(`Cannot use ${unhackName(name)} with integer valtype`);
|
437
|
-
|
438
436
|
let wasm = builtinVars[name];
|
439
437
|
if (wasm.usesImports) scope.usesImports = true;
|
440
438
|
|
@@ -508,9 +506,8 @@ const lookup = (scope, name, failEarly = false) => {
|
|
508
506
|
const lookupOrError = (scope, name, failEarly) => lookup(scope, name, failEarly)
|
509
507
|
?? internalThrow(scope, 'ReferenceError', `${unhackName(name)} is not defined`, true);
|
510
508
|
|
511
|
-
const generateIdent = (scope, decl) =>
|
512
|
-
|
513
|
-
};
|
509
|
+
const generateIdent = (scope, decl) =>
|
510
|
+
lookupOrError(scope, decl.name, scope.identFailEarly);
|
514
511
|
|
515
512
|
const generateYield = (scope, decl) => {
|
516
513
|
let arg = decl.argument ?? DEFAULT_VALUE();
|
@@ -763,21 +760,19 @@ const performLogicOp = (scope, op, left, right, leftType, rightType) => {
|
|
763
760
|
];
|
764
761
|
};
|
765
762
|
|
766
|
-
const concatStrings = (scope, left, right, leftType, rightType) =>
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
...leftType,
|
763
|
+
const concatStrings = (scope, left, right, leftType, rightType) => [
|
764
|
+
...left,
|
765
|
+
...(valtypeBinary === Valtype.i32 ? [ [ Opcodes.f64_convert_i32_s ] ] : []),
|
766
|
+
...leftType,
|
771
767
|
|
772
|
-
|
773
|
-
|
774
|
-
|
768
|
+
...right,
|
769
|
+
...(valtypeBinary === Valtype.i32 ? [ [ Opcodes.f64_convert_i32_s ] ] : []),
|
770
|
+
...rightType,
|
775
771
|
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
};
|
772
|
+
[ Opcodes.call, includeBuiltin(scope, '__Porffor_concatStrings').index ],
|
773
|
+
...setLastType(scope),
|
774
|
+
...(valtypeBinary === Valtype.i32 ? [ Opcodes.i32_trunc_sat_f64_u ] : []),
|
775
|
+
];
|
781
776
|
|
782
777
|
const compareStrings = (scope, left, right, leftType, rightType, noConv = false) => {
|
783
778
|
if (noConv) return [
|
@@ -1241,89 +1236,87 @@ const generateBinaryExp = (scope, decl) => {
|
|
1241
1236
|
return out;
|
1242
1237
|
};
|
1243
1238
|
|
1244
|
-
const asmFuncToAsm = (scope, func, extra) => {
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1249
|
-
|
1250
|
-
|
1251
|
-
|
1252
|
-
|
1253
|
-
}
|
1239
|
+
const asmFuncToAsm = (scope, func, extra) => func(scope, {
|
1240
|
+
Valtype, Opcodes, TYPES, TYPE_NAMES, usedTypes, typeSwitch, makeString, internalThrow,
|
1241
|
+
getNodeType, generate, generateIdent,
|
1242
|
+
builtin: (n, offset = false) => {
|
1243
|
+
let idx = funcIndex[n] ?? importedFuncs[n];
|
1244
|
+
if (idx == null && builtinFuncs[n]) {
|
1245
|
+
includeBuiltin(scope, n);
|
1246
|
+
idx = funcIndex[n];
|
1247
|
+
}
|
1254
1248
|
|
1255
|
-
|
1256
|
-
|
1249
|
+
scope.includes ??= new Set();
|
1250
|
+
scope.includes.add(n);
|
1257
1251
|
|
1258
|
-
|
1259
|
-
|
1252
|
+
if (idx == null) throw new Error(`builtin('${n}') failed: could not find func (from ${scope.name})`);
|
1253
|
+
if (offset) idx -= importedFuncs.length;
|
1260
1254
|
|
1261
|
-
|
1262
|
-
|
1263
|
-
|
1264
|
-
|
1265
|
-
|
1266
|
-
|
1267
|
-
|
1255
|
+
return idx;
|
1256
|
+
},
|
1257
|
+
hasFunc: x => funcIndex[x] != null,
|
1258
|
+
funcRef: name => {
|
1259
|
+
if (funcIndex[name] == null && builtinFuncs[name]) {
|
1260
|
+
includeBuiltin(scope, name);
|
1261
|
+
}
|
1268
1262
|
|
1269
|
-
|
1270
|
-
|
1271
|
-
|
1272
|
-
|
1273
|
-
|
1274
|
-
|
1275
|
-
|
1276
|
-
|
1277
|
-
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1263
|
+
const func = funcByName(name);
|
1264
|
+
return funcRef(func);
|
1265
|
+
},
|
1266
|
+
glbl: (opcode, name, type) => {
|
1267
|
+
const globalName = '#porf#' + name; // avoid potential name clashing with user js
|
1268
|
+
if (!globals[globalName]) {
|
1269
|
+
const idx = globals['#ind']++;
|
1270
|
+
globals[globalName] = { idx, type };
|
1271
|
+
|
1272
|
+
const tmpIdx = globals['#ind']++;
|
1273
|
+
globals[globalName + '#glbl_inited'] = { idx: tmpIdx, type: Valtype.i32 };
|
1274
|
+
}
|
1281
1275
|
|
1282
|
-
|
1283
|
-
|
1284
|
-
|
1276
|
+
const out = [
|
1277
|
+
[ opcode, globals[globalName].idx ]
|
1278
|
+
];
|
1285
1279
|
|
1286
|
-
|
1287
|
-
|
1288
|
-
|
1289
|
-
|
1290
|
-
|
1291
|
-
|
1292
|
-
|
1293
|
-
|
1294
|
-
|
1295
|
-
|
1296
|
-
|
1297
|
-
|
1298
|
-
|
1280
|
+
scope.initedGlobals ??= new Set();
|
1281
|
+
if (!scope.initedGlobals.has(name)) {
|
1282
|
+
scope.initedGlobals.add(name);
|
1283
|
+
if (scope.globalInits[name]) out.unshift(
|
1284
|
+
[ Opcodes.global_get, globals[globalName + '#glbl_inited'].idx ],
|
1285
|
+
[ Opcodes.i32_eqz ],
|
1286
|
+
[ Opcodes.if, Blocktype.void ],
|
1287
|
+
...asmFuncToAsm(scope, scope.globalInits[name]),
|
1288
|
+
number(1, Valtype.i32),
|
1289
|
+
[ Opcodes.global_set, globals[globalName + '#glbl_inited'].idx ],
|
1290
|
+
[ Opcodes.end ]
|
1291
|
+
);
|
1292
|
+
}
|
1299
1293
|
|
1300
|
-
|
1301
|
-
|
1302
|
-
|
1303
|
-
|
1304
|
-
|
1305
|
-
|
1306
|
-
|
1294
|
+
return out;
|
1295
|
+
},
|
1296
|
+
loc: (name, type) => {
|
1297
|
+
if (!scope.locals[name]) {
|
1298
|
+
const idx = scope.localInd++;
|
1299
|
+
scope.locals[name] = { idx, type };
|
1300
|
+
}
|
1307
1301
|
|
1308
|
-
|
1309
|
-
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1313
|
-
|
1314
|
-
|
1315
|
-
|
1316
|
-
|
1317
|
-
|
1318
|
-
|
1319
|
-
|
1320
|
-
|
1321
|
-
|
1322
|
-
|
1323
|
-
|
1324
|
-
|
1325
|
-
|
1326
|
-
};
|
1302
|
+
return scope.locals[name].idx;
|
1303
|
+
},
|
1304
|
+
t: (types, wasm) => {
|
1305
|
+
if (types.some(x => usedTypes.has(x))) {
|
1306
|
+
return wasm();
|
1307
|
+
} else {
|
1308
|
+
return [ [ null, () => {
|
1309
|
+
if (types.some(x => usedTypes.has(x))) return wasm();
|
1310
|
+
return [];
|
1311
|
+
} ] ];
|
1312
|
+
}
|
1313
|
+
},
|
1314
|
+
i32ify: wasm => {
|
1315
|
+
wasm.push(Opcodes.i32_to_u);
|
1316
|
+
return wasm;
|
1317
|
+
},
|
1318
|
+
allocPage: (scope, name) => allocPage({ scope, pages }, name)
|
1319
|
+
}, extra);
|
1327
1320
|
|
1328
1321
|
const asmFunc = (name, { wasm, params = [], typedParams = false, locals: localTypes = [], globals: globalTypes = [], globalInits = [], returns = [], returnType, localNames = [], globalNames = [], table = false, constr = false, hasRestArgument = false, usesTag = false, usesImports = false, usedTypes = [] } = {}) => {
|
1329
1322
|
if (wasm == null) { // called with no built-in
|
@@ -1395,9 +1388,8 @@ const includeBuiltin = (scope, builtin) => {
|
|
1395
1388
|
return asmFunc(builtin, builtinFuncs[builtin]);
|
1396
1389
|
};
|
1397
1390
|
|
1398
|
-
const generateLogicExp = (scope, decl) =>
|
1399
|
-
|
1400
|
-
};
|
1391
|
+
const generateLogicExp = (scope, decl) =>
|
1392
|
+
performLogicOp(scope, decl.operator, generate(scope, decl.left), generate(scope, decl.right), getNodeType(scope, decl.left), getNodeType(scope, decl.right));
|
1401
1393
|
|
1402
1394
|
const isExistingProtoFunc = name => {
|
1403
1395
|
if (name.startsWith('__Array_prototype')) return !!prototypeFuncs[TYPES.array][name.slice(18)];
|
@@ -2452,7 +2444,6 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
2452
2444
|
idx = importedFuncs[name];
|
2453
2445
|
scope.usesImports = true;
|
2454
2446
|
} else if (Object.hasOwn(builtinFuncs, name)) {
|
2455
|
-
if (builtinFuncs[name].floatOnly && valtype !== 'f64') throw new Error(`Cannot use built-in ${unhackName(name)} with integer valtype`);
|
2456
2447
|
if (decl._new && !builtinFuncs[name].constr) return internalThrow(scope, 'TypeError', `${unhackName(name)} is not a constructor`, true);
|
2457
2448
|
|
2458
2449
|
includeBuiltin(scope, name);
|
@@ -3204,7 +3195,7 @@ const setDefaultFuncName = (decl, name) => {
|
|
3204
3195
|
const generateVarDstr = (scope, kind, pattern, init, defaultValue, global) => {
|
3205
3196
|
// statically analyzed ffi dlopen hack to let 2c handle it
|
3206
3197
|
if (init && init.type === 'CallExpression' && init.callee.name === '__Porffor_dlopen') {
|
3207
|
-
if (Prefs.target !== 'native' && !Prefs.native) throw new Error('Porffor.dlopen is only supported for native target (use --native)');
|
3198
|
+
if (Prefs.target !== 'native' && Prefs.target !== 'c' && !Prefs.native) throw new Error('Porffor.dlopen is only supported for native target (use --native)');
|
3208
3199
|
|
3209
3200
|
// disable pgo if using ffi (lol)
|
3210
3201
|
Prefs.pgo = false;
|
@@ -5322,9 +5313,7 @@ const generateTry = (scope, decl) => {
|
|
5322
5313
|
return out;
|
5323
5314
|
};
|
5324
5315
|
|
5325
|
-
const generateEmpty = (scope, decl) =>
|
5326
|
-
return [ number(UNDEFINED) ];
|
5327
|
-
};
|
5316
|
+
const generateEmpty = (scope, decl) => [ number(UNDEFINED) ];
|
5328
5317
|
|
5329
5318
|
const generateMeta = (scope, decl) => {
|
5330
5319
|
if (decl.meta.name === 'new' && decl.property.name === 'target') {
|
@@ -6461,7 +6450,7 @@ const generateFunc = (scope, decl, forceNoExpr = false) => {
|
|
6461
6450
|
index: currentFuncIndex++,
|
6462
6451
|
arrow,
|
6463
6452
|
constr: !arrow && !decl.generator && !decl.async && !decl._method, // constructable
|
6464
|
-
method: decl._method || decl.generator || decl.async, // has this but not constructable
|
6453
|
+
method: !arrow && (decl._method || decl.generator || decl.async), // has this but not constructable
|
6465
6454
|
async: decl.async,
|
6466
6455
|
subclass: decl._subclass, _onlyConstr: decl._onlyConstr, _onlyThisMethod: decl._onlyThisMethod,
|
6467
6456
|
strict: scope.strict || decl.strict,
|
@@ -6540,10 +6529,34 @@ const generateFunc = (scope, decl, forceNoExpr = false) => {
|
|
6540
6529
|
);
|
6541
6530
|
}
|
6542
6531
|
|
6532
|
+
if (typeAnno.type === TYPES.string) {
|
6533
|
+
wasm.push(
|
6534
|
+
[ Opcodes.local_get, func.locals[name].idx + 1 ],
|
6535
|
+
number(TYPES.string, Valtype.i32),
|
6536
|
+
[ Opcodes.i32_ne ],
|
6537
|
+
[ Opcodes.if, Blocktype.void ],
|
6538
|
+
[ Opcodes.local_get, func.locals[name].idx ],
|
6539
|
+
[ Opcodes.f64_convert_i32_s ],
|
6540
|
+
[ Opcodes.local_get, func.locals[name].idx + 1 ],
|
6541
|
+
[ Opcodes.call, includeBuiltin(scope, '__ecma262_ToString').index ],
|
6542
|
+
[ Opcodes.local_set, func.locals[name].idx + 1 ],
|
6543
|
+
Opcodes.i32_trunc_sat_f64_s,
|
6544
|
+
[ Opcodes.local_set, func.locals[name].idx ],
|
6545
|
+
[ Opcodes.local_get, func.locals[name].idx + 1 ],
|
6546
|
+
number(TYPES.bytestring, Valtype.i32),
|
6547
|
+
[ Opcodes.i32_eq ],
|
6548
|
+
[ Opcodes.if, Blocktype.void ],
|
6549
|
+
[ Opcodes.local_get, func.locals[name].idx ],
|
6550
|
+
[ Opcodes.call, includeBuiltin(scope, '__Porffor_bytestringToString').index ],
|
6551
|
+
[ Opcodes.local_set, func.locals[name].idx ],
|
6552
|
+
[ Opcodes.end ],
|
6553
|
+
[ Opcodes.end ]
|
6554
|
+
);
|
6555
|
+
}
|
6556
|
+
|
6543
6557
|
if ([
|
6544
6558
|
TYPES.date, TYPES.number, TYPES.promise, TYPES.symbol, TYPES.function,
|
6545
|
-
TYPES.set, TYPES.map,
|
6546
|
-
TYPES.weakref, TYPES.weakset, TYPES.weakmap,
|
6559
|
+
TYPES.set, TYPES.map, TYPES.weakref, TYPES.weakset, TYPES.weakmap,
|
6547
6560
|
TYPES.arraybuffer, TYPES.sharedarraybuffer, TYPES.dataview
|
6548
6561
|
].includes(typeAnno.type)) {
|
6549
6562
|
let types = [ typeAnno.type ];
|
@@ -6558,8 +6571,6 @@ const generateFunc = (scope, decl, forceNoExpr = false) => {
|
|
6558
6571
|
);
|
6559
6572
|
}
|
6560
6573
|
}
|
6561
|
-
|
6562
|
-
// todo: if string, try converting to it to one
|
6563
6574
|
}
|
6564
6575
|
|
6565
6576
|
if (def) wasm.push(
|
package/foo
ADDED
File without changes
|
package/package.json
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "porffor",
|
3
3
|
"description": "An ahead-of-time JavaScript compiler",
|
4
|
-
"version": "0.56.
|
4
|
+
"version": "0.56.3",
|
5
5
|
"author": "Oliver Medhurst <honk@goose.icu>",
|
6
6
|
"license": "MIT",
|
7
7
|
"scripts": {},
|
8
8
|
"dependencies": {
|
9
|
-
"acorn": "^8.14.
|
9
|
+
"acorn": "^8.14.1",
|
10
10
|
"node-repl-polyfill": "github:CanadaHonk/node-repl-polyfill"
|
11
11
|
},
|
12
12
|
"optionalDependencies": {
|
package/r.cjs
CHANGED
@@ -1,298 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
// otherCache = cache.get(left);
|
15
|
-
// if (!otherCache) cache.set(left, otherCache = new Map());
|
16
|
-
// otherCache.set(right, result);
|
17
|
-
|
18
|
-
// otherCache = cache.get(right);
|
19
|
-
// if (!otherCache) cache.set(right, otherCache = new Map());
|
20
|
-
// otherCache.set(left, result);
|
21
|
-
// }
|
22
|
-
|
23
|
-
// function getCache(cache, left, right) {
|
24
|
-
// var otherCache;
|
25
|
-
// var result;
|
26
|
-
|
27
|
-
// otherCache = cache.get(left);
|
28
|
-
// result = otherCache && otherCache.get(right);
|
29
|
-
// if (result) return result;
|
30
|
-
|
31
|
-
// otherCache = cache.get(right);
|
32
|
-
// result = otherCache && otherCache.get(left);
|
33
|
-
// if (result) return result;
|
34
|
-
|
35
|
-
// return UNKNOWN;
|
36
|
-
// }
|
37
|
-
|
38
|
-
// function cacheComparison(a, b, compare, cache) {
|
39
|
-
// var result = compare(a, b, cache);
|
40
|
-
// if (cache && (result === EQUAL || result === NOT_EQUAL)) {
|
41
|
-
// setCache(cache, a, b, result);
|
42
|
-
// }
|
43
|
-
// return result;
|
44
|
-
// }
|
45
|
-
|
46
|
-
// function isBoxed(value) {
|
47
|
-
// return value instanceof String
|
48
|
-
// || value instanceof Number
|
49
|
-
// || value instanceof Boolean
|
50
|
-
// || value instanceof Symbol;
|
51
|
-
// }
|
52
|
-
|
53
|
-
// function fail() {
|
54
|
-
// return NOT_EQUAL;
|
55
|
-
// }
|
56
|
-
|
57
|
-
// function compareIf(a, b, test, compare, cache) {
|
58
|
-
// return !test(a)
|
59
|
-
// ? !test(b) ? UNKNOWN : NOT_EQUAL
|
60
|
-
// : !test(b) ? NOT_EQUAL : cacheComparison(a, b, compare, cache);
|
61
|
-
// }
|
62
|
-
|
63
|
-
// function compareEquality(a, b, cache) {
|
64
|
-
// return compareIf(a, b, isOptional, compareOptionality)
|
65
|
-
// || compareIf(a, b, isPrimitiveEquatable, comparePrimitiveEquality)
|
66
|
-
// || compareIf(a, b, isObjectEquatable, compareObjectEquality, cache)
|
67
|
-
// || NOT_EQUAL;
|
68
|
-
// }
|
69
|
-
|
70
|
-
// function tryCompareStrictEquality(a, b) {
|
71
|
-
// return a === b ? EQUAL : UNKNOWN;
|
72
|
-
// }
|
73
|
-
|
74
|
-
// function tryCompareTypeOfEquality(a, b) {
|
75
|
-
// return typeof a !== typeof b ? NOT_EQUAL : UNKNOWN;
|
76
|
-
// }
|
77
|
-
|
78
|
-
// function tryCompareToStringTagEquality(a, b) {
|
79
|
-
// var aTag = Symbol.toStringTag in a ? a[Symbol.toStringTag] : undefined;
|
80
|
-
// var bTag = Symbol.toStringTag in b ? b[Symbol.toStringTag] : undefined;
|
81
|
-
// return aTag !== bTag ? NOT_EQUAL : UNKNOWN;
|
82
|
-
// }
|
83
|
-
|
84
|
-
// function isOptional(value) {
|
85
|
-
// return value === undefined
|
86
|
-
// || value === null;
|
87
|
-
// }
|
88
|
-
|
89
|
-
// function compareOptionality(a, b) {
|
90
|
-
// return tryCompareStrictEquality(a, b)
|
91
|
-
// || NOT_EQUAL;
|
92
|
-
// }
|
93
|
-
|
94
|
-
// function isPrimitiveEquatable(value) {
|
95
|
-
// switch (typeof value) {
|
96
|
-
// case 'string':
|
97
|
-
// case 'number':
|
98
|
-
// case 'boolean':
|
99
|
-
// case 'symbol':
|
100
|
-
// return true;
|
101
|
-
// default:
|
102
|
-
// return isBoxed(value);
|
103
|
-
// }
|
104
|
-
// }
|
105
|
-
|
106
|
-
// function comparePrimitiveEquality(a, b) {
|
107
|
-
// if (isBoxed(a)) a = a.valueOf();
|
108
|
-
// if (isBoxed(b)) b = b.valueOf();
|
109
|
-
|
110
|
-
// return tryCompareStrictEquality(a, b)
|
111
|
-
// || tryCompareTypeOfEquality(a, b)
|
112
|
-
// || compareIf(a, b, isNaNEquatable, compareNaNEquality)
|
113
|
-
// || NOT_EQUAL;
|
114
|
-
// }
|
115
|
-
|
116
|
-
// function isNaNEquatable(value) {
|
117
|
-
// return typeof value === 'number';
|
118
|
-
// }
|
119
|
-
|
120
|
-
// function compareNaNEquality(a, b) {
|
121
|
-
// return isNaN(a) && isNaN(b) ? EQUAL : NOT_EQUAL;
|
122
|
-
// }
|
123
|
-
|
124
|
-
// function isObjectEquatable(value) {
|
125
|
-
// return typeof value === 'object';
|
126
|
-
// }
|
127
|
-
|
128
|
-
// function compareObjectEquality(a, b, cache) {
|
129
|
-
// if (!cache) cache = new Map();
|
130
|
-
|
131
|
-
// return getCache(cache, a, b)
|
132
|
-
// || setCache(cache, a, b, EQUAL) // consider equal for now
|
133
|
-
// || cacheComparison(a, b, tryCompareStrictEquality, cache)
|
134
|
-
// || cacheComparison(a, b, tryCompareToStringTagEquality, cache)
|
135
|
-
// || compareIf(a, b, isValueOfEquatable, compareValueOfEquality)
|
136
|
-
// || compareIf(a, b, isToStringEquatable, compareToStringEquality)
|
137
|
-
// || compareIf(a, b, isArrayLikeEquatable, compareArrayLikeEquality, cache)
|
138
|
-
// || compareIf(a, b, isStructurallyEquatable, compareStructuralEquality, cache)
|
139
|
-
// || compareIf(a, b, isIterableEquatable, compareIterableEquality, cache)
|
140
|
-
// || cacheComparison(a, b, fail, cache);
|
141
|
-
// }
|
142
|
-
|
143
|
-
// function isValueOfEquatable(value) {
|
144
|
-
// return value instanceof Date;
|
145
|
-
// }
|
146
|
-
|
147
|
-
// function compareValueOfEquality(a, b) {
|
148
|
-
// return compareIf(a.valueOf(), b.valueOf(), isPrimitiveEquatable, comparePrimitiveEquality)
|
149
|
-
// || NOT_EQUAL;
|
150
|
-
// }
|
151
|
-
|
152
|
-
// function isToStringEquatable(value) {
|
153
|
-
// return value instanceof RegExp;
|
154
|
-
// }
|
155
|
-
|
156
|
-
// function compareToStringEquality(a, b) {
|
157
|
-
// return compareIf(a.toString(), b.toString(), isPrimitiveEquatable, comparePrimitiveEquality)
|
158
|
-
// || NOT_EQUAL;
|
159
|
-
// }
|
160
|
-
|
161
|
-
// function isArrayLikeEquatable(value) {
|
162
|
-
// return Array.isArray(value)
|
163
|
-
// || value instanceof Uint8Array
|
164
|
-
// || value instanceof Uint8ClampedArray
|
165
|
-
// || value instanceof Uint16Array
|
166
|
-
// || value instanceof Uint32Array
|
167
|
-
// || value instanceof Int8Array
|
168
|
-
// || value instanceof Int16Array
|
169
|
-
// || value instanceof Int32Array
|
170
|
-
// || value instanceof Float32Array
|
171
|
-
// || value instanceof Float64Array;
|
172
|
-
// }
|
173
|
-
|
174
|
-
// function compareArrayLikeEquality(a, b, cache) {
|
175
|
-
// if (a.length !== b.length) return NOT_EQUAL;
|
176
|
-
// for (var i = 0; i < a.length; i++) {
|
177
|
-
// if (compareEquality(a[i], b[i], cache) === NOT_EQUAL) {
|
178
|
-
// return NOT_EQUAL;
|
179
|
-
// }
|
180
|
-
// }
|
181
|
-
// return EQUAL;
|
182
|
-
// }
|
183
|
-
|
184
|
-
// function isStructurallyEquatable(value) {
|
185
|
-
// return !(value instanceof Promise // only comparable by reference
|
186
|
-
// || value instanceof WeakMap // only comparable by reference
|
187
|
-
// || value instanceof WeakSet // only comparable by reference
|
188
|
-
// || value instanceof Map // comparable via @@iterator
|
189
|
-
// || value instanceof Set); // comparable via @@iterator
|
190
|
-
// }
|
191
|
-
|
192
|
-
// function compareStructuralEquality(a, b, cache) {
|
193
|
-
// var aKeys = [];
|
194
|
-
// for (var key in a) aKeys.push(key);
|
195
|
-
|
196
|
-
// var bKeys = [];
|
197
|
-
// for (var key in b) bKeys.push(key);
|
198
|
-
|
199
|
-
// if (aKeys.length !== bKeys.length) {
|
200
|
-
// return NOT_EQUAL;
|
201
|
-
// }
|
202
|
-
|
203
|
-
// aKeys.sort();
|
204
|
-
// bKeys.sort();
|
205
|
-
|
206
|
-
// for (var i = 0; i < aKeys.length; i++) {
|
207
|
-
// var aKey = aKeys[i];
|
208
|
-
// var bKey = bKeys[i];
|
209
|
-
// if (compareEquality(aKey, bKey, cache) === NOT_EQUAL) {
|
210
|
-
// return NOT_EQUAL;
|
211
|
-
// }
|
212
|
-
// if (compareEquality(a[aKey], b[bKey], cache) === NOT_EQUAL) {
|
213
|
-
// return NOT_EQUAL;
|
214
|
-
// }
|
215
|
-
// }
|
216
|
-
|
217
|
-
// return EQUAL;
|
218
|
-
// }
|
219
|
-
|
220
|
-
// // hack: do iterables via for..of
|
221
|
-
// function isIterableEquatable(value) {
|
222
|
-
// try {
|
223
|
-
// for (const _ of value) { break; }
|
224
|
-
// return true;
|
225
|
-
// } catch {
|
226
|
-
// return false;
|
227
|
-
// }
|
228
|
-
// }
|
229
|
-
|
230
|
-
// function compareIterableEquality(a, b, cache) {
|
231
|
-
// let aValues = [];
|
232
|
-
// for (const x of a) aValues.push(x);
|
233
|
-
|
234
|
-
// let bValues = [];
|
235
|
-
// for (const x of b) bValues.push(x);
|
236
|
-
|
237
|
-
// return compareArrayLikeEquality(aValues, bValues, cache);
|
238
|
-
// }
|
239
|
-
|
240
|
-
// var __assert_deepEqual__compare = (a, b) => {
|
241
|
-
// return compareEquality(a, b) === EQUAL;
|
242
|
-
// };
|
243
|
-
|
244
|
-
// var __assert_deepEqual = (actual, expected) => {
|
245
|
-
// if (!assert.deepEqual._compare(actual, expected)) {
|
246
|
-
// throw new Test262Error('assert.deepEqual failed');
|
247
|
-
// }
|
248
|
-
// };
|
249
|
-
|
250
|
-
// __assert_deepEqual([], []);
|
251
|
-
|
252
|
-
// let x = {};
|
253
|
-
// x.__proto__ = { wow() { console.log(0); } };
|
254
|
-
// Object.defineProperty(x, '__proto__', { value: { wow() { console.log(1); } } });
|
255
|
-
// // x.__proto__ = { wow() { console.log(2); } };
|
256
|
-
// x.wow();
|
257
|
-
|
258
|
-
// var stringSet;
|
259
|
-
|
260
|
-
// class C {
|
261
|
-
// get #_() { console.log('get'); return 'get string'; }
|
262
|
-
// set #_(param) { console.log('set', param); stringSet = param; }
|
263
|
-
|
264
|
-
// getPrivateReference() {
|
265
|
-
// return this.#_;
|
266
|
-
// }
|
267
|
-
|
268
|
-
// setPrivateReference(value) {
|
269
|
-
// this.#_ = value;
|
270
|
-
// }
|
271
|
-
// };
|
272
|
-
|
273
|
-
// var inst = new C();
|
274
|
-
// console.log(inst.getPrivateReference());
|
275
|
-
// inst.setPrivateReference('set string');
|
276
|
-
// console.log(stringSet);
|
277
|
-
|
278
|
-
// let o = { set foo(x) { console.log('set foo', x); }, __proto__: { set bar(x) { console.log('set bar', x); } } };
|
279
|
-
|
280
|
-
// o.foo = 1;
|
281
|
-
// o.bar = 2;
|
282
|
-
|
283
|
-
// class C {
|
284
|
-
// // static #method = () => 1;
|
285
|
-
// static #method() {
|
286
|
-
// return 'Test262';
|
287
|
-
// }
|
288
|
-
|
289
|
-
// static getPrivateMethod() {
|
290
|
-
// this.#method = () => 2;
|
291
|
-
// return this.#method();
|
292
|
-
// }
|
293
|
-
// }
|
294
|
-
|
295
|
-
// console.log(C.getPrivateMethod())
|
1
|
+
class C {
|
2
|
+
// static #method = () => 1;
|
3
|
+
static #method() {
|
4
|
+
return 'Test262';
|
5
|
+
}
|
6
|
+
|
7
|
+
static getPrivateMethod() {
|
8
|
+
this.#method = () => 2;
|
9
|
+
return this.#method();
|
10
|
+
}
|
11
|
+
}
|
12
|
+
|
13
|
+
console.log(C.getPrivateMethod())
|
296
14
|
|
297
15
|
// var __assert_throws = (expectedErrorConstructor, func) => {
|
298
16
|
// if (typeof func !== 'function') {
|