Use Promise chaining

This commit is contained in:
Alexey Shvayka 2020-05-27 22:38:55 +03:00 committed by Rick Waldron
parent 919415704b
commit 616978791d
3 changed files with 23 additions and 29 deletions
test
built-ins/AsyncFromSyncIteratorPrototype/throw
language/expressions/async-generator

View File

@ -44,19 +44,16 @@ async function* asyncGenerator() {
} }
var asyncIterator = asyncGenerator(); var asyncIterator = asyncGenerator();
asyncIterator.next().then(function() { var thrownError = { name: "err" };
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) { asyncIterator.next().then(function() {
assert.sameValue(result.value, undefined); return asyncIterator.throw(thrownError);
assert.sameValue(result.done, true); }).then(function(result) {
}).then($DONE, $DONE); throw new Test262Error("Promise should be rejected, got: " + result.value);
} }, function(err) {
).catch($DONE); assert.sameValue(err, thrownError);
}).catch($DONE); return asyncIterator.next().then(function(result) {
assert.sameValue(result.value, undefined);
assert.sameValue(result.done, true);
});
}).then($DONE, $DONE);

View File

@ -47,9 +47,9 @@ async function* asyncGenerator() {
var asyncIterator = asyncGenerator(); var asyncIterator = asyncGenerator();
asyncIterator.next().then(function() { asyncIterator.next().then(function() {
asyncIterator.return(2).then(function(result) { return asyncIterator.return(2).then(function(result) {
assert.sameValue(result.value, 2); assert.sameValue(result.value, 2);
assert.sameValue(result.done, true); assert.sameValue(result.done, true);
assert.sameValue(returnGets, 1); assert.sameValue(returnGets, 1);
}).then($DONE, $DONE); });
}).catch($DONE); }).then($DONE, $DONE);

View File

@ -62,14 +62,11 @@ async function* asyncGenerator() {
var asyncIterator = asyncGenerator(); var asyncIterator = asyncGenerator();
asyncIterator.next().then(function() { asyncIterator.next().then(function() {
asyncIterator.throw().then( return asyncIterator.throw();
function(result) { }).then(function(result) {
throw new Test262Error("Promise should be rejected, got: " + result.value); throw new Test262Error("Promise should be rejected, got: " + result.value);
}, }, function(err) {
function(err) { assert.sameValue(err.constructor, TypeError);
assert.sameValue(err.constructor, TypeError); assert.sameValue(throwGets, 1);
assert.sameValue(throwGets, 1); assert.sameValue(returnGets, 1);
assert.sameValue(returnGets, 1); }).then($DONE, $DONE);
},
).then($DONE, $DONE);
}).catch($DONE);