mirror of https://github.com/tc39/test262.git
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
|
@ -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);
|
|
@ -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…
Reference in New Issue