porffor 0.55.12 → 0.55.13
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/codegen.js +27 -17
- package/package.json +1 -1
- package/r.cjs +86 -0
- package/runner/index.js +1 -1
package/compiler/codegen.js
CHANGED
@@ -2037,15 +2037,18 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
2037
2037
|
name = func.name;
|
2038
2038
|
}
|
2039
2039
|
|
2040
|
-
if (!decl._new && name === 'eval') {
|
2040
|
+
if (!decl._new && (name === 'eval' || (decl.callee.type === 'SequenceExpression' && decl.callee.expressions.at(-1)?.name === 'eval'))) {
|
2041
2041
|
const known = knownValue(scope, decl.arguments[0]);
|
2042
2042
|
if (known !== unknownValue) {
|
2043
|
-
// known
|
2043
|
+
// eval('with known/literal string')
|
2044
2044
|
const code = String(known);
|
2045
2045
|
|
2046
2046
|
let parsed;
|
2047
2047
|
try {
|
2048
|
-
parsed =
|
2048
|
+
parsed = {
|
2049
|
+
type: 'BlockStatement',
|
2050
|
+
body: parse(code).body.map(objectHack)
|
2051
|
+
};
|
2049
2052
|
} catch (e) {
|
2050
2053
|
if (e.name === 'SyntaxError') {
|
2051
2054
|
// throw syntax errors of evals at runtime instead
|
@@ -2055,11 +2058,24 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
2055
2058
|
throw e;
|
2056
2059
|
}
|
2057
2060
|
|
2061
|
+
if (decl.callee.type === 'SequenceExpression' || decl.optional) {
|
2062
|
+
// indirect, use separate func+scope
|
2063
|
+
const [ func ] = generateFunc({}, {
|
2064
|
+
type: 'ArrowFunctionExpression',
|
2065
|
+
body: parsed,
|
2066
|
+
expression: true
|
2067
|
+
}, true);
|
2068
|
+
|
2069
|
+
func.generate();
|
2070
|
+
|
2071
|
+
return [
|
2072
|
+
[ Opcodes.call, func.index ],
|
2073
|
+
...setLastType(scope)
|
2074
|
+
];
|
2075
|
+
}
|
2076
|
+
|
2058
2077
|
scope.inEval = true;
|
2059
|
-
const out = generate(scope,
|
2060
|
-
type: 'BlockStatement',
|
2061
|
-
body: parsed.body
|
2062
|
-
});
|
2078
|
+
const out = generate(scope, parsed);
|
2063
2079
|
scope.inEval = false;
|
2064
2080
|
|
2065
2081
|
out.push(...setLastType(scope, getNodeType(scope, getLastNode(parsed.body))));
|
@@ -2070,12 +2086,12 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
2070
2086
|
if (name === 'Function') {
|
2071
2087
|
const known = knownValue(scope, decl.arguments[0]);
|
2072
2088
|
if (known !== unknownValue) {
|
2073
|
-
//
|
2089
|
+
// new Function('with known/literal string')
|
2074
2090
|
const code = String(known);
|
2075
2091
|
|
2076
2092
|
let parsed;
|
2077
2093
|
try {
|
2078
|
-
parsed = parse(`(function(){${code}})`);
|
2094
|
+
parsed = objectHack(parse(`(function(){${code}})`));
|
2079
2095
|
} catch (e) {
|
2080
2096
|
if (e.name === 'SyntaxError') {
|
2081
2097
|
// throw syntax errors of evals at runtime instead
|
@@ -3512,12 +3528,7 @@ const generateVar = (scope, decl) => {
|
|
3512
3528
|
return out;
|
3513
3529
|
};
|
3514
3530
|
|
3515
|
-
const privateIDName = name => '
|
3516
|
-
const privateIdentifierToIdentifier = decl => ({
|
3517
|
-
type: 'Identifier',
|
3518
|
-
name: privateIDName(decl.name)
|
3519
|
-
});
|
3520
|
-
|
3531
|
+
const privateIDName = name => '__#' + name;
|
3521
3532
|
const getProperty = (decl, forceValueStr = false) => {
|
3522
3533
|
const prop = decl.property ?? decl.key;
|
3523
3534
|
if (decl.computed) return prop;
|
@@ -6489,8 +6500,7 @@ const generateFunc = (scope, decl, forceNoExpr = false) => {
|
|
6489
6500
|
start: decl.start,
|
6490
6501
|
locals: {},
|
6491
6502
|
localInd: 0,
|
6492
|
-
// value, type
|
6493
|
-
returns: [ valtypeBinary, Valtype.i32 ],
|
6503
|
+
returns: [ valtypeBinary, Valtype.i32 ], // value, type
|
6494
6504
|
name,
|
6495
6505
|
index: currentFuncIndex++,
|
6496
6506
|
arrow,
|
package/package.json
CHANGED
package/r.cjs
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
// 'use strict';
|
2
|
+
function foo() {
|
3
|
+
'use strict';
|
4
|
+
console.log(this);
|
5
|
+
eval('console.log(this)');
|
6
|
+
(0, eval)('console.log(this)');
|
7
|
+
eval?.('console.log(this)');
|
8
|
+
}
|
9
|
+
|
10
|
+
foo();
|
11
|
+
|
12
|
+
// let o = { set foo(x) { console.log('set foo', x); }, __proto__: { set bar(x) { console.log('set bar', x); } } };
|
13
|
+
|
14
|
+
// o.foo = 1;
|
15
|
+
// o.bar = 2;
|
16
|
+
|
17
|
+
// class C {
|
18
|
+
// // static #method = () => 1;
|
19
|
+
// static #method() {
|
20
|
+
// return 'Test262';
|
21
|
+
// }
|
22
|
+
|
23
|
+
// static getPrivateMethod() {
|
24
|
+
// this.#method = () => 2;
|
25
|
+
// return this.#method();
|
26
|
+
// }
|
27
|
+
// }
|
28
|
+
|
29
|
+
// console.log(C.getPrivateMethod())
|
30
|
+
|
31
|
+
// var __assert_throws = (expectedErrorConstructor, func) => {
|
32
|
+
// if (typeof func !== 'function') {
|
33
|
+
// throw new Test262Error('assert.throws invoked with a non-function value');
|
34
|
+
// }
|
35
|
+
|
36
|
+
// try {
|
37
|
+
// func();
|
38
|
+
// } catch {
|
39
|
+
// return;
|
40
|
+
// }
|
41
|
+
|
42
|
+
// throw new Test262Error('assert.throws failed');
|
43
|
+
// };
|
44
|
+
|
45
|
+
// var __assert__isSameValue = (a, b) => {
|
46
|
+
// if (a === b) {
|
47
|
+
// // Handle +/-0 vs. -/+0
|
48
|
+
// return a !== 0 || 1 / a === 1 / b;
|
49
|
+
// }
|
50
|
+
|
51
|
+
// // Handle NaN vs. NaN
|
52
|
+
// return a !== a && b !== b;
|
53
|
+
// };
|
54
|
+
|
55
|
+
// var __assert_sameValue = (actual, expected) => {
|
56
|
+
// if (__assert__isSameValue(actual, expected)) {
|
57
|
+
// return;
|
58
|
+
// }
|
59
|
+
|
60
|
+
// throw new Test262Error('assert.sameValue failed');
|
61
|
+
// };
|
62
|
+
|
63
|
+
// (function() {
|
64
|
+
// eval(
|
65
|
+
// '__assert_throws(ReferenceError, function() {\
|
66
|
+
// f;\
|
67
|
+
// }, "An initialized binding is not created prior to evaluation");\
|
68
|
+
// __assert_sameValue(\
|
69
|
+
// typeof f,\
|
70
|
+
// "undefined",\
|
71
|
+
// "An uninitialized binding is not created prior to evaluation"\
|
72
|
+
// );\
|
73
|
+
// \
|
74
|
+
// {\
|
75
|
+
// let f = 123;if (false) ; else function f() { }}\
|
76
|
+
// \
|
77
|
+
// __assert_throws(ReferenceError, function() {\
|
78
|
+
// f;\
|
79
|
+
// }, "An initialized binding is not created following evaluation");\
|
80
|
+
// __assert_sameValue(\
|
81
|
+
// typeof f,\
|
82
|
+
// "undefined",\
|
83
|
+
// "An uninitialized binding is not created following evaluation"\
|
84
|
+
// );'
|
85
|
+
// );
|
86
|
+
// }());
|