mirror of https://github.com/tc39/test262.git
Add AsyncFromSyncIterator tests
This commit is contained in:
parent
7f53ea671c
commit
02013fd1d6
|
@ -0,0 +1,53 @@
|
|||
// Copyright (C) 2020 Alexey Shvayka. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-%asyncfromsynciteratorprototype%.return
|
||||
description: >
|
||||
If syncIterator's "return" method is `null`,
|
||||
a Promise resolved with `undefined` value is returned.
|
||||
info: |
|
||||
%AsyncFromSyncIteratorPrototype%.return ( value )
|
||||
|
||||
[...]
|
||||
5. Let return be GetMethod(syncIterator, "return").
|
||||
[...]
|
||||
7. If return is undefined, then
|
||||
a. Let iterResult be ! CreateIterResultObject(value, true).
|
||||
b. Perform ! Call(promiseCapability.[[Resolve]], undefined, « iterResult »).
|
||||
c. Return promiseCapability.[[Promise]].
|
||||
|
||||
GetMethod ( V, P )
|
||||
|
||||
[...]
|
||||
2. Let func be ? GetV(V, P).
|
||||
3. If func is either undefined or null, return undefined.
|
||||
flags: [async]
|
||||
features: [async-iteration]
|
||||
---*/
|
||||
|
||||
var iterationCount = 0;
|
||||
var returnGets = 0;
|
||||
|
||||
var syncIterator = {
|
||||
[Symbol.iterator]() {
|
||||
return this;
|
||||
},
|
||||
next() {
|
||||
return {value: 1, done: false};
|
||||
},
|
||||
get return() {
|
||||
returnGets += 1;
|
||||
return null;
|
||||
},
|
||||
};
|
||||
|
||||
(async function() {
|
||||
for await (let _ of syncIterator) {
|
||||
iterationCount += 1;
|
||||
break;
|
||||
}
|
||||
|
||||
assert.sameValue(iterationCount, 1);
|
||||
assert.sameValue(returnGets, 1);
|
||||
}()).then($DONE, $DONE);
|
|
@ -0,0 +1,62 @@
|
|||
// Copyright (C) 2020 Alexey Shvayka. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-%asyncfromsynciteratorprototype%.throw
|
||||
description: >
|
||||
If syncIterator's "throw" method is `null`,
|
||||
a Promise rejected with provided value is returned.
|
||||
info: |
|
||||
%AsyncFromSyncIteratorPrototype%.throw ( value )
|
||||
|
||||
[...]
|
||||
5. Let throw be GetMethod(syncIterator, "throw").
|
||||
[...]
|
||||
7. If throw is undefined, then
|
||||
a. Perform ! Call(promiseCapability.[[Reject]], undefined, « value »).
|
||||
b. Return promiseCapability.[[Promise]].
|
||||
|
||||
GetMethod ( V, P )
|
||||
|
||||
[...]
|
||||
2. Let func be ? GetV(V, P).
|
||||
3. If func is either undefined or null, return undefined.
|
||||
flags: [async]
|
||||
features: [async-iteration]
|
||||
---*/
|
||||
|
||||
var throwGets = 0;
|
||||
var syncIterator = {
|
||||
[Symbol.iterator]() {
|
||||
return this;
|
||||
},
|
||||
next() {
|
||||
return {value: 1, done: false};
|
||||
},
|
||||
get throw() {
|
||||
throwGets += 1;
|
||||
return null;
|
||||
},
|
||||
};
|
||||
|
||||
async function* asyncGenerator() {
|
||||
yield* syncIterator;
|
||||
}
|
||||
|
||||
var asyncIterator = asyncGenerator();
|
||||
asyncIterator.next().then(function() {
|
||||
var thrownError = { name: "err" };
|
||||
asyncIterator.throw(thrownError).then(
|
||||
function(result) {
|
||||
throw new Test262Error("Promise should be rejected, got: " + result.value);
|
||||
},
|
||||
function(err) {
|
||||
assert.sameValue(err, thrownError);
|
||||
|
||||
asyncIterator.next().then(function(result) {
|
||||
assert.sameValue(result.value, undefined);
|
||||
assert.sameValue(result.done, true);
|
||||
}).then($DONE, $DONE);
|
||||
}
|
||||
).catch($DONE);
|
||||
}).catch($DONE);
|
Loading…
Reference in New Issue