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

for-await-of: dstr-assignment, default template

parent 2b0a8cc1
No related branches found
No related tags found
No related merge requests found
Showing
with 635 additions and 0 deletions
// Copyright (C) 2017 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: >
If the Initializer is present and v is undefined, the Initializer should be
evaluated and the result assigned to the target reference.
template: default
---*/
//- setup
var v2, vNull, vHole, vUndefined, vOob;
//- elems
[v2 = 10, vNull = 11, vHole = 12, vUndefined = 13, vOob = 14]
//- vals
[2, null, , undefined]
//- body
assert.sameValue(v2, 2);
assert.sameValue(vNull, null);
assert.sameValue(vHole, 12);
assert.sameValue(vUndefined, 13);
assert.sameValue(vOob, 14);
//- teardown
promise
.then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE)
.then($DONE, $DONE);
// Copyright (C) 2017 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: >
The Initializer should only be evaluated if v is undefined.
template: default
---*/
//- setup
var flag1 = false, flag2 = false;
var _;
//- elems
[ _ = flag1 = true, _ = flag2 = true ]
//- vals
[14]
//- body
assert.sameValue(flag1, false);
assert.sameValue(flag2, true);
//- teardown
promise
.then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE)
.then($DONE, $DONE);
// Copyright (C) 2017 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Assignment of function `name` attribute (ArrowFunction)
template: default
info: >
AssignmentElement[Yield] : DestructuringAssignmentTarget Initializeropt
[...]
7. If Initializer is present and value is undefined and
IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of
DestructuringAssignmentTarget are both true, then
a. Let hasNameProperty be HasOwnProperty(v, "name").
b. ReturnIfAbrupt(hasNameProperty).
c. If hasNameProperty is false, perform SetFunctionName(v,
GetReferencedName(lref)).
includes: [propertyHelper.js]
---*/
//- setup
var arrow;
//- elems
[ arrow = () => {} ]
//- vals
[]
//- body
assert.sameValue(arrow.name, 'arrow');
verifyNotEnumerable(arrow, 'name');
verifyNotWritable(arrow, 'name');
verifyConfigurable(arrow, 'name');
//- teardown
promise
.then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE)
.then($DONE, $DONE);
// Copyright (C) 2017 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Assignment of function `name` attribute (ClassExpression)
template: default
info: >
AssignmentElement[Yield] : DestructuringAssignmentTarget Initializeropt
[...]
7. If Initializer is present and value is undefined and
IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of
DestructuringAssignmentTarget are both true, then
a. Let hasNameProperty be HasOwnProperty(v, "name").
b. ReturnIfAbrupt(hasNameProperty).
c. If hasNameProperty is false, perform SetFunctionName(v,
GetReferencedName(lref)).
includes: [propertyHelper.js]
features: [class]
---*/
//- setup
var xCls, cls, xCls2;
//- elems
[ xCls = class x {}, cls = class {}, xCls2 = class { static name() {} } ]
//- vals
[]
//- body
assert(xCls.name !== 'xCls');
assert(xCls2.name !== 'xCls2');
assert.sameValue(cls.name, 'cls');
verifyNotEnumerable(cls, 'name');
verifyNotWritable(cls, 'name');
verifyConfigurable(cls, 'name');
//- teardown
promise
.then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE)
.then($DONE, $DONE);
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: >
Assignment of function `name` attribute (CoverParenthesizedExpression)
template: default
info: >
AssignmentElement[Yield] : DestructuringAssignmentTarget Initializeropt
[...]
7. If Initializer is present and value is undefined and
IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of
DestructuringAssignmentTarget are both true, then
a. Let hasNameProperty be HasOwnProperty(v, "name").
b. ReturnIfAbrupt(hasNameProperty).
c. If hasNameProperty is false, perform SetFunctionName(v,
GetReferencedName(lref)).
includes: [propertyHelper.js]
---*/
//- setup
var xCover, cover;
//- elems
[ xCover = (0, function() {}), cover = (function() {}) ]
//- vals
[]
//- body
assert(xCover.name !== 'xCover');
assert.sameValue(cover.name, 'cover');
verifyNotEnumerable(cover, 'name');
verifyNotWritable(cover, 'name');
verifyConfigurable(cover, 'name');
//- teardown
promise
.then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE)
.then($DONE, $DONE);
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Assignment of function `name` attribute (FunctionExpression)
template: default
info: >
AssignmentElement[Yield] : DestructuringAssignmentTarget Initializeropt
[...]
7. If Initializer is present and value is undefined and
IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of
DestructuringAssignmentTarget are both true, then
a. Let hasNameProperty be HasOwnProperty(v, "name").
b. ReturnIfAbrupt(hasNameProperty).
c. If hasNameProperty is false, perform SetFunctionName(v,
GetReferencedName(lref)).
includes: [propertyHelper.js]
features: [class]
---*/
//- setup
var xFn, fn;
//- elems
[ xFn = function x() {}, fn = function() {} ]
//- vals
[]
//- body
assert(xFn.name !== 'xFn');
assert.sameValue(fn.name, 'fn');
verifyNotEnumerable(fn, 'name');
verifyNotWritable(fn, 'name');
verifyConfigurable(fn, 'name');
//- teardown
promise
.then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE)
.then($DONE, $DONE);
// Copyright (C) 2017 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Assignment of function `name` attribute (GeneratorExpression)
template: default
info: >
AssignmentElement[Yield] : DestructuringAssignmentTarget Initializeropt
[...]
7. If Initializer is present and value is undefined and
IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of
DestructuringAssignmentTarget are both true, then
a. Let hasNameProperty be HasOwnProperty(v, "name").
b. ReturnIfAbrupt(hasNameProperty).
c. If hasNameProperty is false, perform SetFunctionName(v,
GetReferencedName(lref)).
includes: [propertyHelper.js]
features: [generators]
---*/
//- setup
var xGen, gen;
//- elems
[ xGen = function* x() {}, gen = function*() {} ]
//- vals
[]
//- body
assert.notSameValue(xGen.name, 'xGen');
assert.sameValue(gen.name, 'gen');
verifyNotEnumerable(gen, 'name');
verifyNotWritable(gen, 'name');
verifyConfigurable(gen, 'name');
//- teardown
promise
.then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE)
.then($DONE, $DONE);
// Copyright (C) 2017 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: >
The Initializer in an AssignmentElement may be an `in` expression.
template: default
---*/
//- setup
var x;
//- elems
[ x = 'x' in {} ]
//- vals
[]
//- body
assert.sameValue(x, false);
//- teardown
promise
.then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE)
.then($DONE, $DONE);
// Copyright (C) 2017 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: >
Initializer values should be assigned in left-to-right order.
template: default
---*/
//- setup
var x = 0;
var a, b;
//- elems
[ a = x += 1, b = x *= 2 ]
//- vals
[]
//- body
assert.sameValue(a, 1);
assert.sameValue(b, 2);
assert.sameValue(x, 2);
//- teardown
promise
.then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE)
.then($DONE, $DONE);
// Copyright (C) 2017 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: >
Identifiers that appear as the DestructuringAssignmentTarget in an
AssignmentElement should take on the iterated value corresponding to their
position in the ArrayAssignmentPattern.
template: default
flags: [noStrict]
---*/
//- setup
var argument, eval;
//- elems
[arguments = 4, eval = 5]
//- vals
[]
//- body
assert.sameValue(arguments, 4);
assert.sameValue(eval, 5);
//- teardown
promise
.then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE)
.then($DONE, $DONE);
// Copyright (C) 2017 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: >
IteratorClose is not called when assignment evaluation has exhausted the
iterator
info: |
ArrayAssignmentPattern : [ AssignmentElementList ]
[...]
5. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, result).
6. Return result.
features: [Symbol.iterator]
template: default
esid: sec-runtime-semantics-destructuringassignmentevaluation
---*/
//- setup
var nextCount = 0;
var returnCount = 0;
var _;
var iterable = {};
var iterator = {
next: function() {
nextCount += 1;
return { done: true };
},
return: function() {
returnCount += 1;
return {};
}
};
iterable[Symbol.iterator] = function() {
return iterator;
};
//- elems
[ _ ]
//- vals
iterable
//- body
assert.sameValue(nextCount, 1);
assert.sameValue(returnCount, 0);
//- teardown
promise
.then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE)
.then($DONE, $DONE);
// Copyright (C) 2017 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: >
IteratorClose is called when assignment evaluation has not exhausted the
iterator
info: |
ArrayAssignmentPattern : [ AssignmentElementList ]
[...]
5. If iteratorRecord.[[done]] is false, return IteratorClose(iterator,
result).
6. Return result.
7.4.6 IteratorClose( iterator, completion )
[...]
6. Let innerResult be Call(return, iterator, « »).
[...]
features: [Symbol.iterator]
template: default
esid: sec-runtime-semantics-destructuringassignmentevaluation
---*/
//- setup
var nextCount = 0;
var returnCount = 0;
var thisValue = null;
var args = null;
var _;
var iterable = {};
var iterator = {
next: function() {
nextCount += 1;
// Set an upper-bound to limit unnecessary iteration in non-conformant
// implementations
return { done: nextCount > 10 };
},
return: function() {
returnCount += 1;
thisValue = this;
args = arguments;
return {};
}
};
iterable[Symbol.iterator] = function() {
return iterator;
};
//- elems
[ _ ]
//- vals
iterable
//- body
assert.sameValue(nextCount, 1);
assert.sameValue(returnCount, 1);
assert.sameValue(thisValue, iterator, 'correct `this` value');
assert(!!args, 'arguments object provided');
assert.sameValue(args.length, 0, 'zero arguments specified');
//- teardown
promise
.then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE)
.then($DONE, $DONE);
// Copyright (C) 2017 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: >
When a `yield` token appears within the DestructuringAssignmentTarget of a
nested destructuring assignment outside of strict mode, it behaves as an
IdentifierReference.
template: default
flags: [noStrict]
---*/
//- setup
var yield = 'prop';
var x = {};
//- elems
[[x[yield]]]
//- vals
[[22]]
//- body
assert.sameValue(x.prop, 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: >
When DestructuringAssignmentTarget is an array literal, it should be parsed
parsed as a DestructuringAssignmentPattern and evaluated as a destructuring
assignment.
template: default
---*/
//- setup
var x;
//- elems
[[x]]
//- vals
[[1]]
//- body
assert.sameValue(x, 1);
// Copyright (C) 2017 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: >
When a `yield` token appears within the Initializer of a nested
destructuring assignment and within a generator function body, it behaves
as a YieldExpression.
template: async-generator
---*/
//- setup
var x;
//- elems
[{ x = yield }]
//- vals
[{}]
//- teardown
iter.next().then(iterationResult => {
assert.sameValue(iterationResult.value, undefined);
assert.sameValue(iterationResult.done, false);
assert.sameValue(x, undefined);
iter.next(4).then(iterationResult => {
assert.sameValue(iterationResult.value, undefined);
assert.sameValue(iterationResult.done, true);
assert.sameValue(x, 4);
}, $DONE).then($DONE, $DONE);
}, $DONE).catch($DONE);
// Copyright (C) 2017 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: >
When a `yield` token appears within the Initializer of a nested
destructuring assignment outside of a generator function body, it behaves
as an IdentifierReference.
template: async-function
flags: [noStrict]
---*/
//- setup
var yield = 2;
var x;
//- elems
[{ x = yield }]
//- vals
[{}]
//- body
assert.sameValue(x, 2);
//- teardown
promise
.then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE)
.then($DONE, $DONE);
// Copyright (C) 2017 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: >
When DestructuringAssignmentTarget is an object literal, it should be
parsed as a DestructuringAssignmentPattern and evaluated as a destructuring
assignment.
template: default
---*/
//- setup
var x;
//- elems
[{ x }]
//- vals
[{ x: 2 }]
//- body
assert.sameValue(x, 2);
//- teardown
promise
.then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE)
.then($DONE, $DONE);
// Copyright (C) 2017 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: >
If the DestructuringAssignmentTarget of an AssignmentElement is a
PropertyReference, it should not be evaluated.
template: default
---*/
//- setup
var x, setValue;
x = {
get y() {
$ERROR('The property should not be accessed.');
},
set y(val) {
setValue = val;
}
};
//- elems
[x.y]
//- vals
[23]
//- body
assert.sameValue(setValue, 23);
//- teardown
promise
.then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE)
.then($DONE, $DONE);
// Copyright (C) 2017 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: >
The DestructuringAssignmentTarget of an AssignmentElement may be a
PropertyReference.
template: default
---*/
//- setup
var x = {};
//- elems
[x.y]
//- vals
[4]
//- body
assert.sameValue(x.y, 4);
//- teardown
promise
.then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE)
.then($DONE, $DONE);
// Copyright (C) 2017 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: >
Outside of strict mode, if the the assignment target is an unresolvable
reference, a new `var` binding should be created in the environment record.
template: default
flags: [noStrict]
---*/
//- elems
[ unresolvable ]
//- vals
[]
//- body
assert.sameValue(unresolvable, undefined);
//- teardown
promise
.then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE)
.then($DONE, $DONE);
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