mirror of https://github.com/tc39/test262.git
async-iteration: AsyncFromSyncIteratorPrototype next/throw/return
This commit is contained in:
parent
0192e0d70e
commit
4a3e19b3e4
|
@ -0,0 +1,52 @@
|
|||
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-%asyncfromsynciteratorprototype%.next
|
||||
description: next() will reject promise if getter `done` abrupt completes
|
||||
info: |
|
||||
%AsyncFromSyncIteratorPrototype%.next ( value )
|
||||
...
|
||||
2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
||||
...
|
||||
5. Let nextResult be IteratorNext(syncIteratorRecord, value).
|
||||
6. IfAbruptRejectPromise(nextResult, promiseCapability).
|
||||
7. Let nextDone be IteratorComplete(nextResult).
|
||||
8. IfAbruptRejectPromise(nextDone, promiseCapability).
|
||||
...
|
||||
18. Return promiseCapability.[[Promise]].
|
||||
|
||||
flags: [async]
|
||||
features: [async-iteration]
|
||||
---*/
|
||||
|
||||
var thrownError = new Error("Catch me.");
|
||||
|
||||
var obj = {
|
||||
[Symbol.iterator]() {
|
||||
return {
|
||||
next() {
|
||||
return {
|
||||
get done() {
|
||||
throw thrownError;
|
||||
},
|
||||
value: 1
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
async function* asyncg() {
|
||||
yield* obj;
|
||||
}
|
||||
|
||||
asyncg().next().then(
|
||||
function (result) {
|
||||
throw new Test262Error("Promise should be rejected.");
|
||||
},
|
||||
function (err) {
|
||||
assert.sameValue(err, thrownError, "Promise should be rejected with thrown error");
|
||||
}
|
||||
).then($DONE, $DONE);
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-%asyncfromsynciteratorprototype%.next
|
||||
description: next() will reject promise if getter `value` abrupt completes
|
||||
info: |
|
||||
%AsyncFromSyncIteratorPrototype%.next ( value )
|
||||
...
|
||||
2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
||||
...
|
||||
5. Let nextResult be IteratorNext(syncIteratorRecord, value).
|
||||
6. IfAbruptRejectPromise(nextResult, promiseCapability).
|
||||
7. Let nextDone be IteratorComplete(nextResult).
|
||||
8. If AbruptRejectPromise(nextDone, promiseCapability).
|
||||
9. Let nextValue be IteratorValue(nextResult).
|
||||
10. IfAbruptRejectPromise(nextValue, promiseCapability).
|
||||
...
|
||||
18. Return promiseCapability.[[Promise]].
|
||||
|
||||
flags: [async]
|
||||
features: [async-iteration]
|
||||
---*/
|
||||
|
||||
var thrownError = new Error("Catch me.");
|
||||
|
||||
var obj = {
|
||||
[Symbol.iterator]() {
|
||||
return {
|
||||
next() {
|
||||
return {
|
||||
get value() {
|
||||
throw thrownError;
|
||||
},
|
||||
done: false
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
async function* asyncg() {
|
||||
yield* obj;
|
||||
}
|
||||
|
||||
asyncg().next().then(
|
||||
function (result) {
|
||||
throw new Test262Error("Promise should be rejected.");
|
||||
},
|
||||
function (err) {
|
||||
assert.sameValue(err, thrownError, "Promise should be rejected with thrown error");
|
||||
}
|
||||
).then($DONE, $DONE);
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-%asyncfromsynciteratorprototype%.next
|
||||
description: next() returns a promise for an IteratorResult object
|
||||
info: |
|
||||
%AsyncFromSyncIteratorPrototype%.next ( value )
|
||||
...
|
||||
2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
||||
...
|
||||
5. Let nextResult be IteratorNext(syncIteratorRecord, value).
|
||||
6. IfAbruptRejectPromise(nextResult, promiseCapability).
|
||||
7. Let nextDone be IteratorComplete(nextResult).
|
||||
8. If AbruptRejectPromise(nextDone, promiseCapability).
|
||||
9. Let nextValue be IteratorValue(nextResult).
|
||||
10. IfAbruptRejectPromise(nextValue, promiseCapability).
|
||||
...
|
||||
14. Let steps be the algorithm steps defined in Async-from-Sync Iterator Value Unwrap Functions.
|
||||
|
||||
Async-from-Sync Iterator Value Unwrap Functions
|
||||
1. Return ! CreateIterResultObject(value, F.[[Done]]).
|
||||
|
||||
flags: [async]
|
||||
features: [async-iteration]
|
||||
---*/
|
||||
|
||||
function* g() {}
|
||||
|
||||
async function* asyncg() {
|
||||
yield* g();
|
||||
}
|
||||
|
||||
asyncg().next().then(function (result) {
|
||||
assert(
|
||||
Object.hasOwnProperty.call(result, 'value'), 'Has "own" property `value`'
|
||||
);
|
||||
assert(
|
||||
Object.hasOwnProperty.call(result, 'done'), 'Has "own" property `done`'
|
||||
);
|
||||
assert.sameValue(Object.getPrototypeOf(result), Object.prototype);
|
||||
}).then($DONE, $DONE);
|
|
@ -0,0 +1,43 @@
|
|||
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-%asyncfromsynciteratorprototype%.next
|
||||
description: next() will reject promise if sync iterator next() function returns an aburpt completion
|
||||
info: |
|
||||
%AsyncFromSyncIteratorPrototype%.next ( value )
|
||||
...
|
||||
2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
||||
...
|
||||
5. Let nextResult be IteratorNext(syncIteratorRecord, value).
|
||||
6. IfAbruptRejectPromise(nextResult, promiseCapability).
|
||||
7. Let nextDone be IteratorComplete(nextResult).
|
||||
8. If AbruptRejectPromise(nextDone, promiseCapability).
|
||||
9. Let nextValue be IteratorValue(nextResult).
|
||||
10. IfAbruptRejectPromise(nextValue, promiseCapability).
|
||||
...
|
||||
18. Return promiseCapability.[[Promise]].
|
||||
|
||||
flags: [async]
|
||||
features: [async-iteration]
|
||||
---*/
|
||||
|
||||
var thrownError = new Error("Catch me.");
|
||||
|
||||
function* g() {
|
||||
throw thrownError;
|
||||
}
|
||||
|
||||
async function* asyncg() {
|
||||
yield* g();
|
||||
}
|
||||
|
||||
asyncg().next().then(
|
||||
function (result) {
|
||||
throw new Test262Error("Promise should be rejected.");
|
||||
},
|
||||
function (err) {
|
||||
assert.sameValue(err, thrownError, "Promise should be rejected with thrown error");
|
||||
}
|
||||
).then($DONE, $DONE);
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-%asyncfromsynciteratorprototype%.next
|
||||
description: next() will unwrap a Promise value return by the sync iterator
|
||||
info: |
|
||||
%AsyncFromSyncIteratorPrototype%.next ( value )
|
||||
...
|
||||
2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
||||
...
|
||||
5. Let nextResult be IteratorNext(syncIteratorRecord, value).
|
||||
6. IfAbruptRejectPromise(nextResult, promiseCapability).
|
||||
7. Let nextDone be IteratorComplete(nextResult).
|
||||
8. If AbruptRejectPromise(nextDone, promiseCapability).
|
||||
9. Let nextValue be IteratorValue(nextResult).
|
||||
10. IfAbruptRejectPromise(nextValue, promiseCapability).
|
||||
...
|
||||
14. Let steps be the algorithm steps defined in Async-from-Sync Iterator Value Unwrap Functions.
|
||||
|
||||
Async-from-Sync Iterator Value Unwrap Functions
|
||||
An async-from-sync iterator value unwrap function is an anonymous built-in
|
||||
function that is used by methods of %AsyncFromSyncIteratorPrototype% when
|
||||
processing the value field of an IteratorResult object, in order to wait for
|
||||
its value if it is a promise and re-package the result in a new "unwrapped"
|
||||
IteratorResult object. Each async iterator value unwrap function has a
|
||||
[[Done]] internal slot.
|
||||
|
||||
flags: [async]
|
||||
features: [async-iteration]
|
||||
---*/
|
||||
|
||||
function* g() {
|
||||
yield Promise.resolve(1);
|
||||
}
|
||||
|
||||
async function* asyncg() {
|
||||
yield* g();
|
||||
}
|
||||
|
||||
asyncg().next().then(function (result) {
|
||||
assert.sameValue(result.value, 1, "result.value should be unwrapped promise, got: " + result.value)
|
||||
}).then($DONE, $DONE);
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-%asyncfromsynciteratorprototype%.next
|
||||
description: >
|
||||
"next" returns a promise for an IteratorResult object
|
||||
info: |
|
||||
%AsyncFromSyncIteratorPrototype%.next ( value )
|
||||
...
|
||||
2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
||||
...
|
||||
18. Return promiseCapability.[[Promise]].
|
||||
|
||||
flags: [async]
|
||||
features: [async-iteration]
|
||||
---*/
|
||||
|
||||
function* g() {
|
||||
}
|
||||
|
||||
async function* asyncg() {
|
||||
yield* g();
|
||||
}
|
||||
|
||||
var result = asyncg().next();
|
||||
assert(result instanceof Promise)
|
|
@ -0,0 +1,70 @@
|
|||
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-%asyncfromsynciteratorprototype%.return
|
||||
description: return() will reject promise if getter `done` abrupt completes
|
||||
info: |
|
||||
%AsyncFromSyncIteratorPrototype%.return ( value )
|
||||
...
|
||||
2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
||||
...
|
||||
5. Let return be GetMethod(syncIterator, "return").
|
||||
...
|
||||
8. Let returnResult be Call(return, syncIterator, « value »).
|
||||
9. IfAbruptRejectPromise(returnResult, promiseCapability).
|
||||
...
|
||||
11. Let returnDone be IteratorComplete(returnResult).
|
||||
12. IfAbruptRejectPromise(returnDone, promiseCapability).
|
||||
13. Let returnValue be IteratorValue(returnResult).
|
||||
14. IfAbruptRejectPromise(returnValue, promiseCapability).
|
||||
...
|
||||
22. Return promiseCapability.[[Promise]].
|
||||
|
||||
flags: [async]
|
||||
features: [async-iteration]
|
||||
---*/
|
||||
|
||||
var thrownError = new Error("Catch me.");
|
||||
|
||||
var obj = {
|
||||
[Symbol.iterator]() {
|
||||
return {
|
||||
next() {
|
||||
return { value: 1, done: false };
|
||||
},
|
||||
return() {
|
||||
return {
|
||||
get done() {
|
||||
throw thrownError;
|
||||
},
|
||||
value: 1
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
async function* asyncg() {
|
||||
yield* obj;
|
||||
}
|
||||
|
||||
var iter = asyncg();
|
||||
|
||||
iter.next().then(function(result) {
|
||||
|
||||
iter.return().then(
|
||||
function (result) {
|
||||
throw new Test262Error("Promise should be rejected, got: " + result.value);
|
||||
},
|
||||
function (err) {
|
||||
assert.sameValue(err, thrownError, "Promise should be rejected with thrown error");
|
||||
|
||||
iter.next().then(({ done, value }) => {
|
||||
assert.sameValue(done, true, 'the iterator is completed');
|
||||
assert.sameValue(value, undefined, 'value is undefined');
|
||||
}).then($DONE, $DONE);
|
||||
}
|
||||
).catch($DONE);
|
||||
|
||||
}).catch($DONE);
|
|
@ -0,0 +1,70 @@
|
|||
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-%asyncfromsynciteratorprototype%.return
|
||||
description: return() will reject promise if getter `value` abrupt completes
|
||||
info: |
|
||||
%AsyncFromSyncIteratorPrototype%.return ( value )
|
||||
...
|
||||
2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
||||
...
|
||||
5. Let return be GetMethod(syncIterator, "return").
|
||||
...
|
||||
8. Let returnResult be Call(return, syncIterator, « value »).
|
||||
9. IfAbruptRejectPromise(returnResult, promiseCapability).
|
||||
...
|
||||
11. Let returnDone be IteratorComplete(returnResult).
|
||||
12. IfAbruptRejectPromise(returnDone, promiseCapability).
|
||||
13. Let returnValue be IteratorValue(returnResult).
|
||||
14. IfAbruptRejectPromise(returnValue, promiseCapability).
|
||||
...
|
||||
22. Return promiseCapability.[[Promise]].
|
||||
|
||||
flags: [async]
|
||||
features: [async-iteration]
|
||||
---*/
|
||||
|
||||
|
||||
var thrownError = new Error("Catch me.");
|
||||
var obj = {
|
||||
[Symbol.iterator]() {
|
||||
return {
|
||||
next() {
|
||||
return { value: 1, done: false };
|
||||
},
|
||||
return() {
|
||||
return {
|
||||
get value() {
|
||||
throw thrownError;
|
||||
},
|
||||
done: false
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
async function* asyncg() {
|
||||
yield* obj;
|
||||
}
|
||||
|
||||
var iter = asyncg();
|
||||
|
||||
iter.next().then(function(result) {
|
||||
|
||||
iter.return().then(
|
||||
function (result) {
|
||||
throw new Test262Error("Promise should be rejected, got: " + result.value);
|
||||
},
|
||||
function (err) {
|
||||
assert.sameValue(err, thrownError, "Promise should be rejected with thrown error");
|
||||
|
||||
iter.next().then(({ done, value }) => {
|
||||
assert.sameValue(done, true, 'the iterator is completed');
|
||||
assert.sameValue(value, undefined, 'value is undefined');
|
||||
}).then($DONE, $DONE);
|
||||
}
|
||||
).catch($DONE);
|
||||
|
||||
}).catch($DONE);
|
|
@ -0,0 +1,63 @@
|
|||
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-%asyncfromsynciteratorprototype%.return
|
||||
description: return() will unwrap a Promise value return by the sync iterator
|
||||
info: |
|
||||
%AsyncFromSyncIteratorPrototype%.return ( value )
|
||||
...
|
||||
2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
||||
...
|
||||
5. Let return be GetMethod(syncIterator, "return").
|
||||
...
|
||||
17. Let steps be the algorithm steps defined in Async-from-Sync Iterator Value Unwrap Functions.
|
||||
...
|
||||
22. Return promiseCapability.[[Promise]].
|
||||
|
||||
Async-from-Sync Iterator Value Unwrap Functions
|
||||
An async-from-sync iterator value unwrap function is an anonymous built-in
|
||||
function that is used by methods of %AsyncFromSyncIteratorPrototype% when
|
||||
processing the value field of an IteratorResult object, in order to wait for
|
||||
its value if it is a promise and re-package the result in a new "unwrapped"
|
||||
IteratorResult object. Each async iterator value unwrap function has a
|
||||
[[Done]] internal slot.
|
||||
|
||||
flags: [async]
|
||||
features: [async-iteration]
|
||||
---*/
|
||||
|
||||
var obj = {
|
||||
[Symbol.iterator]() {
|
||||
return {
|
||||
next() {
|
||||
return { value: 1, done: false };
|
||||
},
|
||||
return() {
|
||||
return {
|
||||
value: Promise.resolve(42),
|
||||
done: true
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
async function* asyncg() {
|
||||
yield* obj;
|
||||
}
|
||||
|
||||
let iter = asyncg();
|
||||
|
||||
iter.next().then(function (result) {
|
||||
iter.return().then(
|
||||
function (result) {
|
||||
assert.sameValue(result.value, 42, "Result.value should be unwrapped, got: " + result.value);
|
||||
|
||||
iter.next().then(({ done, value }) => {
|
||||
assert.sameValue(done, true, 'the iterator is completed');
|
||||
assert.sameValue(value, undefined, 'value is undefined');
|
||||
}).then($DONE, $DONE);
|
||||
}
|
||||
).catch($DONE);
|
||||
}).then($DONE, $DONE);
|
|
@ -0,0 +1,55 @@
|
|||
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-%asyncfromsynciteratorprototype%.return
|
||||
description: return() will return a iterator result object when built-in sync throw is called
|
||||
info: |
|
||||
%AsyncFromSyncIteratorPrototype%.return ( value )
|
||||
...
|
||||
2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
||||
...
|
||||
5. Let return be GetMethod(syncIterator, "return").
|
||||
...
|
||||
8. Let returnResult be Call(return, syncIterator, « value »).
|
||||
...
|
||||
22. Return promiseCapability.[[Promise]].
|
||||
|
||||
Generator.prototype.return ( value )
|
||||
1. Let g be the this value.
|
||||
2. Let C be Completion{[[Type]]: return, [[Value]]: value, [[Target]]: empty}.
|
||||
3. Return ? GeneratorResumeAbrupt(g, C).
|
||||
|
||||
flags: [async]
|
||||
features: [async-iteration]
|
||||
---*/
|
||||
|
||||
function* g() {
|
||||
yield 42;
|
||||
throw new Test262Error('return closes iter');
|
||||
yield 43;
|
||||
}
|
||||
|
||||
async function* asyncg() {
|
||||
yield* g();
|
||||
}
|
||||
|
||||
var iter = asyncg();
|
||||
var val = 'some specific return value'
|
||||
|
||||
iter.next().then(function(result) {
|
||||
|
||||
// return will call sync generator prototype built-in function return
|
||||
iter.return(val).then(function(result) {
|
||||
|
||||
assert.sameValue(result.done, true, 'the iterator is completed');
|
||||
assert.sameValue(result.value, val, 'expect agrument to `return`');
|
||||
|
||||
iter.next().then(({ done, value }) => {
|
||||
assert.sameValue(done, true, 'the iterator is completed');
|
||||
assert.sameValue(value, undefined, 'value is undefined');
|
||||
}).then($DONE, $DONE);
|
||||
|
||||
}).catch($DONE);
|
||||
|
||||
}).catch($DONE);
|
|
@ -0,0 +1,59 @@
|
|||
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-%asyncfromsynciteratorprototype%.return
|
||||
description: return() will return rejected promise if getter of `return` abrupt completes
|
||||
info: |
|
||||
%AsyncFromSyncIteratorPrototype%.return ( value )
|
||||
...
|
||||
2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
||||
...
|
||||
5. Let return be GetMethod(syncIterator, "return").
|
||||
6. IfAbruptRejectPromise(return, promiseCapability).
|
||||
...
|
||||
22. Return promiseCapability.[[Promise]].
|
||||
|
||||
flags: [async]
|
||||
features: [async-iteration]
|
||||
---*/
|
||||
|
||||
var thrownError = new Error("Catch me.");
|
||||
|
||||
var obj = {
|
||||
[Symbol.iterator]() {
|
||||
return {
|
||||
next() {
|
||||
return { value: 1, done: false };
|
||||
},
|
||||
get return() {
|
||||
throw thrownError;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
async function* asyncg() {
|
||||
yield* obj;
|
||||
}
|
||||
|
||||
var iter = asyncg();
|
||||
|
||||
iter.next().then(function(result) {
|
||||
|
||||
iter.return().then(
|
||||
function (result) {
|
||||
throw new Test262Error("Promise should be rejected, got: " + result.value);
|
||||
},
|
||||
function (err) {
|
||||
assert.sameValue(err, thrownError, "Promise should be rejected with thrown error");
|
||||
|
||||
iter.next().then(({ done, value }) => {
|
||||
assert.sameValue(done, true, 'the iterator is completed');
|
||||
assert.sameValue(value, undefined, 'value is undefined');
|
||||
}).then($DONE, $DONE);
|
||||
}
|
||||
).catch($DONE);
|
||||
|
||||
}).catch($DONE);
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-%asyncfromsynciteratorprototype%.return
|
||||
description: return() will return rejected promise if getter of `return` abrupt completes
|
||||
info: |
|
||||
%AsyncFromSyncIteratorPrototype%.return ( value )
|
||||
...
|
||||
2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
||||
...
|
||||
5. Let return be GetMethod(syncIterator, "return").
|
||||
6. IfAbruptRejectPromise(return, promiseCapability).
|
||||
...
|
||||
8. Let returnResult be Call(return, syncIterator, « value »).
|
||||
...
|
||||
10. If Type(returnResult) is not Object,
|
||||
a. Perform ! Call(promiseCapability.[[Reject]], undefined, « a TypeError exception »).
|
||||
b. Return promiseCapability.[[Promise]].
|
||||
...
|
||||
22. Return promiseCapability.[[Promise]].
|
||||
|
||||
flags: [async]
|
||||
features: [async-iteration]
|
||||
---*/
|
||||
|
||||
var thrownError = new Error("Catch me.");
|
||||
|
||||
var obj = {
|
||||
[Symbol.iterator]() {
|
||||
return {
|
||||
next() {
|
||||
return { value: 1, done: false };
|
||||
},
|
||||
return() {
|
||||
throw thrownError;
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
async function* asyncg() {
|
||||
yield* obj;
|
||||
}
|
||||
|
||||
var iter = asyncg();
|
||||
|
||||
iter.next().then(function(result) {
|
||||
|
||||
iter.return().then(
|
||||
function (result) {
|
||||
throw new Test262Error("Promise should be rejected, got: " + result.value);
|
||||
},
|
||||
function (err) {
|
||||
assert.sameValue(err, thrownError, "Promise should be rejected with thrown error");
|
||||
|
||||
iter.next().then(({ done, value }) => {
|
||||
assert.sameValue(done, true, 'the iterator is completed');
|
||||
assert.sameValue(value, undefined, 'value is undefined');
|
||||
}).then($DONE, $DONE);
|
||||
}
|
||||
).catch($DONE);
|
||||
|
||||
}).catch($DONE);
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-%asyncfromsynciteratorprototype%.return
|
||||
description: return() will return rejected promise if getter of `return` abrupt completes
|
||||
info: |
|
||||
%AsyncFromSyncIteratorPrototype%.return ( value )
|
||||
...
|
||||
2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
||||
...
|
||||
5. Let return be GetMethod(syncIterator, "return").
|
||||
6. IfAbruptRejectPromise(return, promiseCapability).
|
||||
...
|
||||
8. Let returnResult be Call(return, syncIterator, « value »).
|
||||
...
|
||||
10. If Type(returnResult) is not Object,
|
||||
a. Perform ! Call(promiseCapability.[[Reject]], undefined, « a TypeError exception »).
|
||||
b. Return promiseCapability.[[Promise]].
|
||||
...
|
||||
22. Return promiseCapability.[[Promise]].
|
||||
|
||||
flags: [async]
|
||||
features: [async-iteration]
|
||||
---*/
|
||||
|
||||
var obj = {
|
||||
[Symbol.iterator]() {
|
||||
return {
|
||||
next() {
|
||||
return { value: 1, done: false };
|
||||
},
|
||||
return() {
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
async function* asyncg() {
|
||||
yield* obj;
|
||||
}
|
||||
|
||||
var iter = asyncg();
|
||||
|
||||
iter.next().then(function(result) {
|
||||
|
||||
iter.return().then(
|
||||
function (result) {
|
||||
throw new Test262Error("Promise should be rejected, got: " + result.value);
|
||||
},
|
||||
function (err) {
|
||||
let typeerror = err instanceof TypeError;
|
||||
assert(typeerror, "Expect TypeError, got: " + err);
|
||||
|
||||
iter.next().then(({ done, value }) => {
|
||||
assert.sameValue(done, true, 'the iterator is completed');
|
||||
assert.sameValue(value, undefined, 'value is undefined');
|
||||
}).then($DONE, $DONE);
|
||||
}
|
||||
).catch($DONE);
|
||||
|
||||
}).catch($DONE);
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-%asyncfromsynciteratorprototype%.throw
|
||||
description: return() will return value undefined if sync `return` is undefined
|
||||
info: |
|
||||
%AsyncFromSyncIteratorPrototype%.return ( value )
|
||||
...
|
||||
2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
||||
...
|
||||
5. Let return be GetMethod(syncIterator, "return").
|
||||
6. IfAbruptRejectPromise(return, promiseCapability).
|
||||
7. If return is undefined, then
|
||||
a. Let iterResult be ! CreateIterResultObject(value, true).
|
||||
b. Perform ! Call(promiseCapability.[[Resolve]], undefined, « iterResult »).
|
||||
c. Return promiseCapability.[[Promise]].
|
||||
|
||||
flags: [async]
|
||||
features: [async-iteration]
|
||||
---*/
|
||||
|
||||
|
||||
var obj = {
|
||||
[Symbol.iterator]() {
|
||||
return {
|
||||
next() {
|
||||
return { value: 1, done: false };
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
async function* asyncg() {
|
||||
yield* obj;
|
||||
}
|
||||
|
||||
var iter = asyncg();
|
||||
|
||||
iter.next().then(function(result) {
|
||||
|
||||
iter.return().then(function(result) {
|
||||
|
||||
assert.sameValue(result.done, true, 'the iterator is completed');
|
||||
assert.sameValue(result.value, undefined, 'expect value to be undefined');
|
||||
|
||||
iter.next().then(({ done, value }) => {
|
||||
assert.sameValue(done, true, 'the iterator is completed');
|
||||
assert.sameValue(value, undefined, 'value is undefined');
|
||||
}).then($DONE, $DONE);
|
||||
|
||||
}).catch($DONE);
|
||||
|
||||
}).catch($DONE);
|
|
@ -0,0 +1,69 @@
|
|||
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-%asyncfromsynciteratorprototype%.throw
|
||||
description: throw() will reject promise if getter `done` abrupt completes
|
||||
info: |
|
||||
%AsyncFromSyncIteratorPrototype%.throw ( value )
|
||||
...
|
||||
2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
||||
...
|
||||
5. Let throw be GetMethod(syncIterator, "throw").
|
||||
...
|
||||
8. Let throwResult be Call(throw, syncIterator, « value »).
|
||||
...
|
||||
11. Let throwDone be IteratorComplete(throwResult).
|
||||
12. IfAbruptRejectPromise(throwDone, promiseCapability).
|
||||
13. Let throwValue be IteratorValue(throwResult).
|
||||
14. IfAbruptRejectPromise(throwValue, promiseCapability).
|
||||
...
|
||||
20. Return promiseCapability.[[Promise]].
|
||||
|
||||
flags: [async]
|
||||
features: [async-iteration]
|
||||
---*/
|
||||
|
||||
var thrownError = new Error("Catch me.");
|
||||
|
||||
var obj = {
|
||||
[Symbol.iterator]() {
|
||||
return {
|
||||
next() {
|
||||
return { value: 1, done: false };
|
||||
},
|
||||
throw() {
|
||||
return {
|
||||
get done() {
|
||||
throw thrownError;
|
||||
},
|
||||
value: 1
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
async function* asyncg() {
|
||||
yield* obj;
|
||||
}
|
||||
|
||||
var iter = asyncg();
|
||||
|
||||
iter.next().then(function(result) {
|
||||
|
||||
iter.throw().then(
|
||||
function (result) {
|
||||
throw new Test262Error("Promise should be rejected, got: " + result.value);
|
||||
},
|
||||
function (err) {
|
||||
assert.sameValue(err, thrownError, "Promise should be rejected with thrown error");
|
||||
|
||||
iter.next().then(({ done, value }) => {
|
||||
assert.sameValue(done, true, 'the iterator is completed');
|
||||
assert.sameValue(value, undefined, 'value is undefined');
|
||||
}).then($DONE, $DONE);
|
||||
}
|
||||
).catch($DONE);
|
||||
|
||||
}).catch($DONE);
|
|
@ -0,0 +1,69 @@
|
|||
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-%asyncfromsynciteratorprototype%.throw
|
||||
description: throw() will reject promise if getter `value` abrupt completes
|
||||
info: |
|
||||
%AsyncFromSyncIteratorPrototype%.throw ( value )
|
||||
...
|
||||
2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
||||
...
|
||||
5. Let throw be GetMethod(syncIterator, "throw").
|
||||
...
|
||||
8. Let throwResult be Call(throw, syncIterator, « value »).
|
||||
...
|
||||
11. Let throwDone be IteratorComplete(throwResult).
|
||||
12. IfAbruptRejectPromise(throwDone, promiseCapability).
|
||||
13. Let throwValue be IteratorValue(throwResult).
|
||||
14. IfAbruptRejectPromise(throwValue, promiseCapability).
|
||||
...
|
||||
20. Return promiseCapability.[[Promise]].
|
||||
|
||||
flags: [async]
|
||||
features: [async-iteration]
|
||||
---*/
|
||||
|
||||
var thrownError = new Error("Catch me.");
|
||||
|
||||
var obj = {
|
||||
[Symbol.iterator]() {
|
||||
return {
|
||||
next() {
|
||||
return { value: 1, done: false };
|
||||
},
|
||||
throw() {
|
||||
return {
|
||||
get value() {
|
||||
throw thrownError;
|
||||
},
|
||||
done: false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
async function* asyncg() {
|
||||
yield* obj;
|
||||
}
|
||||
|
||||
var iter = asyncg();
|
||||
|
||||
iter.next().then(function(result) {
|
||||
|
||||
iter.throw().then(
|
||||
function (result) {
|
||||
throw new Test262Error("Promise should be rejected, got: " + result.value);
|
||||
},
|
||||
function (err) {
|
||||
assert.sameValue(err, thrownError, "Promise should be rejected with thrown error");
|
||||
|
||||
iter.next().then(({ done, value }) => {
|
||||
assert.sameValue(done, true, 'the iterator is completed');
|
||||
assert.sameValue(value, undefined, 'value is undefined');
|
||||
}).then($DONE, $DONE);
|
||||
}
|
||||
).catch($DONE);
|
||||
|
||||
}).catch($DONE);
|
|
@ -0,0 +1,65 @@
|
|||
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-%asyncfromsynciteratorprototype%.throw
|
||||
description: throw() will unwrap a Promise value return by the sync iterator
|
||||
info: |
|
||||
%AsyncFromSyncIteratorPrototype%.throw ( value )
|
||||
...
|
||||
2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
||||
...
|
||||
5. Let throw be GetMethod(syncIterator, "throw").
|
||||
...
|
||||
17. Let steps be the algorithm steps defined in Async-from-Sync Iterator Value Unwrap Functions.
|
||||
...
|
||||
20. Return promiseCapability.[[Promise]].
|
||||
|
||||
Async-from-Sync Iterator Value Unwrap Functions
|
||||
An async-from-sync iterator value unwrap function is an anonymous built-in
|
||||
function that is used by methods of %AsyncFromSyncIteratorPrototype% when
|
||||
processing the value field of an IteratorResult object, in order to wait for
|
||||
its value if it is a promise and re-package the result in a new "unwrapped"
|
||||
IteratorResult object. Each async iterator value unwrap function has a
|
||||
[[Done]] internal slot.
|
||||
|
||||
flags: [async]
|
||||
features: [async-iteration]
|
||||
---*/
|
||||
|
||||
var thrownError = new Error("Don't catch me.")
|
||||
|
||||
var obj = {
|
||||
[Symbol.iterator]() {
|
||||
return {
|
||||
next() {
|
||||
return { value: 1, done: false };
|
||||
},
|
||||
throw() {
|
||||
return {
|
||||
value: Promise.resolve(42),
|
||||
done: true
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
async function* asyncg() {
|
||||
yield* obj;
|
||||
}
|
||||
|
||||
let iter = asyncg();
|
||||
|
||||
iter.next().then(function (result) {
|
||||
iter.throw(thrownError).then(
|
||||
function (result) {
|
||||
assert.sameValue(result.value, 42, "Result.value should be unwrapped, got: " + result.value);
|
||||
|
||||
iter.next().then(({ done, value }) => {
|
||||
assert.sameValue(done, true, 'the iterator is completed');
|
||||
assert.sameValue(value, undefined, 'value is undefined');
|
||||
}).then($DONE, $DONE);
|
||||
}
|
||||
).catch($DONE);
|
||||
}).then($DONE, $DONE);
|
|
@ -0,0 +1,59 @@
|
|||
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-%asyncfromsynciteratorprototype%.throw
|
||||
description: throw() will call default sync throw
|
||||
info: |
|
||||
%AsyncFromSyncIteratorPrototype%.throw ( value )
|
||||
...
|
||||
2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
||||
...
|
||||
5. Let throw be GetMethod(syncIterator, "throw").
|
||||
...
|
||||
8. Let throwResult be Call(throw, syncIterator, « value »)
|
||||
9. IfAbruptRejectPromise(throwResult, promiseCapability).
|
||||
...
|
||||
22. Return promiseCapability.[[Promise]].
|
||||
|
||||
Generator.prototype.throw ( exception )
|
||||
1. Let g be the this value.
|
||||
2. Let C be Completion{[[Type]]: throw, [[Value]]: exception, [[Target]]: empty}.
|
||||
3. Return ? GeneratorResumeAbrupt(g, C).
|
||||
|
||||
flags: [async]
|
||||
features: [async-iteration]
|
||||
---*/
|
||||
|
||||
var thrownError = new Error("Catch me.")
|
||||
|
||||
function* g() {
|
||||
yield 42;
|
||||
throw new Test262Error('throw closes iter');
|
||||
yield 43;
|
||||
}
|
||||
|
||||
async function* asyncg() {
|
||||
yield* g();
|
||||
}
|
||||
|
||||
var iter = asyncg();
|
||||
|
||||
iter.next().then(function(result) {
|
||||
|
||||
// throw will call sync generator prototype built-in function throw
|
||||
iter.throw(thrownError).then(
|
||||
function(result) {
|
||||
throw new Test262Error('throw should cause rejection of promise');
|
||||
},
|
||||
function(err) {
|
||||
assert.sameValue(err, thrownError, "promise should be reject with custom error, got: " + err)
|
||||
|
||||
iter.next().then(({ done, value }) => {
|
||||
assert.sameValue(done, true, 'the iterator is completed');
|
||||
assert.sameValue(value, undefined, 'value is undefined');
|
||||
}).then($DONE, $DONE);
|
||||
}
|
||||
).catch($DONE);
|
||||
|
||||
}).catch($DONE);
|
|
@ -0,0 +1,59 @@
|
|||
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-%asyncfromsynciteratorprototype%.throw
|
||||
description: throw() will return rejected promise if getter of `throw` abrupt completes
|
||||
info: |
|
||||
%AsyncFromSyncIteratorPrototype%.return ( value )
|
||||
...
|
||||
2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
||||
...
|
||||
5. Let return be GetMethod(syncIterator, "throw").
|
||||
6. IfAbruptRejectPromise(throw, promiseCapability).
|
||||
...
|
||||
22. Return promiseCapability.[[Promise]].
|
||||
|
||||
flags: [async]
|
||||
features: [async-iteration]
|
||||
---*/
|
||||
|
||||
var thrownError = new Error("Catch me.");
|
||||
|
||||
var obj = {
|
||||
[Symbol.iterator]() {
|
||||
return {
|
||||
next() {
|
||||
return { value: 1, done: false };
|
||||
},
|
||||
get throw() {
|
||||
throw thrownError;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
async function* asyncg() {
|
||||
yield* obj;
|
||||
}
|
||||
|
||||
var iter = asyncg();
|
||||
|
||||
iter.next().then(function(result) {
|
||||
|
||||
iter.throw().then(
|
||||
function (result) {
|
||||
throw new Test262Error("Promise should be rejected, got: " + result.value);
|
||||
},
|
||||
function (err) {
|
||||
assert.sameValue(err, thrownError, "Promise should be rejected with thrown error");
|
||||
|
||||
iter.next().then(({ done, value }) => {
|
||||
assert.sameValue(done, true, 'the iterator is completed');
|
||||
assert.sameValue(value, undefined, 'value is undefined');
|
||||
}).then($DONE, $DONE);
|
||||
}
|
||||
).catch($DONE);
|
||||
|
||||
}).catch($DONE);
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-%asyncfromsynciteratorprototype%.throw
|
||||
description: throw() will return rejected promise if getter of `throw` abrupt completes
|
||||
info: |
|
||||
%AsyncFromSyncIteratorPrototype%.throw ( value )
|
||||
...
|
||||
2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
||||
...
|
||||
5. Let throw be GetMethod(syncIterator, "throw").
|
||||
6. IfAbruptRejectPromise(throw, promiseCapability).
|
||||
...
|
||||
8. Let throwResult be Call(throw, syncIterator, « value »).
|
||||
9. IfAbruptRejectPromise(throwResult, promiseCapability).
|
||||
...
|
||||
22. Return promiseCapability.[[Promise]].
|
||||
|
||||
flags: [async]
|
||||
features: [async-iteration]
|
||||
---*/
|
||||
|
||||
var thrownError = new Error("Catch me.");
|
||||
|
||||
var obj = {
|
||||
[Symbol.iterator]() {
|
||||
return {
|
||||
next() {
|
||||
return { value: 1, done: false };
|
||||
},
|
||||
throw() {
|
||||
throw thrownError;
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
async function* asyncg() {
|
||||
yield* obj;
|
||||
}
|
||||
|
||||
var iter = asyncg();
|
||||
|
||||
iter.next().then(function(result) {
|
||||
|
||||
iter.throw().then(
|
||||
function (result) {
|
||||
throw new Test262Error("Promise should be rejected, got: " + result.value);
|
||||
},
|
||||
function (err) {
|
||||
assert.sameValue(err, thrownError, "Promise should be rejected with thrown error");
|
||||
|
||||
iter.next().then(({ done, value }) => {
|
||||
assert.sameValue(done, true, 'the iterator is completed');
|
||||
assert.sameValue(value, undefined, 'value is undefined');
|
||||
}).then($DONE, $DONE);
|
||||
}
|
||||
).catch($DONE);
|
||||
|
||||
}).catch($DONE);
|
|
@ -0,0 +1,64 @@
|
|||
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-%asyncfromsynciteratorprototype%.throw
|
||||
description: throw() will return rejected promise if getter of `throw` abrupt completes
|
||||
info: |
|
||||
%AsyncFromSyncIteratorPrototype%.throw ( value )
|
||||
...
|
||||
2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
||||
...
|
||||
5. Let throw be GetMethod(syncIterator, "throw").
|
||||
6. IfAbruptRejectPromise(thow, promiseCapability).
|
||||
...
|
||||
8. Let throwResult be Call(throw, syncIterator, « value »).
|
||||
...
|
||||
10. If Type(throwResult) is not Object,
|
||||
a. Perform ! Call(promiseCapability.[[Reject]], undefined, « a TypeError exception »).
|
||||
b. Return promiseCapability.[[Promise]].
|
||||
|
||||
flags: [async]
|
||||
features: [async-iteration]
|
||||
---*/
|
||||
|
||||
var thrownError = new Error("Don't catch me.")
|
||||
|
||||
var obj = {
|
||||
[Symbol.iterator]() {
|
||||
return {
|
||||
next() {
|
||||
return { value: 1, done: false };
|
||||
},
|
||||
throw() {
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
async function* asyncg() {
|
||||
yield* obj;
|
||||
}
|
||||
|
||||
var iter = asyncg();
|
||||
|
||||
iter.next().then(function(result) {
|
||||
|
||||
iter.throw(thrownError).then(
|
||||
function (result) {
|
||||
throw new Test262Error("Promise should be rejected, got: " + result.value);
|
||||
},
|
||||
function (err) {
|
||||
let typeerror = err instanceof TypeError;
|
||||
assert(typeerror, "Expect TypeError, got: " + err);
|
||||
|
||||
iter.next().then(({ done, value }) => {
|
||||
assert.sameValue(done, true, 'the iterator is completed');
|
||||
assert.sameValue(value, undefined, 'value is undefined');
|
||||
}).then($DONE, $DONE);
|
||||
}
|
||||
).catch($DONE);
|
||||
|
||||
}).catch($DONE);
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-%asyncfromsynciteratorprototype%.throw
|
||||
description: throw() will return rejected promise if sync `throw` undefined
|
||||
info: |
|
||||
%AsyncFromSyncIteratorPrototype%.throw ( value )
|
||||
...
|
||||
2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
||||
...
|
||||
5. Let return be GetMethod(syncIterator, "throw").
|
||||
6. IfAbruptRejectPromise(throw, promiseCapability).
|
||||
7. If throw is undefined, then
|
||||
a. Perform ! Call(promiseCapability.[[Reject]], undefined, « value »).
|
||||
b. Return promiseCapability.[[Promise]].
|
||||
|
||||
flags: [async]
|
||||
features: [async-iteration]
|
||||
---*/
|
||||
|
||||
var obj = {
|
||||
[Symbol.iterator]() {
|
||||
return {
|
||||
next() {
|
||||
return { value: 1, done: false };
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
async function* asyncg() {
|
||||
yield* obj;
|
||||
}
|
||||
|
||||
var iter = asyncg();
|
||||
|
||||
iter.next().then(function(result) {
|
||||
|
||||
iter.throw().then(
|
||||
function (result) {
|
||||
throw new Test262Error("Promise should be rejected, got: " + result.value);
|
||||
},
|
||||
function (err) {
|
||||
assert.sameValue(err, undefined, "Promise should be rejected with undefined");
|
||||
|
||||
iter.next().then(({ done, value }) => {
|
||||
assert.sameValue(done, true, 'the iterator is completed');
|
||||
assert.sameValue(value, undefined, 'value is undefined');
|
||||
}).then($DONE, $DONE);
|
||||
}
|
||||
).catch($DONE);
|
||||
|
||||
}).catch($DONE);
|
||||
|
Loading…
Reference in New Issue