diff --git a/test/built-ins/ShadowRealm/prototype/evaluate/errors-from-the-other-realm-is-wrapped-into-a-typeerror.js b/test/built-ins/ShadowRealm/prototype/evaluate/errors-from-the-other-realm-is-wrapped-into-a-typeerror.js index fa5367a4d72..75171ffb5bb 100644 --- a/test/built-ins/ShadowRealm/prototype/evaluate/errors-from-the-other-realm-is-wrapped-into-a-typeerror.js +++ b/test/built-ins/ShadowRealm/prototype/evaluate/errors-from-the-other-realm-is-wrapped-into-a-typeerror.js @@ -19,3 +19,8 @@ assert.throws(SyntaxError, () => r.evaluate('...'), 'SyntaxError exposed to Pare assert.throws(TypeError, () => r.evaluate('throw 42'), 'throw primitive => TypeError'); assert.throws(TypeError, () => r.evaluate('throw new ReferenceError("aaa")'), 'custom ctor => TypeError'); assert.throws(TypeError, () => r.evaluate('throw new TypeError("aaa")'), 'Child TypeError => Parent TypeError'); +assert.throws(TypeError, () => r.evaluate('eval("...");'), 'syntaxerror parsing coming after runtime evaluation'); +assert.throws(TypeError, () => r.evaluate(` + 'use strict'; + eval("var public = 1;"); +`), 'strict-mode only syntaxerror parsing coming after runtime evaluation'); diff --git a/test/built-ins/ShadowRealm/prototype/evaluate/no-conditional-strict-mode.js b/test/built-ins/ShadowRealm/prototype/evaluate/no-conditional-strict-mode.js new file mode 100644 index 00000000000..252b0b68650 --- /dev/null +++ b/test/built-ins/ShadowRealm/prototype/evaluate/no-conditional-strict-mode.js @@ -0,0 +1,34 @@ +// Copyright (C) 2021 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-shadowrealm.prototype.evaluate +description: > + The new realm has no conditional strict mode based on its outer realm +info: | + This test should always run with the outer realm in both strict and non + strict mode to verify the realm code starts in non-strict mode. +features: [ShadowRealm] +---*/ + +assert.sameValue( + typeof ShadowRealm.prototype.evaluate, + 'function', + 'This test must fail if ShadowRealm.prototype.evaluate is not a function' +); + +const r = new ShadowRealm(); + +const res = r.evaluate(` + function lol() { + arguments = 42; // This would be a SyntaxError if in strict mode + + return arguments; + } + lol; +`); + +assert.sameValue(res(), 42); + +const res2 = r.evaluate('var public = 1; 42'); + +assert.sameValue(res2, 42); diff --git a/test/built-ins/ShadowRealm/prototype/evaluate/throws-syntaxerror-on-bad-syntax.js b/test/built-ins/ShadowRealm/prototype/evaluate/throws-syntaxerror-on-bad-syntax.js new file mode 100644 index 00000000000..3df0089fccf --- /dev/null +++ b/test/built-ins/ShadowRealm/prototype/evaluate/throws-syntaxerror-on-bad-syntax.js @@ -0,0 +1,30 @@ +// Copyright (C) 2021 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-shadowrealm.prototype.evaluate +description: > + ShadowRealm.prototype.evaluate throws a SyntaxError if the syntax can't be parsed +features: [ShadowRealm] +---*/ + +assert.sameValue( + typeof ShadowRealm.prototype.evaluate, + 'function', + 'This test must fail if ShadowRealm.prototype.evaluate is not a function' +); + +const r = new ShadowRealm(); + +assert.throws(SyntaxError, () => r.evaluate('...'), 'SyntaxError exposed to Parent'); +assert.throws(SyntaxError, () => r.evaluate(` + "use strict"; + throw "do not evaluate"; + function lol(){ + arguments = 1; + } +`), 'Strict mode only SyntaxError, setting value to a fn arguments'); +assert.throws(SyntaxError, () => r.evaluate(` + "use strict"; + throw "do not evaluate"; + var public = 1; +`), 'Strict mode only SyntaxError, var public');