Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Destructuring Binding - syntax and simple initialization #460

Merged
merged 2 commits into from
Jan 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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);
});
Original file line number Diff line number Diff line change
@@ -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();
});
Original file line number Diff line number Diff line change
@@ -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([]));
Original file line number Diff line number Diff line change
@@ -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]) {}
Original file line number Diff line number Diff line change
@@ -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: []}]) {}
Original file line number Diff line number Diff line change
@@ -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,]) {}
Original file line number Diff line number Diff line change
@@ -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([,,]) {}
Original file line number Diff line number Diff line change
@@ -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([]) {}
Original file line number Diff line number Diff line change
@@ -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]}) {}
Original file line number Diff line number Diff line change
@@ -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({}) {}
Original file line number Diff line number Diff line change
@@ -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}) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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,}) {}
Original file line number Diff line number Diff line change
@@ -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}) {}
Original file line number Diff line number Diff line change
@@ -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}}}) {}
Loading