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

View File

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

View File

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