From be195c38ca216170205ef1e46581c59596fd0420 Mon Sep 17 00:00:00 2001 From: Mike Pennisi <mike@mikepennisi.com> Date: Mon, 18 Apr 2016 13:34:46 -0400 Subject: [PATCH] Add omitted destructuring binding forms Add test templates for destructuring binding as it occurs in previously-overlooked productions (various IterationStatements and the TryStatement). --- src/dstr-binding/default/for-const.template | 47 +++++++++++++++++++ src/dstr-binding/default/for-let.template | 47 +++++++++++++++++++ .../default/for-of-const.template | 47 +++++++++++++++++++ src/dstr-binding/default/for-of-let.template | 47 +++++++++++++++++++ src/dstr-binding/default/for-of-var.template | 44 +++++++++++++++++ src/dstr-binding/default/for-var.template | 40 ++++++++++++++++ src/dstr-binding/default/try.template | 27 +++++++++++ 7 files changed, 299 insertions(+) create mode 100644 src/dstr-binding/default/for-const.template create mode 100644 src/dstr-binding/default/for-let.template create mode 100644 src/dstr-binding/default/for-of-const.template create mode 100644 src/dstr-binding/default/for-of-let.template create mode 100644 src/dstr-binding/default/for-of-var.template create mode 100644 src/dstr-binding/default/for-var.template create mode 100644 src/dstr-binding/default/try.template diff --git a/src/dstr-binding/default/for-const.template b/src/dstr-binding/default/for-const.template new file mode 100644 index 0000000000..cc89ba30d4 --- /dev/null +++ b/src/dstr-binding/default/for-const.template @@ -0,0 +1,47 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +path: language/statements/for/dstr-const- +name: for statement +esid: sec-for-statement-runtime-semantics-labelledevaluation +es6id: 13.7.4.7 +features: [destructuring-binding] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env as the arguments. +---*/ + +var iterCount = 0; + +for (const /*{ elems }*/ = /*{ vals }*/; iterCount < 1; ) { + /*{ body }*/ + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); diff --git a/src/dstr-binding/default/for-let.template b/src/dstr-binding/default/for-let.template new file mode 100644 index 0000000000..d904941088 --- /dev/null +++ b/src/dstr-binding/default/for-let.template @@ -0,0 +1,47 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +path: language/statements/for/dstr-let- +name: for statement +esid: sec-for-statement-runtime-semantics-labelledevaluation +es6id: 13.7.4.7 +features: [destructuring-binding] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env as the arguments. +---*/ + +var iterCount = 0; + +for (let /*{ elems }*/ = /*{ vals }*/; iterCount < 1; ) { + /*{ body }*/ + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); diff --git a/src/dstr-binding/default/for-of-const.template b/src/dstr-binding/default/for-of-const.template new file mode 100644 index 0000000000..c84dfa74a3 --- /dev/null +++ b/src/dstr-binding/default/for-of-const.template @@ -0,0 +1,47 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +path: language/statements/for-of/dstr-const- +name: for-of statement +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +es6id: 13.7.5.11 +features: [destructuring-binding] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] +---*/ + +var iterCount = 0; + +for (const /*{ elems }*/ of [/*{ vals }*/]) { + /*{ body }*/ + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); diff --git a/src/dstr-binding/default/for-of-let.template b/src/dstr-binding/default/for-of-let.template new file mode 100644 index 0000000000..c4366ad2c0 --- /dev/null +++ b/src/dstr-binding/default/for-of-let.template @@ -0,0 +1,47 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +path: language/statements/for-of/dstr-let- +name: for-of statement +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +es6id: 13.7.5.11 +features: [destructuring-binding] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] +---*/ + +var iterCount = 0; + +for (let /*{ elems }*/ of [/*{ vals }*/]) { + /*{ body }*/ + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); diff --git a/src/dstr-binding/default/for-of-var.template b/src/dstr-binding/default/for-of-var.template new file mode 100644 index 0000000000..53feb6f438 --- /dev/null +++ b/src/dstr-binding/default/for-of-var.template @@ -0,0 +1,44 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +path: language/statements/for-of/dstr-var- +name: for-of statement +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +es6id: 13.7.5.11 +features: [destructuring-binding] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] +---*/ + +var iterCount = 0; + +for (var /*{ elems }*/ of [/*{ vals }*/]) { + /*{ body }*/ + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); diff --git a/src/dstr-binding/default/for-var.template b/src/dstr-binding/default/for-var.template new file mode 100644 index 0000000000..e2122ecd70 --- /dev/null +++ b/src/dstr-binding/default/for-var.template @@ -0,0 +1,40 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +path: language/statements/for/dstr-var- +name: for statement +esid: sec-for-statement-runtime-semantics-labelledevaluation +es6id: 13.7.4.7 +features: [destructuring-binding] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + 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 iterCount = 0; + +for (var /*{ elems }*/ = /*{ vals }*/; iterCount < 1; ) { + /*{ body }*/ + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); diff --git a/src/dstr-binding/default/try.template b/src/dstr-binding/default/try.template new file mode 100644 index 0000000000..da603c64b6 --- /dev/null +++ b/src/dstr-binding/default/try.template @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +path: language/statements/try/dstr- +name: try statement +esid: sec-runtime-semantics-catchclauseevaluation +es6id: 13.15.7 +features: [destructuring-binding] +info: | + Catch : catch ( CatchParameter ) Block + + [...] + 5. Let status be the result of performing BindingInitialization for + CatchParameter passing thrownValue and catchEnv as arguments. + [...] +---*/ + +var ranCatch = false; + +try { + throw /*{ vals }*/; +} catch (/*{ elems }*/) { + /*{ body }*/ + ranCatch = true; +} + +assert(ranCatch, 'executed `catch` block'); -- GitLab