diff options
Diffstat (limited to 'js/src/tests/test262/language/statements/variable')
182 files changed, 5510 insertions, 0 deletions
diff --git a/js/src/tests/test262/language/statements/variable/12.2.1-10-s.js b/js/src/tests/test262/language/statements/variable/12.2.1-10-s.js new file mode 100644 index 0000000000..54d933fcbe --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/12.2.1-10-s.js @@ -0,0 +1,12 @@ +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-10-s +description: "Strict Mode: an indirect eval assigning into 'eval' does not throw" +---*/ + + var s = eval; + s('eval = 42;'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/12.2.1-11.js b/js/src/tests/test262/language/statements/variable/12.2.1-11.js new file mode 100644 index 0000000000..854980d2b6 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/12.2.1-11.js @@ -0,0 +1,15 @@ +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-11 +description: arguments as var identifier in eval code is allowed +flags: [noStrict] +---*/ + +function testcase() { + eval("var arguments;"); + } +testcase(); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/12.2.1-16-s.js b/js/src/tests/test262/language/statements/variable/12.2.1-16-s.js new file mode 100644 index 0000000000..1b75fdb127 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/12.2.1-16-s.js @@ -0,0 +1,13 @@ +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-16-s +description: > + A Function constructor (called as a function) declaring a var + named 'arguments' does not throw a SyntaxError +---*/ + + Function('var arguments;'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/12.2.1-17-s-strict.js b/js/src/tests/test262/language/statements/variable/12.2.1-17-s-strict.js new file mode 100644 index 0000000000..edaf94bdd1 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/12.2.1-17-s-strict.js @@ -0,0 +1,17 @@ +'use strict'; +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-17-s +description: > + A Function constructor (called as a function) assigning into + 'arguments' will not throw any error if contained within strict + mode and its body does not start with strict mode +flags: [onlyStrict] +---*/ + + var f = Function('arguments = 42;'); + f(); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/12.2.1-18-s-strict.js b/js/src/tests/test262/language/statements/variable/12.2.1-18-s-strict.js new file mode 100644 index 0000000000..4334110e71 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/12.2.1-18-s-strict.js @@ -0,0 +1,18 @@ +'use strict'; +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-18-s +description: > + A direct eval declaring a var named 'arguments' throws SyntaxError + in strict mode +flags: [onlyStrict] +---*/ + + +assert.throws(SyntaxError, function() { + eval('var arguments;'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/12.2.1-19-s-strict.js b/js/src/tests/test262/language/statements/variable/12.2.1-19-s-strict.js new file mode 100644 index 0000000000..4706b20390 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/12.2.1-19-s-strict.js @@ -0,0 +1,18 @@ +'use strict'; +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-19-s +description: > + A direct eval assigning into 'arguments' throws SyntaxError in + strict mode +flags: [onlyStrict] +---*/ + + +assert.throws(SyntaxError, function() { + eval('arguments = 42;'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/12.2.1-1gs-strict.js b/js/src/tests/test262/language/statements/variable/12.2.1-1gs-strict.js new file mode 100644 index 0000000000..fff81efffc --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/12.2.1-1gs-strict.js @@ -0,0 +1,19 @@ +// |reftest| error:SyntaxError +'use strict'; +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-1gs +description: > + Strict Mode - SyntaxError is thrown if a VariableDeclaration + occurs within strict code and its Identifier is eval +negative: + phase: parse + type: SyntaxError +flags: [onlyStrict] +---*/ + +$DONOTEVALUATE(); + +for (var eval in arrObj) { } diff --git a/js/src/tests/test262/language/statements/variable/12.2.1-2-s-strict.js b/js/src/tests/test262/language/statements/variable/12.2.1-2-s-strict.js new file mode 100644 index 0000000000..7f6f843434 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/12.2.1-2-s-strict.js @@ -0,0 +1,18 @@ +'use strict'; +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-2-s +description: > + eval - a function assigning into 'eval' throws SyntaxError in + strict mode +flags: [onlyStrict] +---*/ + + +assert.throws(SyntaxError, function() { + eval('function foo() { eval = 42; }; foo()'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/12.2.1-20-s.js b/js/src/tests/test262/language/statements/variable/12.2.1-20-s.js new file mode 100644 index 0000000000..4e1e663afb --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/12.2.1-20-s.js @@ -0,0 +1,14 @@ +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-20-s +description: > + Strict Mode: an indirect eval declaring a var named 'arguments' + does not throw +---*/ + + var s = eval; + s('var arguments;'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/12.2.1-21-s.js b/js/src/tests/test262/language/statements/variable/12.2.1-21-s.js new file mode 100644 index 0000000000..db5f1411ed --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/12.2.1-21-s.js @@ -0,0 +1,14 @@ +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-21-s +description: > + Strict Mode: an indirect eval assigning into 'arguments' does not + throw +---*/ + + var s = eval; + s('arguments = 42;'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/12.2.1-22-s.js b/js/src/tests/test262/language/statements/variable/12.2.1-22-s.js new file mode 100644 index 0000000000..13b0d1863c --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/12.2.1-22-s.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: 12.2.1-22-s +description: > + arguments as global var identifier throws SyntaxError in strict + mode +---*/ + + var indirectEval = eval; +assert.throws(SyntaxError, function() { + indirectEval("'use strict'; var arguments;"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/12.2.1-3-s-strict.js b/js/src/tests/test262/language/statements/variable/12.2.1-3-s-strict.js new file mode 100644 index 0000000000..190e43d150 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/12.2.1-3-s-strict.js @@ -0,0 +1,18 @@ +'use strict'; +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-3-s +description: > + eval - a function expr declaring a var named 'eval' throws + SyntaxError in strict mode +flags: [onlyStrict] +---*/ + + +assert.throws(SyntaxError, function() { + eval('(function () { var eval; })'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/12.2.1-4-s-strict.js b/js/src/tests/test262/language/statements/variable/12.2.1-4-s-strict.js new file mode 100644 index 0000000000..bd27ca01f8 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/12.2.1-4-s-strict.js @@ -0,0 +1,18 @@ +'use strict'; +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-4-s +description: > + eval - a function expr assigning into 'eval' throws a SyntaxError + in strict mode +flags: [onlyStrict] +---*/ + + +assert.throws(SyntaxError, function() { + eval('(function () { eval = 42; })()'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/12.2.1-4gs-strict.js b/js/src/tests/test262/language/statements/variable/12.2.1-4gs-strict.js new file mode 100644 index 0000000000..ce102473c1 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/12.2.1-4gs-strict.js @@ -0,0 +1,19 @@ +// |reftest| error:SyntaxError +'use strict'; +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-4gs +description: > + Strict Mode - SyntaxError is thrown if a VariableDeclarationNoIn + occurs within strict code and its Identifier is arguments +negative: + phase: parse + type: SyntaxError +flags: [onlyStrict] +---*/ + +$DONOTEVALUATE(); + +var arguments; diff --git a/js/src/tests/test262/language/statements/variable/12.2.1-5-s.js b/js/src/tests/test262/language/statements/variable/12.2.1-5-s.js new file mode 100644 index 0000000000..385e85d2fa --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/12.2.1-5-s.js @@ -0,0 +1,12 @@ +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-5-s +description: > + a Function declaring var named 'eval' does not throw SyntaxError +---*/ + + Function('var eval;'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/12.2.1-6-s-strict.js b/js/src/tests/test262/language/statements/variable/12.2.1-6-s-strict.js new file mode 100644 index 0000000000..03dfd7037b --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/12.2.1-6-s-strict.js @@ -0,0 +1,17 @@ +'use strict'; +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-6-s +description: > + eval - a Function assigning into 'eval' will not throw any error + if contained within strict mode and its body does not start with + strict mode +flags: [onlyStrict] +---*/ + + var f = Function('eval = 42;'); + f(); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/12.2.1-7-s-strict.js b/js/src/tests/test262/language/statements/variable/12.2.1-7-s-strict.js new file mode 100644 index 0000000000..9fd17ec4d5 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/12.2.1-7-s-strict.js @@ -0,0 +1,18 @@ +'use strict'; +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-7-s +description: > + eval - a direct eval declaring a var named 'eval' throws + SyntaxError in strict mode +flags: [onlyStrict] +---*/ + + +assert.throws(SyntaxError, function() { + eval('var eval;'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/12.2.1-8-s-strict.js b/js/src/tests/test262/language/statements/variable/12.2.1-8-s-strict.js new file mode 100644 index 0000000000..1bd90d77dc --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/12.2.1-8-s-strict.js @@ -0,0 +1,18 @@ +'use strict'; +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-8-s +description: > + eval - a direct eval assigning into 'eval' throws SyntaxError in + strict mode +flags: [onlyStrict] +---*/ + + +assert.throws(SyntaxError, function() { + eval('eval = 42;'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/12.2.1-9-s.js b/js/src/tests/test262/language/statements/variable/12.2.1-9-s.js new file mode 100644 index 0000000000..d055dfb118 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/12.2.1-9-s.js @@ -0,0 +1,13 @@ +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-9-s +description: > + an indirect eval declaring a var named 'eval' does not throw +---*/ + + var s = eval; + s('var eval;'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/S12.2_A1.js b/js/src/tests/test262/language/statements/variable/S12.2_A1.js new file mode 100644 index 0000000000..42c92a7ead --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/S12.2_A1.js @@ -0,0 +1,51 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + Variables are created when the program is entered. Variables are initialised to "undefined" + when created. A variable with an Initialiser is assigned the value of its AssignmentExpression when the + VariableStatement is executed, not when the variable is created +es5id: 12.2_A1 +description: Creating variables after entering the execution scope +---*/ + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +try { + __x = __x; + __y = __x ? "good fellow" : "liar"; // __y assigned to "liar" since __x undefined + __z = __z === __x ? 1 : 0; // __z assigned to 1 since both __x and __z are undefined +} catch (e) { + throw new Test262Error('#1: Using declarated variable before it declaration is admitted'); +} +// +////////////////////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////////////////////// +//CHECK#2 +assert.throws(ReferenceError, function() { + __something__undefined = __something__undefined; +}); +// +////////////////////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////////////////////// +//CHECK#3 +if ((__y !== "liar")&(__z !== 1)) { + throw new Test262Error('#3: (__y === "liar") and (__z === 1). Actual: __y ==='+__y+' and __z ==='+__z ); +} +// +////////////////////////////////////////////////////////////////////////////// + +var __x, __y = true, __z = __y ? "smeagol" : "golum"; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#4 +if (!__y&!(__z = "smeagol")) { + throw new Test262Error('#4: A variable with an Initialiser is assigned the value of its AssignmentExpression when the VariableStatement is executed'); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/S12.2_A10.js b/js/src/tests/test262/language/statements/variable/S12.2_A10.js new file mode 100644 index 0000000000..a3545227ce --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/S12.2_A10.js @@ -0,0 +1,24 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: "\"var\" statement within \"for\" statement is allowed" +es5id: 12.2_A10 +description: Declaring variable within a "for" IterationStatement +---*/ + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +try { + __ind=__ind; +} catch (e) { + throw new Test262Error('#1: var inside "for" is admitted '+e.message); +} +// +////////////////////////////////////////////////////////////////////////////// + +for (var __ind;;){ + break; +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/S12.2_A11.js b/js/src/tests/test262/language/statements/variable/S12.2_A11.js new file mode 100644 index 0000000000..430e588523 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/S12.2_A11.js @@ -0,0 +1,29 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: When using property attributes, {ReadOnly} is not used +es5id: 12.2_A11 +description: Changing variable value using property attributes +---*/ + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +this['__declared__var'] = "baloon"; +if (this['__declared__var'] !== "baloon") { + throw new Test262Error('#1: this[\'__declared__var\'] === "baloon". Actual: this[\'__declared__var\'] ==='+ this['__declared__var'] ); +} +// +////////////////////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////////////////////// +//CHECK#2 +if (__declared__var !== "baloon") { + throw new Test262Error('#2: __declared__var === "baloon". Actual: __declared__var ==='+ __declared__var ); +} +// +////////////////////////////////////////////////////////////////////////////// + +var __declared__var; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/S12.2_A12.js b/js/src/tests/test262/language/statements/variable/S12.2_A12.js new file mode 100644 index 0000000000..7c4357d3bd --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/S12.2_A12.js @@ -0,0 +1,22 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: VariableDeclaration within "do-while" loop is allowed +es5id: 12.2_A12 +description: Declaring variable within "do-while" statement +---*/ + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +try { + x=x; +} catch (e) { + throw new Test262Error('#1: Declaration variable inside "do-while" statement is admitted'); +} +// +////////////////////////////////////////////////////////////////////////////// + +do var x; while (false); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/S12.2_A2.js b/js/src/tests/test262/language/statements/variable/S12.2_A2.js new file mode 100644 index 0000000000..be9496eba0 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/S12.2_A2.js @@ -0,0 +1,52 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + Variables are defined with global scope (that is, they are created as + members of the global object, as described in 10.1.3) using property + attributes { DontDelete} +es5id: 12.2_A2 +description: > + Checking if deleting global variables that have the attributes + {DontDelete} fails +flags: [noStrict] +---*/ + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (delete(__variable)) { + throw new Test262Error('#1: delete(__variable)===false'); +} +// +////////////////////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////////////////////// +//CHECK#2 +if (delete(this["__variable"])) { + throw new Test262Error('#2: delete(this["__variable"])===false'); +} +// +////////////////////////////////////////////////////////////////////////////// + + +var __variable; +var __variable = "defined"; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#3 +if (delete(__variable) | delete(this["__variable"])) { + throw new Test262Error('#3: (delete(__variable) | delete(this["__variable"]))===false' ); +} +// +////////////////////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////////////////////// +//CHECK#4 +if ((__variable !== "defined")|(this["__variable"] !=="defined")) { + throw new Test262Error('#4: __variable === "defined" and this["__variable"] ==="defined"'); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/S12.2_A3.js b/js/src/tests/test262/language/statements/variable/S12.2_A3.js new file mode 100644 index 0000000000..d60312ae65 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/S12.2_A3.js @@ -0,0 +1,55 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: FunctionDeclaration produces a new scope +es5id: 12.2_A3 +description: Using Global scope and Function scope together +---*/ + +var __var = "OUT"; + +(function(){ + var __var ="IN"; + (function(){__var = "INNER_SPACE";})(); + (function(){var __var = "INNER_SUN";})(); + ////////////////////////////////////////////////////////////////////////////// + //CHECK#1 + if (__var !== "INNER_SPACE") { + throw new Test262Error('#1: __var === "INNER_SPACE". Actual: __var ==='+ __var ); + } + // + ////////////////////////////////////////////////////////////////////////////// +})(); + +////////////////////////////////////////////////////////////////////////////// +//CHECK#2 +if (__var !== "OUT") { + throw new Test262Error('#2: __var === "OUT". Actual: __var ==='+ __var ); +} +// +////////////////////////////////////////////////////////////////////////////// + + +(function(){ + __var ="IN"; + (function(){__var = "INNERED"})(); + (function(){var __var = "INNAGER"})(); + ////////////////////////////////////////////////////////////////////////////// + //CHECK#3 + if (__var!=="INNERED") { + throw new Test262Error('#3: __var==="INNERED". Actual: __var==='+ __var ); + } + // + ////////////////////////////////////////////////////////////////////////////// +})(); + +////////////////////////////////////////////////////////////////////////////// +//CHECK#4 +if (__var!=="INNERED") { + throw new Test262Error('#4: __var==="INNERED". Actual: __var==='+ __var ); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/S12.2_A4.js b/js/src/tests/test262/language/statements/variable/S12.2_A4.js new file mode 100644 index 0000000000..e77f51d29f --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/S12.2_A4.js @@ -0,0 +1,30 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Unicode characters in variable Identifier are allowed +es5id: 12.2_A4 +description: Create and use unicode characters in variable Identifier +---*/ + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +try { + __var=__var; +} catch (e) { + throw new Test262Error('#1: Unicode characters in variable Identifier allowed'); +} +// +////////////////////////////////////////////////////////////////////////////// + +var \u005f\u005f\u0076\u0061\u0072 = 1; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#2 +if (__var !== 1) { + throw new Test262Error('#2: __var === 1. Actual: __var ==='+ __var ); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/S12.2_A5.js b/js/src/tests/test262/language/statements/variable/S12.2_A5.js new file mode 100644 index 0000000000..0c1c374efb --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/S12.2_A5.js @@ -0,0 +1,33 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + VariableDeclaration within Eval statement is initialized as the program + reaches the eval statement +es5id: 12.2_A5 +description: Executing eval("var x") +flags: [noStrict] +---*/ + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +assert.throws(ReferenceError, function() { + x=x; +}); +// +////////////////////////////////////////////////////////////////////////////// + +eval("var x"); + +////////////////////////////////////////////////////////////////////////////// +//CHECK#2 +try{ + x=x; +}catch(e){ + throw new Test262Error('#2: VariableDeclaration inside Eval statement is initialized when program reaches the eval statement '+e.message); +}; +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/S12.2_A6_T1.js b/js/src/tests/test262/language/statements/variable/S12.2_A6_T1.js new file mode 100644 index 0000000000..6daa61bb21 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/S12.2_A6_T1.js @@ -0,0 +1,36 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: VariableDeclaration within "try-catch" statement is allowed +es5id: 12.2_A6_T1 +description: Declaring variable within "try-catch" statement +---*/ + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +try{ + intry__var=intry__var; +}catch(e){ + throw new Test262Error('#1: Variable declaration inside "try" block is admitted'); +}; +// +////////////////////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////////////////////// +//CHECK#2 +try{ + incatch__var=incatch__var; +}catch(e){ + throw new Test262Error('#2: Variable declaration inside "catch" block is admitted'); +}; +// +////////////////////////////////////////////////////////////////////////////// + +try{ + var intry__var; +}catch(e){ + var incatch__var; +}; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/S12.2_A6_T2.js b/js/src/tests/test262/language/statements/variable/S12.2_A6_T2.js new file mode 100644 index 0000000000..563ce40c32 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/S12.2_A6_T2.js @@ -0,0 +1,38 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: VariableDeclaration within "try-catch" statement is allowed +es5id: 12.2_A6_T2 +description: Declaring variables within "try-catch" statement +---*/ + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +try{ + intry__intry__var=intry__intry__var; + intry__incatch__var=intry__incatch__var; + incatch__intry__var=incatch__intry__var; + incatch__incatch__var=incatch__incatch__var; +}catch(e){ + throw new Test262Error('#1: Variable declaration inside "try-catch" block is admitted'); +}; +// +////////////////////////////////////////////////////////////////////////////// + +try{ + try { + var intry__intry__var; + } catch (e) { + var intry__incatch__var; + } +}catch(e){ + try { + var incatch__intry__var; + } catch (e) { + var incatch__incatch__var; + } + +}; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/S12.2_A7.js b/js/src/tests/test262/language/statements/variable/S12.2_A7.js new file mode 100644 index 0000000000..6e58224dd6 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/S12.2_A7.js @@ -0,0 +1,25 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: VariableDeclaration within "for" statement is allowed +es5id: 12.2_A7 +description: Declaring variable within "for" statement +---*/ + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +try{ + infor_var = infor_var; +}catch(e){ + throw new Test262Error('#1: Variable declaration inside "for" loop is admitted'); +}; +// +////////////////////////////////////////////////////////////////////////////// + +for (;;){ + break; + var infor_var; +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/S12.2_A8_T1.js b/js/src/tests/test262/language/statements/variable/S12.2_A8_T1.js new file mode 100644 index 0000000000..569fd0b3b4 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/S12.2_A8_T1.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Only AssignmentExpression is admitted when variable is initialized +es5id: 12.2_A8_T1 +description: Checking if execution of "var x += 1" fails +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +var x += 1; +// +////////////////////////////////////////////////////////////////////////////// diff --git a/js/src/tests/test262/language/statements/variable/S12.2_A8_T2.js b/js/src/tests/test262/language/statements/variable/S12.2_A8_T2.js new file mode 100644 index 0000000000..7fbb78a499 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/S12.2_A8_T2.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Only AssignmentExpression is admitted when variable is initialized +es5id: 12.2_A8_T2 +description: Checking if execution of "var x | true" fails +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +var x | true; +// +////////////////////////////////////////////////////////////////////////////// diff --git a/js/src/tests/test262/language/statements/variable/S12.2_A8_T3.js b/js/src/tests/test262/language/statements/variable/S12.2_A8_T3.js new file mode 100644 index 0000000000..c0502a0959 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/S12.2_A8_T3.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Only AssignmentExpression is admitted when variable is initialized +es5id: 12.2_A8_T3 +description: Checking if execution of "var x && 1" fails +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +var x && 1; +// +////////////////////////////////////////////////////////////////////////////// diff --git a/js/src/tests/test262/language/statements/variable/S12.2_A8_T4.js b/js/src/tests/test262/language/statements/variable/S12.2_A8_T4.js new file mode 100644 index 0000000000..e2712ad4c7 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/S12.2_A8_T4.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Only AssignmentExpression is admitted when variable is initialized +es5id: 12.2_A8_T4 +description: Checking if execution of "var x++" fails +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +var x++; +// +////////////////////////////////////////////////////////////////////////////// diff --git a/js/src/tests/test262/language/statements/variable/S12.2_A8_T5.js b/js/src/tests/test262/language/statements/variable/S12.2_A8_T5.js new file mode 100644 index 0000000000..1c641b49e3 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/S12.2_A8_T5.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Only AssignmentExpression is admitted when variable is initialized +es5id: 12.2_A8_T5 +description: Checking if execution of "var --x" fails +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +var --x; +// +////////////////////////////////////////////////////////////////////////////// diff --git a/js/src/tests/test262/language/statements/variable/S12.2_A8_T6.js b/js/src/tests/test262/language/statements/variable/S12.2_A8_T6.js new file mode 100644 index 0000000000..c45cbe2dc0 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/S12.2_A8_T6.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Only AssignmentExpression is admitted when variable is initialized +es5id: 12.2_A8_T6 +description: Checking if execution of "var x*1" fails +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +var x*1; +// +////////////////////////////////////////////////////////////////////////////// diff --git a/js/src/tests/test262/language/statements/variable/S12.2_A8_T7.js b/js/src/tests/test262/language/statements/variable/S12.2_A8_T7.js new file mode 100644 index 0000000000..46d51448c6 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/S12.2_A8_T7.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Only AssignmentExpression is admitted when variable is initialized +es5id: 12.2_A8_T7 +description: Checking if execution of "var x>>1" fails +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +var x>>1; +// +////////////////////////////////////////////////////////////////////////////// diff --git a/js/src/tests/test262/language/statements/variable/S12.2_A8_T8.js b/js/src/tests/test262/language/statements/variable/S12.2_A8_T8.js new file mode 100644 index 0000000000..f83d7bc49a --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/S12.2_A8_T8.js @@ -0,0 +1,22 @@ +// |reftest| error:SyntaxError +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Only AssignmentExpression is admitted when variable is initialized +es5id: 12.2_A8_T8 +description: Checking if execution of "var x in __arr" fails +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +__arr = []; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +var x in __arr; +// +////////////////////////////////////////////////////////////////////////////// diff --git a/js/src/tests/test262/language/statements/variable/S12.2_A9.js b/js/src/tests/test262/language/statements/variable/S12.2_A9.js new file mode 100644 index 0000000000..ff67277bc5 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/S12.2_A9.js @@ -0,0 +1,28 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: When using property attributes, {DontEnum} is not used +es5id: 12.2_A9 +description: > + Enumerating property attributes of "this" and then searching for + the declared variable +---*/ + +var enumed; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +for (var __prop in this){ + if (__prop === "__declared__var") + enumed=true; +} +if (!(enumed)) { + throw new Test262Error('#1: When using property attributes, {DontEnum} not used'); +} +// +////////////////////////////////////////////////////////////////////////////// + +var __declared__var; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/S14_A1.js b/js/src/tests/test262/language/statements/variable/S14_A1.js new file mode 100644 index 0000000000..0e1c7c67de --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/S14_A1.js @@ -0,0 +1,35 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: FunctionExpression must be localed in a reacheable fragment of the program +es5id: 14_A1 +description: Declaring a function within an "if" Expression +---*/ + +var THERE = "I'm there"; +var HERE = "I'm here"; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if ( __func !== undefined) { + throw new Test262Error('#1: __func === undefined. Actual: __func ==='+ __func ); +} +// +////////////////////////////////////////////////////////////////////////////// + +if (true){ + var __func = function(){return HERE;}; +} else { + var __func = function (){return THERE;}; +}; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#2 +if (__func() !== HERE) { + throw new Test262Error('#2: __func() === HERE. Actual: __func() ==='+ __func() ); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/arguments-fn-non-strict.js b/js/src/tests/test262/language/statements/variable/arguments-fn-non-strict.js new file mode 100644 index 0000000000..0b4f69396a --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/arguments-fn-non-strict.js @@ -0,0 +1,16 @@ +// Copyright (c) 2018 Mike Pennisi. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-12 +esid: sec-variable-statement +description: > + arguments as local var identifier is allowed within a function declaration +flags: [noStrict] +---*/ + +function f() { + var arguments; +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/arguments-fn-strict-list-final-init-strict.js b/js/src/tests/test262/language/statements/variable/arguments-fn-strict-list-final-init-strict.js new file mode 100644 index 0000000000..85c424a3ed --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/arguments-fn-strict-list-final-init-strict.js @@ -0,0 +1,22 @@ +// |reftest| error:SyntaxError +'use strict'; +// Copyright (c) 2018 Mike Pennisi. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-28-s +esid: sec-variable-statement +description: > + arguments as local var identifier assigned to throws SyntaxError + in strict mode within a function declaration +flags: [onlyStrict] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +function f() { + var a, arguments = 42; +} diff --git a/js/src/tests/test262/language/statements/variable/arguments-fn-strict-list-final-strict.js b/js/src/tests/test262/language/statements/variable/arguments-fn-strict-list-final-strict.js new file mode 100644 index 0000000000..673f75871b --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/arguments-fn-strict-list-final-strict.js @@ -0,0 +1,22 @@ +// |reftest| error:SyntaxError +'use strict'; +// Copyright (c) 2018 Mike Pennisi. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-30-s +esid: sec-variable-statement +description: > + arguments as local var identifier throws SyntaxError in strict mode within a + function declaration +flags: [onlyStrict] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +function f() { + var a = 42, arguments; +} diff --git a/js/src/tests/test262/language/statements/variable/arguments-fn-strict-list-first-init-strict.js b/js/src/tests/test262/language/statements/variable/arguments-fn-strict-list-first-init-strict.js new file mode 100644 index 0000000000..4edda98e1a --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/arguments-fn-strict-list-first-init-strict.js @@ -0,0 +1,21 @@ +// |reftest| error:SyntaxError +'use strict'; +// Copyright (c) 2018 Mike Pennisi. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-variable-statement +description: > + arguments as local var identifier throws SyntaxError in strict mode within a + function declaration +flags: [onlyStrict] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +function f() { + var arguments = 42, a; +} diff --git a/js/src/tests/test262/language/statements/variable/arguments-fn-strict-list-first-strict.js b/js/src/tests/test262/language/statements/variable/arguments-fn-strict-list-first-strict.js new file mode 100644 index 0000000000..92eaa10feb --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/arguments-fn-strict-list-first-strict.js @@ -0,0 +1,22 @@ +// |reftest| error:SyntaxError +'use strict'; +// Copyright (c) 2018 Mike Pennisi. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-25-s +esid: sec-variable-statement +description: > + arguments as local var identifier throws SyntaxError in strict mode within a + function declaration +flags: [onlyStrict] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +function f() { + var arguments, a; +} diff --git a/js/src/tests/test262/language/statements/variable/arguments-fn-strict-list-middle-init-strict.js b/js/src/tests/test262/language/statements/variable/arguments-fn-strict-list-middle-init-strict.js new file mode 100644 index 0000000000..2145140e71 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/arguments-fn-strict-list-middle-init-strict.js @@ -0,0 +1,21 @@ +// |reftest| error:SyntaxError +'use strict'; +// Copyright (c) 2018 Mike Pennisi. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-variable-statement +description: > + arguments as local var identifier throws SyntaxError in strict mode within a + function declaration +flags: [onlyStrict] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +function f() { + var a, arguments = 42, b; +} diff --git a/js/src/tests/test262/language/statements/variable/arguments-fn-strict-list-middle-strict.js b/js/src/tests/test262/language/statements/variable/arguments-fn-strict-list-middle-strict.js new file mode 100644 index 0000000000..8304db3dca --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/arguments-fn-strict-list-middle-strict.js @@ -0,0 +1,22 @@ +// |reftest| error:SyntaxError +'use strict'; +// Copyright (c) 2018 Mike Pennisi. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-33-s +esid: sec-variable-statement +description: > + arguments as local var identifier throws SyntaxError in strict mode within a + function declaration +flags: [onlyStrict] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +function f() { + var a, arguments, b; +} diff --git a/js/src/tests/test262/language/statements/variable/arguments-fn-strict-list-repeated-strict.js b/js/src/tests/test262/language/statements/variable/arguments-fn-strict-list-repeated-strict.js new file mode 100644 index 0000000000..9120c2cb89 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/arguments-fn-strict-list-repeated-strict.js @@ -0,0 +1,22 @@ +// |reftest| error:SyntaxError +'use strict'; +// Copyright (c) 2018 Mike Pennisi. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-32-s +esid: sec-variable-statement +description: > + arguments as local var identifier defined twice and assigned once + throws SyntaxError in strict mode within a function declaration +flags: [onlyStrict] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +function f() { + var arguments, arguments = 42; +} diff --git a/js/src/tests/test262/language/statements/variable/arguments-fn-strict-single-init-strict.js b/js/src/tests/test262/language/statements/variable/arguments-fn-strict-single-init-strict.js new file mode 100644 index 0000000000..9876d1b3c9 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/arguments-fn-strict-single-init-strict.js @@ -0,0 +1,22 @@ +// |reftest| error:SyntaxError +'use strict'; +// Copyright (c) 2018 Mike Pennisi. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-23-s +esid: sec-variable-statement +description: > + arguments as local var identifier assigned to throws SyntaxError + in strict mode within a function declaration +flags: [onlyStrict] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +function f() { + var arguments = 42; +} diff --git a/js/src/tests/test262/language/statements/variable/arguments-fn-strict-single-strict.js b/js/src/tests/test262/language/statements/variable/arguments-fn-strict-single-strict.js new file mode 100644 index 0000000000..7249d3898a --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/arguments-fn-strict-single-strict.js @@ -0,0 +1,22 @@ +// |reftest| error:SyntaxError +'use strict'; +// Copyright (c) 2018 Mike Pennisi. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-12-s +esid: sec-variable-statement +description: > + arguments as local var identifier throws SyntaxError in strict mode within a + function declaration +flags: [onlyStrict] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +function f() { + var arguments; +} diff --git a/js/src/tests/test262/language/statements/variable/arguments-non-strict.js b/js/src/tests/test262/language/statements/variable/arguments-non-strict.js new file mode 100644 index 0000000000..040ef95026 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/arguments-non-strict.js @@ -0,0 +1,13 @@ +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-12 +esid: sec-variable-statement +description: arguments as local var identifier is allowed +flags: [noStrict] +---*/ + +var arguments; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/arguments-strict-list-final-init-strict.js b/js/src/tests/test262/language/statements/variable/arguments-strict-list-final-init-strict.js new file mode 100644 index 0000000000..007685d2d8 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/arguments-strict-list-final-init-strict.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +'use strict'; +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-28-s +esid: sec-variable-statement +description: > + arguments as local var identifier assigned to throws SyntaxError + in strict mode +flags: [onlyStrict] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +var a, arguments = 42; diff --git a/js/src/tests/test262/language/statements/variable/arguments-strict-list-final-strict.js b/js/src/tests/test262/language/statements/variable/arguments-strict-list-final-strict.js new file mode 100644 index 0000000000..d094fab1b5 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/arguments-strict-list-final-strict.js @@ -0,0 +1,18 @@ +// |reftest| error:SyntaxError +'use strict'; +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-30-s +esid: sec-variable-statement +description: arguments as local var identifier throws SyntaxError in strict mode +flags: [onlyStrict] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +var a = 42, arguments; diff --git a/js/src/tests/test262/language/statements/variable/arguments-strict-list-first-init-strict.js b/js/src/tests/test262/language/statements/variable/arguments-strict-list-first-init-strict.js new file mode 100644 index 0000000000..3f4901e41a --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/arguments-strict-list-first-init-strict.js @@ -0,0 +1,17 @@ +// |reftest| error:SyntaxError +'use strict'; +// Copyright (c) 2018 Mike Pennisi. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-variable-statement +description: arguments as local var identifier throws SyntaxError in strict mode +flags: [onlyStrict] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +var arguments = 42, a; diff --git a/js/src/tests/test262/language/statements/variable/arguments-strict-list-first-strict.js b/js/src/tests/test262/language/statements/variable/arguments-strict-list-first-strict.js new file mode 100644 index 0000000000..e1c050e1e2 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/arguments-strict-list-first-strict.js @@ -0,0 +1,18 @@ +// |reftest| error:SyntaxError +'use strict'; +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-25-s +esid: sec-variable-statement +description: arguments as local var identifier throws SyntaxError in strict mode +flags: [onlyStrict] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +var arguments, a; diff --git a/js/src/tests/test262/language/statements/variable/arguments-strict-list-middle-init-strict.js b/js/src/tests/test262/language/statements/variable/arguments-strict-list-middle-init-strict.js new file mode 100644 index 0000000000..ee3de5a5af --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/arguments-strict-list-middle-init-strict.js @@ -0,0 +1,17 @@ +// |reftest| error:SyntaxError +'use strict'; +// Copyright (c) 2018 Mike Pennisi. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-variable-statement +description: arguments as local var identifier throws SyntaxError in strict mode +flags: [onlyStrict] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +var a, arguments = 42, b; diff --git a/js/src/tests/test262/language/statements/variable/arguments-strict-list-middle-strict.js b/js/src/tests/test262/language/statements/variable/arguments-strict-list-middle-strict.js new file mode 100644 index 0000000000..c993698fdd --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/arguments-strict-list-middle-strict.js @@ -0,0 +1,18 @@ +// |reftest| error:SyntaxError +'use strict'; +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-33-s +esid: sec-variable-statement +description: arguments as local var identifier throws SyntaxError in strict mode +flags: [onlyStrict] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +var a, arguments, b; diff --git a/js/src/tests/test262/language/statements/variable/arguments-strict-list-repeated-strict.js b/js/src/tests/test262/language/statements/variable/arguments-strict-list-repeated-strict.js new file mode 100644 index 0000000000..ca6f305efb --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/arguments-strict-list-repeated-strict.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +'use strict'; +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-32-s +esid: sec-variable-statement +description: > + arguments as local var identifier defined twice and assigned once + throws SyntaxError in strict mode +flags: [onlyStrict] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +var arguments, arguments = 42; diff --git a/js/src/tests/test262/language/statements/variable/arguments-strict-single-init-strict.js b/js/src/tests/test262/language/statements/variable/arguments-strict-single-init-strict.js new file mode 100644 index 0000000000..a6b3d082bb --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/arguments-strict-single-init-strict.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +'use strict'; +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-23-s +esid: sec-variable-statement +description: > + arguments as local var identifier assigned to throws SyntaxError + in strict mode +flags: [onlyStrict] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +var arguments = 42; diff --git a/js/src/tests/test262/language/statements/variable/arguments-strict-single-strict.js b/js/src/tests/test262/language/statements/variable/arguments-strict-single-strict.js new file mode 100644 index 0000000000..c7165638db --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/arguments-strict-single-strict.js @@ -0,0 +1,18 @@ +// |reftest| error:SyntaxError +'use strict'; +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-12-s +esid: sec-variable-statement +description: arguments as local var identifier throws SyntaxError in strict mode +flags: [onlyStrict] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +var arguments; diff --git a/js/src/tests/test262/language/statements/variable/binding-resolution.js b/js/src/tests/test262/language/statements/variable/binding-resolution.js new file mode 100644 index 0000000000..ca201de00a --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/binding-resolution.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-variable-statement-runtime-semantics-evaluation +es6id: 13.3.2.4 +description: Binding is resolve prior to evaluation of Initializer +info: | + VariableDeclaration : BindingIdentifier Initializer + + 1. Let bindingId be StringValue of BindingIdentifier. + 2. Let lhs be ? ResolveBinding(bindingId). + 3. Let rhs be the result of evaluating Initializer. + [...] +flags: [noStrict] +---*/ + +var obj = { test262id: 1 }; + +with (obj) { + var test262id = delete obj.test262id; +} + +assert.sameValue(obj.test262id, true); +assert.sameValue(test262id, undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/browser.js b/js/src/tests/test262/language/statements/variable/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/browser.js diff --git a/js/src/tests/test262/language/statements/variable/cptn-value.js b/js/src/tests/test262/language/statements/variable/cptn-value.js new file mode 100644 index 0000000000..89df566e72 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/cptn-value.js @@ -0,0 +1,39 @@ +// 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-variable-statement-runtime-semantics-evaluation +es6id: 13.3.2.4 +description: Returns an empty completion +info: | + VariableStatement : var VariableDeclarationList ; + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). +---*/ + +assert.sameValue( + eval('var test262id1;'), undefined, 'Single declaration without initializer' +); +assert.sameValue( + eval('var test262id2 = 2;'), + undefined, + 'Single declaration bearing initializer' +); +assert.sameValue( + eval('var test262id3 = 3, test262id4;'), + undefined, + 'Multiple declarations, final without initializer' +); +assert.sameValue( + eval('var test262id5, test262id6 = 6;'), + undefined, + 'Multiple declarations, final bearing initializer' +); + +assert.sameValue(eval('7; var test262id8;'), 7); +assert.sameValue(eval('9; var test262id10 = 10;'), 9); +assert.sameValue(eval('11; var test262id12 = 12, test262id13;'), 11); +assert.sameValue(eval('14; var test262id15, test262id16 = 16;'), 14); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-init-iter-close.js b/js/src/tests/test262/language/statements/variable/dstr/ary-init-iter-close.js new file mode 100644 index 0000000000..cf9c4b2b06 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-init-iter-close.js @@ -0,0 +1,46 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-init-iter-close.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: Iterator is closed when not exhausted by pattern evaluation (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + [...] + 4. If iteratorRecord.[[done]] is false, return ? IteratorClose(iterator, + result). + [...] + +---*/ +var doneCallCount = 0; +var iter = {}; +iter[Symbol.iterator] = function() { + return { + next: function() { + return { value: null, done: false }; + }, + return: function() { + doneCallCount += 1; + return {}; + } + }; +}; + +var [x] = iter; + +assert.sameValue(doneCallCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-init-iter-get-err-array-prototype.js b/js/src/tests/test262/language/statements/variable/dstr/ary-init-iter-get-err-array-prototype.js new file mode 100644 index 0000000000..2c7460a7a8 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-init-iter-get-err-array-prototype.js @@ -0,0 +1,41 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-init-iter-get-err-array-prototype.case +// - src/dstr-binding/error/var-stmt.template +/*--- +description: Abrupt completion returned by GetIterator (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + 1. Let iteratorRecord be ? GetIterator(value). + + GetIterator ( obj [ , hint [ , method ] ] ) + + [...] + 4. Let iterator be ? Call(method, obj). + + Call ( F, V [ , argumentsList ] ) + + [...] + 2. If IsCallable(F) is false, throw a TypeError exception. + +---*/ +delete Array.prototype[Symbol.iterator]; + +assert.throws(TypeError, function() { + var [x, y, z] = [1, 2, 3]; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-init-iter-get-err.js b/js/src/tests/test262/language/statements/variable/dstr/ary-init-iter-get-err.js new file mode 100644 index 0000000000..1ec614b85b --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-init-iter-get-err.js @@ -0,0 +1,35 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-init-iter-get-err.case +// - src/dstr-binding/error/var-stmt.template +/*--- +description: Abrupt completion returned by GetIterator (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + 1. Let iterator be GetIterator(value). + 2. ReturnIfAbrupt(iterator). + +---*/ +var iter = {}; +iter[Symbol.iterator] = function() { + throw new Test262Error(); +}; + +assert.throws(Test262Error, function() { + var [x] = iter; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-init-iter-no-close.js b/js/src/tests/test262/language/statements/variable/dstr/ary-init-iter-no-close.js new file mode 100644 index 0000000000..9f6b250cac --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-init-iter-no-close.js @@ -0,0 +1,46 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-init-iter-no-close.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: Iterator is not closed when exhausted by pattern evaluation (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + [...] + 4. If iteratorRecord.[[done]] is false, return ? IteratorClose(iterator, + result). + [...] + +---*/ +var doneCallCount = 0; +var iter = {}; +iter[Symbol.iterator] = function() { + return { + next: function() { + return { value: null, done: true }; + }, + return: function() { + doneCallCount += 1; + return {}; + } + }; +}; + +var [x] = iter; + +assert.sameValue(doneCallCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-name-iter-val.js b/js/src/tests/test262/language/statements/variable/dstr/ary-name-iter-val.js new file mode 100644 index 0000000000..f51338da5f --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-name-iter-val.js @@ -0,0 +1,45 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-name-iter-val.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: SingleNameBinding with normal value iteration (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + [...] + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set + iteratorRecord.[[done]] to true. + iii. ReturnIfAbrupt(v). + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var [x, y, z] = [1, 2, 3]; + +assert.sameValue(x, 1); +assert.sameValue(y, 2); +assert.sameValue(z, 3); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-ary-elem-init.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-ary-elem-init.js new file mode 100644 index 0000000000..e81012a038 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-ary-elem-init.js @@ -0,0 +1,37 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elem-init.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: BindingElement with array binding pattern and initializer is used (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + +var [[x, y, z] = [4, 5, 6]] = []; + +assert.sameValue(x, 4); +assert.sameValue(y, 5); +assert.sameValue(z, 6); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-ary-elem-iter.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-ary-elem-iter.js new file mode 100644 index 0000000000..a60ce48e79 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-ary-elem-iter.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elem-iter.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + [...] + e. Else, + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + +var [[x, y, z] = [4, 5, 6]] = [[7, 8, 9]]; + +assert.sameValue(x, 7); +assert.sameValue(y, 8); +assert.sameValue(z, 9); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-ary-elision-init.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-ary-elision-init.js new file mode 100644 index 0000000000..0bffceb663 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-ary-elision-init.js @@ -0,0 +1,44 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elision-init.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: BindingElement with array binding pattern and initializer is used (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + +---*/ +var first = 0; +var second = 0; +function* g() { + first += 1; + yield; + second += 1; +}; + +var [[,] = g()] = []; + +assert.sameValue(first, 1); +assert.sameValue(second, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-ary-elision-iter.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-ary-elision-iter.js new file mode 100644 index 0000000000..22ea483fc2 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-ary-elision-iter.js @@ -0,0 +1,41 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elision-iter.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + [...] + e. Else, + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + +---*/ +var callCount = 0; +function* g() { + callCount += 1; +}; + +var [[,] = g()] = [[]]; + +assert.sameValue(callCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-ary-empty-init.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-ary-empty-init.js new file mode 100644 index 0000000000..cf21fbc8df --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-ary-empty-init.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-empty-init.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: BindingElement with array binding pattern and initializer is used (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + +---*/ +var initCount = 0; +var iterCount = 0; +var iter = function*() { iterCount += 1; }(); + +var [[] = function() { initCount += 1; return iter; }()] = []; + +assert.sameValue(initCount, 1); +assert.sameValue(iterCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-ary-empty-iter.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-ary-empty-iter.js new file mode 100644 index 0000000000..1e435ee936 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-ary-empty-iter.js @@ -0,0 +1,37 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-empty-iter.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + [...] + e. Else, + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ +var initCount = 0; + +var [[] = function() { initCount += 1; }()] = [[23]]; + +assert.sameValue(initCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-ary-rest-init.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-ary-rest-init.js new file mode 100644 index 0000000000..12ab532187 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-ary-rest-init.js @@ -0,0 +1,41 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-rest-init.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: BindingElement with array binding pattern and initializer is used (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ +var values = [2, 1, 3]; + +var [[...x] = values] = []; + +assert(Array.isArray(x)); +assert.sameValue(x[0], 2); +assert.sameValue(x[1], 1); +assert.sameValue(x[2], 3); +assert.sameValue(x.length, 3); +assert.notSameValue(x, values); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-ary-rest-iter.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-ary-rest-iter.js new file mode 100644 index 0000000000..9fdc221cb6 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-ary-rest-iter.js @@ -0,0 +1,44 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-rest-iter.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + [...] + e. Else, + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ +var values = [2, 1, 3]; +var initCount = 0; + +var [[...x] = function() { initCount += 1; }()] = [values]; + +assert(Array.isArray(x)); +assert.sameValue(x[0], 2); +assert.sameValue(x[1], 1); +assert.sameValue(x[2], 3); +assert.sameValue(x.length, 3); +assert.notSameValue(x, values); +assert.sameValue(initCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-ary-val-null.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-ary-val-null.js new file mode 100644 index 0000000000..c0962ac95d --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-ary-val-null.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-val-null.case +// - src/dstr-binding/error/var-stmt.template +/*--- +description: Nested array destructuring with a null value (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPattern Initializeropt + + 1. If iteratorRecord.[[done]] is false, then + [...] + e. Else + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + 1. Let iterator be GetIterator(value). + 2. ReturnIfAbrupt(iterator). +---*/ + +assert.throws(TypeError, function() { + var [[x]] = [null]; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-init-exhausted.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-init-exhausted.js new file mode 100644 index 0000000000..63848c4c36 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-init-exhausted.js @@ -0,0 +1,36 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-exhausted.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: Destructuring initializer with an exhausted iterator (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 5. If iteratorRecord.[[done]] is true, let v be undefined. + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var [x = 23] = []; + +assert.sameValue(x, 23); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-init-fn-name-arrow.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-init-fn-name-arrow.js new file mode 100644 index 0000000000..7f21576544 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-init-fn-name-arrow.js @@ -0,0 +1,37 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-arrow.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: SingleNameBinding does assign name to arrow functions (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var [arrow = () => {}] = []; + +assert.sameValue(arrow.name, 'arrow'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-init-fn-name-class.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-init-fn-name-class.js new file mode 100644 index 0000000000..c67cda8537 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-init-fn-name-class.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-class.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: SingleNameBinding assigns `name` to "anonymous" classes (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var [cls = class {}, xCls = class X {}, xCls2 = class { static name() {} }] = []; + +assert.sameValue(cls.name, 'cls'); +assert.notSameValue(xCls.name, 'xCls'); +assert.notSameValue(xCls2.name, 'xCls2'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-init-fn-name-cover.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-init-fn-name-cover.js new file mode 100644 index 0000000000..89af1c63e2 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-init-fn-name-cover.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-cover.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: SingleNameBinding does assign name to "anonymous" functions "through" cover grammar (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var [cover = (function () {}), xCover = (0, function() {})] = []; + +assert.sameValue(cover.name, 'cover'); +assert.notSameValue(xCover.name, 'xCover'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-init-fn-name-fn.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-init-fn-name-fn.js new file mode 100644 index 0000000000..bdfd33ae9d --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-init-fn-name-fn.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-fn.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: SingleNameBinding assigns name to "anonymous" functions (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var [fn = function () {}, xFn = function x() {}] = []; + +assert.sameValue(fn.name, 'fn'); +assert.notSameValue(xFn.name, 'xFn'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-init-fn-name-gen.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-init-fn-name-gen.js new file mode 100644 index 0000000000..a8cda1b7c7 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-init-fn-name-gen.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-gen.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: SingleNameBinding assigns name to "anonymous" generator functions (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). + +---*/ + +var [gen = function* () {}, xGen = function* x() {}] = []; + +assert.sameValue(gen.name, 'gen'); +assert.notSameValue(xGen.name, 'xGen'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-init-hole.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-init-hole.js new file mode 100644 index 0000000000..28f5879d11 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-init-hole.js @@ -0,0 +1,32 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-hole.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: Destructuring initializer with a "hole" (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + SingleNameBinding : BindingIdentifier Initializeropt + [...] 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + [...] + 7. If environment is undefined, return PutValue(lhs, v). 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var [x = 23] = [,]; + +assert.sameValue(x, 23); +// another statement + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-init-skipped.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-init-skipped.js new file mode 100644 index 0000000000..3203ba5cf4 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-init-skipped.js @@ -0,0 +1,41 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-skipped.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: Destructuring initializer is not evaluated when value is not `undefined` (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ +var initCount = 0; +function counter() { + initCount += 1; +} + +var [w = counter(), x = counter(), y = counter(), z = counter()] = [null, 0, false, '']; + +assert.sameValue(w, null); +assert.sameValue(x, 0); +assert.sameValue(y, false); +assert.sameValue(z, ''); +assert.sameValue(initCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-init-throws.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-init-throws.js new file mode 100644 index 0000000000..46caa22350 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-init-throws.js @@ -0,0 +1,33 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-throws.case +// - src/dstr-binding/error/var-stmt.template +/*--- +description: Destructuring initializer returns an abrupt completion (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). +---*/ + +assert.throws(Test262Error, function() { + var [x = (function() { throw new Test262Error(); })()] = [undefined]; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-init-undef.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-init-undef.js new file mode 100644 index 0000000000..2684c5c25e --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-init-undef.js @@ -0,0 +1,35 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-undef.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: Destructuring initializer with an undefined value (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var [x = 23] = [undefined]; + +assert.sameValue(x, 23); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-init-unresolvable.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-init-unresolvable.js new file mode 100644 index 0000000000..7cceead4cb --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-init-unresolvable.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-unresolvable.case +// - src/dstr-binding/error/var-stmt.template +/*--- +description: Destructuring initializer is an unresolvable reference (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + + 6.2.3.1 GetValue (V) + + 1. ReturnIfAbrupt(V). + 2. If Type(V) is not Reference, return V. + 3. Let base be GetBase(V). + 4. If IsUnresolvableReference(V), throw a ReferenceError exception. +---*/ + +assert.throws(ReferenceError, function() { + var [ x = unresolvableReference ] = []; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-iter-complete.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-iter-complete.js new file mode 100644 index 0000000000..e25ae048fd --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-iter-complete.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-complete.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: SingleNameBinding when value iteration completes (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + [...] + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var [x] = []; + +assert.sameValue(x, undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-iter-done.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-iter-done.js new file mode 100644 index 0000000000..f85d3838ff --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-iter-done.js @@ -0,0 +1,34 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-done.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: SingleNameBinding when value iteration was completed previously (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + [...] + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var [_, x] = []; + +assert.sameValue(x, undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-iter-step-err.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-iter-step-err.js new file mode 100644 index 0000000000..1686e71f20 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-iter-step-err.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-step-err.case +// - src/dstr-binding/error/var-stmt.template +/*--- +description: Error forwarding when IteratorStep returns an abrupt completion (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + +---*/ +var g = {}; +g[Symbol.iterator] = function() { + return { + next: function() { + throw new Test262Error(); + } + }; +}; + +assert.throws(Test262Error, function() { + var [x] = g; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-iter-val-array-prototype.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-iter-val-array-prototype.js new file mode 100644 index 0000000000..9b90489faf --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-iter-val-array-prototype.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-val-array-prototype.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: Array destructuring uses overriden Array.prototype[Symbol.iterator] (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [Symbol.iterator, generators, destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializer_opt + + 1. Let bindingId be StringValue of BindingIdentifier. + 2. Let lhs be ? ResolveBinding(bindingId, environment). + 3. If iteratorRecord.[[Done]] is false, then + a. Let next be IteratorStep(iteratorRecord). + b. If next is an abrupt completion, set iteratorRecord.[[Done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[Done]] to true. + e. Else, + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set iteratorRecord.[[Done]] to true. + iii. ReturnIfAbrupt(v). + [...] + 7. Return InitializeReferencedBinding(lhs, v). + +---*/ +Array.prototype[Symbol.iterator] = function* () { + if (this.length > 0) { + yield this[0]; + } + if (this.length > 1) { + yield this[1]; + } + if (this.length > 2) { + yield 42; + } +}; + +var [x, y, z] = [1, 2, 3]; + +assert.sameValue(x, 1); +assert.sameValue(y, 2); +assert.sameValue(z, 42); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-iter-val-err.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-iter-val-err.js new file mode 100644 index 0000000000..1fa5565afb --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-iter-val-err.js @@ -0,0 +1,53 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-val-err.case +// - src/dstr-binding/error/var-stmt.template +/*--- +description: Error forwarding when IteratorValue returns an abrupt completion (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set iteratorRecord.[[done]] to + true. + iii. ReturnIfAbrupt(v). + +---*/ +var poisonedValue = Object.defineProperty({}, 'value', { + get: function() { + throw new Test262Error(); + } +}); +var g = {}; +g[Symbol.iterator] = function() { + return { + next: function() { + return poisonedValue; + } + }; +}; + +assert.throws(Test262Error, function() { + var [x] = g; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-iter-val.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-iter-val.js new file mode 100644 index 0000000000..d10c641887 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-iter-val.js @@ -0,0 +1,45 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-val.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: SingleNameBinding when value iteration was completed previously (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + [...] + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set + iteratorRecord.[[done]] to true. + iii. ReturnIfAbrupt(v). + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var [x, y, z] = [1, 2, 3]; + +assert.sameValue(x, 1); +assert.sameValue(y, 2); +assert.sameValue(z, 3); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-static-init-await-invalid.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-static-init-await-invalid.js new file mode 100644 index 0000000000..2362980f23 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-static-init-await-invalid.js @@ -0,0 +1,27 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-class-definitions-static-semantics-early-errors +description: BindingIdentifier may not be `await` within class static blocks +info: | + BindingIdentifier : Identifier + + [...] + - It is a Syntax Error if the code matched by this production is nested, + directly or indirectly (but not crossing function or static initialization + block boundaries), within a ClassStaticBlock and the StringValue of + Identifier is "await". +negative: + phase: parse + type: SyntaxError +features: [class-static-block] +---*/ + +$DONOTEVALUATE(); + +class C { + static { + var [await] = []; + } +} diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-static-init-await-valid.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-static-init-await-valid.js new file mode 100644 index 0000000000..05c40ef15a --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-id-static-init-await-valid.js @@ -0,0 +1,20 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-class-definitions-static-semantics-early-errors +description: The `await` keyword is interpreted as an identifier within arrow function bodies +info: | + ClassStaticBlockBody : ClassStaticBlockStatementList + + [...] + - It is a Syntax Error if ContainsAwait of ClassStaticBlockStatementList is true. +features: [class-static-block] +---*/ + +class C { + static { + (() => { var [await] = []; }); + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-obj-id-init.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-obj-id-init.js new file mode 100644 index 0000000000..65a6ee4fcc --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-obj-id-init.js @@ -0,0 +1,37 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-id-init.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: BindingElement with object binding pattern and initializer is used (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + +var [{ x, y, z } = { x: 44, y: 55, z: 66 }] = []; + +assert.sameValue(x, 44); +assert.sameValue(y, 55); +assert.sameValue(z, 66); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-obj-id.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-obj-id.js new file mode 100644 index 0000000000..105f30859f --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-obj-id.js @@ -0,0 +1,37 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-id.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: BindingElement with object binding pattern and initializer is not used (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + +var [{ x, y, z } = { x: 44, y: 55, z: 66 }] = [{ x: 11, y: 22, z: 33 }]; + +assert.sameValue(x, 11); +assert.sameValue(y, 22); +assert.sameValue(z, 33); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-obj-prop-id-init.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-obj-prop-id-init.js new file mode 100644 index 0000000000..087bbe1145 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-obj-prop-id-init.js @@ -0,0 +1,47 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-prop-id-init.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: BindingElement with object binding pattern and initializer is used (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + +var [{ u: v, w: x, y: z } = { u: 444, w: 555, y: 666 }] = []; + +assert.sameValue(v, 444); +assert.sameValue(x, 555); +assert.sameValue(z, 666); + +assert.throws(ReferenceError, function() { + u; +}); +assert.throws(ReferenceError, function() { + w; +}); +assert.throws(ReferenceError, function() { + y; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-obj-prop-id.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-obj-prop-id.js new file mode 100644 index 0000000000..8e8894f6fb --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-obj-prop-id.js @@ -0,0 +1,47 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-prop-id.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: BindingElement with object binding pattern and initializer is not used (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + +var [{ u: v, w: x, y: z } = { u: 444, w: 555, y: 666 }] = [{ u: 777, w: 888, y: 999 }]; + +assert.sameValue(v, 777); +assert.sameValue(x, 888); +assert.sameValue(z, 999); + +assert.throws(ReferenceError, function() { + u; +}); +assert.throws(ReferenceError, function() { + w; +}); +assert.throws(ReferenceError, function() { + y; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-obj-val-null.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-obj-val-null.js new file mode 100644 index 0000000000..bd61c18cf5 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-obj-val-null.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-val-null.case +// - src/dstr-binding/error/var-stmt.template +/*--- +description: Nested object destructuring with a null value (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPattern Initializeropt + + 1. If iteratorRecord.[[done]] is false, then + [...] + e. Else + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ObjectBindingPattern + + 1. Let valid be RequireObjectCoercible(value). + 2. ReturnIfAbrupt(valid). +---*/ + +assert.throws(TypeError, function() { + var [{ x }] = [null]; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-obj-val-undef.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-obj-val-undef.js new file mode 100644 index 0000000000..3adf77242e --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elem-obj-val-undef.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-val-undef.case +// - src/dstr-binding/error/var-stmt.template +/*--- +description: Nested object destructuring with a value of `undefined` (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPattern Initializeropt + + 1. If iteratorRecord.[[done]] is false, then + [...] + e. Else + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ObjectBindingPattern + + 1. Let valid be RequireObjectCoercible(value). + 2. ReturnIfAbrupt(valid). +---*/ + +assert.throws(TypeError, function() { + var [{ x }] = []; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elision-exhausted.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elision-exhausted.js new file mode 100644 index 0000000000..f4437dca24 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elision-exhausted.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elision-exhausted.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: Elision accepts exhausted iterator (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ Elision ] + + 1. Return the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with iteratorRecord + as the argument. + + 12.14.5.3 Runtime Semantics: IteratorDestructuringAssignmentEvaluation + + Elision : , + + 1. If iteratorRecord.[[done]] is false, then + [...] + 2. Return NormalCompletion(empty). + +---*/ +var iter = function*() {}(); +iter.next(); + +var [,] = iter; + + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elision-step-err.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elision-step-err.js new file mode 100644 index 0000000000..bef65b3a13 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elision-step-err.js @@ -0,0 +1,49 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elision-step-err.case +// - src/dstr-binding/error/var-stmt.template +/*--- +description: Elision advances iterator and forwards abrupt completions (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ Elision ] + + 1. Return the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with iteratorRecord + as the argument. + + 12.14.5.3 Runtime Semantics: IteratorDestructuringAssignmentEvaluation + + Elision : , + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + +---*/ +var following = 0; +var iter =function* () { + throw new Test262Error(); + following += 1; +}(); + +assert.throws(Test262Error, function() { + var [,] = iter; +}); + +iter.next(); +assert.sameValue(following, 0, 'Iterator was properly closed.'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elision.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elision.js new file mode 100644 index 0000000000..886aaecabc --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-elision.js @@ -0,0 +1,51 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elision.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: Elision advances iterator (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ Elision ] + + 1. Return the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with iteratorRecord + as the argument. + + 12.14.5.3 Runtime Semantics: IteratorDestructuringAssignmentEvaluation + + Elision : , + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + 2. Return NormalCompletion(empty). + +---*/ +var first = 0; +var second = 0; +function* g() { + first += 1; + yield; + second += 1; +}; + +var [,] = g(); + +assert.sameValue(first, 1); +assert.sameValue(second, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-empty.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-empty.js new file mode 100644 index 0000000000..be2d1e3025 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-empty.js @@ -0,0 +1,34 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-empty.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: No iteration occurs for an "empty" array binding pattern (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ ] + + 1. Return NormalCompletion(empty). + +---*/ +var iterations = 0; +var iter = function*() { + iterations += 1; +}(); + +var [] = iter; + +assert.sameValue(iterations, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-ary-elem.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-ary-elem.js new file mode 100644 index 0000000000..cacb6f1b6c --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-ary-elem.js @@ -0,0 +1,58 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-elem.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: Rest element containing an array BindingElementList pattern (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + [...] + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set + iteratorRecord.[[done]] to true. + iii. ReturnIfAbrupt(v). + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var [...[x, y, z]] = [3, 4, 5]; + +assert.sameValue(x, 3); +assert.sameValue(y, 4); +assert.sameValue(z, 5); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-ary-elision.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-ary-elision.js new file mode 100644 index 0000000000..1db09b4cfa --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-ary-elision.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-elision.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: Rest element containing an elision (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ Elision ] + + 1. Return the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with iteratorRecord + as the argument. + + 12.14.5.3 Runtime Semantics: IteratorDestructuringAssignmentEvaluation + + Elision : , + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + 2. Return NormalCompletion(empty). + +---*/ +var first = 0; +var second = 0; +function* g() { + first += 1; + yield; + second += 1; +}; + +var [...[,]] = g(); + +assert.sameValue(first, 1); +assert.sameValue(second, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-ary-empty.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-ary-empty.js new file mode 100644 index 0000000000..124aff3c68 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-ary-empty.js @@ -0,0 +1,47 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-empty.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: Rest element containing an "empty" array pattern (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ ] + + 1. Return NormalCompletion(empty). + +---*/ +var iterations = 0; +var iter = function*() { + iterations += 1; +}(); + +var [...[]] = iter; + +assert.sameValue(iterations, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-ary-rest.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-ary-rest.js new file mode 100644 index 0000000000..75dbabe464 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-ary-rest.js @@ -0,0 +1,43 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-rest.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: Rest element containing a rest element (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] +---*/ +var values = [1, 2, 3]; + +var [...[...x]] = values; + +assert(Array.isArray(x)); +assert.sameValue(x.length, 3); +assert.sameValue(x[0], 1); +assert.sameValue(x[1], 2); +assert.sameValue(x[2], 3); +assert.notSameValue(x, values); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-id-direct.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-id-direct.js new file mode 100644 index 0000000000..4ed7fcc21f --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-id-direct.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-direct.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: Lone rest element (direct binding) (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +includes: [compareArray.js] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingIdentifier + + [...] + 2. Let A be ! ArrayCreate(0). + 3. Let n be 0. + 4. Repeat, + [...] + f. Perform ! CreateDataPropertyOrThrow(A, ! ToString(n), nextValue). + g. Set n to n + 1. + +---*/ + +var [...x] = [1]; + +assert(Array.isArray(x)); +assert.compareArray(x, [1]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-id-elision-next-err.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-id-elision-next-err.js new file mode 100644 index 0000000000..a0cfb5a60d --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-id-elision-next-err.js @@ -0,0 +1,35 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-elision-next-err.case +// - src/dstr-binding/error/var-stmt.template +/*--- +description: Rest element following elision elements (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + ArrayBindingPattern : [ Elisionopt BindingRestElement ] + 1. If Elision is present, then + a. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with + iteratorRecord as the argument. + b. ReturnIfAbrupt(status). + 2. Return the result of performing IteratorBindingInitialization for + BindingRestElement with iteratorRecord and environment as arguments. + +---*/ +var iter = (function*() { throw new Test262Error(); })(); + +assert.throws(Test262Error, function() { + var [, ...x] = iter; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-id-elision.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-id-elision.js new file mode 100644 index 0000000000..c862c524e2 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-id-elision.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-elision.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: Rest element following elision elements (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + ArrayBindingPattern : [ Elisionopt BindingRestElement ] + 1. If Elision is present, then + a. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with + iteratorRecord as the argument. + b. ReturnIfAbrupt(status). + 2. Return the result of performing IteratorBindingInitialization for + BindingRestElement with iteratorRecord and environment as arguments. +---*/ +var values = [1, 2, 3, 4, 5]; + +var [ , , ...x] = values; + +assert(Array.isArray(x)); +assert.sameValue(x.length, 3); +assert.sameValue(x[0], 3); +assert.sameValue(x[1], 4); +assert.sameValue(x[2], 5); +assert.notSameValue(x, values); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-id-exhausted.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-id-exhausted.js new file mode 100644 index 0000000000..574e98191f --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-id-exhausted.js @@ -0,0 +1,35 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-exhausted.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: RestElement applied to an exhausted iterator (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + BindingRestElement : ... BindingIdentifier + 1. Let lhs be ResolveBinding(StringValue of BindingIdentifier, + environment). + 2. ReturnIfAbrupt(lhs). 3. Let A be ArrayCreate(0). 4. Let n=0. 5. Repeat, + [...] + b. If iteratorRecord.[[done]] is true, then + i. If environment is undefined, return PutValue(lhs, A). + ii. Return InitializeReferencedBinding(lhs, A). + +---*/ + +var [, , ...x] = [1, 2]; + +assert(Array.isArray(x)); +assert.sameValue(x.length, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-id-iter-step-err.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-id-iter-step-err.js new file mode 100644 index 0000000000..a2ef82b2f2 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-id-iter-step-err.js @@ -0,0 +1,46 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-iter-step-err.case +// - src/dstr-binding/error/var-stmt.template +/*--- +description: Error forwarding when IteratorStep returns an abrupt completion (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + BindingRestElement : ... BindingIdentifier + 1. Let lhs be ResolveBinding(StringValue of BindingIdentifier, + environment). + 2. ReturnIfAbrupt(lhs). 3. Let A be ArrayCreate(0). 4. Let n=0. 5. Repeat, + a. If iteratorRecord.[[done]] is false, + i. Let next be IteratorStep(iteratorRecord.[[iterator]]). + ii. If next is an abrupt completion, set iteratorRecord.[[done]] to + true. + iii. ReturnIfAbrupt(next). + +---*/ +var first = 0; +var second = 0; +var iter = function*() { + first += 1; + throw new Test262Error(); + second += 1; +}(); + +assert.throws(Test262Error, function() { + var [...x] = iter; +}); + +iter.next(); +assert.sameValue(first, 1); +assert.sameValue(second, 0, 'Iterator is closed following abrupt completion.'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-id-iter-val-err.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-id-iter-val-err.js new file mode 100644 index 0000000000..bd0305efc1 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-id-iter-val-err.js @@ -0,0 +1,48 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-iter-val-err.case +// - src/dstr-binding/error/var-stmt.template +/*--- +description: Error forwarding when IteratorValue returns an abrupt completion (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + BindingRestElement : ... BindingIdentifier + 1. Let lhs be ResolveBinding(StringValue of BindingIdentifier, + environment). + 2. ReturnIfAbrupt(lhs). 3. Let A be ArrayCreate(0). 4. Let n=0. 5. Repeat, + [...] + c. Let nextValue be IteratorValue(next). + d. If nextValue is an abrupt completion, set iteratorRecord.[[done]] to + true. + e. ReturnIfAbrupt(nextValue). + +---*/ +var poisonedValue = Object.defineProperty({}, 'value', { + get: function() { + throw new Test262Error(); + } +}); +var iter = {}; +iter[Symbol.iterator] = function() { + return { + next: function() { + return poisonedValue; + } + }; +}; + +assert.throws(Test262Error, function() { + var [...x] = iter; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-id.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-id.js new file mode 100644 index 0000000000..f07bfa71dd --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-id.js @@ -0,0 +1,36 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: Lone rest element (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + BindingRestElement : ... BindingIdentifier + [...] 3. Let A be ArrayCreate(0). [...] 5. Repeat + [...] + f. Let status be CreateDataProperty(A, ToString (n), nextValue). + [...] +---*/ +var values = [1, 2, 3]; + +var [...x] = values; + +assert(Array.isArray(x)); +assert.sameValue(x.length, 3); +assert.sameValue(x[0], 1); +assert.sameValue(x[1], 2); +assert.sameValue(x[2], 3); +assert.notSameValue(x, values); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-init-ary.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-init-ary.js new file mode 100644 index 0000000000..6ee1d80bf9 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-init-ary.js @@ -0,0 +1,32 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-init-ary.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: Rest element (nested array pattern) does not support initializer (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + +var [...[ x ] = []] = []; + + diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-init-id.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-init-id.js new file mode 100644 index 0000000000..f768852992 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-init-id.js @@ -0,0 +1,32 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-init-id.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: Rest element (identifier) does not support initializer (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + +var [...x = []] = []; + + diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-init-obj.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-init-obj.js new file mode 100644 index 0000000000..644192fab8 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-init-obj.js @@ -0,0 +1,32 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-init-obj.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: Rest element (nested object pattern) does not support initializer (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + +var [...{ x } = []] = []; + + diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-not-final-ary.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-not-final-ary.js new file mode 100644 index 0000000000..6fea1f9691 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-not-final-ary.js @@ -0,0 +1,32 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-not-final-ary.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: Rest element (array binding pattern) may not be followed by any element (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + +var [...[x], y] = [1, 2, 3]; + + diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-not-final-id.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-not-final-id.js new file mode 100644 index 0000000000..bb5d22cbf6 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-not-final-id.js @@ -0,0 +1,32 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-not-final-id.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: Rest element (identifier) may not be followed by any element (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + +var [...x, y] = [1, 2, 3]; + + diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-not-final-obj.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-not-final-obj.js new file mode 100644 index 0000000000..1e707c59ca --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-not-final-obj.js @@ -0,0 +1,32 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-not-final-obj.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: Rest element (object binding pattern) may not be followed by any element (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + +var [...{ x }, y] = [1, 2, 3]; + + diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-obj-id.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-obj-id.js new file mode 100644 index 0000000000..fb98d127db --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-obj-id.js @@ -0,0 +1,36 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-obj-id.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: Rest element containing an object binding pattern (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] +---*/ + +var [...{ length }] = [1, 2, 3]; + +assert.sameValue(length, 3); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-obj-prop-id.js b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-obj-prop-id.js new file mode 100644 index 0000000000..f166ee12c2 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/ary-ptrn-rest-obj-prop-id.js @@ -0,0 +1,43 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-obj-prop-id.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: Rest element containing an object binding pattern (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] +---*/ +let length = "outer"; + +var [...{ 0: v, 1: w, 2: x, 3: y, length: z }] = [7, 8, 9]; + +assert.sameValue(v, 7); +assert.sameValue(w, 8); +assert.sameValue(x, 9); +assert.sameValue(y, undefined); +assert.sameValue(z, 3); + +assert.sameValue(length, "outer", "the length prop is not set as a binding name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/browser.js b/js/src/tests/test262/language/statements/variable/dstr/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/browser.js diff --git a/js/src/tests/test262/language/statements/variable/dstr/obj-init-null.js b/js/src/tests/test262/language/statements/variable/dstr/obj-init-null.js new file mode 100644 index 0000000000..25807416d0 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/obj-init-null.js @@ -0,0 +1,29 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-init-null.case +// - src/dstr-binding/error/var-stmt.template +/*--- +description: Value specifed for object binding pattern must be object coercible (null) (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + Runtime Semantics: BindingInitialization + + ObjectBindingPattern : { } + + 1. Return NormalCompletion(empty). +---*/ + +assert.throws(TypeError, function() { + var {} = null; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/obj-init-undefined.js b/js/src/tests/test262/language/statements/variable/dstr/obj-init-undefined.js new file mode 100644 index 0000000000..bbe2086fe2 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/obj-init-undefined.js @@ -0,0 +1,29 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-init-undefined.case +// - src/dstr-binding/error/var-stmt.template +/*--- +description: Value specifed for object binding pattern must be object coercible (undefined) (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + Runtime Semantics: BindingInitialization + + ObjectBindingPattern : { } + + 1. Return NormalCompletion(empty). +---*/ + +assert.throws(TypeError, function() { + var {} = undefined; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-elem-id-static-init-await-invalid.js b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-elem-id-static-init-await-invalid.js new file mode 100644 index 0000000000..0f2f432521 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-elem-id-static-init-await-invalid.js @@ -0,0 +1,27 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-class-definitions-static-semantics-early-errors +description: BindingIdentifier may not be `await` within class static blocks +info: | + BindingIdentifier : Identifier + + [...] + - It is a Syntax Error if the code matched by this production is nested, + directly or indirectly (but not crossing function or static initialization + block boundaries), within a ClassStaticBlock and the StringValue of + Identifier is "await". +negative: + phase: parse + type: SyntaxError +features: [class-static-block] +---*/ + +$DONOTEVALUATE(); + +class C { + static { + var {await} = {}; + } +} diff --git a/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-elem-id-static-init-await-valid.js b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-elem-id-static-init-await-valid.js new file mode 100644 index 0000000000..2e66d5e15c --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-elem-id-static-init-await-valid.js @@ -0,0 +1,20 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-class-definitions-static-semantics-early-errors +description: The `await` keyword is interpreted as an identifier within arrow function bodies +info: | + ClassStaticBlockBody : ClassStaticBlockStatementList + + [...] + - It is a Syntax Error if ContainsAwait of ClassStaticBlockStatementList is true. +features: [class-static-block] +---*/ + +class C { + static { + (() => { var {await} = {}; }); + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-empty.js b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-empty.js new file mode 100644 index 0000000000..ab3b84007e --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-empty.js @@ -0,0 +1,35 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-empty.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: No property access occurs for an "empty" object binding pattern (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + Runtime Semantics: BindingInitialization + + ObjectBindingPattern : { } + + 1. Return NormalCompletion(empty). +---*/ +var accessCount = 0; +var obj = Object.defineProperty({}, 'attr', { + get: function() { + accessCount += 1; + } +}); + +var {} = obj; + +assert.sameValue(accessCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-id-get-value-err.js b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-id-get-value-err.js new file mode 100644 index 0000000000..aefb5610ca --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-id-get-value-err.js @@ -0,0 +1,36 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-get-value-err.case +// - src/dstr-binding/error/var-stmt.template +/*--- +description: Error thrown when accessing the corresponding property of the value object (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. Let v be GetV(value, propertyName). + 5. ReturnIfAbrupt(v). +---*/ +var poisonedProperty = Object.defineProperty({}, 'poisoned', { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + var { poisoned } = poisonedProperty; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-id-init-fn-name-arrow.js b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-id-init-fn-name-arrow.js new file mode 100644 index 0000000000..0eba33a0ca --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-id-init-fn-name-arrow.js @@ -0,0 +1,36 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-arrow.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: SingleNameBinding assigns `name` to arrow functions (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). +---*/ + +var { arrow = () => {} } = {}; + +assert.sameValue(arrow.name, 'arrow'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-id-init-fn-name-class.js b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-id-init-fn-name-class.js new file mode 100644 index 0000000000..f8ea6ddbbc --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-id-init-fn-name-class.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-class.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: SingleNameBinding assigns `name` to "anonymous" classes (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). +---*/ + +var { cls = class {}, xCls = class X {}, xCls2 = class { static name() {} } } = {}; + +assert.sameValue(cls.name, 'cls'); +assert.notSameValue(xCls.name, 'xCls'); +assert.notSameValue(xCls2.name, 'xCls2'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-id-init-fn-name-cover.js b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-id-init-fn-name-cover.js new file mode 100644 index 0000000000..68ca9796cb --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-id-init-fn-name-cover.js @@ -0,0 +1,37 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-cover.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: SingleNameBinding assigns `name` to "anonymous" functions "through" cover grammar (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). +---*/ + +var { cover = (function () {}), xCover = (0, function() {}) } = {}; + +assert.sameValue(cover.name, 'cover'); +assert.notSameValue(xCover.name, 'xCover'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-id-init-fn-name-fn.js b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-id-init-fn-name-fn.js new file mode 100644 index 0000000000..8d8f6947db --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-id-init-fn-name-fn.js @@ -0,0 +1,37 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-fn.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: SingleNameBinding assigns name to "anonymous" functions (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). +---*/ + +var { fn = function () {}, xFn = function x() {} } = {}; + +assert.sameValue(fn.name, 'fn'); +assert.notSameValue(xFn.name, 'xFn'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-id-init-fn-name-gen.js b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-id-init-fn-name-gen.js new file mode 100644 index 0000000000..30d95a4af9 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-id-init-fn-name-gen.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-gen.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: SingleNameBinding assigns name to "anonymous" generator functions (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). + +---*/ + +var { gen = function* () {}, xGen = function* x() {} } = {}; + +assert.sameValue(gen.name, 'gen'); +assert.notSameValue(xGen.name, 'xGen'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-id-init-skipped.js b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-id-init-skipped.js new file mode 100644 index 0000000000..d1baeb3bdc --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-id-init-skipped.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-skipped.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: Destructuring initializer is not evaluated when value is not `undefined` (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + [...] +---*/ +var initCount = 0; +function counter() { + initCount += 1; +} + +var { w = counter(), x = counter(), y = counter(), z = counter() } = { w: null, x: 0, y: false, z: '' }; + +assert.sameValue(w, null); +assert.sameValue(x, 0); +assert.sameValue(y, false); +assert.sameValue(z, ''); +assert.sameValue(initCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-id-init-throws.js b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-id-init-throws.js new file mode 100644 index 0000000000..1e75ef8341 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-id-init-throws.js @@ -0,0 +1,36 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-throws.case +// - src/dstr-binding/error/var-stmt.template +/*--- +description: Error thrown when evaluating the initializer (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). +---*/ +function thrower() { + throw new Test262Error(); +} + +assert.throws(Test262Error, function() { + var { x = thrower() } = {}; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-id-init-unresolvable.js b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-id-init-unresolvable.js new file mode 100644 index 0000000000..d54db87ace --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-id-init-unresolvable.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-unresolvable.case +// - src/dstr-binding/error/var-stmt.template +/*--- +description: Destructuring initializer is an unresolvable reference (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + + 6.2.3.1 GetValue (V) + + 1. ReturnIfAbrupt(V). + 2. If Type(V) is not Reference, return V. + 3. Let base be GetBase(V). + 4. If IsUnresolvableReference(V), throw a ReferenceError exception. +---*/ + +assert.throws(ReferenceError, function() { + var { x = unresolvableReference } = {}; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-id-trailing-comma.js b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-id-trailing-comma.js new file mode 100644 index 0000000000..ddac1252fd --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-id-trailing-comma.js @@ -0,0 +1,30 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-trailing-comma.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: Trailing comma is allowed following BindingPropertyList (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3 Destructuring Binding Patterns + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } +---*/ + +var { x, } = { x: 23 }; + +assert.sameValue(x, 23); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-list-err.js b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-list-err.js new file mode 100644 index 0000000000..921006037e --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-list-err.js @@ -0,0 +1,37 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-list-err.case +// - src/dstr-binding/error/var-stmt.template +/*--- +description: Binding property list evaluation is interrupted by an abrupt completion (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPropertyList : BindingPropertyList , BindingProperty + + 1. Let status be the result of performing BindingInitialization for + BindingPropertyList using value and environment as arguments. + 2. ReturnIfAbrupt(status). +---*/ +var initCount = 0; +function thrower() { + throw new Test262Error(); +} + +assert.throws(Test262Error, function() { + var { a, b = thrower(), c = ++initCount } = {}; +}); + +assert.sameValue(initCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-ary-init.js b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-ary-init.js new file mode 100644 index 0000000000..b025997d29 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-ary-init.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary-init.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: Object binding pattern with "nested" array binding pattern using initializer (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +var { w: [x, y, z] = [4, 5, 6] } = {}; + +assert.sameValue(x, 4); +assert.sameValue(y, 5); +assert.sameValue(z, 6); + +assert.throws(ReferenceError, function() { + w; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-ary-trailing-comma.js b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-ary-trailing-comma.js new file mode 100644 index 0000000000..b4d3eaf82a --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-ary-trailing-comma.js @@ -0,0 +1,30 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary-trailing-comma.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: Trailing comma is allowed following BindingPropertyList (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3 Destructuring Binding Patterns + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } +---*/ + +var { x: [y], } = { x: [45] }; + +assert.sameValue(y,45); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-ary-value-null.js b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-ary-value-null.js new file mode 100644 index 0000000000..5168246598 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-ary-value-null.js @@ -0,0 +1,31 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary-value-null.case +// - src/dstr-binding/error/var-stmt.template +/*--- +description: Object binding pattern with "nested" array binding pattern taking the `null` value (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +assert.throws(TypeError, function() { + var { w: [x, y, z] = [4, 5, 6] } = { w: null }; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-ary.js b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-ary.js new file mode 100644 index 0000000000..a23101d21e --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-ary.js @@ -0,0 +1,37 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: Object binding pattern with "nested" array binding pattern not using initializer (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +var { w: [x, y, z] = [4, 5, 6] } = { w: [7, undefined, ] }; + +assert.sameValue(x, 7); +assert.sameValue(y, undefined); +assert.sameValue(z, undefined); + +assert.throws(ReferenceError, function() { + w; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-eval-err.js b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-eval-err.js new file mode 100644 index 0000000000..3b6551747c --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-eval-err.js @@ -0,0 +1,33 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-eval-err.case +// - src/dstr-binding/error/var-stmt.template +/*--- +description: Evaluation of property name returns an abrupt completion (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingProperty : PropertyName : BindingElement + + 1. Let P be the result of evaluating PropertyName + 2. ReturnIfAbrupt(P). +---*/ +function thrower() { + throw new Test262Error(); +} + +assert.throws(Test262Error, function() { + var { [thrower()]: x } = {}; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-id-get-value-err.js b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-id-get-value-err.js new file mode 100644 index 0000000000..911f8e11d7 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-id-get-value-err.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-get-value-err.case +// - src/dstr-binding/error/var-stmt.template +/*--- +description: Error thrown when accessing the corresponding property of the value object (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + BindingElement : BindingPattern Initializeropt + + 1. Let v be GetV(value, propertyName). + 2. ReturnIfAbrupt(v). +---*/ +var initEvalCount = 0; +var poisonedProperty = Object.defineProperty({}, 'poisoned', { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + var { poisoned: x = ++initEvalCount } = poisonedProperty; +}); + +assert.sameValue(initEvalCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-id-init-skipped.js b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-id-init-skipped.js new file mode 100644 index 0000000000..8824ad0256 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-id-init-skipped.js @@ -0,0 +1,52 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init-skipped.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: Destructuring initializer is not evaluated when value is not `undefined` (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + BindingElement : BindingPattern Initializeropt + + [...] + 3. If Initializer is present and v is undefined, then + [...] +---*/ +var initCount = 0; +function counter() { + initCount += 1; +} + +var { s: t = counter(), u: v = counter(), w: x = counter(), y: z = counter() } = { s: null, u: 0, w: false, y: '' }; + +assert.sameValue(t, null); +assert.sameValue(v, 0); +assert.sameValue(x, false); +assert.sameValue(z, ''); +assert.sameValue(initCount, 0); + +assert.throws(ReferenceError, function() { + s; +}); +assert.throws(ReferenceError, function() { + u; +}); +assert.throws(ReferenceError, function() { + w; +}); +assert.throws(ReferenceError, function() { + y; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-id-init-throws.js b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-id-init-throws.js new file mode 100644 index 0000000000..71fadba268 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-id-init-throws.js @@ -0,0 +1,36 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init-throws.case +// - src/dstr-binding/error/var-stmt.template +/*--- +description: Error thrown when evaluating the initializer (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + BindingElement : BindingPattern Initializeropt + + [...] + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). +---*/ +function thrower() { + throw new Test262Error(); +} + +assert.throws(Test262Error, function() { + var { x: y = thrower() } = {}; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-id-init-unresolvable.js b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-id-init-unresolvable.js new file mode 100644 index 0000000000..a8af3edb85 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-id-init-unresolvable.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init-unresolvable.case +// - src/dstr-binding/error/var-stmt.template +/*--- +description: Destructuring initializer is an unresolvable reference (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + BindingElement : BindingPattern Initializeropt + + [...] + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + + 6.2.3.1 GetValue (V) + + 1. ReturnIfAbrupt(V). + 2. If Type(V) is not Reference, return V. + 3. Let base be GetBase(V). + 4. If IsUnresolvableReference(V), throw a ReferenceError exception. +---*/ + +assert.throws(ReferenceError, function() { + var { x: y = unresolvableReference } = {}; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-id-init.js b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-id-init.js new file mode 100644 index 0000000000..1b161593d7 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-id-init.js @@ -0,0 +1,33 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: Binding as specified via property name, identifier, and initializer (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var { x: y = 33 } = { }; + +assert.sameValue(y, 33); +assert.throws(ReferenceError, function() { + x; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-id-trailing-comma.js b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-id-trailing-comma.js new file mode 100644 index 0000000000..dbf92f8fe9 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-id-trailing-comma.js @@ -0,0 +1,34 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-trailing-comma.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: Trailing comma is allowed following BindingPropertyList (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3 Destructuring Binding Patterns + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } +---*/ + +var { x: y, } = { x: 23 }; + +assert.sameValue(y, 23); + +assert.throws(ReferenceError, function() { + x; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-id.js b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-id.js new file mode 100644 index 0000000000..dc38848835 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-id.js @@ -0,0 +1,33 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: Binding as specified via property name and identifier (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var { x: y } = { x: 23 }; + +assert.sameValue(y, 23); +assert.throws(ReferenceError, function() { + x; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-obj-init.js b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-obj-init.js new file mode 100644 index 0000000000..8ce671f1ee --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-obj-init.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj-init.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: Object binding pattern with "nested" object binding pattern using initializer (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +var { w: { x, y, z } = { x: 4, y: 5, z: 6 } } = { w: undefined }; + +assert.sameValue(x, 4); +assert.sameValue(y, 5); +assert.sameValue(z, 6); + +assert.throws(ReferenceError, function() { + w; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-obj-value-null.js b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-obj-value-null.js new file mode 100644 index 0000000000..c3092c3865 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-obj-value-null.js @@ -0,0 +1,31 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj-value-null.case +// - src/dstr-binding/error/var-stmt.template +/*--- +description: Object binding pattern with "nested" object binding pattern taking the `null` value (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +assert.throws(TypeError, function() { + var { w: { x, y, z } = { x: 4, y: 5, z: 6 } } = { w: null }; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-obj-value-undef.js b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-obj-value-undef.js new file mode 100644 index 0000000000..18fc35e28e --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-obj-value-undef.js @@ -0,0 +1,31 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj-value-undef.case +// - src/dstr-binding/error/var-stmt.template +/*--- +description: Object binding pattern with "nested" object binding pattern taking the `null` value (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +assert.throws(TypeError, function() { + var { w: { x, y, z } = undefined } = { }; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-obj.js b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-obj.js new file mode 100644 index 0000000000..db807ea7e1 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-prop-obj.js @@ -0,0 +1,37 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: Object binding pattern with "nested" object binding pattern not using initializer (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +var { w: { x, y, z } = { x: 4, y: 5, z: 6 } } = { w: { x: undefined, z: 7 } }; + +assert.sameValue(x, undefined); +assert.sameValue(y, undefined); +assert.sameValue(z, 7); + +assert.throws(ReferenceError, function() { + w; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-rest-getter.js b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-rest-getter.js new file mode 100644 index 0000000000..2bb84a29b3 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-rest-getter.js @@ -0,0 +1,32 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-rest-getter.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: Getter is called when obj is being deconstructed to a rest Object (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [object-rest, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. +---*/ +var count = 0; + +var {...x} = { get v() { count++; return 2; } }; + +assert.sameValue(count, 1); + +verifyProperty(x, "v", { + enumerable: true, + writable: true, + configurable: true, + value: 2 +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-rest-skip-non-enumerable.js b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-rest-skip-non-enumerable.js new file mode 100644 index 0000000000..0a6c4cd5ad --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-rest-skip-non-enumerable.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-rest-skip-non-enumerable.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: Rest object doesn't contain non-enumerable properties (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [object-rest, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. +---*/ +var o = {a: 3, b: 4}; +Object.defineProperty(o, "x", { value: 4, enumerable: false }); + +var {...rest} = o; + +assert.sameValue(rest.x, undefined); + +verifyProperty(rest, "a", { + enumerable: true, + writable: true, + configurable: true, + value: 3 +}); + +verifyProperty(rest, "b", { + enumerable: true, + writable: true, + configurable: true, + value: 4 +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-rest-val-obj.js b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-rest-val-obj.js new file mode 100644 index 0000000000..32d5f0c7c5 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/obj-ptrn-rest-val-obj.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-rest-val-obj.case +// - src/dstr-binding/default/var-stmt.template +/*--- +description: Rest object contains just unextracted data (`var` statement) +esid: sec-variable-statement-runtime-semantics-evaluation +features: [object-rest, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. +---*/ + +var {a, b, ...rest} = {x: 1, y: 2, a: 5, b: 3}; + +assert.sameValue(rest.a, undefined); +assert.sameValue(rest.b, undefined); + +verifyProperty(rest, "x", { + enumerable: true, + writable: true, + configurable: true, + value: 1 +}); + +verifyProperty(rest, "y", { + enumerable: true, + writable: true, + configurable: true, + value: 2 +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/dstr/shell.js b/js/src/tests/test262/language/statements/variable/dstr/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/dstr/shell.js diff --git a/js/src/tests/test262/language/statements/variable/eval-non-strict.js b/js/src/tests/test262/language/statements/variable/eval-non-strict.js new file mode 100644 index 0000000000..c3e99ebd70 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/eval-non-strict.js @@ -0,0 +1,12 @@ +// Copyright (c) 2018 Mike Pennisi. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-variable-statement +description: arguments as local var identifier is allowed +flags: [noStrict] +---*/ + +var eval; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/eval-strict-list-final-init-strict.js b/js/src/tests/test262/language/statements/variable/eval-strict-list-final-init-strict.js new file mode 100644 index 0000000000..9b503bab34 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/eval-strict-list-final-init-strict.js @@ -0,0 +1,17 @@ +// |reftest| error:SyntaxError +'use strict'; +// Copyright (c) 2018 Mike Pennisi. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-variable-statement +description: eval as local var identifier throws SyntaxError in strict mode +flags: [onlyStrict] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +var a, eval = 42; diff --git a/js/src/tests/test262/language/statements/variable/eval-strict-list-final-strict.js b/js/src/tests/test262/language/statements/variable/eval-strict-list-final-strict.js new file mode 100644 index 0000000000..fc204f752c --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/eval-strict-list-final-strict.js @@ -0,0 +1,18 @@ +// |reftest| error:SyntaxError +'use strict'; +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-26-s +esid: sec-variable-statement +description: eval as local var identifier throws SyntaxError in strict mode +flags: [onlyStrict] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +var a, eval; diff --git a/js/src/tests/test262/language/statements/variable/eval-strict-list-first-init-strict.js b/js/src/tests/test262/language/statements/variable/eval-strict-list-first-init-strict.js new file mode 100644 index 0000000000..509d23641a --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/eval-strict-list-first-init-strict.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +'use strict'; +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-27-s +esid: sec-variable-statement +description: > + eval as local var identifier assigned to throws SyntaxError in + strict mode +flags: [onlyStrict] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +var eval = 42, a; diff --git a/js/src/tests/test262/language/statements/variable/eval-strict-list-first-strict.js b/js/src/tests/test262/language/statements/variable/eval-strict-list-first-strict.js new file mode 100644 index 0000000000..1536764666 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/eval-strict-list-first-strict.js @@ -0,0 +1,18 @@ +// |reftest| error:SyntaxError +'use strict'; +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-29-s +esid: sec-variable-statement +description: eval as local var identifier throws SyntaxError in strict mode +flags: [onlyStrict] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +var eval, a = 42; diff --git a/js/src/tests/test262/language/statements/variable/eval-strict-list-middle-init-strict.js b/js/src/tests/test262/language/statements/variable/eval-strict-list-middle-init-strict.js new file mode 100644 index 0000000000..e06213ec85 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/eval-strict-list-middle-init-strict.js @@ -0,0 +1,17 @@ +// |reftest| error:SyntaxError +'use strict'; +// Copyright (c) 2018 Mike Pennisi. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-variable-statement +description: arguments as local var identifier throws SyntaxError in strict mode +flags: [onlyStrict] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +var a, eval = 42, b; diff --git a/js/src/tests/test262/language/statements/variable/eval-strict-list-middle-strict.js b/js/src/tests/test262/language/statements/variable/eval-strict-list-middle-strict.js new file mode 100644 index 0000000000..167771c72d --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/eval-strict-list-middle-strict.js @@ -0,0 +1,17 @@ +// |reftest| error:SyntaxError +'use strict'; +// Copyright (c) 2018 Mike Pennisi. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-variable-statement +description: arguments as local var identifier throws SyntaxError in strict mode +flags: [onlyStrict] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +var a, eval, b; diff --git a/js/src/tests/test262/language/statements/variable/eval-strict-list-repeated-strict.js b/js/src/tests/test262/language/statements/variable/eval-strict-list-repeated-strict.js new file mode 100644 index 0000000000..fd344ee621 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/eval-strict-list-repeated-strict.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +'use strict'; +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-31-s +esid: sec-variable-statement +description: > + eval as local var identifier defined twice throws SyntaxError in + strict mode +flags: [onlyStrict] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +var eval, eval; diff --git a/js/src/tests/test262/language/statements/variable/eval-strict-single-init-strict.js b/js/src/tests/test262/language/statements/variable/eval-strict-single-init-strict.js new file mode 100644 index 0000000000..f39ce6c73d --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/eval-strict-single-init-strict.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +'use strict'; +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-24-s +esid: sec-variable-statement +description: > + eval as local var identifier assigned to throws SyntaxError in + strict mode +flags: [onlyStrict] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +var eval = 42; diff --git a/js/src/tests/test262/language/statements/variable/eval-strict-single-strict.js b/js/src/tests/test262/language/statements/variable/eval-strict-single-strict.js new file mode 100644 index 0000000000..80cd179894 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/eval-strict-single-strict.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +'use strict'; +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.2.1-1-s +esid: sec-variable-statement +description: > + eval - a function declaring a var named 'eval' throws SyntaxError + in strict mode +flags: [onlyStrict] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +var eval; diff --git a/js/src/tests/test262/language/statements/variable/fn-name-arrow.js b/js/src/tests/test262/language/statements/variable/fn-name-arrow.js new file mode 100644 index 0000000000..871c30ecec --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/fn-name-arrow.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 13.3.2.4 +description: Assignment of function `name` attribute (ArrowFunction) +info: | + VariableDeclaration : BindingIdentifier Initializer + + [...] + 7. If IsAnonymousFunctionDefinition(Initializer) is true, then + a. Let hasNameProperty be HasOwnProperty(value, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(value, + bindingId). +includes: [propertyHelper.js] +---*/ + +var arrow = () => {}; + +assert.sameValue(arrow.name, 'arrow'); +verifyNotEnumerable(arrow, 'name'); +verifyNotWritable(arrow, 'name'); +verifyConfigurable(arrow, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/fn-name-class.js b/js/src/tests/test262/language/statements/variable/fn-name-class.js new file mode 100644 index 0000000000..5b8086b264 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/fn-name-class.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 13.3.2.4 +description: Assignment of function `name` attribute (ClassExpression) +info: | + VariableDeclaration : BindingIdentifier Initializer + + [...] + 7. If IsAnonymousFunctionDefinition(Initializer) is true, then + a. Let hasNameProperty be HasOwnProperty(value, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(value, + bindingId). +includes: [propertyHelper.js] +features: [class] +---*/ + +var xCls = class x {}; +var cls = class {}; +var xCls2 = class { static name() {} }; + +assert.notSameValue(xCls.name, 'xCls'); +assert.notSameValue(xCls2.name, 'xCls2'); + +assert.sameValue(cls.name, 'cls'); +verifyNotEnumerable(cls, 'name'); +verifyNotWritable(cls, 'name'); +verifyConfigurable(cls, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/fn-name-cover.js b/js/src/tests/test262/language/statements/variable/fn-name-cover.js new file mode 100644 index 0000000000..a7751c981e --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/fn-name-cover.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 13.3.2.4 +description: > + Assignment of function `name` attribute (CoverParenthesizedExpression) +info: | + VariableDeclaration : BindingIdentifier Initializer + + [...] + 7. If IsAnonymousFunctionDefinition(Initializer) is true, then + a. Let hasNameProperty be HasOwnProperty(value, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(value, + bindingId). +includes: [propertyHelper.js] +---*/ + +var xCover = (0, function() {}); +var cover = (function() {}); + +assert(xCover.name !== 'xCover'); + +assert.sameValue(cover.name, 'cover'); +verifyNotEnumerable(cover, 'name'); +verifyNotWritable(cover, 'name'); +verifyConfigurable(cover, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/fn-name-fn.js b/js/src/tests/test262/language/statements/variable/fn-name-fn.js new file mode 100644 index 0000000000..06c0f4c0dc --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/fn-name-fn.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 13.3.2.4 +description: Assignment of function `name` attribute (FunctionExpression) +info: | + VariableDeclaration : BindingIdentifier Initializer + + [...] + 7. If IsAnonymousFunctionDefinition(Initializer) is true, then + a. Let hasNameProperty be HasOwnProperty(value, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(value, + bindingId). +includes: [propertyHelper.js] +---*/ + +var xFn = function x() {}; +var fn = function() {}; + +assert(xFn.name !== 'xFn'); + +assert.sameValue(fn.name, 'fn'); +verifyNotEnumerable(fn, 'name'); +verifyNotWritable(fn, 'name'); +verifyConfigurable(fn, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/fn-name-gen.js b/js/src/tests/test262/language/statements/variable/fn-name-gen.js new file mode 100644 index 0000000000..dc3eba1c17 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/fn-name-gen.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 13.3.2.4 +description: Assignment of function `name` attribute (GeneratorExpression) +info: | + VariableDeclaration : BindingIdentifier Initializer + + [...] + 7. If IsAnonymousFunctionDefinition(Initializer) is true, then + a. Let hasNameProperty be HasOwnProperty(value, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(value, + bindingId). +includes: [propertyHelper.js] +features: [generators] +---*/ + +var xGen = function* x() {}; +var gen = function*() {}; + +assert(xGen.name !== 'xGen'); + +assert.sameValue(gen.name, 'gen'); +verifyNotEnumerable(gen, 'name'); +verifyNotWritable(gen, 'name'); +verifyConfigurable(gen, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/variable/id-arguments-strict-strict.js b/js/src/tests/test262/language/statements/variable/id-arguments-strict-strict.js new file mode 100644 index 0000000000..961c69423c --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/id-arguments-strict-strict.js @@ -0,0 +1,18 @@ +// |reftest| error:SyntaxError +'use strict'; +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es5id: 11.13.1-4-28-s +description: > + Strict Mode - SyntaxError is thrown if the identifier 'arguments' appears + as the LeftHandSideExpression of simple assignment(=) under strict mode +negative: + phase: parse + type: SyntaxError +flags: [onlyStrict] +---*/ + +$DONOTEVALUATE(); + +var arguments; diff --git a/js/src/tests/test262/language/statements/variable/id-eval-strict-strict.js b/js/src/tests/test262/language/statements/variable/id-eval-strict-strict.js new file mode 100644 index 0000000000..01069c6963 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/id-eval-strict-strict.js @@ -0,0 +1,18 @@ +// |reftest| error:SyntaxError +'use strict'; +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es5id: 11.13.1-4-28-s +description: > + Strict Mode - SyntaxError is thrown if the identifier 'eval' appears as the + LeftHandSideExpression of simple assignment(=) under strict mode +negative: + phase: parse + type: SyntaxError +flags: [onlyStrict] +---*/ + +$DONOTEVALUATE(); + +var eval; diff --git a/js/src/tests/test262/language/statements/variable/shell.js b/js/src/tests/test262/language/statements/variable/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/shell.js diff --git a/js/src/tests/test262/language/statements/variable/static-init-await-binding-invalid.js b/js/src/tests/test262/language/statements/variable/static-init-await-binding-invalid.js new file mode 100644 index 0000000000..25951f4372 --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/static-init-await-binding-invalid.js @@ -0,0 +1,27 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-class-definitions-static-semantics-early-errors +description: BindingIdentifier may not be `await` within class static blocks +info: | + BindingIdentifier : Identifier + + [...] + - It is a Syntax Error if the code matched by this production is nested, + directly or indirectly (but not crossing function or static initialization + block boundaries), within a ClassStaticBlock and the StringValue of + Identifier is "await". +negative: + phase: parse + type: SyntaxError +features: [class-static-block] +---*/ + +$DONOTEVALUATE(); + +class C { + static { + var await; + } +} diff --git a/js/src/tests/test262/language/statements/variable/static-init-await-binding-valid.js b/js/src/tests/test262/language/statements/variable/static-init-await-binding-valid.js new file mode 100644 index 0000000000..31835e0d9a --- /dev/null +++ b/js/src/tests/test262/language/statements/variable/static-init-await-binding-valid.js @@ -0,0 +1,20 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-class-definitions-static-semantics-early-errors +description: The `await` keyword is interpreted as an identifier within arrow function bodies +info: | + ClassStaticBlockBody : ClassStaticBlockStatementList + + [...] + - It is a Syntax Error if ContainsAwait of ClassStaticBlockStatementList is true. +features: [class-static-block] +---*/ + +class C { + static { + (() => { var await; }); + } +} + +reportCompare(0, 0); |