Skip to content
Snippets Groups Projects
Commit 60a6a7c8 authored by Rick Waldron's avatar Rick Waldron Committed by GitHub
Browse files

Merge pull request #1039 from rwaldron/dstr-assignment_for-await-of

[WIP] for-await-of: dstr-assignment, templates & cases
parents e8fb452d d4fde0a5
No related branches found
No related tags found
No related merge requests found
Showing
with 706 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
let 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
let flag1 = false, flag2 = false;
let _;
//- 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. If hasNameProperty is false, perform SetFunctionName(v, GetReferencedName(lref)).
includes: [propertyHelper.js]
---*/
//- setup
let 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. If hasNameProperty is false, perform SetFunctionName(v, GetReferencedName(lref)).
includes: [propertyHelper.js]
features: [class]
---*/
//- setup
let 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) 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 (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. If hasNameProperty is false, perform SetFunctionName(v, GetReferencedName(lref)).
includes: [propertyHelper.js]
---*/
//- setup
let 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) 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 (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. If hasNameProperty is false, perform SetFunctionName(v, GetReferencedName(lref)).
includes: [propertyHelper.js]
features: [class]
---*/
//- setup
let xFnexp, fnexp;
//- elems
[ xFnexp = function x() {}, fnexp = function() {} ]
//- vals
[]
//- body
assert(xFnexp.name !== 'xFnexp');
assert.sameValue(fnexp.name, 'fnexp');
verifyNotEnumerable(fnexp, 'name');
verifyNotWritable(fnexp, 'name');
verifyConfigurable(fnexp, '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. If hasNameProperty is false, perform SetFunctionName(v, GetReferencedName(lref)).
includes: [propertyHelper.js]
features: [generators]
---*/
//- setup
let 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
let 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: >
Value retrieval of Initializer obeys `let` semantics.
template: default
es6id: 12.14.5.3
features: [let]
---*/
//- setup
let x;
//- elems
[ x = y ]
//- vals
[]
//- teardown
promise.then(() => $DONE('Promise incorrectly fulfilled.'), ({ constructor }) => {
assert.sameValue(constructor, ReferenceError);
}).then($DONE, $DONE);
let y;
// 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
let x = 0;
let 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
let 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: >
When a `yield` token appears within the Initializer of an
AssignmentElement within a generator function body, it behaves as a
YieldExpression.
template: async-generator
es6id: 12.14.5.4
features: [generators]
---*/
//- setup
let value = [];
let x;
//- elems
[ x = yield ]
//- vals
[]
//- teardown
iter.next().then(result => {
assert.sameValue(result.value, undefined);
assert.sameValue(result.done, false);
assert.sameValue(x, undefined);
iter.next(4).then(result => {
assert.sameValue(result.value, undefined);
assert.sameValue(result.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 an AssignmentElement
outside of a generator function body, it behaves as an IdentifierReference.
template: error-async-function-syntax
es6id: 12.14.5.4
flags: [onlyStrict]
negative:
phase: early
type: SyntaxError
---*/
//- elems
[ x = yield ]
//- vals
[]
// 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 an AssignmentElement
outside of a generator function body, it behaves as an IdentifierReference.
template: async-function
es6id: 12.14.5.4
flags: [noStrict]
---*/
//- setup
let yield = 4;
let x;
//- elems
[ x = yield ]
//- vals
[]
//- body
assert.sameValue(x, 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: Abrupt completion returned from GetIterator
info: |
ArrayAssignmentPattern : [ AssignmentElementList ]
1. Let iterator be ? GetIterator(value).
features: [Symbol.iterator]
template: async-generator
es6id: 12.14.5.2
esid: sec-runtime-semantics-destructuringassignmentevaluation
---*/
//- setup
let iterable = {
[Symbol.iterator]() {
throw new Test262Error();
}
};
let _;
//- elems
[ _ ]
//- vals
iterable
//- teardown
iter.next().then(() => $DONE('Promise incorrectly fulfilled.'), ({ constructor }) => {
assert.sameValue(constructor, Test262Error);
}).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: Abrupt completion returned from IteratorClose
info: |
ArrayAssignmentPattern : [ AssignmentElementList ]
[...]
4. If iteratorRecord.[[Done]] is false, return ? IteratorClose(iterator, result).
features: [Symbol.iterator]
template: async-generator
es6id: 12.14.5.2
esid: sec-runtime-semantics-destructuringassignmentevaluation
---*/
//- setup
let nextCount = 0;
let returnCount = 0;
let _;
let iterator = {
next() {
nextCount += 1;
// Set an upper-bound to limit unnecessary iteration in non-conformant
// implementations
return { done: nextCount > 10 };
},
return() {
returnCount += 1;
throw new Test262Error();
}
};
let iterable = {
[Symbol.iterator]() {
return iterator;
}
};
//- elems
[ _ ]
//- vals
iterable
//- teardown
iter.next().then(() => $DONE('Promise incorrectly fulfilled.'), ({ constructor }) => {
assert.sameValue(nextCount, 1);
assert.sameValue(returnCount, 1);
assert.sameValue(constructor, Test262Error);
}).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 throws a TypeError when `return` returns a non-Object value
info: |
ArrayAssignmentPattern : [ AssignmentElementList ]
[...]
4. If iteratorRecord.[[Done]] is false, return ? IteratorClose(iterator, result).
5. Return result.
7.4.6 IteratorClose( iterator, completion )
[...]
5. Let innerResult be Call(return, iterator, « »).
6. If completion.[[Type]] is throw, return Completion(completion).
7. If innerResult.[[Type]] is throw, return Completion(innerResult).
8. If Type(innerResult.[[Value]]) is not Object, throw a TypeError exception.
features: [Symbol.iterator]
template: async-generator
es6id: 12.14.5.2
esid: sec-runtime-semantics-destructuringassignmentevaluation
---*/
//- setup
let _;
let nextCount = 0;
let iterator = {
next() {
nextCount += 1;
// Set an upper-bound to limit unnecessary iteration in non-conformant
// implementations
return { done: nextCount > 10 };
},
return() {
return null;
}
};
let iterable = {
[Symbol.iterator]() {
return iterator;
}
};
//- elems
[ _ ]
//- vals
iterable
//- teardown
iter.next().then(() => $DONE('Promise incorrectly fulfilled.'), ({ constructor }) => {
assert.sameValue(nextCount, 1);
assert.sameValue(constructor, TypeError);
}).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 ]
[...]
4. If iteratorRecord.[[Done]] is false, return ? IteratorClose(iterator, result).
5. Return result.
features: [Symbol.iterator]
template: async-generator
esid: sec-runtime-semantics-destructuringassignmentevaluation
---*/
//- setup
let nextCount = 0;
let returnCount = 0;
let _;
let iterator = {
next() {
nextCount += 1;
return { done: true };
},
return() {
returnCount += 1;
return {};
}
};
let iterable = {
[Symbol.iterator]() {
return iterator;
}
};
//- elems
[ _ ]
//- vals
iterable
//- body
assert.sameValue(nextCount, 1);
assert.sameValue(returnCount, 0);
//- teardown
iter.next().then(() => {
assert.sameValue(iterCount, 1);
}).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 ]
[...]
4. If iteratorRecord.[[Done]] is false, return ? IteratorClose(iterator, result).
5. Return result.
7.4.6 IteratorClose ( iterator, completion )
[...]
5. Let innerResult be Call(return, iterator, « »).
[...]
features: [Symbol.iterator]
template: default
esid: sec-runtime-semantics-destructuringassignmentevaluation
---*/
//- setup
let nextCount = 0;
let returnCount = 0;
let thisValue = null;
let args = null;
let _;
let iterable = {};
let iterator = {
next() {
nextCount += 1;
// Set an upper-bound to limit unnecessary iteration in non-conformant
// implementations
return { done: nextCount > 10 };
},
return() {
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: >
IteratorClose throws a TypeError when `return` returns a non-Object value
info: |
ArrayAssignmentPattern : [ AssignmentElementList ]
[...]
4. If iteratorRecord.[[Done]] is false, return ? IteratorClose(iterator, result).
5. Return result.
7.4.6 IteratorClose( iterator, completion )
[...]
5. Let innerResult be Call(return, iterator, « »).
6. If completion.[[Type]] is throw, return Completion(completion).
7. If innerResult.[[Type]] is throw, return Completion(innerResult).
8. If Type(innerResult.[[Value]]) is not Object, throw a TypeError exception.
features: [Symbol.iterator, generators]
template: async-generator
es6id: 12.14.5.2
esid: sec-runtime-semantics-destructuringassignmentevaluation
---*/
//- setup
let unreachable = 0;
let iterator = {
return() {
return null;
}
};
let iterable = {
[Symbol.iterator]() {
return iterator;
}
};
//- elems
[ {}[yield] ]
//- vals
iterable
//- body
unreachable += 1;
//- teardown
iter.next().then(() => $DONE('Promise incorrectly fulfilled.'), ({ constructor }) => {
assert.sameValue(unreachable, 0);
assert.sameValue(constructor, TypeError);
}).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