Skip to content
Snippets Groups Projects
Commit fd3510dd authored by Rick Waldron's avatar Rick Waldron
Browse files

Move async-iteration specific dstr-assignment templates into own src directory

parent e4b64ecc
No related branches found
No related tags found
No related merge requests found
Showing
with 606 additions and 0 deletions
// Copyright (C) 2016 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: function() {
return { value: null, done: false };
},
return: function() {
doneCallCount += 1;
return {};
}
};
};
//- elems
[x]
//- vals
iter
//- body
assert.sameValue(doneCallCount, 1);
// Copyright (C) 2016 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).
2. ReturnIfAbrupt(iterator).
features: [Symbol.iterator]
---*/
//- setup
var iter = {};
iter[Symbol.iterator] = function() {
throw new Test262Error();
};
//- elems
[x]
//- vals
iter
//- error
Test262Error
// Copyright (C) 2016 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: function() {
return { value: null, done: true };
},
return: function() {
doneCallCount += 1;
return {};
}
};
};
//- elems
[x]
//- vals
iter
//- body
assert.sameValue(doneCallCount, 0);
// Copyright (C) 2016 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 Initializeropt
[...]
4. If iteratorRecord.[[done]] is false, then
a. Let next be IteratorStep(iteratorRecord.[[iterator]]).
b. If next is an abrupt completion, set iteratorRecord.[[done]] to true.
c. ReturnIfAbrupt(next).
d. If next is false, set iteratorRecord.[[done]] to true.
e. Else,
[...]
i. Let v be IteratorValue(next).
ii. If v is an abrupt completion, set
iteratorRecord.[[done]] to true.
iii. ReturnIfAbrupt(v).
5. If iteratorRecord.[[done]] is true, let v be undefined.
[...]
8. Return InitializeReferencedBinding(lhs, v).
---*/
//- elems
[x, y, z]
//- vals
[1, 2, 3]
//- body
assert.sameValue(x, 1);
assert.sameValue(y, 2);
assert.sameValue(z, 3);
// Copyright (C) 2016 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 : BindingPatternInitializer opt
[...]
2. If iteratorRecord.[[done]] is true, let v be undefined.
3. If Initializer is present and v is undefined, then
a. Let defaultValue be the result of evaluating Initializer.
b. Let v be ? GetValue(defaultValue).
4. Return the result of performing BindingInitialization of BindingPattern
with v and environment as the arguments.
---*/
//- elems
[[x, y, z] = [4, 5, 6]]
//- vals
[]
//- body
assert.sameValue(x, 4);
assert.sameValue(y, 5);
assert.sameValue(z, 6);
// Copyright (C) 2016 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 : BindingPatternInitializer opt
1. If iteratorRecord.[[done]] is false, then
a. Let next be IteratorStep(iteratorRecord.[[iterator]]).
[...]
e. Else,
i. Let v be IteratorValue(next).
[...]
4. Return the result of performing BindingInitialization of BindingPattern
with v and environment as the arguments.
---*/
//- elems
[[x, y, z] = [4, 5, 6]]
//- vals
[[7, 8, 9]]
//- body
assert.sameValue(x, 7);
assert.sameValue(y, 8);
assert.sameValue(z, 9);
// Copyright (C) 2016 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 : BindingPatternInitializer opt
[...]
2. If iteratorRecord.[[done]] is true, let v be undefined.
3. If Initializer is present and v is undefined, then
a. Let defaultValue be the result of evaluating Initializer.
b. Let v be ? GetValue(defaultValue).
4. Return the result of performing BindingInitialization of BindingPattern
with v and environment as the arguments.
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);
// Copyright (C) 2016 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 : BindingPatternInitializer opt
1. If iteratorRecord.[[done]] is false, then
a. Let next be IteratorStep(iteratorRecord.[[iterator]]).
[...]
e. Else,
i. Let v be IteratorValue(next).
[...]
4. Return the result of performing BindingInitialization of BindingPattern
with v and environment as the arguments.
features: [generators]
---*/
//- setup
var callCount = 0;
function* g() {
callCount += 1;
};
//- elems
[[,] = g()]
//- vals
[[]]
//- body
assert.sameValue(callCount, 0);
// Copyright (C) 2016 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 : BindingPatternInitializer opt
[...]
2. If iteratorRecord.[[done]] is true, let v be undefined.
3. If Initializer is present and v is undefined, then
a. Let defaultValue be the result of evaluating Initializer.
b. Let v be ? GetValue(defaultValue).
4. Return the result of performing BindingInitialization of BindingPattern
with v and environment as the arguments.
---*/
//- 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);
// Copyright (C) 2016 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 : BindingPatternInitializer opt
1. If iteratorRecord.[[done]] is false, then
a. Let next be IteratorStep(iteratorRecord.[[iterator]]).
[...]
e. Else,
i. Let v be IteratorValue(next).
[...]
4. Return the result of performing BindingInitialization of BindingPattern
with v and environment as the arguments.
---*/
//- setup
var initCount = 0;
//- elems
[[] = function() { initCount += 1; }()]
//- vals
[[23]]
//- body
assert.sameValue(initCount, 0);
// Copyright (C) 2016 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 : BindingPatternInitializer opt
[...]
2. If iteratorRecord.[[done]] is true, let v be undefined.
3. If Initializer is present and v is undefined, then
a. Let defaultValue be the result of evaluating Initializer.
b. Let v be ? GetValue(defaultValue).
4. Return the result of performing BindingInitialization of BindingPattern
with v and environment as the arguments.
---*/
//- 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);
// Copyright (C) 2016 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 : BindingPatternInitializer opt
1. If iteratorRecord.[[done]] is false, then
a. Let next be IteratorStep(iteratorRecord.[[iterator]]).
[...]
e. Else,
i. Let v be IteratorValue(next).
[...]
4. Return the result of performing BindingInitialization of BindingPattern
with v and environment as the arguments.
---*/
//- 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);
// Copyright (C) 2016 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 Initializeropt
1. If iteratorRecord.[[done]] is false, then
[...]
e. Else
i. Let v be IteratorValue(next).
[...]
4. Return the result of performing BindingInitialization of BindingPattern
with v and environment as the arguments.
13.3.3.5 Runtime Semantics: BindingInitialization
BindingPattern : ArrayBindingPattern
1. Let iterator be GetIterator(value).
2. ReturnIfAbrupt(iterator).
---*/
//- elems
[[x]]
//- vals
[null]
//- error
TypeError
// Copyright (C) 2016 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 Initializeropt
[...]
5. If iteratorRecord.[[done]] is true, let v be undefined.
6. If Initializer is present and v is undefined, then
a. Let defaultValue be the result of evaluating Initializer.
b. Let v be GetValue(defaultValue).
[...]
7. If environment is undefined, return PutValue(lhs, v).
8. Return InitializeReferencedBinding(lhs, v).
---*/
//- elems
[x = 23]
//- vals
[]
//- body
assert.sameValue(x, 23);
// Copyright (C) 2016 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 Initializeropt
[...]
6. If Initializer is present and v is undefined, then
a. Let defaultValue be the result of evaluating Initializer.
b. Let v be GetValue(defaultValue).
c. ReturnIfAbrupt(v).
d. If IsAnonymousFunctionDefinition(Initializer) is true, then
[...]
7. If environment is undefined, return PutValue(lhs, v).
8. Return InitializeReferencedBinding(lhs, v).
---*/
//- elems
[arrow = () => {}]
//- vals
[]
//- body
assert.sameValue(arrow.name, 'arrow');
// Copyright (C) 2016 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 Initializeropt
[...]
6. If Initializer is present and v is undefined, then
a. Let defaultValue be the result of evaluating Initializer.
b. Let v be GetValue(defaultValue).
c. ReturnIfAbrupt(v).
d. If IsAnonymousFunctionDefinition(Initializer) is true, then
[...]
7. If environment is undefined, return PutValue(lhs, v).
8. Return InitializeReferencedBinding(lhs, v).
---*/
//- 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');
// Copyright (C) 2016 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 Initializeropt
[...]
6. If Initializer is present and v is undefined, then
a. Let defaultValue be the result of evaluating Initializer.
b. Let v be GetValue(defaultValue).
c. ReturnIfAbrupt(v).
d. If IsAnonymousFunctionDefinition(Initializer) is true, then
[...]
7. If environment is undefined, return PutValue(lhs, v).
8. Return InitializeReferencedBinding(lhs, v).
---*/
//- elems
[cover = (function () {}), xCover = (0, function() {})]
//- vals
[]
//- body
assert.sameValue(cover.name, 'cover');
assert.notSameValue(xCover.name, 'xCover');
// Copyright (C) 2016 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 Initializeropt
[...]
6. If Initializer is present and v is undefined, then
a. Let defaultValue be the result of evaluating Initializer.
b. Let v be GetValue(defaultValue).
c. ReturnIfAbrupt(v).
d. If IsAnonymousFunctionDefinition(Initializer) is true, then
[...]
7. If environment is undefined, return PutValue(lhs, v).
8. Return InitializeReferencedBinding(lhs, v).
---*/
//- elems
[fn = function () {}, xFn = function x() {}]
//- vals
[]
//- body
assert.sameValue(fn.name, 'fn');
assert.notSameValue(xFn.name, 'xFn');
// Copyright (C) 2016 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 Initializeropt
[...]
6. If Initializer is present and v is undefined, then
a. Let defaultValue be the result of evaluating Initializer.
b. Let v be GetValue(defaultValue).
c. ReturnIfAbrupt(v).
d. If IsAnonymousFunctionDefinition(Initializer) is true, then
[...]
7. If environment is undefined, return PutValue(lhs, v).
8. Return InitializeReferencedBinding(lhs, v).
---*/
//- elems
[gen = function* () {}, xGen = function* x() {}]
//- vals
[]
//- body
assert.sameValue(gen.name, 'gen');
assert.notSameValue(xGen.name, 'xGen');
// Copyright (C) 2016 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 Initializeropt
[...]
6. If Initializer is present and v is undefined, then
a. Let defaultValue be the result of evaluating Initializer.
b. Let v be GetValue(defaultValue).
[...]
7. If environment is undefined, return PutValue(lhs, v).
8. Return InitializeReferencedBinding(lhs, v).
---*/
//- elems
[x = 23]
//- vals
[,]
//- body
assert.sameValue(x, 23);
// another statement
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment