mirror of https://github.com/tc39/test262.git
Merge pull request #1044 from rwaldron/dstr-binding-async-iteration
Move dstr-binding for-await-of cases and templates to dstr-binding-async-iteration. Fixes gh-1043
This commit is contained in:
commit
e8fb452df8
|
@ -0,0 +1,37 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: Iterator is closed when not exhausted by pattern evaluation
|
||||
template: default
|
||||
info: |
|
||||
13.3.3.5 Runtime Semantics: BindingInitialization
|
||||
|
||||
BindingPattern : ArrayBindingPattern
|
||||
|
||||
[...]
|
||||
4. If iteratorRecord.[[done]] is false, return ? IteratorClose(iterator,
|
||||
result).
|
||||
[...]
|
||||
features: [Symbol.iterator]
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
var doneCallCount = 0;
|
||||
var iter = {};
|
||||
iter[Symbol.iterator] = function() {
|
||||
return {
|
||||
next() {
|
||||
return { value: null, done: false };
|
||||
},
|
||||
return() {
|
||||
doneCallCount += 1;
|
||||
return {};
|
||||
}
|
||||
};
|
||||
};
|
||||
//- elems
|
||||
[x]
|
||||
//- vals
|
||||
iter
|
||||
//- body
|
||||
assert.sameValue(doneCallCount, 1);
|
|
@ -0,0 +1,25 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: Abrupt completion returned by GetIterator
|
||||
template: error
|
||||
info: |
|
||||
13.3.3.5 Runtime Semantics: BindingInitialization
|
||||
|
||||
BindingPattern : ArrayBindingPattern
|
||||
|
||||
1. Let iterator be ? GetIterator(value).
|
||||
features: [Symbol.iterator]
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
var iter = {};
|
||||
iter[Symbol.iterator] = function() {
|
||||
throw new Test262Error();
|
||||
};
|
||||
//- elems
|
||||
[x]
|
||||
//- vals
|
||||
iter
|
||||
//- error
|
||||
Test262Error
|
|
@ -0,0 +1,37 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: Iterator is not closed when exhausted by pattern evaluation
|
||||
template: default
|
||||
info: |
|
||||
13.3.3.5 Runtime Semantics: BindingInitialization
|
||||
|
||||
BindingPattern : ArrayBindingPattern
|
||||
|
||||
[...]
|
||||
4. If iteratorRecord.[[done]] is false, return ? IteratorClose(iterator,
|
||||
result).
|
||||
[...]
|
||||
features: [Symbol.iterator]
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
var doneCallCount = 0;
|
||||
var iter = {};
|
||||
iter[Symbol.iterator] = function() {
|
||||
return {
|
||||
next() {
|
||||
return { value: null, done: true };
|
||||
},
|
||||
return() {
|
||||
doneCallCount += 1;
|
||||
return {};
|
||||
}
|
||||
};
|
||||
};
|
||||
//- elems
|
||||
[x]
|
||||
//- vals
|
||||
iter
|
||||
//- body
|
||||
assert.sameValue(doneCallCount, 0);
|
|
@ -0,0 +1,34 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: SingleNameBinding with normal value iteration
|
||||
template: default
|
||||
info: |
|
||||
13.3.3.6 Runtime Semantics: IteratorBindingInitialization
|
||||
|
||||
SingleNameBinding : BindingIdentifier Initializer_opt
|
||||
|
||||
[...]
|
||||
3. 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).
|
||||
4. If iteratorRecord.[[done]] is true, let v be undefined.
|
||||
[...]
|
||||
7. Return InitializeReferencedBinding(lhs, v).
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
[x, y, z]
|
||||
//- vals
|
||||
[1, 2, 3]
|
||||
//- body
|
||||
assert.sameValue(x, 1);
|
||||
assert.sameValue(y, 2);
|
||||
assert.sameValue(z, 3);
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: BindingElement with array binding pattern and initializer is used
|
||||
template: default
|
||||
info: |
|
||||
13.3.3.6 Runtime Semantics: IteratorBindingInitialization
|
||||
|
||||
BindingElement : BindingPattern Initializer_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.
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
[[x, y, z] = [4, 5, 6]]
|
||||
//- vals
|
||||
[]
|
||||
//- body
|
||||
assert.sameValue(x, 4);
|
||||
assert.sameValue(y, 5);
|
||||
assert.sameValue(z, 6);
|
|
@ -0,0 +1,28 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: BindingElement with array binding pattern and initializer is not used
|
||||
template: default
|
||||
info: |
|
||||
13.3.3.6 Runtime Semantics: IteratorBindingInitialization
|
||||
|
||||
BindingElement : BindingPattern Initializer_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.
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
[[x, y, z] = [4, 5, 6]]
|
||||
//- vals
|
||||
[[7, 8, 9]]
|
||||
//- body
|
||||
assert.sameValue(x, 7);
|
||||
assert.sameValue(y, 8);
|
||||
assert.sameValue(z, 9);
|
|
@ -0,0 +1,35 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: BindingElement with array binding pattern and initializer is used
|
||||
template: default
|
||||
info: |
|
||||
13.3.3.6 Runtime Semantics: IteratorBindingInitialization
|
||||
|
||||
BindingElement : BindingPattern Initializer_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.
|
||||
features: [generators]
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
var first = 0;
|
||||
var second = 0;
|
||||
function* g() {
|
||||
first += 1;
|
||||
yield;
|
||||
second += 1;
|
||||
};
|
||||
//- elems
|
||||
[[,] = g()]
|
||||
//- vals
|
||||
[]
|
||||
//- body
|
||||
assert.sameValue(first, 1);
|
||||
assert.sameValue(second, 0);
|
|
@ -0,0 +1,32 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: BindingElement with array binding pattern and initializer is not used
|
||||
template: default
|
||||
info: |
|
||||
13.3.3.6 Runtime Semantics: IteratorBindingInitialization
|
||||
|
||||
BindingElement : BindingPattern Initializer_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.
|
||||
features: [generators]
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
var callCount = 0;
|
||||
function* g() {
|
||||
callCount += 1;
|
||||
};
|
||||
//- elems
|
||||
[[,] = g()]
|
||||
//- vals
|
||||
[[]]
|
||||
//- body
|
||||
assert.sameValue(callCount, 0);
|
|
@ -0,0 +1,30 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: BindingElement with array binding pattern and initializer is used
|
||||
template: default
|
||||
info: |
|
||||
13.3.3.6 Runtime Semantics: IteratorBindingInitialization
|
||||
|
||||
BindingElement : BindingPattern Initializer_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.
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
var initCount = 0;
|
||||
var iterCount = 0;
|
||||
var iter = function*() { iterCount += 1; }();
|
||||
//- elems
|
||||
[[] = function() { initCount += 1; return iter; }()]
|
||||
//- vals
|
||||
[]
|
||||
//- body
|
||||
assert.sameValue(initCount, 1);
|
||||
assert.sameValue(iterCount, 0);
|
|
@ -0,0 +1,28 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: BindingElement with array binding pattern and initializer is not used
|
||||
template: default
|
||||
info: |
|
||||
13.3.3.6 Runtime Semantics: IteratorBindingInitialization
|
||||
|
||||
BindingElement : BindingPattern Initializer_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.
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
var initCount = 0;
|
||||
//- elems
|
||||
[[] = function() { initCount += 1; }()]
|
||||
//- vals
|
||||
[[23]]
|
||||
//- body
|
||||
assert.sameValue(initCount, 0);
|
|
@ -0,0 +1,32 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: BindingElement with array binding pattern and initializer is used
|
||||
template: default
|
||||
info: |
|
||||
13.3.3.6 Runtime Semantics: IteratorBindingInitialization
|
||||
|
||||
BindingElement : BindingPattern Initializer_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.
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
var values = [2, 1, 3];
|
||||
//- elems
|
||||
[[...x] = values]
|
||||
//- vals
|
||||
[]
|
||||
//- body
|
||||
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);
|
|
@ -0,0 +1,35 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: BindingElement with array binding pattern and initializer is not used
|
||||
template: default
|
||||
info: |
|
||||
13.3.3.6 Runtime Semantics: IteratorBindingInitialization
|
||||
|
||||
BindingElement : BindingPattern Initializer_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.
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
var values = [2, 1, 3];
|
||||
var initCount = 0;
|
||||
//- elems
|
||||
[[...x] = function() { initCount += 1; }()]
|
||||
//- vals
|
||||
[values]
|
||||
//- body
|
||||
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);
|
|
@ -0,0 +1,31 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: Nested array destructuring with a null value
|
||||
template: error
|
||||
info: |
|
||||
13.3.3.6 Runtime Semantics: IteratorBindingInitialization
|
||||
|
||||
BindingElement : BindingPattern Initializer_opt
|
||||
|
||||
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).
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
[[x]]
|
||||
//- vals
|
||||
[null]
|
||||
//- error
|
||||
TypeError
|
|
@ -0,0 +1,26 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: Destructuring initializer with an exhausted iterator
|
||||
template: default
|
||||
info: |
|
||||
13.3.3.6 Runtime Semantics: IteratorBindingInitialization
|
||||
|
||||
SingleNameBinding : BindingIdentifier Initializer_opt
|
||||
|
||||
[...]
|
||||
4. If iteratorRecord.[[done]] is true, let v be undefined.
|
||||
5. If Initializer is present and v is undefined, then
|
||||
a. Let defaultValue be the result of evaluating Initializer.
|
||||
b. Let v be GetValue(defaultValue).
|
||||
[...]
|
||||
6. If environment is undefined, return PutValue(lhs, v).
|
||||
7. Return InitializeReferencedBinding(lhs, v).
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
[x = 23]
|
||||
//- vals
|
||||
[]
|
||||
//- body
|
||||
assert.sameValue(x, 23);
|
|
@ -0,0 +1,26 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: SingleNameBinding does assign name to arrow functions
|
||||
template: default
|
||||
info: |
|
||||
13.3.3.6 Runtime Semantics: IteratorBindingInitialization
|
||||
|
||||
SingleNameBinding : BindingIdentifier Initializer_opt
|
||||
|
||||
[...]
|
||||
5. If Initializer is present and v is undefined, then
|
||||
a. Let defaultValue be the result of evaluating Initializer.
|
||||
b. Set v to ? GetValue(defaultValue).
|
||||
c. If IsAnonymousFunctionDefinition(Initializer) is true, then
|
||||
[...]
|
||||
6. If environment is undefined, return PutValue(lhs, v).
|
||||
7. Return InitializeReferencedBinding(lhs, v).
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
[arrow = () => {}]
|
||||
//- vals
|
||||
[]
|
||||
//- body
|
||||
assert.sameValue(arrow.name, 'arrow');
|
|
@ -0,0 +1,28 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: SingleNameBinding assigns `name` to "anonymous" classes
|
||||
template: default
|
||||
info: |
|
||||
13.3.3.6 Runtime Semantics: IteratorBindingInitialization
|
||||
|
||||
SingleNameBinding : BindingIdentifier Initializer_opt
|
||||
|
||||
[...]
|
||||
5. If Initializer is present and v is undefined, then
|
||||
a. Let defaultValue be the result of evaluating Initializer.
|
||||
b. Set v to ? GetValue(defaultValue).
|
||||
c. If IsAnonymousFunctionDefinition(Initializer) is true, then
|
||||
[...]
|
||||
6. If environment is undefined, return PutValue(lhs, v).
|
||||
7. Return InitializeReferencedBinding(lhs, v).
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
[cls = class {}, xCls = class X {}, xCls2 = class { static name() {} }]
|
||||
//- vals
|
||||
[]
|
||||
//- body
|
||||
assert.sameValue(cls.name, 'cls');
|
||||
assert.notSameValue(xCls.name, 'xCls');
|
||||
assert.notSameValue(xCls2.name, 'xCls2');
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: SingleNameBinding does assign name to "anonymous" functions "through" cover grammar
|
||||
template: default
|
||||
info: |
|
||||
13.3.3.6 Runtime Semantics: IteratorBindingInitialization
|
||||
|
||||
SingleNameBinding : BindingIdentifier Initializer_opt
|
||||
|
||||
[...]
|
||||
5. If Initializer is present and v is undefined, then
|
||||
a. Let defaultValue be the result of evaluating Initializer.
|
||||
b. Set v to ? GetValue(defaultValue).
|
||||
c. If IsAnonymousFunctionDefinition(Initializer) is true, then
|
||||
[...]
|
||||
6. If environment is undefined, return PutValue(lhs, v).
|
||||
7. Return InitializeReferencedBinding(lhs, v).
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
[cover = (function () {}), xCover = (0, function() {})]
|
||||
//- vals
|
||||
[]
|
||||
//- body
|
||||
assert.sameValue(cover.name, 'cover');
|
||||
assert.notSameValue(xCover.name, 'xCover');
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: SingleNameBinding assigns name to "anonymous" functions
|
||||
template: default
|
||||
info: |
|
||||
13.3.3.6 Runtime Semantics: IteratorBindingInitialization
|
||||
|
||||
SingleNameBinding : BindingIdentifier Initializer_opt
|
||||
|
||||
[...]
|
||||
5. If Initializer is present and v is undefined, then
|
||||
a. Let defaultValue be the result of evaluating Initializer.
|
||||
b. Set v to ? GetValue(defaultValue).
|
||||
c. If IsAnonymousFunctionDefinition(Initializer) is true, then
|
||||
[...]
|
||||
6. If environment is undefined, return PutValue(lhs, v).
|
||||
7. Return InitializeReferencedBinding(lhs, v).
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
[fn = function () {}, xFn = function x() {}]
|
||||
//- vals
|
||||
[]
|
||||
//- body
|
||||
assert.sameValue(fn.name, 'fn');
|
||||
assert.notSameValue(xFn.name, 'xFn');
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: SingleNameBinding assigns name to "anonymous" generator functions
|
||||
template: default
|
||||
info: |
|
||||
13.3.3.6 Runtime Semantics: IteratorBindingInitialization
|
||||
|
||||
SingleNameBinding : BindingIdentifier Initializer_opt
|
||||
|
||||
[...]
|
||||
5. If Initializer is present and v is undefined, then
|
||||
a. Let defaultValue be the result of evaluating Initializer.
|
||||
b. Set v to ? GetValue(defaultValue).
|
||||
c. If IsAnonymousFunctionDefinition(Initializer) is true, then
|
||||
[...]
|
||||
6. If environment is undefined, return PutValue(lhs, v).
|
||||
7. Return InitializeReferencedBinding(lhs, v).
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
[gen = function* () {}, xGen = function* x() {}]
|
||||
//- vals
|
||||
[]
|
||||
//- body
|
||||
assert.sameValue(gen.name, 'gen');
|
||||
assert.notSameValue(xGen.name, 'xGen');
|
|
@ -0,0 +1,26 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: Destructuring initializer with a "hole"
|
||||
template: default
|
||||
info: >
|
||||
13.3.3.6 Runtime Semantics: IteratorBindingInitialization
|
||||
|
||||
SingleNameBinding : BindingIdentifier Initializer_opt
|
||||
|
||||
[...]
|
||||
5. If Initializer is present and v is undefined, then
|
||||
a. Let defaultValue be the result of evaluating Initializer.
|
||||
b. Let v be GetValue(defaultValue).
|
||||
[...]
|
||||
6. If environment is undefined, return PutValue(lhs, v).
|
||||
7. Return InitializeReferencedBinding(lhs, v).
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
[x = 23]
|
||||
//- vals
|
||||
[,]
|
||||
//- body
|
||||
assert.sameValue(x, 23);
|
||||
// another statement
|
|
@ -0,0 +1,32 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: Destructuring initializer is not evaluated when value is not `undefined`
|
||||
template: default
|
||||
info: |
|
||||
13.3.3.6 Runtime Semantics: IteratorBindingInitialization
|
||||
|
||||
SingleNameBinding : BindingIdentifier Initializer_opt
|
||||
|
||||
[...]
|
||||
6. If Initializer is present and v is undefined, then
|
||||
[...]
|
||||
7. If environment is undefined, return PutValue(lhs, v).
|
||||
7. Return InitializeReferencedBinding(lhs, v).
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
var initCount = 0;
|
||||
function counter() {
|
||||
initCount += 1;
|
||||
}
|
||||
//- elems
|
||||
[w = counter(), x = counter(), y = counter(), z = counter()]
|
||||
//- vals
|
||||
[null, 0, false, '']
|
||||
//- body
|
||||
assert.sameValue(w, null);
|
||||
assert.sameValue(x, 0);
|
||||
assert.sameValue(y, false);
|
||||
assert.sameValue(z, '');
|
||||
assert.sameValue(initCount, 0);
|
|
@ -0,0 +1,22 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: Destructuring initializer returns an abrupt completion
|
||||
template: error
|
||||
info: |
|
||||
13.3.3.6 Runtime Semantics: IteratorBindingInitialization
|
||||
|
||||
SingleNameBinding : BindingIdentifier Initializer_opt
|
||||
|
||||
[...]
|
||||
5. If Initializer is present and v is undefined, then
|
||||
a. Let defaultValue be the result of evaluating Initializer.
|
||||
b. Set v to ? GetValue(defaultValue).
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
[x = (function() { throw new Test262Error(); })()]
|
||||
//- vals
|
||||
[undefined]
|
||||
//- error
|
||||
Test262Error
|
|
@ -0,0 +1,25 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: Destructuring initializer with an undefined value
|
||||
template: default
|
||||
info: |
|
||||
13.3.3.6 Runtime Semantics: IteratorBindingInitialization
|
||||
|
||||
SingleNameBinding : BindingIdentifier Initializer_opt
|
||||
|
||||
[...]
|
||||
5. If Initializer is present and v is undefined, then
|
||||
a. Let defaultValue be the result of evaluating Initializer.
|
||||
b. Let v be GetValue(defaultValue).
|
||||
[...]
|
||||
6. If environment is undefined, return PutValue(lhs, v).
|
||||
7. Return InitializeReferencedBinding(lhs, v).
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
[x = 23]
|
||||
//- vals
|
||||
[undefined]
|
||||
//- body
|
||||
assert.sameValue(x, 23);
|
|
@ -0,0 +1,29 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: Destructuring initializer is an unresolvable reference
|
||||
template: error
|
||||
info: |
|
||||
13.3.3.6 Runtime Semantics: IteratorBindingInitialization
|
||||
|
||||
SingleNameBinding : BindingIdentifier Initializer_opt
|
||||
|
||||
[...]
|
||||
5. If Initializer is present and v is undefined, then
|
||||
a. Let defaultValue be the result of evaluating Initializer.
|
||||
b. Set v to ? GetValue(defaultValue).
|
||||
|
||||
6.2.4.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.
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
[ x = unresolvableReference ]
|
||||
//- vals
|
||||
[]
|
||||
//- error
|
||||
ReferenceError
|
|
@ -0,0 +1,29 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: SingleNameBinding when value iteration completes
|
||||
template: default
|
||||
info: |
|
||||
13.3.3.6 Runtime Semantics: IteratorBindingInitialization
|
||||
|
||||
SingleNameBinding : BindingIdentifier Initializer_opt
|
||||
|
||||
[...]
|
||||
3. 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,
|
||||
[...]
|
||||
4. If iteratorRecord.[[done]] is true, let v be undefined.
|
||||
[...]
|
||||
7. Return InitializeReferencedBinding(lhs, v).
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
[x]
|
||||
//- vals
|
||||
[]
|
||||
//- body
|
||||
assert.sameValue(x, undefined);
|
|
@ -0,0 +1,24 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: SingleNameBinding when value iteration was completed previously
|
||||
template: default
|
||||
info: |
|
||||
13.3.3.6 Runtime Semantics: IteratorBindingInitialization
|
||||
|
||||
SingleNameBinding : BindingIdentifier Initializer_opt
|
||||
|
||||
[...]
|
||||
3. If iteratorRecord.[[done]] is false, then
|
||||
[...]
|
||||
4. If iteratorRecord.[[done]] is true, let v be undefined.
|
||||
[...]
|
||||
7. Return InitializeReferencedBinding(lhs, v).
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
[_, x]
|
||||
//- vals
|
||||
[]
|
||||
//- body
|
||||
assert.sameValue(x, undefined);
|
|
@ -0,0 +1,32 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: Error forwarding when IteratorStep returns an abrupt completion
|
||||
template: error
|
||||
info: |
|
||||
13.3.3.6 Runtime Semantics: IteratorBindingInitialization
|
||||
|
||||
SingleNameBinding : BindingIdentifier Initializer_opt
|
||||
|
||||
[...]
|
||||
3. 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).
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
var g = {};
|
||||
g[Symbol.iterator] = function() {
|
||||
return {
|
||||
next() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
};
|
||||
//- elems
|
||||
[x]
|
||||
//- vals
|
||||
g
|
||||
//- error
|
||||
Test262Error
|
|
@ -0,0 +1,43 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: Error forwarding when IteratorValue returns an abrupt completion
|
||||
template: error
|
||||
info: |
|
||||
13.3.3.6 Runtime Semantics: IteratorBindingInitialization
|
||||
|
||||
SingleNameBinding : BindingIdentifier Initializer_opt
|
||||
|
||||
[...]
|
||||
3. 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).
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
var poisonedValue = Object.defineProperty({}, 'value', {
|
||||
get: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
var g = {};
|
||||
g[Symbol.iterator] = function() {
|
||||
return {
|
||||
next() {
|
||||
return poisonedValue;
|
||||
}
|
||||
};
|
||||
};
|
||||
//- elems
|
||||
[x]
|
||||
//- vals
|
||||
g
|
||||
//- error
|
||||
Test262Error
|
|
@ -0,0 +1,34 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: SingleNameBinding when value iteration was completed previously
|
||||
template: default
|
||||
info: |
|
||||
13.3.3.6 Runtime Semantics: IteratorBindingInitialization
|
||||
|
||||
SingleNameBinding : BindingIdentifier Initializer_opt
|
||||
|
||||
[...]
|
||||
3. 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).
|
||||
4. If iteratorRecord.[[done]] is true, let v be undefined.
|
||||
[...]
|
||||
7. Return InitializeReferencedBinding(lhs, v).
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
[x, y, z]
|
||||
//- vals
|
||||
[1, 2, 3]
|
||||
//- body
|
||||
assert.sameValue(x, 1);
|
||||
assert.sameValue(y, 2);
|
||||
assert.sameValue(z, 3);
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: BindingElement with object binding pattern and initializer is used
|
||||
template: default
|
||||
info: |
|
||||
13.3.3.6 Runtime Semantics: IteratorBindingInitialization
|
||||
|
||||
BindingElement : BindingPattern Initializer_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.
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
[{ x, y, z } = { x: 44, y: 55, z: 66 }]
|
||||
//- vals
|
||||
[]
|
||||
//- body
|
||||
assert.sameValue(x, 44);
|
||||
assert.sameValue(y, 55);
|
||||
assert.sameValue(z, 66);
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: BindingElement with object binding pattern and initializer is not used
|
||||
template: default
|
||||
info: |
|
||||
13.3.3.6 Runtime Semantics: IteratorBindingInitialization
|
||||
|
||||
BindingElement : BindingPattern Initializer_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.
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
[{ x, y, z } = { x: 44, y: 55, z: 66 }]
|
||||
//- vals
|
||||
[{ x: 11, y: 22, z: 33 }]
|
||||
//- body
|
||||
assert.sameValue(x, 11);
|
||||
assert.sameValue(y, 22);
|
||||
assert.sameValue(z, 33);
|
|
@ -0,0 +1,37 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: BindingElement with object binding pattern and initializer is used
|
||||
template: default
|
||||
info: |
|
||||
13.3.3.6 Runtime Semantics: IteratorBindingInitialization
|
||||
|
||||
BindingElement : BindingPattern Initializer_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.
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
[{ u: v, w: x, y: z } = { u: 444, w: 555, y: 666 }]
|
||||
//- vals
|
||||
[]
|
||||
//- body
|
||||
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;
|
||||
});
|
|
@ -0,0 +1,37 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: BindingElement with object binding pattern and initializer is not used
|
||||
template: default
|
||||
info: |
|
||||
13.3.3.6 Runtime Semantics: IteratorBindingInitialization
|
||||
|
||||
BindingElement : BindingPattern Initializer_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.
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
[{ u: v, w: x, y: z } = { u: 444, w: 555, y: 666 }]
|
||||
//- vals
|
||||
[{ u: 777, w: 888, y: 999 }]
|
||||
//- body
|
||||
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;
|
||||
});
|
|
@ -0,0 +1,32 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: Nested object destructuring with a null value
|
||||
template: error
|
||||
info: |
|
||||
13.3.3.6 Runtime Semantics: IteratorBindingInitialization
|
||||
|
||||
BindingElement : BindingPattern Initializer_opt
|
||||
|
||||
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).
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
[{ x }]
|
||||
//- vals
|
||||
[null]
|
||||
//- error
|
||||
TypeError
|
|
@ -0,0 +1,32 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: Nested object destructuring with a value of `undefined`
|
||||
template: error
|
||||
info: |
|
||||
13.3.3.6 Runtime Semantics: IteratorBindingInitialization
|
||||
|
||||
BindingElement : BindingPattern Initializer_opt
|
||||
|
||||
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).
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
[{ x }]
|
||||
//- vals
|
||||
[]
|
||||
//- error
|
||||
TypeError
|
|
@ -0,0 +1,31 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: Elision accepts exhausted iterator
|
||||
template: default
|
||||
info: |
|
||||
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).
|
||||
features: [generator]
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
var iter = function*() {}();
|
||||
iter.next();
|
||||
//- elems
|
||||
[,]
|
||||
//- vals
|
||||
iter
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
template: iter-close
|
||||
desc: >
|
||||
The iterator is properly consumed by the destructuring pattern
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
const iter = (function* () {
|
||||
yield;
|
||||
yield;
|
||||
})();
|
||||
|
||||
//- elems
|
||||
[,]
|
||||
//- iter
|
||||
iter
|
||||
//- assertions
|
||||
assert.sameValue(iter.next().done, true, 'iteration occurred as expected');
|
|
@ -0,0 +1,39 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: Elision advances iterator and forwards abrupt completions
|
||||
template: error
|
||||
info: |
|
||||
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).
|
||||
features: [generator]
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
var following = 0;
|
||||
var iter = function* () {
|
||||
throw new Test262Error();
|
||||
following += 1;
|
||||
}();
|
||||
//- elems
|
||||
[,]
|
||||
//- vals
|
||||
iter
|
||||
//- error
|
||||
Test262Error
|
||||
//- rejectBody
|
||||
assert.sameValue(following, 0, "iterator is properly closed");
|
|
@ -0,0 +1,42 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: Elision advances iterator
|
||||
template: default
|
||||
info: |
|
||||
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).
|
||||
features: [generator]
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
var first = 0;
|
||||
var second = 0;
|
||||
function* g() {
|
||||
first += 1;
|
||||
yield;
|
||||
second += 1;
|
||||
};
|
||||
//- elems
|
||||
[,]
|
||||
//- vals
|
||||
g()
|
||||
//- body
|
||||
assert.sameValue(first, 1);
|
||||
assert.sameValue(second, 0);
|
|
@ -0,0 +1,25 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: No iteration occurs for an "empty" array binding pattern
|
||||
template: default
|
||||
info: |
|
||||
13.3.3.6 Runtime Semantics: IteratorBindingInitialization
|
||||
|
||||
ArrayBindingPattern : [ ]
|
||||
|
||||
1. Return NormalCompletion(empty).
|
||||
features: [generators]
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
var iterations = 0;
|
||||
var iter = function*() {
|
||||
iterations += 1;
|
||||
}();
|
||||
//- elems
|
||||
[]
|
||||
//- vals
|
||||
iter
|
||||
//- body
|
||||
assert.sameValue(iterations, 0);
|
|
@ -0,0 +1,47 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
template: default
|
||||
desc: Rest element containing an array BindingElementList pattern
|
||||
info: |
|
||||
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 Initializer_opt
|
||||
|
||||
[...]
|
||||
3. 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).
|
||||
4. If iteratorRecord.[[done]] is true, let v be undefined.
|
||||
[...]
|
||||
7. Return InitializeReferencedBinding(lhs, v).
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
[...[x, y, z]]
|
||||
//- vals
|
||||
[3, 4, 5]
|
||||
//- body
|
||||
assert.sameValue(x, 3);
|
||||
assert.sameValue(y, 4);
|
||||
assert.sameValue(z, 5);
|
|
@ -0,0 +1,55 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
template: default
|
||||
desc: Rest element containing an elision
|
||||
info: |
|
||||
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).
|
||||
features: [generators]
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
var first = 0;
|
||||
var second = 0;
|
||||
function* g() {
|
||||
first += 1;
|
||||
yield;
|
||||
second += 1;
|
||||
};
|
||||
//- elems
|
||||
[...[,]]
|
||||
//- vals
|
||||
g()
|
||||
//- body
|
||||
assert.sameValue(first, 1);
|
||||
assert.sameValue(second, 1);
|
|
@ -0,0 +1,38 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
template: default
|
||||
desc: Rest element containing an "empty" array pattern
|
||||
info: |
|
||||
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).
|
||||
features: [generators]
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
var iterations = 0;
|
||||
var iter = function*() {
|
||||
iterations += 1;
|
||||
}();
|
||||
//- elems
|
||||
[...[]]
|
||||
//- vals
|
||||
iter
|
||||
//- body
|
||||
assert.sameValue(iterations, 1);
|
|
@ -0,0 +1,34 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
template: default
|
||||
desc: Rest element containing a rest element
|
||||
info: |
|
||||
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.
|
||||
[...]
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
var values = [1, 2, 3];
|
||||
//- elems
|
||||
[...[...x]]
|
||||
//- vals
|
||||
values
|
||||
//- body
|
||||
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);
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
template: error
|
||||
desc: Rest element following elision elements
|
||||
info: >
|
||||
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.
|
||||
features: [generators]
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
var iter = (function*() { throw new Test262Error(); })();
|
||||
//- elems
|
||||
[, ...x]
|
||||
//- vals
|
||||
iter
|
||||
//- error
|
||||
Test262Error
|
|
@ -0,0 +1,32 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
template: default
|
||||
desc: Rest element following elision elements
|
||||
info: >
|
||||
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.
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
var values = [1, 2, 3, 4, 5];
|
||||
//- elems
|
||||
[ , , ...x]
|
||||
//- vals
|
||||
values
|
||||
//- body
|
||||
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);
|
|
@ -0,0 +1,30 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
template: default
|
||||
desc: RestElement applied to an exhausted iterator
|
||||
info: >
|
||||
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).
|
||||
features: [Symbol.iterator]
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
[, , ...x]
|
||||
//- vals
|
||||
[1, 2]
|
||||
//- body
|
||||
assert(Array.isArray(x));
|
||||
assert.sameValue(x.length, 0);
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
template: iter-close
|
||||
desc: >
|
||||
The iterator is properly consumed by the destructuring pattern
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
const iter = (function* () {
|
||||
yield;
|
||||
yield;
|
||||
})();
|
||||
|
||||
//- elems
|
||||
[...x]
|
||||
//- iter
|
||||
iter
|
||||
//- assertions
|
||||
assert.sameValue(iter.next().done, true, 'iteration occurred as expected');
|
|
@ -0,0 +1,38 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
template: error
|
||||
desc: Error forwarding when IteratorStep returns an abrupt completion
|
||||
info: >
|
||||
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).
|
||||
features: [generators]
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
var first = 0;
|
||||
var second = 0;
|
||||
var iter = function*() {
|
||||
first += 1;
|
||||
throw new Test262Error();
|
||||
second += 1;
|
||||
}();
|
||||
//- elems
|
||||
[...x]
|
||||
//- vals
|
||||
iter
|
||||
//- error
|
||||
Test262Error
|
|
@ -0,0 +1,44 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
template: error
|
||||
desc: Error forwarding when IteratorValue returns an abrupt completion
|
||||
info: >
|
||||
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).
|
||||
features: [Symbol.iterator]
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
var poisonedValue = Object.defineProperty({}, 'value', {
|
||||
get: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
var iter = {};
|
||||
iter[Symbol.iterator] = function() {
|
||||
return {
|
||||
next() {
|
||||
return poisonedValue;
|
||||
}
|
||||
};
|
||||
};
|
||||
//- elems
|
||||
[...x]
|
||||
//- vals
|
||||
iter
|
||||
//- error
|
||||
Test262Error
|
|
@ -0,0 +1,32 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
template: default
|
||||
desc: Lone rest element
|
||||
info: >
|
||||
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).
|
||||
[...]
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
var values = [1, 2, 3];
|
||||
//- elems
|
||||
[...x]
|
||||
//- vals
|
||||
values
|
||||
//- body
|
||||
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);
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
template: default
|
||||
desc: Reset element (nested array pattern) does not support initializer
|
||||
negative:
|
||||
phase: early
|
||||
type: SyntaxError
|
||||
info: >
|
||||
13.3.3 Destructuring Binding Patterns
|
||||
|
||||
ArrayBindingPattern[Yield] :
|
||||
[ Elisionopt BindingRestElement[?Yield]opt ]
|
||||
[ BindingElementList[?Yield] ]
|
||||
[ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ]
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
[...[ x ] = []]
|
||||
//- vals
|
||||
[]
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
template: default
|
||||
desc: Reset element (identifier) does not support initializer
|
||||
negative:
|
||||
phase: early
|
||||
type: SyntaxError
|
||||
info: >
|
||||
13.3.3 Destructuring Binding Patterns
|
||||
|
||||
ArrayBindingPattern[Yield] :
|
||||
[ Elisionopt BindingRestElement[?Yield]opt ]
|
||||
[ BindingElementList[?Yield] ]
|
||||
[ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ]
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
[...x = []]
|
||||
//- vals
|
||||
[]
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
template: default
|
||||
desc: Reset element (nested object pattern) does not support initializer
|
||||
negative:
|
||||
phase: early
|
||||
type: SyntaxError
|
||||
info: >
|
||||
13.3.3 Destructuring Binding Patterns
|
||||
|
||||
ArrayBindingPattern[Yield] :
|
||||
[ Elisionopt BindingRestElement[?Yield]opt ]
|
||||
[ BindingElementList[?Yield] ]
|
||||
[ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ]
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
[...{ x } = []]
|
||||
//- vals
|
||||
[]
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
template: default
|
||||
desc: Rest element (array binding pattern) may not be followed by any element
|
||||
negative:
|
||||
phase: early
|
||||
type: SyntaxError
|
||||
info: >
|
||||
13.3.3 Destructuring Binding Patterns
|
||||
|
||||
ArrayBindingPattern[Yield] :
|
||||
[ Elisionopt BindingRestElement[?Yield]opt ]
|
||||
[ BindingElementList[?Yield] ]
|
||||
[ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ]
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
[...[x], y]
|
||||
//- vals
|
||||
[1, 2, 3]
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
template: default
|
||||
desc: Rest element (identifier) may not be followed by any element
|
||||
negative:
|
||||
phase: early
|
||||
type: SyntaxError
|
||||
info: >
|
||||
13.3.3 Destructuring Binding Patterns
|
||||
|
||||
ArrayBindingPattern[Yield] :
|
||||
[ Elisionopt BindingRestElement[?Yield]opt ]
|
||||
[ BindingElementList[?Yield] ]
|
||||
[ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ]
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
[...x, y]
|
||||
//- vals
|
||||
[1, 2, 3]
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
template: default
|
||||
desc: Rest element (object binding pattern) may not be followed by any element
|
||||
negative:
|
||||
phase: early
|
||||
type: SyntaxError
|
||||
info: >
|
||||
13.3.3 Destructuring Binding Patterns
|
||||
|
||||
ArrayBindingPattern[Yield] :
|
||||
[ Elisionopt BindingRestElement[?Yield]opt ]
|
||||
[ BindingElementList[?Yield] ]
|
||||
[ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ]
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
[...{ x }, y]
|
||||
//- vals
|
||||
[1, 2, 3]
|
|
@ -0,0 +1,26 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
template: default
|
||||
desc: Rest element containing an object binding pattern
|
||||
info: |
|
||||
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.
|
||||
[...]
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
[...{ length }]
|
||||
//- vals
|
||||
[1, 2, 3]
|
||||
//- body
|
||||
assert.sameValue(length, 3);
|
|
@ -0,0 +1,34 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
template: default
|
||||
desc: Rest element containing an object binding pattern
|
||||
info: |
|
||||
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.
|
||||
[...]
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
let length = "outer";
|
||||
//- elems
|
||||
[...{ 0: v, 1: w, 2: x, 3: y, length: z }]
|
||||
//- vals
|
||||
[7, 8, 9]
|
||||
//- body
|
||||
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");
|
|
@ -43,6 +43,11 @@ async function fn() {
|
|||
}
|
||||
|
||||
fn()
|
||||
.then(_ => { throw new Test262Error("Expected async function to reject, but resolved."); }, ({ constructor }) => assert.sameValue(constructor, /*{ error }*/))
|
||||
.then(_ => {
|
||||
throw new Test262Error("Expected async function to reject, but resolved.");
|
||||
}, ({ constructor }) => {
|
||||
assert.sameValue(constructor, /*{ error }*/);
|
||||
/*{ rejectBody }*/
|
||||
})
|
||||
.then($DONE, $DONE);
|
||||
|
|
@ -43,6 +43,11 @@ async function fn() {
|
|||
}
|
||||
|
||||
fn()
|
||||
.then(_ => { throw new Test262Error("Expected async function to reject, but resolved."); }, ({ constructor }) => assert.sameValue(constructor, /*{ error }*/))
|
||||
.then(_ => {
|
||||
throw new Test262Error("Expected async function to reject, but resolved.");
|
||||
}, ({ constructor }) => {
|
||||
assert.sameValue(constructor, /*{ error }*/);
|
||||
/*{ rejectBody }*/
|
||||
})
|
||||
.then($DONE, $DONE);
|
||||
|
|
@ -43,5 +43,10 @@ async function fn() {
|
|||
}
|
||||
|
||||
fn()
|
||||
.then(_ => { throw new Test262Error("Expected async function to reject, but resolved."); }, ({ constructor }) => assert.sameValue(constructor, /*{ error }*/))
|
||||
.then(_ => {
|
||||
throw new Test262Error("Expected async function to reject, but resolved.");
|
||||
}, ({ constructor }) => {
|
||||
assert.sameValue(constructor, /*{ error }*/);
|
||||
/*{ rejectBody }*/
|
||||
})
|
||||
.then($DONE, $DONE);
|
|
@ -43,6 +43,10 @@ async function * gen() {
|
|||
}
|
||||
|
||||
gen().next()
|
||||
.then(_ => { throw new Test262Error("Expected async function to reject, but resolved."); }, ({ constructor }) => assert.sameValue(constructor, /*{ error }*/))
|
||||
.then(_ => {
|
||||
throw new Test262Error("Expected async function to reject, but resolved.");
|
||||
}, ({ constructor }) => {
|
||||
assert.sameValue(constructor, /*{ error }*/);
|
||||
/*{ rejectBody }*/
|
||||
})
|
||||
.then($DONE, $DONE);
|
||||
|
|
@ -43,5 +43,10 @@ async function * gen() {
|
|||
}
|
||||
|
||||
gen().next()
|
||||
.then(_ => { throw new Test262Error("Expected async function to reject, but resolved."); }, ({ constructor }) => assert.sameValue(constructor, /*{ error }*/))
|
||||
.then(_ => {
|
||||
throw new Test262Error("Expected async function to reject, but resolved.");
|
||||
}, ({ constructor }) => {
|
||||
assert.sameValue(constructor, /*{ error }*/);
|
||||
/*{ rejectBody }*/
|
||||
})
|
||||
.then($DONE, $DONE);
|
|
@ -43,6 +43,11 @@ async function * gen() {
|
|||
}
|
||||
|
||||
gen().next()
|
||||
.then(_ => { throw new Test262Error("Expected async function to reject, but resolved."); }, ({ constructor }) => assert.sameValue(constructor, /*{ error }*/))
|
||||
.then(_ => {
|
||||
throw new Test262Error("Expected async function to reject, but resolved.");
|
||||
}, ({ constructor }) => {
|
||||
assert.sameValue(constructor, /*{ error }*/);
|
||||
/*{ rejectBody }*/
|
||||
})
|
||||
.then($DONE, $DONE);
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
template: error
|
||||
desc: Value specifed for object binding pattern must be object coercible (null)
|
||||
info: |
|
||||
Runtime Semantics: BindingInitialization
|
||||
|
||||
ObjectBindingPattern : { }
|
||||
|
||||
1. Return NormalCompletion(empty).
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
{}
|
||||
//- vals
|
||||
null
|
||||
//- error
|
||||
TypeError
|
|
@ -0,0 +1,19 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
template: error
|
||||
desc: Value specifed for object binding pattern must be object coercible (undefined)
|
||||
info: |
|
||||
Runtime Semantics: BindingInitialization
|
||||
|
||||
ObjectBindingPattern : { }
|
||||
|
||||
1. Return NormalCompletion(empty).
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
{}
|
||||
//- vals
|
||||
undefined
|
||||
//- error
|
||||
TypeError
|
|
@ -0,0 +1,26 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
template: default
|
||||
desc: No property access occurs for an "empty" object binding pattern
|
||||
info: |
|
||||
Runtime Semantics: BindingInitialization
|
||||
|
||||
ObjectBindingPattern : { }
|
||||
|
||||
1. Return NormalCompletion(empty).
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
var accessCount = 0;
|
||||
var obj = Object.defineProperty({}, 'attr', {
|
||||
get: function() {
|
||||
accessCount += 1;
|
||||
}
|
||||
});
|
||||
//- elems
|
||||
{}
|
||||
//- vals
|
||||
obj
|
||||
//- body
|
||||
assert.sameValue(accessCount, 0);
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
template: error
|
||||
desc: Error thrown when accessing the corresponding property of the value object
|
||||
info: |
|
||||
13.3.3.7 Runtime Semantics: KeyedBindingInitialization
|
||||
|
||||
SingleNameBinding : BindingIdentifier Initializer_opt
|
||||
|
||||
[...]
|
||||
4. Let v be GetV(value, propertyName).
|
||||
5. ReturnIfAbrupt(v).
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
var poisonedProperty = Object.defineProperty({}, 'poisoned', {
|
||||
get: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
//- elems
|
||||
{ poisoned }
|
||||
//- vals
|
||||
poisonedProperty
|
||||
//- error
|
||||
Test262Error
|
|
@ -0,0 +1,26 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: SingleNameBinding assigns `name` to arrow functions
|
||||
template: default
|
||||
info: |
|
||||
13.3.3.7 Runtime Semantics: KeyedBindingInitialization
|
||||
|
||||
SingleNameBinding : BindingIdentifier Initializer_opt
|
||||
|
||||
[...]
|
||||
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).
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
{ arrow = () => {} }
|
||||
//- vals
|
||||
{}
|
||||
//- body
|
||||
assert.sameValue(arrow.name, 'arrow');
|
|
@ -0,0 +1,28 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: SingleNameBinding assigns `name` to "anonymous" classes
|
||||
template: default
|
||||
info: |
|
||||
13.3.3.7 Runtime Semantics: KeyedBindingInitialization
|
||||
|
||||
SingleNameBinding : BindingIdentifier Initializer_opt
|
||||
|
||||
[...]
|
||||
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).
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
{ cls = class {}, xCls = class X {}, xCls2 = class { static name() {} } }
|
||||
//- vals
|
||||
{}
|
||||
//- body
|
||||
assert.sameValue(cls.name, 'cls');
|
||||
assert.notSameValue(xCls.name, 'xCls');
|
||||
assert.notSameValue(xCls2.name, 'xCls2');
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: SingleNameBinding assigns `name` to "anonymous" functions "through" cover grammar
|
||||
template: default
|
||||
info: |
|
||||
13.3.3.7 Runtime Semantics: KeyedBindingInitialization
|
||||
|
||||
SingleNameBinding : BindingIdentifier Initializer_opt
|
||||
|
||||
[...]
|
||||
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).
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
{ cover = (function () {}), xCover = (0, function() {}) }
|
||||
//- vals
|
||||
{}
|
||||
//- body
|
||||
assert.sameValue(cover.name, 'cover');
|
||||
assert.notSameValue(xCover.name, 'xCover');
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: SingleNameBinding assigns name to "anonymous" functions
|
||||
template: default
|
||||
info: |
|
||||
13.3.3.7 Runtime Semantics: KeyedBindingInitialization
|
||||
|
||||
SingleNameBinding : BindingIdentifier Initializer_opt
|
||||
|
||||
[...]
|
||||
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).
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
{ fn = function () {}, xFn = function x() {} }
|
||||
//- vals
|
||||
{}
|
||||
//- body
|
||||
assert.sameValue(fn.name, 'fn');
|
||||
assert.notSameValue(xFn.name, 'xFn');
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: SingleNameBinding assigns name to "anonymous" generator functions
|
||||
template: default
|
||||
info: |
|
||||
13.3.3.7 Runtime Semantics: KeyedBindingInitialization
|
||||
|
||||
SingleNameBinding : BindingIdentifier Initializer_opt
|
||||
|
||||
[...]
|
||||
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).
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
{ gen = function* () {}, xGen = function* x() {} }
|
||||
//- vals
|
||||
{}
|
||||
//- body
|
||||
assert.sameValue(gen.name, 'gen');
|
||||
assert.notSameValue(xGen.name, 'xGen');
|
|
@ -0,0 +1,31 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: Destructuring initializer is not evaluated when value is not `undefined`
|
||||
template: default
|
||||
info: |
|
||||
13.3.3.7 Runtime Semantics: KeyedBindingInitialization
|
||||
|
||||
SingleNameBinding : BindingIdentifier Initializer_opt
|
||||
|
||||
[...]
|
||||
6. If Initializer is present and v is undefined, then
|
||||
[...]
|
||||
[...]
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
var initCount = 0;
|
||||
function counter() {
|
||||
initCount += 1;
|
||||
}
|
||||
//- elems
|
||||
{ w = counter(), x = counter(), y = counter(), z = counter() }
|
||||
//- vals
|
||||
{ w: null, x: 0, y: false, z: '' }
|
||||
//- body
|
||||
assert.sameValue(w, null);
|
||||
assert.sameValue(x, 0);
|
||||
assert.sameValue(y, false);
|
||||
assert.sameValue(z, '');
|
||||
assert.sameValue(initCount, 0);
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
template: error
|
||||
desc: Error thrown when evaluating the initializer
|
||||
info: |
|
||||
13.3.3.7 Runtime Semantics: KeyedBindingInitialization
|
||||
|
||||
SingleNameBinding : BindingIdentifier Initializer_opt
|
||||
|
||||
[...]
|
||||
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).
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
function thrower() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
//- elems
|
||||
{ x = thrower() }
|
||||
//- vals
|
||||
{}
|
||||
//- error
|
||||
Test262Error
|
|
@ -0,0 +1,29 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
desc: Destructuring initializer is an unresolvable reference
|
||||
template: error
|
||||
info: |
|
||||
13.3.3.7 Runtime Semantics: KeyedBindingInitialization
|
||||
|
||||
SingleNameBinding : BindingIdentifier Initializer_opt
|
||||
|
||||
[...]
|
||||
5. If Initializer is present and v is undefined, then
|
||||
a. Let defaultValue be the result of evaluating Initializer.
|
||||
b. Set v to ? GetValue(defaultValue).
|
||||
|
||||
6.2.4.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.
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
{ x = unresolvableReference }
|
||||
//- vals
|
||||
{}
|
||||
//- error
|
||||
ReferenceError
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
template: default
|
||||
desc: Trailing comma is allowed following BindingPropertyList
|
||||
info: |
|
||||
13.3.3 Destructuring Binding Patterns
|
||||
|
||||
ObjectBindingPattern[Yield] :
|
||||
{ }
|
||||
{ BindingPropertyList[?Yield] }
|
||||
{ BindingPropertyList[?Yield] , }
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
{ x, }
|
||||
//- vals
|
||||
{ x: 23 }
|
||||
//- body
|
||||
assert.sameValue(x, 23);
|
|
@ -0,0 +1,26 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
template: error
|
||||
desc: Binding property list evaluation is interrupted by an abrupt completion
|
||||
info: |
|
||||
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).
|
||||
---*/
|
||||
|
||||
//- setup
|
||||
var initCount = 0;
|
||||
function thrower() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
//- elems
|
||||
{ a, b = thrower(), c = ++initCount }
|
||||
//- vals
|
||||
{}
|
||||
//- error
|
||||
Test262Error
|
|
@ -0,0 +1,28 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
template: default
|
||||
desc: Object binding pattern with "nested" array binding pattern using initializer
|
||||
info: |
|
||||
13.3.3.7 Runtime Semantics: KeyedBindingInitialization
|
||||
|
||||
[...]
|
||||
4. If Initializer is present and v is undefined, then
|
||||
a. Let defaultValue be the result of evaluating Initializer.
|
||||
b. Set v to ? GetValue(defaultValue).
|
||||
4. Return the result of performing BindingInitialization for BindingPattern
|
||||
passing v and environment as arguments.
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
{ w: [x, y, z] = [4, 5, 6] }
|
||||
//- vals
|
||||
{}
|
||||
//- body
|
||||
assert.sameValue(x, 4);
|
||||
assert.sameValue(y, 5);
|
||||
assert.sameValue(z, 6);
|
||||
|
||||
assert.throws(ReferenceError, function() {
|
||||
w;
|
||||
});
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
template: default
|
||||
desc: Trailing comma is allowed following BindingPropertyList
|
||||
info: |
|
||||
13.3.3 Destructuring Binding Patterns
|
||||
|
||||
ObjectBindingPattern[Yield] :
|
||||
{ }
|
||||
{ BindingPropertyList[?Yield] }
|
||||
{ BindingPropertyList[?Yield] , }
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
{ x: [y], }
|
||||
//- vals
|
||||
{ x: [45] }
|
||||
//- body
|
||||
assert.sameValue(y,45);
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
template: error
|
||||
desc: Object binding pattern with "nested" array binding pattern taking the `null` value
|
||||
info: |
|
||||
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.
|
||||
---*/
|
||||
|
||||
//- elems
|
||||
{ w: [x, y, z] = [4, 5, 6] }
|
||||
//- vals
|
||||
{ w: null }
|
||||
//- error
|
||||
TypeError
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue