mirror of
https://github.com/tc39/test262.git
synced 2025-07-26 23:44:27 +02:00
async-iteration: yield Promise.reject(value) is treated as throw value (rejects)
- http://tc39.github.io/tc39-notes/2017-05_may-25.html#15iva-revisiting-async-generator-yield-behavior - http://tc39.github.io/tc39-notes/2017-05_may-25.html#conclusionresolution-12 Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
This commit is contained in:
parent
bcea4333fc
commit
eaec1ffe2f
27
src/async-generators/yield-promise-reject-next-catch.case
Normal file
27
src/async-generators/yield-promise-reject-next-catch.case
Normal file
@ -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: yield Promise.reject(value) is treated as throw value
|
||||||
|
template: default
|
||||||
|
flags: [async]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
//- setup
|
||||||
|
let error = new Error();
|
||||||
|
//- body
|
||||||
|
yield Promise.reject(error);
|
||||||
|
yield "unreachable";
|
||||||
|
//- assertions
|
||||||
|
iter.next().then(() => {
|
||||||
|
throw new Test262Error("Promise incorrectly resolved.");
|
||||||
|
}).catch(rejectValue => {
|
||||||
|
// yield Promise.reject(error);
|
||||||
|
assert.sameValue(rejectValue, error);
|
||||||
|
|
||||||
|
iter.next().then(({done, value}) => {
|
||||||
|
// iter is closed now.
|
||||||
|
assert.sameValue(done, true, "The value of IteratorResult.done is `true`");
|
||||||
|
assert.sameValue(value, undefined, "The value of IteratorResult.value is `undefined`");
|
||||||
|
}).then($DONE, $DONE);
|
||||||
|
});
|
@ -0,0 +1,33 @@
|
|||||||
|
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
desc: yield * [Promise.reject(value)] is treated as throw value
|
||||||
|
template: default
|
||||||
|
flags: [async]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
//- setup
|
||||||
|
let error = new Error();
|
||||||
|
async function * readFile() {
|
||||||
|
yield Promise.reject(error);
|
||||||
|
yield "unreachable";
|
||||||
|
}
|
||||||
|
//- body
|
||||||
|
for await (let line of readFile()) {
|
||||||
|
yield line;
|
||||||
|
}
|
||||||
|
//- assertions
|
||||||
|
iter.next().then(() => {
|
||||||
|
throw new Test262Error("Promise incorrectly resolved.");
|
||||||
|
}, rejectValue => {
|
||||||
|
|
||||||
|
// yield Promise.reject(error);
|
||||||
|
assert.sameValue(rejectValue, error);
|
||||||
|
|
||||||
|
iter.next().then(({done, value}) => {
|
||||||
|
// iter is closed now.
|
||||||
|
assert.sameValue(done, true, "The value of IteratorResult.done is `true`");
|
||||||
|
assert.sameValue(value, undefined, "The value of IteratorResult.value is `undefined`");
|
||||||
|
}).then($DONE, $DONE);
|
||||||
|
}).catch($DONE);
|
@ -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: yield Promise.reject(value) in for-await-of is treated as throw value
|
||||||
|
template: default
|
||||||
|
flags: [async]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
//- setup
|
||||||
|
let error = new Error();
|
||||||
|
let iterable = [
|
||||||
|
Promise.reject(error),
|
||||||
|
"unreachable"
|
||||||
|
];
|
||||||
|
//- body
|
||||||
|
for await (let value of iterable) {
|
||||||
|
yield value;
|
||||||
|
}
|
||||||
|
//- assertions
|
||||||
|
iter.next().then(() => {
|
||||||
|
throw new Test262Error("Promise incorrectly resolved.");
|
||||||
|
}, rejectValue => {
|
||||||
|
// yield Promise.reject(error);
|
||||||
|
assert.sameValue(rejectValue, error);
|
||||||
|
|
||||||
|
iter.next().then(({done, value}) => {
|
||||||
|
// iter is closed now.
|
||||||
|
assert.sameValue(done, true, "The value of IteratorResult.done is `true`");
|
||||||
|
assert.sameValue(value, undefined, "The value of IteratorResult.value is `undefined`");
|
||||||
|
}).then($DONE, $DONE);
|
||||||
|
}).catch($DONE);
|
@ -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: yield * (async iterator) is treated as throw value
|
||||||
|
template: default
|
||||||
|
flags: [async]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
//- setup
|
||||||
|
let error = new Error();
|
||||||
|
async function * readFile() {
|
||||||
|
yield Promise.reject(error);
|
||||||
|
yield "unreachable";
|
||||||
|
}
|
||||||
|
//- body
|
||||||
|
yield * readFile();
|
||||||
|
|
||||||
|
//- assertions
|
||||||
|
iter.next().then(() => {
|
||||||
|
throw new Test262Error("Promise incorrectly resolved.");
|
||||||
|
}, rejectValue => {
|
||||||
|
// yield Promise.reject(error);
|
||||||
|
assert.sameValue(rejectValue, error);
|
||||||
|
|
||||||
|
iter.next().then(({done, value}) => {
|
||||||
|
// iter is closed now.
|
||||||
|
assert.sameValue(done, true, "The value of IteratorResult.done is `true`");
|
||||||
|
assert.sameValue(value, undefined, "The value of IteratorResult.value is `undefined`");
|
||||||
|
}).then($DONE, $DONE);
|
||||||
|
}).then($DONE, $DONE);
|
@ -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: yield * (async iterator) is treated as throw value
|
||||||
|
template: default
|
||||||
|
flags: [async]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
//- setup
|
||||||
|
let error = new Error();
|
||||||
|
let iterable = [
|
||||||
|
Promise.reject(error),
|
||||||
|
"unreachable"
|
||||||
|
];
|
||||||
|
//- body
|
||||||
|
yield * iterable;
|
||||||
|
//- assertions
|
||||||
|
iter.next().then(() => {
|
||||||
|
throw new Test262Error("Promise incorrectly resolved.");
|
||||||
|
}, rejectValue => {
|
||||||
|
// yield Promise.reject(error);
|
||||||
|
assert.sameValue(rejectValue, error);
|
||||||
|
|
||||||
|
iter.next().then(({done, value}) => {
|
||||||
|
// iter is closed now.
|
||||||
|
assert.sameValue(done, true, "The value of IteratorResult.done is `true`");
|
||||||
|
assert.sameValue(value, undefined, "The value of IteratorResult.value is `undefined`");
|
||||||
|
}).then($DONE, $DONE);
|
||||||
|
}).catch($DONE);
|
27
src/async-generators/yield-promise-reject-next.case
Normal file
27
src/async-generators/yield-promise-reject-next.case
Normal file
@ -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: yield Promise.reject(value) is treated as throw value
|
||||||
|
template: default
|
||||||
|
flags: [async]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
//- setup
|
||||||
|
let error = new Error();
|
||||||
|
//- body
|
||||||
|
yield Promise.reject(error);
|
||||||
|
yield "unreachable";
|
||||||
|
//- assertions
|
||||||
|
iter.next().then(() => {
|
||||||
|
throw new Test262Error("Promise incorrectly resolved.");
|
||||||
|
}, rejectValue => {
|
||||||
|
// yield Promise.reject(error);
|
||||||
|
assert.sameValue(rejectValue, error);
|
||||||
|
|
||||||
|
iter.next().then(({done, value}) => {
|
||||||
|
// iter is closed now.
|
||||||
|
assert.sameValue(done, true, "The value of IteratorResult.done is `true`");
|
||||||
|
assert.sameValue(value, undefined, "The value of IteratorResult.value is `undefined`");
|
||||||
|
}).then($DONE, $DONE);
|
||||||
|
}).catch($DONE);
|
Loading…
x
Reference in New Issue
Block a user