mirror of https://github.com/tc39/test262.git
Add yield* tests
This commit is contained in:
parent
ef12a8b11c
commit
9cfcd7bcb0
|
@ -0,0 +1,55 @@
|
|||
// Copyright (C) 2020 Alexey Shvayka. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-generator-function-definitions-runtime-semantics-evaluation
|
||||
description: >
|
||||
If iterator's "return" method is `null`,
|
||||
received completion is forwarded to the runtime.
|
||||
info: |
|
||||
YieldExpression : yield * AssignmentExpression
|
||||
|
||||
[...]
|
||||
7. Repeat,
|
||||
[...]
|
||||
c. Else,
|
||||
i. Assert: received.[[Type]] is return.
|
||||
ii. Let return be ? GetMethod(iterator, "return").
|
||||
iii. If return is undefined, then
|
||||
[...]
|
||||
2. Return Completion(received).
|
||||
|
||||
GetMethod ( V, P )
|
||||
|
||||
[...]
|
||||
2. Let func be ? GetV(V, P).
|
||||
3. If func is either undefined or null, return undefined.
|
||||
features: [Symbol.asyncIterator, async-iteration]
|
||||
flags: [async]
|
||||
---*/
|
||||
|
||||
var returnGets = 0;
|
||||
var asyncIterable = {
|
||||
[Symbol.asyncIterator]: function() {
|
||||
return this;
|
||||
},
|
||||
next: function() {
|
||||
return {value: 1, done: false};
|
||||
},
|
||||
get return() {
|
||||
returnGets += 1;
|
||||
return null;
|
||||
},
|
||||
};
|
||||
|
||||
async function* asyncGenerator() {
|
||||
yield* asyncIterable;
|
||||
}
|
||||
|
||||
var asyncIterator = asyncGenerator();
|
||||
asyncIterator.next().then(function() {
|
||||
asyncIterator.return(2).then(function(result) {
|
||||
assert.sameValue(result.value, 2);
|
||||
assert.sameValue(result.done, true);
|
||||
assert.sameValue(returnGets, 1);
|
||||
}).then($DONE, $DONE);
|
||||
}).catch($DONE);
|
|
@ -0,0 +1,75 @@
|
|||
// Copyright (C) 2020 Alexey Shvayka. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-generator-function-definitions-runtime-semantics-evaluation
|
||||
description: >
|
||||
If iterator's "throw" method is `null`,
|
||||
AsyncIteratorClose is called before rising TypeError.
|
||||
info: |
|
||||
YieldExpression : yield * AssignmentExpression
|
||||
|
||||
[...]
|
||||
7. Repeat,
|
||||
[...]
|
||||
b. Else if received.[[Type]] is throw, then
|
||||
i. Let throw be ? GetMethod(iterator, "throw").
|
||||
ii. If throw is not undefined, then
|
||||
[...]
|
||||
iii. Else,
|
||||
[...]
|
||||
3. If generatorKind is async, perform ? AsyncIteratorClose(iteratorRecord, closeCompletion).
|
||||
[...]
|
||||
6. Throw a TypeError exception.
|
||||
|
||||
GetMethod ( V, P )
|
||||
|
||||
[...]
|
||||
2. Let func be ? GetV(V, P).
|
||||
3. If func is either undefined or null, return undefined.
|
||||
|
||||
AsyncIteratorClose ( iteratorRecord, completion )
|
||||
|
||||
[...]
|
||||
4. Let innerResult be GetMethod(iterator, "return").
|
||||
5. If innerResult.[[Type]] is normal, then
|
||||
a. Let return be innerResult.[[Value]].
|
||||
b. If return is undefined, return Completion(completion).
|
||||
features: [Symbol.asyncIterator, async-iteration]
|
||||
flags: [async]
|
||||
---*/
|
||||
|
||||
var throwGets = 0;
|
||||
var returnGets = 0;
|
||||
var asyncIterable = {
|
||||
[Symbol.asyncIterator]: function() {
|
||||
return this;
|
||||
},
|
||||
next: function() {
|
||||
return {value: 1, done: false};
|
||||
},
|
||||
get throw() {
|
||||
throwGets += 1;
|
||||
return null;
|
||||
},
|
||||
get return() {
|
||||
returnGets += 1;
|
||||
},
|
||||
};
|
||||
|
||||
async function* asyncGenerator() {
|
||||
yield* asyncIterable;
|
||||
}
|
||||
|
||||
var asyncIterator = asyncGenerator();
|
||||
asyncIterator.next().then(function() {
|
||||
asyncIterator.throw().then(
|
||||
function(result) {
|
||||
throw new Test262Error("Promise should be rejected, got: " + result.value);
|
||||
},
|
||||
function(err) {
|
||||
assert.sameValue(err.constructor, TypeError);
|
||||
assert.sameValue(throwGets, 1);
|
||||
assert.sameValue(returnGets, 1);
|
||||
},
|
||||
).then($DONE, $DONE);
|
||||
}).catch($DONE);
|
|
@ -0,0 +1,55 @@
|
|||
// Copyright (C) 2020 Alexey Shvayka. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-generator-function-definitions-runtime-semantics-evaluation
|
||||
description: >
|
||||
If iterator's "return" method is `null`,
|
||||
received completion is forwarded to the runtime.
|
||||
info: |
|
||||
YieldExpression : yield * AssignmentExpression
|
||||
|
||||
[...]
|
||||
7. Repeat,
|
||||
[...]
|
||||
c. Else,
|
||||
i. Assert: received.[[Type]] is return.
|
||||
ii. Let return be ? GetMethod(iterator, "return").
|
||||
iii. If return is undefined, then
|
||||
[...]
|
||||
2. Return Completion(received).
|
||||
|
||||
GetMethod ( V, P )
|
||||
|
||||
[...]
|
||||
2. Let func be ? GetV(V, P).
|
||||
3. If func is either undefined or null, return undefined.
|
||||
features: [generators, Symbol.iterator]
|
||||
---*/
|
||||
|
||||
var returnGets = 0;
|
||||
var iterable = {
|
||||
next: function() {
|
||||
return {value: 1, done: false};
|
||||
},
|
||||
get return() {
|
||||
returnGets += 1;
|
||||
return null;
|
||||
},
|
||||
};
|
||||
|
||||
iterable[Symbol.iterator] = function() {
|
||||
return iterable;
|
||||
};
|
||||
|
||||
function* generator() {
|
||||
yield* iterable;
|
||||
}
|
||||
|
||||
var iterator = generator();
|
||||
iterator.next();
|
||||
|
||||
var result = iterator.return(2);
|
||||
assert.sameValue(result.value, 2);
|
||||
assert.sameValue(result.done, true);
|
||||
|
||||
assert.sameValue(returnGets, 1);
|
|
@ -0,0 +1,71 @@
|
|||
// Copyright (C) 2020 Alexey Shvayka. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-generator-function-definitions-runtime-semantics-evaluation
|
||||
description: >
|
||||
If iterator's "throw" method is `null`,
|
||||
IteratorClose is called before rising TypeError.
|
||||
info: |
|
||||
YieldExpression : yield * AssignmentExpression
|
||||
|
||||
[...]
|
||||
7. Repeat,
|
||||
[...]
|
||||
b. Else if received.[[Type]] is throw, then
|
||||
i. Let throw be ? GetMethod(iterator, "throw").
|
||||
ii. If throw is not undefined, then
|
||||
[...]
|
||||
iii. Else,
|
||||
[...]
|
||||
4. Else, perform ? IteratorClose(iteratorRecord, closeCompletion).
|
||||
[...]
|
||||
6. Throw a TypeError exception.
|
||||
|
||||
GetMethod ( V, P )
|
||||
|
||||
[...]
|
||||
2. Let func be ? GetV(V, P).
|
||||
3. If func is either undefined or null, return undefined.
|
||||
|
||||
IteratorClose ( iteratorRecord, completion )
|
||||
|
||||
[...]
|
||||
4. Let innerResult be GetMethod(iterator, "return").
|
||||
5. If innerResult.[[Type]] is normal, then
|
||||
a. Let return be innerResult.[[Value]].
|
||||
b. If return is undefined, return Completion(completion).
|
||||
features: [generators, Symbol.iterator]
|
||||
---*/
|
||||
|
||||
var throwGets = 0;
|
||||
var returnGets = 0;
|
||||
var iterable = {
|
||||
next: function() {
|
||||
return {value: 1, done: false};
|
||||
},
|
||||
get throw() {
|
||||
throwGets += 1;
|
||||
return null;
|
||||
},
|
||||
get return() {
|
||||
returnGets += 1;
|
||||
},
|
||||
};
|
||||
|
||||
iterable[Symbol.iterator] = function() {
|
||||
return iterable;
|
||||
};
|
||||
|
||||
function* generator() {
|
||||
yield* iterable;
|
||||
}
|
||||
|
||||
var iterator = generator();
|
||||
iterator.next();
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
iterator.throw();
|
||||
});
|
||||
|
||||
assert.sameValue(throwGets, 1);
|
||||
assert.sameValue(returnGets, 1);
|
Loading…
Reference in New Issue