Skip to content

Commit c6277e1

Browse files
committed
Handle strict mode better in direct eval.
1 parent f016da1 commit c6277e1

3 files changed

Lines changed: 31 additions & 34 deletions

File tree

rhino/src/main/java/org/mozilla/javascript/NativeGlobal.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ private static Object js_unescape(
459459
private static Object js_eval(
460460
Context cx, JSFunction f, Object nt, VarScope s, Object thisObj, Object[] args) {
461461
TopLevel top = ScriptableObject.getTopLevelScope(f.getDeclarationScope());
462-
return ScriptRuntime.evalSpecial(cx, top, top.getGlobalThis(), args, "eval code", 1);
462+
return ScriptRuntime.evalSpecial(cx, top, top.getGlobalThis(), args, "eval code", 1, false);
463463
}
464464

465465
/**

rhino/src/main/java/org/mozilla/javascript/ScriptRuntime.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3471,7 +3471,8 @@ public static Object callSpecial(
34713471

34723472
if (callType == Node.SPECIALCALL_EVAL) {
34733473
if (thisObj.getParentScope() == null && NativeGlobal.isEvalFunction(fun)) {
3474-
return evalSpecial(cx, scope, callerThis, args, filename, lineNumber);
3474+
return evalSpecial(
3475+
cx, scope, callerThis, args, filename, lineNumber, cx.isStrictMode());
34753476
}
34763477
} else {
34773478
throw Kit.codeBug();
@@ -3602,7 +3603,8 @@ public static Object evalSpecial(
36023603
Object thisArg,
36033604
Object[] args,
36043605
String filename,
3605-
int lineNumber) {
3606+
int lineNumber,
3607+
boolean isStrict) {
36063608
if (args.length < 1) return Undefined.instance;
36073609
Object x = args[0];
36083610
if (!(x instanceof CharSequence)) {
@@ -3666,7 +3668,14 @@ public static Object evalSpecial(
36663668
thisArg == Undefined.instance
36673669
? Undefined.SCRIPTABLE_UNDEFINED
36683670
: (Scriptable) thisArg;
3669-
return script.exec(cx, scope, thisObject);
3671+
VarScope evalScope;
3672+
if (isStrict
3673+
|| (script instanceof JSScript && ((JSScript) script).getDescriptor().isStrict())) {
3674+
evalScope = new ScopeObject(scope);
3675+
} else {
3676+
evalScope = scope;
3677+
}
3678+
return script.exec(cx, evalScope, thisObject);
36703679
}
36713680

36723681
/** The typeof operator */

tests/testsrc/test262.properties

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3509,7 +3509,7 @@ language/directive-prologue 2/62 (3.23%)
35093509
14.1-4-s.js non-strict
35103510
14.1-5-s.js non-strict
35113511

3512-
language/eval-code 239/347 (68.88%)
3512+
language/eval-code 227/347 (65.42%)
35133513
direct/arrow-fn-a-following-parameter-is-named-arguments-arrow-func-declare-arguments-assign.js non-strict
35143514
direct/arrow-fn-a-following-parameter-is-named-arguments-arrow-func-declare-arguments-assign-incl-def-param-arrow-arguments.js non-strict
35153515
direct/arrow-fn-a-preceding-parameter-is-named-arguments-arrow-func-declare-arguments-assign.js non-strict
@@ -3614,9 +3614,6 @@ language/eval-code 239/347 (68.88%)
36143614
direct/async-meth-fn-body-cntns-arguments-var-bind-declare-arguments-and-assign.js {unsupported: [async]}
36153615
direct/async-meth-no-pre-existing-arguments-bindings-are-present-declare-arguments.js {unsupported: [async]}
36163616
direct/async-meth-no-pre-existing-arguments-bindings-are-present-declare-arguments-and-assign.js {unsupported: [async]}
3617-
direct/block-decl-eval-source-is-strict-nostrict.js non-strict
3618-
direct/block-decl-eval-source-is-strict-onlystrict.js strict
3619-
direct/block-decl-onlystrict.js strict
36203617
direct/export.js {unsupported: [module]}
36213618
direct/func-decl-a-following-parameter-is-named-arguments-declare-arguments.js non-strict
36223619
direct/func-decl-a-following-parameter-is-named-arguments-declare-arguments-and-assign.js non-strict
@@ -3692,8 +3689,8 @@ language/eval-code 239/347 (68.88%)
36923689
direct/gen-meth-no-pre-existing-arguments-bindings-are-present-declare-arguments-and-assign.js non-strict
36933690
direct/import.js {unsupported: [module]}
36943691
direct/lex-env-distinct-cls.js {unsupported: [class]}
3695-
direct/lex-env-distinct-const.js
3696-
direct/lex-env-distinct-let.js
3692+
direct/lex-env-distinct-const.js non-strict
3693+
direct/lex-env-distinct-let.js non-strict
36973694
direct/lex-env-no-init-cls.js {unsupported: [class]}
36983695
direct/lex-env-no-init-const.js
36993696
direct/lex-env-no-init-let.js
@@ -3713,42 +3710,33 @@ language/eval-code 239/347 (68.88%)
37133710
direct/new.target-arrow.js {unsupported: [new.target]}
37143711
direct/new.target-fn.js {unsupported: [new.target]}
37153712
direct/non-definable-global-var.js non-strict
3716-
direct/switch-case-decl-eval-source-is-strict-nostrict.js non-strict
3717-
direct/switch-case-decl-eval-source-is-strict-onlystrict.js strict
3718-
direct/switch-case-decl-onlystrict.js strict
3719-
direct/switch-dflt-decl-eval-source-is-strict-nostrict.js non-strict
3720-
direct/switch-dflt-decl-eval-source-is-strict-onlystrict.js strict
3721-
direct/switch-dflt-decl-onlystrict.js strict
37223713
direct/var-env-func-init-global-update-configurable.js non-strict
3723-
direct/var-env-func-strict-caller.js strict
3724-
direct/var-env-func-strict-caller-2.js strict
3725-
direct/var-env-func-strict-source.js
37263714
direct/var-env-global-lex-non-strict.js non-strict
37273715
direct/var-env-lower-lex-non-strict.js non-strict
3728-
direct/var-env-var-strict-caller.js strict
3729-
direct/var-env-var-strict-caller-2.js strict
3730-
direct/var-env-var-strict-caller-3.js strict
3731-
direct/var-env-var-strict-source.js
37323716
indirect/always-non-strict.js strict
3733-
indirect/block-decl-strict.js
37343717
indirect/export.js {unsupported: [module]}
37353718
indirect/import.js {unsupported: [module]}
37363719
indirect/lex-env-distinct-cls.js {unsupported: [class]}
3737-
indirect/lex-env-distinct-const.js
3738-
indirect/lex-env-distinct-let.js
3720+
indirect/lex-env-distinct-const.js non-strict
3721+
indirect/lex-env-distinct-let.js non-strict
37393722
indirect/lex-env-no-init-cls.js {unsupported: [class]}
37403723
indirect/lex-env-no-init-const.js
37413724
indirect/lex-env-no-init-let.js
37423725
indirect/new.target.js {unsupported: [new.target]}
3743-
indirect/non-definable-function-with-function.js
3744-
indirect/non-definable-function-with-variable.js
3745-
indirect/non-definable-global-var.js non-strict
3746-
indirect/switch-case-decl-strict.js
3747-
indirect/switch-dflt-decl-strict.js
3726+
indirect/non-definable-function-with-function.js non-strict
3727+
indirect/non-definable-function-with-variable.js non-strict
3728+
indirect/non-definable-global-function.js strict
3729+
indirect/non-definable-global-generator.js strict
3730+
indirect/non-definable-global-var.js
3731+
indirect/realm.js strict
3732+
indirect/var-env-func-init-global-new.js strict
37483733
indirect/var-env-func-init-global-update-configurable.js
3749-
indirect/var-env-func-strict.js
3734+
indirect/var-env-func-init-multi.js strict
3735+
indirect/var-env-func-non-strict.js strict
37503736
indirect/var-env-global-lex-non-strict.js
3751-
indirect/var-env-var-strict.js
3737+
indirect/var-env-var-init-global-exstng.js strict
3738+
indirect/var-env-var-init-global-new.js strict
3739+
indirect/var-env-var-non-strict.js strict
37523740

37533741
~language/export 3/3 (100.0%)
37543742

@@ -5390,7 +5378,7 @@ language/global-code 26/42 (61.9%)
53905378
script-decl-lex-lex.js
53915379
script-decl-lex-restricted-global.js
53925380
script-decl-lex-var.js
5393-
script-decl-lex-var-declared-via-eval.js
5381+
script-decl-lex-var-declared-via-eval.js non-strict
53945382
script-decl-var.js
53955383
script-decl-var-collision.js
53965384
script-decl-var-err.js non-strict

0 commit comments

Comments
 (0)