diff options
Diffstat (limited to 'js/src/tests/test262/language/eval-code/indirect')
63 files changed, 1641 insertions, 0 deletions
diff --git a/js/src/tests/test262/language/eval-code/indirect/always-non-strict-strict.js b/js/src/tests/test262/language/eval-code/indirect/always-non-strict-strict.js new file mode 100644 index 0000000000..96d8424b61 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/always-non-strict-strict.js @@ -0,0 +1,28 @@ +'use strict'; +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Strictness of direct eval is not dependent on strictness of caller +esid: sec-strict-mode-code +info: | + Eval code is strict mode code if it begins with a Directive Prologue that + contains a Use Strict Directive or if the call to eval is a direct eval + that is contained in strict mode code. +flags: [onlyStrict] +---*/ + +var count = 0; + +(0,eval)('var static; count += 1;'); + +assert.sameValue(count, 1); + +(0,eval)('with ({}) {} count += 1;'); + +assert.sameValue(count, 2); + +(0,eval)('unresolvable = null; count += 1;'); + +assert.sameValue(count, 3); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/block-decl-strict.js b/js/src/tests/test262/language/eval-code/indirect/block-decl-strict.js new file mode 100644 index 0000000000..f2adc904d4 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/block-decl-strict.js @@ -0,0 +1,26 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: AnnexB extension not honored in strict mode +es6id: B.3.3.2 +info: | + Block statement in eval code containing a function declaration + + B.3.3.3 Changes to EvalDeclarationInstantiation + + 1. If strict is false, then +---*/ + +var err; + +(0,eval)('"use strict";{ function f() {} }'); + +try { + f; +} catch (exception) { + err = exception; +} + +assert.sameValue(err.constructor, ReferenceError); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/browser.js b/js/src/tests/test262/language/eval-code/indirect/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/browser.js diff --git a/js/src/tests/test262/language/eval-code/indirect/cptn-nrml-empty-block.js b/js/src/tests/test262/language/eval-code/indirect/cptn-nrml-empty-block.js new file mode 100644 index 0000000000..c4d7ac885c --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/cptn-nrml-empty-block.js @@ -0,0 +1,14 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +info: | + If Result(3).type is normal and its completion value is empty, then return + the value undefined +esid: sec-performeval +es5id: 15.1.2.1_A3.2_T1 +description: Block statement +---*/ + +assert.sameValue((0,eval)("{}"), undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/cptn-nrml-empty-do-while.js b/js/src/tests/test262/language/eval-code/indirect/cptn-nrml-empty-do-while.js new file mode 100644 index 0000000000..c0fa9f8f24 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/cptn-nrml-empty-do-while.js @@ -0,0 +1,14 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +info: | + If Result(3).type is normal and its completion value is empty, + then return the value undefined +esid: sec-performeval +es5id: 15.1.2.1_A3.2_T6 +description: do-while statement +---*/ + +assert.sameValue((0,eval)("do ; while(false)"), undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/cptn-nrml-empty-empty.js b/js/src/tests/test262/language/eval-code/indirect/cptn-nrml-empty-empty.js new file mode 100644 index 0000000000..9bc0b415d6 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/cptn-nrml-empty-empty.js @@ -0,0 +1,14 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +info: | + If Result(3).type is normal and its completion value is empty, + then return the value undefined +esid: sec-performeval +es5id: 15.1.2.1_A3.2_T3 +description: Empty statement +---*/ + +assert.sameValue((0,eval)(";"), undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/cptn-nrml-empty-for.js b/js/src/tests/test262/language/eval-code/indirect/cptn-nrml-empty-for.js new file mode 100644 index 0000000000..c864cbee0a --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/cptn-nrml-empty-for.js @@ -0,0 +1,14 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +info: | + If Result(3).type is normal and its completion value is empty, + then return the value undefined +esid: sec-performeval +es5id: 15.1.2.1_A3.2_T8 +description: for statement +---*/ + +assert.sameValue((0,eval)("for(false;false;false);"), undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/cptn-nrml-empty-if.js b/js/src/tests/test262/language/eval-code/indirect/cptn-nrml-empty-if.js new file mode 100644 index 0000000000..3e7cba8a73 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/cptn-nrml-empty-if.js @@ -0,0 +1,14 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +info: | + If Result(3).type is normal and its completion value is empty, + then return the value undefined +esid: sec-performeval +es5id: 15.1.2.1_A3.2_T4 +description: If statement +---*/ + +assert.sameValue((0,eval)("if (false) ;"), undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/cptn-nrml-empty-switch.js b/js/src/tests/test262/language/eval-code/indirect/cptn-nrml-empty-switch.js new file mode 100644 index 0000000000..b8ada36f5d --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/cptn-nrml-empty-switch.js @@ -0,0 +1,14 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +info: | + If Result(3).type is normal and its completion value is empty, + then return the value undefined +esid: sec-performeval +es5id: 15.1.2.1_A3.2_T5 +description: Switch statement +---*/ + +assert.sameValue((0,eval)("switch(1){}"), undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/cptn-nrml-empty-var.js b/js/src/tests/test262/language/eval-code/indirect/cptn-nrml-empty-var.js new file mode 100644 index 0000000000..0af364f670 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/cptn-nrml-empty-var.js @@ -0,0 +1,14 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +info: | + If Result(3).type is normal and its completion value is empty, + then return the value undefined +esid: sec-performeval +es5id: 15.1.2.1_A3.2_T2 +description: Var statement +---*/ + +assert.sameValue((0,eval)("var x = 1"), undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/cptn-nrml-empty-while.js b/js/src/tests/test262/language/eval-code/indirect/cptn-nrml-empty-while.js new file mode 100644 index 0000000000..1218e74bac --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/cptn-nrml-empty-while.js @@ -0,0 +1,14 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +info: | + If Result(3).type is normal and its completion value is empty, + then return the value undefined +esid: sec-performeval +es5id: 15.1.2.1_A3.2_T7 +description: while statement +---*/ + +assert.sameValue((0,eval)("while(false);"), undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/cptn-nrml-expr-obj.js b/js/src/tests/test262/language/eval-code/indirect/cptn-nrml-expr-obj.js new file mode 100644 index 0000000000..5612fd8e74 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/cptn-nrml-expr-obj.js @@ -0,0 +1,19 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +info: | + If Result(3).type is normal and its completion value is a value V, + then return the value V +esid: sec-performeval +es5id: 15.1.2.1_A3.1_T2 +description: Expression statement. Eval return object value +---*/ + +var x = {}; +var y; + +assert.sameValue((0,eval)("y = x"), x, 'AssignmentExpression'); + +assert.sameValue((0,eval)("x"), x, 'IdentifierReference'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/cptn-nrml-expr-prim.js b/js/src/tests/test262/language/eval-code/indirect/cptn-nrml-expr-prim.js new file mode 100644 index 0000000000..6e2d959349 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/cptn-nrml-expr-prim.js @@ -0,0 +1,22 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +info: | + If Result(3).type is normal and its completion value is a value V, + then return the value V +esid: sec-performeval +es5id: 15.1.2.1_A3.1_T1 +description: Expression statement. Eval return primitive value +---*/ + +var x; +assert.sameValue((0,eval)("x = 1"), 1, 'AssignmentExpression'); + +assert.sameValue((0,eval)("1"), 1, 'NumericLiteral'); + +assert.sameValue((0,eval)("'1'"), '1', 'StringLiteral'); + +x = 1; +assert.sameValue((0,eval)("++x"), 2, 'UpdateExpression'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/export.js b/js/src/tests/test262/language/eval-code/indirect/export.js new file mode 100644 index 0000000000..351c028b81 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/export.js @@ -0,0 +1,27 @@ +// |reftest| module +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: The `export` declaration may not appear within eval code +esid: sec-scripts +flags: [module] +info: | + Eval code is the source text supplied to the built-in eval function. More + precisely, if the parameter to the built-in eval function is a String, it + is treated as an ECMAScript Script. The eval code for a particular + invocation of eval is the global code portion of that Script. + + A.5 Scripts and Modules + + Script: + ScriptBodyopt + + ScriptBody: + StatementList +---*/ + +assert.throws(SyntaxError, function() { + (0,eval)('export default null;'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/global-env-rec-catch.js b/js/src/tests/test262/language/eval-code/indirect/global-env-rec-catch.js new file mode 100644 index 0000000000..805bc933a3 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/global-env-rec-catch.js @@ -0,0 +1,24 @@ +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es5id: 10.4.2-1-3 +description: > + Indirect call to eval has context set to global context (catch + block) +---*/ + +var __10_4_2_1_3 = "str"; +function testcase() { + var _eval = eval; + var __10_4_2_1_3 = "str1"; + try { + throw "error"; + } + catch (e) { + var __10_4_2_1_3 = "str2"; + assert(_eval("\'str\' === __10_4_2_1_3"), 'indirect eval'); + } + } +testcase(); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/global-env-rec-eval.js b/js/src/tests/test262/language/eval-code/indirect/global-env-rec-eval.js new file mode 100644 index 0000000000..9d7e908ca4 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/global-env-rec-eval.js @@ -0,0 +1,22 @@ +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es5id: 10.4.2-1-5 +description: > + Indirect call to eval has context set to global context (inside + another eval) +---*/ + +var __10_4_2_1_5 = "str"; +function testcase() { + var __10_4_2_1_5 = "str1"; + var r = eval("\ + var _eval = eval; \ + var __10_4_2_1_5 = \'str2\'; \ + _eval(\"\'str\' === __10_4_2_1_5 \") \ + "); + assert(r); + } +testcase(); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/global-env-rec-fun.js b/js/src/tests/test262/language/eval-code/indirect/global-env-rec-fun.js new file mode 100644 index 0000000000..fb93a149bd --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/global-env-rec-fun.js @@ -0,0 +1,22 @@ +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es5id: 10.4.2-1-2 +description: > + Indirect call to eval has context set to global context (nested + function) +---*/ + +var __10_4_2_1_2 = "str"; +function testcase() { + var _eval = eval; + var __10_4_2_1_2 = "str1"; + function foo() { + var __10_4_2_1_2 = "str2"; + assert(_eval("\'str\' === __10_4_2_1_2"), 'indirect eval'); + } + foo(); + } +testcase(); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/global-env-rec-with.js b/js/src/tests/test262/language/eval-code/indirect/global-env-rec-with.js new file mode 100644 index 0000000000..ffe1d98e51 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/global-env-rec-with.js @@ -0,0 +1,23 @@ +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es5id: 10.4.2-1-4 +description: > + Indirect call to eval has context set to global context (with + block) +flags: [noStrict] +---*/ + +var __10_4_2_1_4 = "str"; +function testcase() { + var o = new Object(); + o.__10_4_2_1_4 = "str2"; + var _eval = eval; + var __10_4_2_1_4 = "str1"; + with (o) { + assert(_eval("\'str\' === __10_4_2_1_4"), 'indirect eval'); + } + } +testcase(); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/global-env-rec.js b/js/src/tests/test262/language/eval-code/indirect/global-env-rec.js new file mode 100644 index 0000000000..3cf25d2e2f --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/global-env-rec.js @@ -0,0 +1,16 @@ +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es5id: 10.4.2-1-1 +description: Indirect call to eval has context set to global context +---*/ + +var __10_4_2_1_1_1 = "str"; +function testcase() { + var _eval = eval; + var __10_4_2_1_1_1 = "str1"; + assert(_eval("\'str\' === __10_4_2_1_1_1"), 'indirect eval'); +} +testcase(); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/import.js b/js/src/tests/test262/language/eval-code/indirect/import.js new file mode 100644 index 0000000000..a2d83cfb61 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/import.js @@ -0,0 +1,27 @@ +// |reftest| module +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: The `import` declaration may not appear within eval code +esid: sec-scripts +flags: [module] +info: | + Eval code is the source text supplied to the built-in eval function. More + precisely, if the parameter to the built-in eval function is a String, it + is treated as an ECMAScript Script. The eval code for a particular + invocation of eval is the global code portion of that Script. + + A.5 Scripts and Modules + + Script: + ScriptBodyopt + + ScriptBody: + StatementList +---*/ + +assert.throws(SyntaxError, function() { + (0,eval)('import v from "./import.js";'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/lex-env-distinct-cls.js b/js/src/tests/test262/language/eval-code/indirect/lex-env-distinct-cls.js new file mode 100644 index 0000000000..695ba3a846 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/lex-env-distinct-cls.js @@ -0,0 +1,37 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-performeval +description: > + Indirect eval code creates a new declarative environment for + lexically-scoped declarations (class) +info: | + [...] + 9. If direct is true, then + [...] + 10. Else, + a. Let lexEnv be NewDeclarativeEnvironment(evalRealm.[[GlobalEnv]]). + [...] +features: [class] +---*/ + +class outside {} + +(0,eval)('class outside {}'); +(0,eval)('"use strict"; class outside {}'); + +(0,eval)('class xNonStrict {}'); + +assert.sameValue(typeof xNonStrict, 'undefined'); +assert.throws(ReferenceError, function() { + xNonStrict; +}); + +(0,eval)('"use strict"; class xStrict {}'); + +assert.sameValue(typeof xStrict, 'undefined'); +assert.throws(ReferenceError, function() { + xStrict; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/lex-env-distinct-const.js b/js/src/tests/test262/language/eval-code/indirect/lex-env-distinct-const.js new file mode 100644 index 0000000000..db39d7fa7a --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/lex-env-distinct-const.js @@ -0,0 +1,37 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-performeval +description: > + Indirect eval code creates a new declarative environment for + lexically-scoped declarations (const) +info: | + [...] + 9. If direct is true, then + [...] + 10. Else, + a. Let lexEnv be NewDeclarativeEnvironment(evalRealm.[[GlobalEnv]]). + [...] +features: [const] +---*/ + +const outside = null; + +(0,eval)('const outside = null;'); +(0,eval)('"use strict"; const outside = null;'); + +(0,eval)('const xNonStrict = null;'); + +assert.sameValue(typeof xNonStrict, 'undefined'); +assert.throws(ReferenceError, function() { + xNonStrict; +}); + +(0,eval)('"use strict"; const xStrict = null;'); + +assert.sameValue(typeof xStrict, 'undefined'); +assert.throws(ReferenceError, function() { + xStrict; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/lex-env-distinct-let.js b/js/src/tests/test262/language/eval-code/indirect/lex-env-distinct-let.js new file mode 100644 index 0000000000..f640f4dd65 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/lex-env-distinct-let.js @@ -0,0 +1,37 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-performeval +description: > + Indirect eval code creates a new declarative environment for + lexically-scoped declarations (let) +info: | + [...] + 9. If direct is true, then + [...] + 10. Else, + a. Let lexEnv be NewDeclarativeEnvironment(evalRealm.[[GlobalEnv]]). + [...] +features: [let] +---*/ + +let outside = 23; + +(0,eval)('let outside;'); +(0,eval)('"use strict"; let outside;'); + +(0,eval)('let xNonStrict = 3;'); + +assert.sameValue(typeof xNonStrict, 'undefined'); +assert.throws(ReferenceError, function() { + xNonStrict; +}); + +(0,eval)('"use strict"; let xStrict = 3;'); + +assert.sameValue(typeof xStrict, 'undefined'); +assert.throws(ReferenceError, function() { + xStrict; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/lex-env-heritage.js b/js/src/tests/test262/language/eval-code/indirect/lex-env-heritage.js new file mode 100644 index 0000000000..cfbc5b5d10 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/lex-env-heritage.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-performeval +description: > + Indirect eval code sets the new declarative environment's outer environment + to the global environment. +info: | + [...] + 9. If direct is true, then + [...] + 10. Else, + a. Let lexEnv be NewDeclarativeEnvironment(evalRealm.[[GlobalEnv]]). + [...] +features: [let] +---*/ + +var actualStrict; +var actualNonStrict; + +let x = 'outside'; +{ + let x = 'inside'; + actualNonStrict = (0,eval)('x;'); + actualStrict = (0,eval)('"use strict"; x;'); +} + +assert.sameValue(actualNonStrict, 'outside', 'non strict mode'); +assert.sameValue(actualStrict, 'outside', 'strict mode'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/lex-env-no-init-cls.js b/js/src/tests/test262/language/eval-code/indirect/lex-env-no-init-cls.js new file mode 100644 index 0000000000..7a67b7bfbb --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/lex-env-no-init-cls.js @@ -0,0 +1,26 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-performeval +description: > + Indirect eval code creates `class` bindings prior to evaluation, but does + not initialize them. +info: | + [...] + 14. For each element d in lexDeclarations do + a. NOTE Lexically declared names are only instantiated here but not + initialized. + b. For each element dn of the BoundNames of d do + i. If IsConstantDeclaration of d is true, then + 1. Perform ? lexEnvRec.CreateImmutableBinding(dn, true). + ii. Else, + 2. Perform ? lexEnvRec.CreateMutableBinding(dn, false). + [...] +features: [class] +---*/ + +assert.throws(ReferenceError, function() { + (0,eval)('typeof C; class C {}'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/lex-env-no-init-const.js b/js/src/tests/test262/language/eval-code/indirect/lex-env-no-init-const.js new file mode 100644 index 0000000000..06d0a49fce --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/lex-env-no-init-const.js @@ -0,0 +1,26 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-performeval +description: > + Indirect eval code creates `const` bindings prior to evaluation but does + not initialize them. +info: | + [...] + 14. For each element d in lexDeclarations do + a. NOTE Lexically declared names are only instantiated here but not + initialized. + b. For each element dn of the BoundNames of d do + i. If IsConstantDeclaration of d is true, then + 1. Perform ? lexEnvRec.CreateImmutableBinding(dn, true). + ii. Else, + 2. Perform ? lexEnvRec.CreateMutableBinding(dn, false). + [...] +features: [const] +---*/ + +assert.throws(ReferenceError, function() { + (0,eval)('typeof x; const x = null;'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/lex-env-no-init-let.js b/js/src/tests/test262/language/eval-code/indirect/lex-env-no-init-let.js new file mode 100644 index 0000000000..f9c8ea401a --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/lex-env-no-init-let.js @@ -0,0 +1,26 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-performeval +description: > + Indirect eval code creates `let` bindings prior to evaluation but does not + initialize them. +info: | + [...] + 14. For each element d in lexDeclarations do + a. NOTE Lexically declared names are only instantiated here but not + initialized. + b. For each element dn of the BoundNames of d do + i. If IsConstantDeclaration of d is true, then + 1. Perform ? lexEnvRec.CreateImmutableBinding(dn, true). + ii. Else, + 2. Perform ? lexEnvRec.CreateMutableBinding(dn, false). + [...] +features: [let] +---*/ + +assert.throws(ReferenceError, function() { + (0,eval)('typeof x; let x;'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/new.target.js b/js/src/tests/test262/language/eval-code/indirect/new.target.js new file mode 100644 index 0000000000..d8c28eb742 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/new.target.js @@ -0,0 +1,46 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-scripts-static-semantics-early-errors +es6id: 15.1.1 +description: > + An indirect eval may not contain `new.target` +info: | + - It is a Syntax Error if StatementList Contains NewTarget unless the source + code containing NewTarget is eval code that is being processed by a direct + eval that is contained in function code that is not the function code of an + ArrowFunction. +features: [new.target] +---*/ + +var caught; + +try { + (0,eval)('new.target;'); +} catch (err) { + caught = err; +} + +assert.sameValue(typeof caught, 'object', 'object value thrown (global code)'); +assert.sameValue( + caught.constructor, SyntaxError, 'SyntaxError thrown (global code)' +); + +caught = null; + +try { + (function() { + (0,eval)('new.target;'); + })(); +} catch (err) { + caught = err; +} + +assert.sameValue( + typeof caught, 'object', 'object value thrown (function code)' +); +assert.sameValue( + caught.constructor, SyntaxError, 'SyntaxError thrown (function code)' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/non-definable-function-with-function.js b/js/src/tests/test262/language/eval-code/indirect/non-definable-function-with-function.js new file mode 100644 index 0000000000..85e36337f3 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/non-definable-function-with-function.js @@ -0,0 +1,51 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-evaldeclarationinstantiation +es6id: 18.2.1.2 +description: > + Global functions are not created if conflicting function declarations were + detected. +info: | + Runtime Semantics: EvalDeclarationInstantiation( body, varEnv, lexEnv, strict) + + ... + 8. For each d in varDeclarations, in reverse list order do + a. If d is neither a VariableDeclaration or a ForBinding, then + i. Assert: d is either a FunctionDeclaration or a GeneratorDeclaration. + ii. NOTE If there are multiple FunctionDeclarations for the same name, + the last declaration is used. + iii. Let fn be the sole element of the BoundNames of d. + iv. If fn is not an element of declaredFunctionNames, then + 1. If varEnvRec is a global Environment Record, then + a. Let fnDefinable be varEnvRec.CanDeclareGlobalFunction(fn). + b. ReturnIfAbrupt(fnDefinable). + c. If fnDefinable is false, throw TypeError exception. + ... + 14. For each production f in functionsToInitialize, do + a. Let fn be the sole element of the BoundNames of f. + b. Let fo be the result of performing InstantiateFunctionObject for f with argument lexEnv. + c. If varEnvRec is a global Environment Record, then + i. Let status be varEnvRec.CreateGlobalFunctionBinding(fn, fo, true). + ii. ReturnIfAbrupt(status). + ... +---*/ + +try { + (0,eval)("function shouldNotBeDefined1() {} function NaN() {} function shouldNotBeDefined2() {}"); +} catch (e) { + // Ignore TypeError exception. +} + +assert.sameValue( + Object.getOwnPropertyDescriptor(this, "shouldNotBeDefined1"), + undefined, + "declaration preceding" +); +assert.sameValue( + Object.getOwnPropertyDescriptor(this, "shouldNotBeDefined2"), + undefined, + "declaration following" +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/non-definable-function-with-variable.js b/js/src/tests/test262/language/eval-code/indirect/non-definable-function-with-variable.js new file mode 100644 index 0000000000..4d4ff171ab --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/non-definable-function-with-variable.js @@ -0,0 +1,48 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-evaldeclarationinstantiation +es6id: 18.2.1.2 +description: > + Global variables are not created if conflicting function declarations were + detected. +info: | + Runtime Semantics: EvalDeclarationInstantiation( body, varEnv, lexEnv, strict) + + ... + 8. For each d in varDeclarations, in reverse list order do + a. If d is neither a VariableDeclaration or a ForBinding, then + i. Assert: d is either a FunctionDeclaration or a GeneratorDeclaration. + ii. NOTE If there are multiple FunctionDeclarations for the same name, the last declaration is used. + iii. Let fn be the sole element of the BoundNames of d. + iv. If fn is not an element of declaredFunctionNames, then + 1. If varEnvRec is a global Environment Record, then + a. Let fnDefinable be varEnvRec.CanDeclareGlobalFunction(fn). + b. ReturnIfAbrupt(fnDefinable). + c. If fnDefinable is false, throw TypeError exception. + ... + 15. For each String vn in declaredVarNames, in list order do + a. If varEnvRec is a global Environment Record, then + i. Let status be varEnvRec.CreateGlobalVarBinding(vn, true). + ii. ReturnIfAbrupt(status). + ... +---*/ + +try { + (0,eval)("var shouldNotBeDefined1; function NaN() {} var shouldNotBeDefined2;"); +} catch (e) { + // Ignore TypeError exception. +} + +assert.sameValue( + Object.getOwnPropertyDescriptor(this, "shouldNotBeDefined1"), + undefined, + "declaration preceding" +); +assert.sameValue( + Object.getOwnPropertyDescriptor(this, "shouldNotBeDefined2"), + undefined, + "declaration following" +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/non-definable-global-function.js b/js/src/tests/test262/language/eval-code/indirect/non-definable-global-function.js new file mode 100644 index 0000000000..6843cb663a --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/non-definable-global-function.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-evaldeclarationinstantiation +es6id: 18.2.1.2 +description: Throws a TypeError if a global function cannot be defined. +info: | + Runtime Semantics: EvalDeclarationInstantiation( body, varEnv, lexEnv, strict) + + ... + 8. For each d in varDeclarations, in reverse list order do + a. If d is neither a VariableDeclaration or a ForBinding, then + i. Assert: d is either a FunctionDeclaration or a GeneratorDeclaration. + ii. NOTE If there are multiple FunctionDeclarations for the same name, + the last declaration is used. + iii. Let fn be the sole element of the BoundNames of d. + iv. If fn is not an element of declaredFunctionNames, then + 1. If varEnvRec is a global Environment Record, then + a. Let fnDefinable be varEnvRec.CanDeclareGlobalFunction(fn). + b. ReturnIfAbrupt(fnDefinable). + c. If fnDefinable is false, throw TypeError exception. + ... +---*/ + +assert.throws(TypeError, function() { + (0,eval)("function NaN() {}"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/non-definable-global-generator.js b/js/src/tests/test262/language/eval-code/indirect/non-definable-global-generator.js new file mode 100644 index 0000000000..d07c68595a --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/non-definable-global-generator.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-evaldeclarationinstantiation +es6id: 18.2.1.2 +description: Throws a TypeError if a global generator function cannot be defined. +info: | + Runtime Semantics: EvalDeclarationInstantiation( body, varEnv, lexEnv, strict) + + ... + 8. For each d in varDeclarations, in reverse list order do + a. If d is neither a VariableDeclaration or a ForBinding, then + i. Assert: d is either a FunctionDeclaration or a GeneratorDeclaration. + ii. NOTE If there are multiple FunctionDeclarations for the same name, + the last declaration is used. + iii. Let fn be the sole element of the BoundNames of d. + iv. If fn is not an element of declaredFunctionNames, then + 1. If varEnvRec is a global Environment Record, then + a. Let fnDefinable be varEnvRec.CanDeclareGlobalFunction(fn). + b. ReturnIfAbrupt(fnDefinable). + c. If fnDefinable is false, throw TypeError exception. + ... +features: [generators] +---*/ + +assert.throws(TypeError, function() { + (0,eval)("function* NaN() {}"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/non-definable-global-var.js b/js/src/tests/test262/language/eval-code/indirect/non-definable-global-var.js new file mode 100644 index 0000000000..7f25c6d9d4 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/non-definable-global-var.js @@ -0,0 +1,37 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-evaldeclarationinstantiation +es6id: 18.2.1.2 +description: Throws a TypeError if a global variable cannot be defined. +info: | + Runtime Semantics: EvalDeclarationInstantiation( body, varEnv, lexEnv, strict) + + ... + 10. For each d in varDeclarations, do + a. If d is a VariableDeclaration or a ForBinding, then + i. For each String vn in the BoundNames of d, do + 1. If vn is not an element of declaredFunctionNames, then + a. If varEnvRec is a global Environment Record, then + i. Let vnDefinable be varEnvRec.CanDeclareGlobalVar(vn). + ii. ReturnIfAbrupt(vnDefinable). + iii. If vnDefinable is false, throw TypeError exception. + ... +---*/ + +var nonExtensible; +try { + Object.preventExtensions(this); + nonExtensible = !Object.isExtensible(this); +} catch (e) { + nonExtensible = false; +} + +// Run test if global object is non-extensible. +if (nonExtensible) { + assert.throws(TypeError, function() { + (0,eval)("var unlikelyVariableName;"); + }); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/non-string-object.js b/js/src/tests/test262/language/eval-code/indirect/non-string-object.js new file mode 100644 index 0000000000..4d5a7da20d --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/non-string-object.js @@ -0,0 +1,22 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +info: If x is not a string value, return x +esid: sec-performeval +es5id: 15.1.2.1_A1.1_T2 +description: Checking all objects +---*/ + +var x = {}; +assert.sameValue((0,eval)(x), x, 'ordinary object'); + +x = new Number(1); +assert.sameValue((0,eval)(x), x, 'Number object'); + +x = new Boolean(true); +assert.sameValue((0,eval)(x), x, 'Boolean object'); + +x = new String("1+1"); +assert.sameValue((0,eval)(x), x, 'String object'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/non-string-primitive.js b/js/src/tests/test262/language/eval-code/indirect/non-string-primitive.js new file mode 100644 index 0000000000..fc8af92af6 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/non-string-primitive.js @@ -0,0 +1,21 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +info: If x is not a string value, return x +esid: sec-performeval +es5id: 15.1.2.1_A1.1_T1 +description: Checking all primitives +---*/ + +var x = 1; +assert.sameValue((0,eval)(x), x, 'Reference'); + +assert.sameValue((0,eval)(1), 1, 'number'); + +assert.sameValue((0,eval)(true), true, 'boolean'); + +assert.sameValue((0,eval)(null), null, 'null'); + +assert.sameValue((0,eval)(undefined), undefined, 'undefined'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/parse-failure-1.js b/js/src/tests/test262/language/eval-code/indirect/parse-failure-1.js new file mode 100644 index 0000000000..3d6a83da54 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/parse-failure-1.js @@ -0,0 +1,17 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +info: If the parse fails, throw a SyntaxError exception (but see also clause 16) +esid: sec-performeval +es5id: 15.1.2.1_A2_T1 +description: > + Checking if execution of "(0,eval)("x = 1; x\u000A++"), catch SyntaxError" + passes +---*/ + +var x; +assert.throws(SyntaxError, function() { + (0,eval)("x = 1; x\u000A++"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/parse-failure-2.js b/js/src/tests/test262/language/eval-code/indirect/parse-failure-2.js new file mode 100644 index 0000000000..cc4762f5af --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/parse-failure-2.js @@ -0,0 +1,15 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +info: If the parse fails, throw a SyntaxError exception (but see also clause 16) +esid: sec-performeval +es5id: 15.1.2.1_A2_T2 +description: Checking if execution of "(0,eval)("x = 1; x\u000A++")" fails +negative: + phase: runtime + type: SyntaxError +---*/ + +var x; +(0,eval)("x = 1; x\u000A++"); diff --git a/js/src/tests/test262/language/eval-code/indirect/parse-failure-3.js b/js/src/tests/test262/language/eval-code/indirect/parse-failure-3.js new file mode 100644 index 0000000000..fcedb7e20f --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/parse-failure-3.js @@ -0,0 +1,24 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +info: | + If Result(3).type is not normal, then Result(3).type must be throw. + Throw Result(3).value as an exception +esid: sec-performeval +es5id: 15.1.2.1_A3.3_T1 +description: Continue statement +---*/ + +assert.throws(SyntaxError, function() { + (0,eval)("continue;"); +}); + +assert.throws(SyntaxError, function() { + for (var i = 0; i <= 1; i++) { + (0,eval)("continue;"); + throw new Test262Error("First iteration should not complete"); + } + throw new Test262Error("Iteration should not complete"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/parse-failure-4.js b/js/src/tests/test262/language/eval-code/indirect/parse-failure-4.js new file mode 100644 index 0000000000..3683440412 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/parse-failure-4.js @@ -0,0 +1,24 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +info: | + If Result(3).type is not normal, then Result(3).type must be throw. + Throw Result(3).value as an exception +esid: sec-performeval +es5id: 15.1.2.1_A3.3_T2 +description: Break statement +---*/ + +assert.throws(SyntaxError, function() { + (0,eval)("break;"); +}); + +assert.throws(SyntaxError, function() { + for (var i = 0; i <= 1; i++) { + (0,eval)("break;"); + throw new Test262Error("First iteration should not complete"); + } + throw new Test262Error("Iteration should not complete"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/parse-failure-5.js b/js/src/tests/test262/language/eval-code/indirect/parse-failure-5.js new file mode 100644 index 0000000000..b2dd8e95e8 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/parse-failure-5.js @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +info: | + If Result(3).type is not normal, then Result(3).type must be throw. + Throw Result(3).value as an exception +esid: sec-performeval +es5id: 15.1.2.1_A3.3_T3 +description: Return statement +---*/ + +var value; + +try { + value = (0,eval)("return;"); + throw new Test262Error('#1.1: return must throw SyntaxError. Actual: ' + value); +} catch(e) { + if ((e instanceof SyntaxError) !== true) { + throw new Test262Error('#1.2: return must throw SyntaxError. Actual: ' + e); + } +} + +assert.throws(SyntaxError, function() { + (0,eval)("return;"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/parse-failure-6.js b/js/src/tests/test262/language/eval-code/indirect/parse-failure-6.js new file mode 100644 index 0000000000..9bd48d27e7 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/parse-failure-6.js @@ -0,0 +1,19 @@ +// Copyright 2020 Qu Xing. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-performeval +description: For statement +info: | + ... + 9. Perform the following substeps in an implementation-dependent order, possibly interleaving parsing and error detection: + a. Let script be the ECMAScript code that is the result of parsing ! UTF16DecodeString(x),for the goal symbol Script. + If the parse fails, throw a SyntaxError exception. If any early errors are detected, throw a SyntaxError exception + (but see also clause 16). + ... +---*/ + +assert.throws(SyntaxError, function() { + (0, eval)("for(;false;)"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/realm.js b/js/src/tests/test262/language/eval-code/indirect/realm.js new file mode 100644 index 0000000000..120e65d058 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/realm.js @@ -0,0 +1,36 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-performeval +es6id: 18.2.1.1 +description: > + Uses the global variable envrionment of the running execution context +info: | + [...] + 12. Let ctx be the running execution context. If direct is true, ctx will be + the execution context that performed the direct eval. If direct is false, + ctx will be the execution context for the invocation of the eval + function. + 13. If direct is true, then + [...] + 14. Else, + a. Let lexEnv be NewDeclarativeEnvironment(evalRealm.[[GlobalEnv]]). + b. Let varEnv be evalRealm.[[GlobalEnv]]. + [...] + 17. Let evalCxt be a new ECMAScript code execution context. + [...] + 21. Set the evalCxt's VariableEnvironment to varEnv. + [...] + 24. Let result be EvalDeclarationInstantiation(body, varEnv, lexEnv, + strictEval). +features: [cross-realm] +---*/ + +var other = $262.createRealm().global; +var otherEval = other.eval; + +otherEval('var x = 23;'); +assert.sameValue(typeof x, 'undefined'); +assert.sameValue(other.x, 23); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/shell.js b/js/src/tests/test262/language/eval-code/indirect/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/shell.js diff --git a/js/src/tests/test262/language/eval-code/indirect/super-call.js b/js/src/tests/test262/language/eval-code/indirect/super-call.js new file mode 100644 index 0000000000..682168f325 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/super-call.js @@ -0,0 +1,48 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-scripts-static-semantics-early-errors +es6id: 15.1.1 +description: > + An indirect eval may not contain SuperCall +info: | + - It is a Syntax Error if StatementList Contains super unless the source code + containing super is eval code that is being processed by a direct eval that + is contained in function code that is not the function code of an + ArrowFunction. +features: [super] +---*/ + +var caught; + +try { + (0,eval)('super();'); +} catch (err) { + caught = err; +} + +assert.sameValue(typeof caught, 'object', 'object value thrown (global code)'); +assert.sameValue( + caught.constructor, SyntaxError, 'SyntaxError thrown (global code)' +); + +caught = null; + +try { + ({ + m() { + (0,eval)('super();'); + } + }).m(); +} catch (err) { + caught = err; +} + +assert.sameValue( + typeof caught, 'object', 'object value thrown (function code)' +); +assert.sameValue( + caught.constructor, SyntaxError, 'SyntaxError thrown (function code)' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/super-prop.js b/js/src/tests/test262/language/eval-code/indirect/super-prop.js new file mode 100644 index 0000000000..753abd2823 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/super-prop.js @@ -0,0 +1,48 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-scripts-static-semantics-early-errors +es6id: 15.1.1 +description: > + An indirect eval may not contain SuperProperty +info: | + - It is a Syntax Error if StatementList Contains super unless the source code + containing super is eval code that is being processed by a direct eval that + is contained in function code that is not the function code of an + ArrowFunction. +features: [super] +---*/ + +var caught; + +try { + (0,eval)('super.property;'); +} catch (err) { + caught = err; +} + +assert.sameValue(typeof caught, 'object', 'object value thrown (global code)'); +assert.sameValue( + caught.constructor, SyntaxError, 'SyntaxError thrown (global code)' +); + +caught = null; + +try { + ({ + m() { + (0,eval)('super.property;'); + } + }).m(); +} catch (err) { + caught = err; +} + +assert.sameValue( + typeof caught, 'object', 'object value thrown (function code)' +); +assert.sameValue( + caught.constructor, SyntaxError, 'SyntaxError thrown (function code)' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/switch-case-decl-strict.js b/js/src/tests/test262/language/eval-code/indirect/switch-case-decl-strict.js new file mode 100644 index 0000000000..73a2ffade1 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/switch-case-decl-strict.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: AnnexB extension not honored in strict mode +es6id: B.3.3.3 +info: | + Function declaration in the `case` clause of a `switch` statement in eval + code + + B.3.3.3 Changes to EvalDeclarationInstantiation + + 1. If strict is false, then +---*/ + +var err; + +(0,eval)('\ + "use strict";\ + switch (1) {\ + case 1:\ + function f() { }\ + }\ +'); + +try { + f; +} catch (exception) { + err = exception; +} + +assert.sameValue(err.constructor, ReferenceError); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/switch-dflt-decl-strict.js b/js/src/tests/test262/language/eval-code/indirect/switch-dflt-decl-strict.js new file mode 100644 index 0000000000..c272028e04 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/switch-dflt-decl-strict.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: AnnexB extension not honored in strict mode +es6id: B.3.3.3 +info: | + Function declaration in the `default` clause of a `switch` statement in + eval code + + B.3.3.3 Changes to EvalDeclarationInstantiation + + 1. If strict is false, then +---*/ + +var err; + +(0,eval)('\ + "use strict";\ + switch (1) {\ + default:\ + function f() { }\ + }\ +'); + +try { + f; +} catch (exception) { + err = exception; +} + +assert.sameValue(err.constructor, ReferenceError); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/this-value-func.js b/js/src/tests/test262/language/eval-code/indirect/this-value-func.js new file mode 100644 index 0000000000..7a4da686f5 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/this-value-func.js @@ -0,0 +1,18 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Direct eval code has the same `this` binding as the calling context + (non-strict function scope) +esid: sec-performeval +---*/ + +var thisValue; + +(function() { + thisValue = (0,eval)('this;'); +}()); + +assert.sameValue(thisValue, this); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/this-value-global.js b/js/src/tests/test262/language/eval-code/indirect/this-value-global.js new file mode 100644 index 0000000000..9e67ec79bd --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/this-value-global.js @@ -0,0 +1,12 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Direct eval code has the same `this` binding as the calling context (global + scope) +esid: sec-performeval +---*/ + +assert.sameValue((0,eval)('this;'), this); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/var-env-func-init-global-new.js b/js/src/tests/test262/language/eval-code/indirect/var-env-func-init-global-new.js new file mode 100644 index 0000000000..b69a199127 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/var-env-func-init-global-new.js @@ -0,0 +1,43 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-evaldeclarationinstantiation +description: Initialization of new global property +info: | + [...] + 15. For each production f in functionsToInitialize, do + a. Let fn be the sole element of the BoundNames of f. + b. Let fo be the result of performing InstantiateFunctionObject for f + with argument lexEnv. + c. If varEnvRec is a global Environment Record, then + i. Perform ? varEnvRec.CreateGlobalFunctionBinding(fn, fo, true). + [...] + + 8.1.1.4.18 CreateGlobalFunctionBinding + + [...] + 5. If existingProp is undefined or existingProp.[[Configurable]] is true, + then + a. Let desc be the PropertyDescriptor{[[Value]]: V, [[Writable]]: true, + [[Enumerable]]: true, [[Configurable]]: D}. + 6. Else, + [...] + 7. Perform ? DefinePropertyOrThrow(globalObject, N, desc). + [...] +includes: [propertyHelper.js] +---*/ + +var initial; + +(0, eval)('initial = f; function f() { return 234; }'); + +verifyProperty(this, 'f', { + writable: true, + enumerable: true, + configurable: true, +}); + +assert.sameValue(typeof initial, 'function'); +assert.sameValue(initial(), 234); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/var-env-func-init-global-update-configurable.js b/js/src/tests/test262/language/eval-code/indirect/var-env-func-init-global-update-configurable.js new file mode 100644 index 0000000000..db2e2a0a79 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/var-env-func-init-global-update-configurable.js @@ -0,0 +1,49 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-evaldeclarationinstantiation +description: Modification of previously-existing configurable global property +info: | + [...] + 15. For each production f in functionsToInitialize, do + a. Let fn be the sole element of the BoundNames of f. + b. Let fo be the result of performing InstantiateFunctionObject for f + with argument lexEnv. + c. If varEnvRec is a global Environment Record, then + i. Perform ? varEnvRec.CreateGlobalFunctionBinding(fn, fo, true). + [...] + + 8.1.1.4.18 CreateGlobalFunctionBinding + + [...] + 5. If existingProp is undefined or existingProp.[[Configurable]] is true, + then + a. Let desc be the PropertyDescriptor{[[Value]]: V, [[Writable]]: true, + [[Enumerable]]: true, [[Configurable]]: D}. + 6. Else, + [...] + 7. Perform ? DefinePropertyOrThrow(globalObject, N, desc). + [...] +includes: [propertyHelper.js] +---*/ + +var initial = null; + +Object.defineProperty(this, 'f', { + enumerable: false, + writable: false, + configurable: true +}); + +(0, eval)('initial = f; function f() { return 345; }'); + +verifyProperty(this, 'f', { + writable: true, + enumerable: true, + configurable: true, +}); + +assert.sameValue(typeof initial, 'function'); +assert.sameValue(initial(), 345); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/var-env-func-init-global-update-non-configurable.js b/js/src/tests/test262/language/eval-code/indirect/var-env-func-init-global-update-non-configurable.js new file mode 100644 index 0000000000..7d8e3dabd4 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/var-env-func-init-global-update-non-configurable.js @@ -0,0 +1,49 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-evaldeclarationinstantiation +description: > + Modification of previously-existing non-configurable global property +info: | + [...] + 15. For each production f in functionsToInitialize, do + a. Let fn be the sole element of the BoundNames of f. + b. Let fo be the result of performing InstantiateFunctionObject for f + with argument lexEnv. + c. If varEnvRec is a global Environment Record, then + i. Perform ? varEnvRec.CreateGlobalFunctionBinding(fn, fo, true). + [...] + + 8.1.1.4.18 CreateGlobalFunctionBinding + + [...] + 5. If existingProp is undefined or existingProp.[[Configurable]] is true, + then + [...] + 6. Else, + b. Let desc be the PropertyDescriptor{[[Value]]: V }. + 7. Perform ? DefinePropertyOrThrow(globalObject, N, desc). + [...] +includes: [propertyHelper.js] +---*/ + +var initial; + +Object.defineProperty(this, 'f', { + enumerable: true, + writable: true, + configurable: false +}); + +(0,eval)('initial = f; function f() { return 2222; }'); + +verifyProperty(this, 'f', { + writable: true, + enumerable: true, + configurable: false, +}); + +assert.sameValue(typeof initial, 'function'); +assert.sameValue(initial(), 2222); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/var-env-func-init-multi.js b/js/src/tests/test262/language/eval-code/indirect/var-env-func-init-multi.js new file mode 100644 index 0000000000..f7a15cfd79 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/var-env-func-init-multi.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-evaldeclarationinstantiation +description: Precedence of final declaration when bindings are duplicated +info: | + [...] + 8. For each d in varDeclarations, in reverse list order do + a. If d is neither a VariableDeclaration or a ForBinding, then + i. Assert: d is either a FunctionDeclaration or a + GeneratorDeclaration. + [...] + iv. If fn is not an element of declaredFunctionNames, then + [...] + 3. Insert d as the first element of functionsToInitialize. + [...] + 15. For each production f in functionsToInitialize, do + a. Let fn be the sole element of the BoundNames of f. + b. Let fo be the result of performing InstantiateFunctionObject for f + with argument lexEnv. + [...] +---*/ + +var initial; + +(0,eval)('initial = f; function f() { return "first"; } function f() { return "second"; }'); + +assert.sameValue(initial(), 'second', 'initial value'); +assert.sameValue(f(), 'second', 'value following declaration evaluation'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/var-env-func-non-strict.js b/js/src/tests/test262/language/eval-code/indirect/var-env-func-non-strict.js new file mode 100644 index 0000000000..64920d29fe --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/var-env-func-non-strict.js @@ -0,0 +1,21 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-performeval +es5id: 10.4.2-2-s +description: > + Non-stict mode indirect eval code cannot instantiate functions in the + variable environment of the caller +---*/ + +var typeofInside; + +(function() { + (0,eval)("function fun() {}"); + typeofInside = typeof fun; +}()); + +assert.sameValue(typeofInside, "function"); +assert.sameValue(typeof fun, "function"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/var-env-func-strict.js b/js/src/tests/test262/language/eval-code/indirect/var-env-func-strict.js new file mode 100644 index 0000000000..bea4105059 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/var-env-func-strict.js @@ -0,0 +1,21 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-performeval +es5id: 10.4.2.1-4-s +description: > + Strict Mode - Strict mode eval code cannot instantiate functions + in the variable environment of the caller to eval. +---*/ + +var typeofInside; + +(function() { + (0,eval)("'use strict'; function fun(){}"); + typeofInside = typeof fun; +}()); + +assert.sameValue(typeofInside, "undefined"); +assert.sameValue(typeof fun, "undefined"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/var-env-global-lex-non-strict.js b/js/src/tests/test262/language/eval-code/indirect/var-env-global-lex-non-strict.js new file mode 100644 index 0000000000..062a03fea9 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/var-env-global-lex-non-strict.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-evaldeclarationinstantiation +description: Variable collision with global lexical binding +info: | + [...] + 5. If strict is false, then + a. If varEnvRec is a global Environment Record, then + i. For each name in varNames, do + 1. If varEnvRec.HasLexicalDeclaration(name) is true, throw a + SyntaxError exception. + 2. NOTE: eval will not create a global var declaration that would + be shadowed by a global lexical declaration. + [...] +features: [let] +---*/ + +let x; +var caught; + +// The `assert.throws` helper function would interfere with the semantics under +// test. +try { + (0,eval)('var x;'); +} catch (err) { + caught = err; +} + +assert.notSameValue(caught, undefined); +assert.sameValue(caught.constructor, SyntaxError); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/var-env-global-lex-strict.js b/js/src/tests/test262/language/eval-code/indirect/var-env-global-lex-strict.js new file mode 100644 index 0000000000..6a1b44a9d2 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/var-env-global-lex-strict.js @@ -0,0 +1,17 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-evaldeclarationinstantiation +description: No variable collision with global lexical binding +info: | + [...] + 5. If strict is false, then + [...] +features: [let] +---*/ + +let x; + +(0,eval)('"use strict"; var x;'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/var-env-lower-lex-non-strict.js b/js/src/tests/test262/language/eval-code/indirect/var-env-lower-lex-non-strict.js new file mode 100644 index 0000000000..f79d7d33e8 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/var-env-lower-lex-non-strict.js @@ -0,0 +1,22 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-evaldeclarationinstantiation +description: No variable collision with lexical binding in lower scope +info: | + [...] + 5. If strict is false, then + [...] + d. Repeat while thisLex is not the same as varEnv, + [...] +features: [let] +---*/ + +{ + let x; + { + (0,eval)('var x;'); + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/var-env-lower-lex-strict.js b/js/src/tests/test262/language/eval-code/indirect/var-env-lower-lex-strict.js new file mode 100644 index 0000000000..1f3b761ed8 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/var-env-lower-lex-strict.js @@ -0,0 +1,20 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-evaldeclarationinstantiation +description: No variable collision with lexical binding in lower scope +info: | + [...] + 5. If strict is false, then + [...] +features: [let] +---*/ + +{ + let x; + { + (0,eval)('"use strict"; var x;'); + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/var-env-var-init-global-exstng.js b/js/src/tests/test262/language/eval-code/indirect/var-env-var-init-global-exstng.js new file mode 100644 index 0000000000..28a07a5ed5 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/var-env-var-init-global-exstng.js @@ -0,0 +1,37 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-evaldeclarationinstantiation +description: Declaration does not modify existing global property +info: | + [...] + 16. For each String vn in declaredVarNames, in list order do + a. If varEnvRec is a global Environment Record, then + i. Perform ? varEnvRec.CreateGlobalVarBinding(vn, true). + [...] + + 8.1.1.4.17 CreateGlobalVarBinding + + [...] + 5. Let extensible be ? IsExtensible(globalObject). + 6. If hasProperty is false and extensible is true, then + [...] + [...] +includes: [propertyHelper.js] +---*/ + +var initial; +var x = 23; + +(0, eval)('initial = x; var x = 45;'); + +verifyProperty(this, 'x', { + value: 45, + writable: true, + enumerable: true, + configurable: false, +}); + +assert.sameValue(initial, 23); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/var-env-var-init-global-new.js b/js/src/tests/test262/language/eval-code/indirect/var-env-var-init-global-new.js new file mode 100644 index 0000000000..6c5b2bd866 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/var-env-var-init-global-new.js @@ -0,0 +1,37 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-evaldeclarationinstantiation +description: Initialization of new global property +info: | + [...] + 16. For each String vn in declaredVarNames, in list order do + a. If varEnvRec is a global Environment Record, then + i. Perform ? varEnvRec.CreateGlobalVarBinding(vn, true). + [...] + + 8.1.1.4.17 CreateGlobalVarBinding + + [...] + 5. Let extensible be ? IsExtensible(globalObject). + 6. If hasProperty is false and extensible is true, then + a. Perform ? ObjRec.CreateMutableBinding(N, D). + b. Perform ? ObjRec.InitializeBinding(N, undefined). + [...] +includes: [propertyHelper.js] +---*/ + +var initial = null; + +(0, eval)('initial = x; var x = 9;'); + +verifyProperty(this, 'x', { + value: 9, + writable: true, + enumerable: true, + configurable: true, +}); + +assert.sameValue(initial, undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/var-env-var-non-strict.js b/js/src/tests/test262/language/eval-code/indirect/var-env-var-non-strict.js new file mode 100644 index 0000000000..8b988997b9 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/var-env-var-non-strict.js @@ -0,0 +1,17 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-performeval +es5id: 10.4.2-2-c-1 +description: Indirect eval code cannot instantiate variable in calling context +---*/ + +(function() { + var x = 0; + (0,eval)("var x = 1;"); + assert.sameValue(x, 0, "x"); +}()); + +assert.sameValue(x, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/eval-code/indirect/var-env-var-strict.js b/js/src/tests/test262/language/eval-code/indirect/var-env-var-strict.js new file mode 100644 index 0000000000..22a9749e68 --- /dev/null +++ b/js/src/tests/test262/language/eval-code/indirect/var-env-var-strict.js @@ -0,0 +1,18 @@ +// Copyright 2011 Google Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 10.4.2.1_A1 +description: > + Strict indirect eval should not leak top level declarations into + the global scope +---*/ + +if (!('foo' in this)) { + (1,eval)('"use strict"; var foo = 88;'); + if ('foo' in this) { + throw new Test262Error("Strict indirect eval leaked a top level declaration"); + } +} + +reportCompare(0, 0); |