From 7e24ed9999cfc1af03d9c7ba0c825eafdee8dbea Mon Sep 17 00:00:00 2001 From: Leonardo Balter Date: Tue, 29 Dec 2015 14:56:40 -0500 Subject: [PATCH 1/2] Destructuring Binding - syntax and simple initialization --- ...lization-requires-object-coercible-null.js | 21 +++++++++ ...ion-requires-object-coercible-undefined.js | 21 +++++++++ ...rns-normal-completion-for-empty-objects.js | 30 +++++++++++++ .../syntax/array-elements-with-initializer.js | 32 +++++++++++++ .../array-elements-with-object-patterns.js | 34 ++++++++++++++ .../array-elements-without-initializer.js | 32 +++++++++++++ .../syntax/array-pattern-with-elisions.js | 18 ++++++++ .../syntax/array-pattern-with-no-elements.js | 17 +++++++ .../binding/syntax/array-rest-elements.js | 28 ++++++++++++ .../object-pattern-with-no-property-list.js | 18 ++++++++ .../syntax/property-list-bindings-elements.js | 45 +++++++++++++++++++ ...roperty-list-followed-by-a-single-comma.js | 24 ++++++++++ .../property-list-single-name-bindings.js | 32 +++++++++++++ .../property-list-with-property-list.js | 26 +++++++++++ .../recursive-array-and-object-patterns.js | 24 ++++++++++ 15 files changed, 402 insertions(+) create mode 100644 test/language/destructuring/binding/initialization-requires-object-coercible-null.js create mode 100644 test/language/destructuring/binding/initialization-requires-object-coercible-undefined.js create mode 100644 test/language/destructuring/binding/initialization-returns-normal-completion-for-empty-objects.js create mode 100644 test/language/destructuring/binding/syntax/array-elements-with-initializer.js create mode 100644 test/language/destructuring/binding/syntax/array-elements-with-object-patterns.js create mode 100644 test/language/destructuring/binding/syntax/array-elements-without-initializer.js create mode 100644 test/language/destructuring/binding/syntax/array-pattern-with-elisions.js create mode 100644 test/language/destructuring/binding/syntax/array-pattern-with-no-elements.js create mode 100644 test/language/destructuring/binding/syntax/array-rest-elements.js create mode 100644 test/language/destructuring/binding/syntax/object-pattern-with-no-property-list.js create mode 100644 test/language/destructuring/binding/syntax/property-list-bindings-elements.js create mode 100644 test/language/destructuring/binding/syntax/property-list-followed-by-a-single-comma.js create mode 100644 test/language/destructuring/binding/syntax/property-list-single-name-bindings.js create mode 100644 test/language/destructuring/binding/syntax/property-list-with-property-list.js create mode 100644 test/language/destructuring/binding/syntax/recursive-array-and-object-patterns.js diff --git a/test/language/destructuring/binding/initialization-requires-object-coercible-null.js b/test/language/destructuring/binding/initialization-requires-object-coercible-null.js new file mode 100644 index 0000000000..7397f490a2 --- /dev/null +++ b/test/language/destructuring/binding/initialization-requires-object-coercible-null.js @@ -0,0 +1,21 @@ +// 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.3.5 +description: > + Cannot convert null argument value to object +info: > + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ObjectBindingPattern + + 1. Let valid be RequireObjectCoercible(value). + 2. ReturnIfAbrupt(valid). +---*/ + +function fn({}) {} + +assert.throws(TypeError, function() { + fn(null); +}); diff --git a/test/language/destructuring/binding/initialization-requires-object-coercible-undefined.js b/test/language/destructuring/binding/initialization-requires-object-coercible-undefined.js new file mode 100644 index 0000000000..58c6c58e4e --- /dev/null +++ b/test/language/destructuring/binding/initialization-requires-object-coercible-undefined.js @@ -0,0 +1,21 @@ +// 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.3.5 +description: > + Cannot convert undefined argument value to object +info: > + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ObjectBindingPattern + + 1. Let valid be RequireObjectCoercible(value). + 2. ReturnIfAbrupt(valid). +---*/ + +function fn({}) {} + +assert.throws(TypeError, function() { + fn(); +}); diff --git a/test/language/destructuring/binding/initialization-returns-normal-completion-for-empty-objects.js b/test/language/destructuring/binding/initialization-returns-normal-completion-for-empty-objects.js new file mode 100644 index 0000000000..5ac7fb1d76 --- /dev/null +++ b/test/language/destructuring/binding/initialization-returns-normal-completion-for-empty-objects.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.3.5 +description: > + Normal completion when initializing an empty ObjectBindingPattern +info: > + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ObjectBindingPattern + + ... + 3. Return the result of performing BindingInitialization for + ObjectBindingPattern using value and environment as arguments. + + ObjectBindingPattern : { } + + 1. Return NormalCompletion(empty). + +---*/ + +function fn({}) { return true; } + +assert(fn(0)); +assert(fn(NaN)); +assert(fn('')); +assert(fn(false)); +assert(fn({})); +assert(fn([])); diff --git a/test/language/destructuring/binding/syntax/array-elements-with-initializer.js b/test/language/destructuring/binding/syntax/array-elements-with-initializer.js new file mode 100644 index 0000000000..25f551f23c --- /dev/null +++ b/test/language/destructuring/binding/syntax/array-elements-with-initializer.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.3 +description: > + The ArrayBindingPattern with an element list with initializers +info: > + Destructuring Binding Patterns - Syntax + + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] + + BindingElementList[Yield] : + BindingElisionElement[?Yield] + BindingElementList[?Yield] , BindingElisionElement[?Yield] + + BindingElisionElement[Yield] : + Elisionopt BindingElement[?Yield] + + BindingElement[Yield ] : + SingleNameBinding[?Yield] + BindingPattern[?Yield] Initializer[In, ?Yield]opt +---*/ + +function fn1([a, b = 42]) {} + +function fn2([a = 42, b,]) {} + +function fn3([a,, b = a, c = 42]) {} diff --git a/test/language/destructuring/binding/syntax/array-elements-with-object-patterns.js b/test/language/destructuring/binding/syntax/array-elements-with-object-patterns.js new file mode 100644 index 0000000000..8bf0df93ec --- /dev/null +++ b/test/language/destructuring/binding/syntax/array-elements-with-object-patterns.js @@ -0,0 +1,34 @@ +// 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.3 +description: > + The ArrayBindingPattern with Object patterns on the element list +info: > + Destructuring Binding Patterns - Syntax + + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] + + BindingElementList[Yield] : + BindingElisionElement[?Yield] + BindingElementList[?Yield] , BindingElisionElement[?Yield] + + BindingElisionElement[Yield] : + Elisionopt BindingElement[?Yield] + + BindingElement[Yield ] : + SingleNameBinding[?Yield] + BindingPattern[?Yield] Initializer[In, ?Yield]opt +---*/ + +function fn1([{}]) {} + +function fn2([{} = 42]) {} + +function fn3([a, {b: c}]) {} + +function fn4([a, {b: []}]) {} diff --git a/test/language/destructuring/binding/syntax/array-elements-without-initializer.js b/test/language/destructuring/binding/syntax/array-elements-without-initializer.js new file mode 100644 index 0000000000..2e0c4cc2bd --- /dev/null +++ b/test/language/destructuring/binding/syntax/array-elements-without-initializer.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.3 +description: > + The ArrayBindingPattern with an element list without initializers +info: > + Destructuring Binding Patterns - Syntax + + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] + + BindingElementList[Yield] : + BindingElisionElement[?Yield] + BindingElementList[?Yield] , BindingElisionElement[?Yield] + + BindingElisionElement[Yield] : + Elisionopt BindingElement[?Yield] + + BindingElement[Yield ] : + SingleNameBinding[?Yield] + BindingPattern[?Yield] Initializer[In, ?Yield]opt +---*/ + +function fn1([a, b]) {} + +function fn2([a, b,]) {} + +function fn3([a,, b,]) {} diff --git a/test/language/destructuring/binding/syntax/array-pattern-with-elisions.js b/test/language/destructuring/binding/syntax/array-pattern-with-elisions.js new file mode 100644 index 0000000000..d2f86f7d2c --- /dev/null +++ b/test/language/destructuring/binding/syntax/array-pattern-with-elisions.js @@ -0,0 +1,18 @@ +// 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.3 +description: > + The ArrayBindingPattern with elisions only +info: > + Destructuring Binding Patterns - Syntax + + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ + +function fn1([,]) {} +function fn2([,,]) {} diff --git a/test/language/destructuring/binding/syntax/array-pattern-with-no-elements.js b/test/language/destructuring/binding/syntax/array-pattern-with-no-elements.js new file mode 100644 index 0000000000..32d5af920a --- /dev/null +++ b/test/language/destructuring/binding/syntax/array-pattern-with-no-elements.js @@ -0,0 +1,17 @@ +// 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.3 +description: > + The ArrayBindingPattern with no elements +info: > + Destructuring Binding Patterns - Syntax + + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ + +function fn([]) {} diff --git a/test/language/destructuring/binding/syntax/array-rest-elements.js b/test/language/destructuring/binding/syntax/array-rest-elements.js new file mode 100644 index 0000000000..a40fac6dcc --- /dev/null +++ b/test/language/destructuring/binding/syntax/array-rest-elements.js @@ -0,0 +1,28 @@ +// 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.3 +description: > + Array Binding Pattern with Rest Element +info: > + Destructuring Binding Patterns - Syntax + + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] + + BindingRestElement[Yield] : + ... BindingIdentifier[?Yield] +---*/ + +function fn1([...args]) {} + +function fn2([,,,,,,,...args]) {} + +function fn3([x, {y}, ...z]) {} + +function fn4([,x, {y}, , ...z]) {} + +function fn5({x: [...y]}) {} diff --git a/test/language/destructuring/binding/syntax/object-pattern-with-no-property-list.js b/test/language/destructuring/binding/syntax/object-pattern-with-no-property-list.js new file mode 100644 index 0000000000..5299f26cb6 --- /dev/null +++ b/test/language/destructuring/binding/syntax/object-pattern-with-no-property-list.js @@ -0,0 +1,18 @@ +// 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.3 +description: > + The ObjectBindingPattern can be `{ }` +info: > + Destructuring Binding Patterns - Syntax + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } + +---*/ + +function fn({}) {} diff --git a/test/language/destructuring/binding/syntax/property-list-bindings-elements.js b/test/language/destructuring/binding/syntax/property-list-bindings-elements.js new file mode 100644 index 0000000000..87a21d1938 --- /dev/null +++ b/test/language/destructuring/binding/syntax/property-list-bindings-elements.js @@ -0,0 +1,45 @@ +// 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.3 +description: > + The ObjectBindingPattern with binding elements +info: > + Destructuring Binding Patterns - Syntax + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } + + BindingPropertyList[Yield] : + BindingProperty[?Yield] + BindingPropertyList[?Yield] , BindingProperty[?Yield] + + BindingProperty[Yield] : + SingleNameBinding[?Yield] + PropertyName[?Yield] : BindingElement[?Yield] + + BindingElement[Yield ] : + SingleNameBinding[?Yield] + BindingPattern[?Yield] Initializer[In, ?Yield]opt + + SingleNameBinding[Yield] : + BindingIdentifier[?Yield] Initializer[In, ?Yield]opt + +---*/ + +// BindingElement w/ SingleNameBinding +function fna({x: y}) {} + +// BindingElement w/ SingleNameBinding with initializer +function fnb({x: y = 42}) {} + +// BindingElement w/ BindingPattern +function fnc({x: {}}) {} +function fnd({x: {y}}) {} + +// BindingElement w/ BindingPattern w/ initializer +function fne({x: {} = 42}) {} +function fnf({x: {y} = 42}) {} diff --git a/test/language/destructuring/binding/syntax/property-list-followed-by-a-single-comma.js b/test/language/destructuring/binding/syntax/property-list-followed-by-a-single-comma.js new file mode 100644 index 0000000000..c5fa12ea69 --- /dev/null +++ b/test/language/destructuring/binding/syntax/property-list-followed-by-a-single-comma.js @@ -0,0 +1,24 @@ +// 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.3 +description: > + The Binding Property List followed by a single comma is a valid syntax +info: > + Destructuring Binding Patterns - Syntax + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } + +---*/ + +function fn1({x,}) {} + +function fn2({a: {p: q, }, }) {} + +function fn3({x,,}) {} + +function fn4({x,,,,,,,}) {} diff --git a/test/language/destructuring/binding/syntax/property-list-single-name-bindings.js b/test/language/destructuring/binding/syntax/property-list-single-name-bindings.js new file mode 100644 index 0000000000..69c745bb3d --- /dev/null +++ b/test/language/destructuring/binding/syntax/property-list-single-name-bindings.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.3 +description: > + The ObjectBindingPattern with a simple property list and single name binding +info: > + Destructuring Binding Patterns - Syntax + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } + + BindingPropertyList[Yield] : + BindingProperty[?Yield] + BindingPropertyList[?Yield] , BindingProperty[?Yield] + + BindingProperty[Yield] : + SingleNameBinding[?Yield] + PropertyName[?Yield] : BindingElement[?Yield] + + SingleNameBinding[Yield] : + BindingIdentifier[?Yield] Initializer[In, ?Yield]opt + +---*/ + +function fna({x}) {} +function fnb({x, y}) {} +function fnc({x = 42}) {} +function fnd({x, y = 42}) {} \ No newline at end of file diff --git a/test/language/destructuring/binding/syntax/property-list-with-property-list.js b/test/language/destructuring/binding/syntax/property-list-with-property-list.js new file mode 100644 index 0000000000..d421e12c07 --- /dev/null +++ b/test/language/destructuring/binding/syntax/property-list-with-property-list.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.3 +description: > + The ObjectBindingPattern with deep binding property lists +info: > + Destructuring Binding Patterns - Syntax + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } + + BindingPropertyList[Yield] : + BindingProperty[?Yield] + BindingPropertyList[?Yield] , BindingProperty[?Yield] + +---*/ + +function fn1({a: {p: q}, b: {r}, c: {s = 0}, d: {}}) {} + +function fn2(x, {a: r, b: s, c: t}, y) {} + +function fn3({x: {y: {z: {} = 42}}}) {} diff --git a/test/language/destructuring/binding/syntax/recursive-array-and-object-patterns.js b/test/language/destructuring/binding/syntax/recursive-array-and-object-patterns.js new file mode 100644 index 0000000000..3c3289f609 --- /dev/null +++ b/test/language/destructuring/binding/syntax/recursive-array-and-object-patterns.js @@ -0,0 +1,24 @@ +// 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.3 +description: > + Recursive array and object binding patterns +info: > + Destructuring Binding Patterns - Syntax + + BindingPattern[Yield] : + ObjectBindingPattern[?Yield] + ArrayBindingPattern[?Yield] +---*/ + +function fn1([{}]) {} + +function fn2([{a: [{}]}]) {} + +function fn3({a: [,,,] = 42}) {} + +function fn4([], [[]], [[[[[[[[[x]]]]]]]]]) {} + +function fn4([[x, y, ...z]]) {} From 5e653f2e6ca14ac1ad8e801955a709cae7ac8a11 Mon Sep 17 00:00:00 2001 From: Leonardo Balter Date: Tue, 29 Dec 2015 16:50:23 -0500 Subject: [PATCH 2/2] ObjectBindingPatterns can't end with multiple commas --- .../syntax/property-list-followed-by-a-single-comma.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/language/destructuring/binding/syntax/property-list-followed-by-a-single-comma.js b/test/language/destructuring/binding/syntax/property-list-followed-by-a-single-comma.js index c5fa12ea69..04c37695f3 100644 --- a/test/language/destructuring/binding/syntax/property-list-followed-by-a-single-comma.js +++ b/test/language/destructuring/binding/syntax/property-list-followed-by-a-single-comma.js @@ -19,6 +19,4 @@ function fn1({x,}) {} function fn2({a: {p: q, }, }) {} -function fn3({x,,}) {} - -function fn4({x,,,,,,,}) {} +function fn3({x,}) {}