-
Notifications
You must be signed in to change notification settings - Fork 497
Async Generator flow control tests #871
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
test/language/expressions/async-generators/return-suspendedStart-promise.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2017 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
author: Caitlin Potter <[email protected]> | ||
esid: pending | ||
description: > | ||
AsyncGeneratorResumeNext: | ||
If completion.[[Type]] is return, and generator.[[AsyncGeneratorState]] is | ||
"suspendedStart", generator is closed without being resumed. | ||
|
||
AsyncGeneratorResolve will unwrap Promise values (steps 6-10) | ||
flags: [async] | ||
---*/ | ||
|
||
var g = async function*() { | ||
throw new Test262Error('Generator must not be resumed.'); | ||
}; | ||
|
||
var it = g(); | ||
var resolve; | ||
var promise = new Promise(function(resolver) { | ||
resolve = resolver; | ||
}); | ||
|
||
it.return(promise).then(function(ret) { | ||
assert.sameValue(ret.value, 'unwrapped-value', 'AsyncGeneratorResolve(generator, completion.[[Value]], true)'); | ||
assert.sameValue(ret.done, true, 'AsyncGeneratorResolve(generator, completion.[[Value]], true)'); | ||
|
||
it.next().then(function(ret) { | ||
assert.sameValue(ret.value, undefined, 'Generator is closed'); | ||
assert.sameValue(ret.done, true, 'Generator is closed'); | ||
}).then($DONE, $DONE); | ||
}).catch($DONE); | ||
|
||
resolve('unwrapped-value'); |
27 changes: 27 additions & 0 deletions
27
test/language/expressions/async-generators/return-suspendedStart.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2017 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
author: Caitlin Potter <[email protected]> | ||
esid: pending | ||
description: > | ||
AsyncGeneratorResumeNext: | ||
If completion.[[Type]] is return, and generator.[[AsyncGeneratorState]] is | ||
"suspendedStart", generator is closed without being resumed. | ||
flags: [async] | ||
---*/ | ||
|
||
var g = async function*() { | ||
throw new Test262Error('Generator must not be resumed.'); | ||
}; | ||
|
||
var it = g(); | ||
it.return('sent-value').then(function(ret) { | ||
assert.sameValue(ret.value, 'sent-value', 'AsyncGeneratorResolve(generator, completion.[[Value]], true)'); | ||
assert.sameValue(ret.done, true, 'AsyncGeneratorResolve(generator, completion.[[Value]], true)'); | ||
|
||
it.next().then(function(ret) { | ||
assert.sameValue(ret.value, undefined, 'Generator is closed'); | ||
assert.sameValue(ret.done, true, 'Generator is closed'); | ||
}).then($DONE, $DONE); | ||
}).catch($DONE); |
41 changes: 41 additions & 0 deletions
41
test/language/expressions/async-generators/return-suspendedYield-promise.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2017 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
author: Caitlin Potter <[email protected]> | ||
esid: pending | ||
description: > | ||
AsyncGeneratorResumeNext: | ||
If completion.[[Type]] is return, and generator.[[AsyncGeneratorState]] is | ||
"suspendedYield", generator is resumed and immediately closes the generator | ||
and returns completion. | ||
flags: [async] | ||
---*/ | ||
|
||
var g = async function*() { | ||
yield 1; | ||
throw new Test262Error('Generator must not be resumed.'); | ||
}; | ||
|
||
var it = g(); | ||
var resolve; | ||
var promise = new Promise(function(resolver) { | ||
resolve = resolver; | ||
}); | ||
it.next().then(function(ret) { | ||
assert.sameValue(ret.value, 1, 'Initial yield'); | ||
assert.sameValue(ret.done, false, 'Initial yield'); | ||
|
||
it.return(promise).then(function(ret) { | ||
assert.sameValue(ret.value, 'unwrapped-value', 'AsyncGeneratorResolve(generator, resultValue, true)'); | ||
assert.sameValue(ret.done, true, 'AsyncGeneratorResolve(generator, resultValue, true)'); | ||
|
||
it.next().then(function(ret) { | ||
assert.sameValue(ret.value, undefined, 'Generator is closed'); | ||
assert.sameValue(ret.done, true, 'Generator is closed'); | ||
}).then($DONE, $DONE); | ||
|
||
}).catch($DONE); | ||
|
||
resolve('unwrapped-value'); | ||
}).catch($DONE); |
40 changes: 40 additions & 0 deletions
40
test/language/expressions/async-generators/return-suspendedYield-try-finally-return.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2017 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
author: Caitlin Potter <[email protected]> | ||
esid: pending | ||
description: > | ||
AsyncGeneratorResumeNext: | ||
If completion.[[Type]] is return, and generator.[[AsyncGeneratorState]] is | ||
"suspendedYield", and generator is resumed within a try-block with an | ||
associated finally block, resume execution within finally. | ||
flags: [async] | ||
---*/ | ||
|
||
var g = async function*() { | ||
try { | ||
yield 1; | ||
throw new Test262Error('Generator must be resumed in finally block.'); | ||
} finally { | ||
return 'done'; | ||
} | ||
}; | ||
|
||
var it = g(); | ||
it.next().then(function(ret) { | ||
assert.sameValue(ret.value, 1, 'Initial yield'); | ||
assert.sameValue(ret.done, false, 'Initial yield'); | ||
|
||
it.return('sent-value').then(function(ret) { | ||
assert.sameValue(ret.value, 'done', 'AsyncGeneratorResolve(generator, resultValue, true)'); | ||
assert.sameValue(ret.done, true, 'AsyncGeneratorResolve(generator, resultValue, true)'); | ||
|
||
it.next().then(function(ret) { | ||
assert.sameValue(ret.value, undefined, 'Generator is closed'); | ||
assert.sameValue(ret.done, true, 'Generator is closed'); | ||
}).then($DONE, $DONE); | ||
|
||
}).catch($DONE); | ||
|
||
}).catch($DONE); |
41 changes: 41 additions & 0 deletions
41
test/language/expressions/async-generators/return-suspendedYield-try-finally-throw.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2017 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
author: Caitlin Potter <[email protected]> | ||
esid: pending | ||
description: > | ||
AsyncGeneratorResumeNext: | ||
If completion.[[Type]] is return, and generator.[[AsyncGeneratorState]] is | ||
"suspendedYield", and generator is resumed within a try-block with an | ||
associated finally block, resume execution within finally. | ||
flags: [async] | ||
---*/ | ||
|
||
var error = new Error("boop"); | ||
var g = async function*() { | ||
try { | ||
yield 1; | ||
throw new Test262Error('Generator must be resumed in finally block.'); | ||
} finally { | ||
throw error; | ||
throw new Test262Error('Generator must not be resumed.'); | ||
} | ||
}; | ||
|
||
var it = g(); | ||
it.next().then(function(ret) { | ||
assert.sameValue(ret.value, 1, 'Initial yield'); | ||
assert.sameValue(ret.done, false, 'Initial yield'); | ||
|
||
it.return('sent-value').then($DONE, function(err) { | ||
assert.sameValue(err, error, 'AsyncGeneratorReject(generator, resultValue)'); | ||
|
||
it.next().then(function(ret) { | ||
assert.sameValue(ret.value, undefined, 'Generator is closed'); | ||
assert.sameValue(ret.done, true, 'Generator is closed'); | ||
}).then($DONE, $DONE); | ||
|
||
}).catch($DONE); | ||
|
||
}).catch($DONE); |
46 changes: 46 additions & 0 deletions
46
test/language/expressions/async-generators/return-suspendedYield-try-finally.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2017 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
author: Caitlin Potter <[email protected]> | ||
esid: pending | ||
description: > | ||
AsyncGeneratorResumeNext: | ||
If completion.[[Type]] is return, and generator.[[AsyncGeneratorState]] is | ||
"suspendedYield", and generator is resumed within a try-block with an | ||
associated finally block, resume execution within finally. | ||
flags: [async] | ||
---*/ | ||
|
||
var g = async function*() { | ||
try { | ||
yield 1; | ||
throw new Test262Error('Generator must be resumed in finally block.'); | ||
} finally { | ||
yield 2; | ||
} | ||
}; | ||
|
||
var it = g(); | ||
it.next().then(function(ret) { | ||
assert.sameValue(ret.value, 1, 'Initial yield'); | ||
assert.sameValue(ret.done, false, 'Initial yield'); | ||
|
||
it.return('sent-value').then(function(ret) { | ||
assert.sameValue(ret.value, 2, 'Yield in finally block'); | ||
assert.sameValue(ret.done, false, 'Yield in finally block'); | ||
|
||
it.next().then(function(ret) { | ||
assert.sameValue(ret.value, 'sent-value', 'AsyncGeneratorResolve(generator, resultValue, true)'); | ||
assert.sameValue(ret.done, true, 'AsyncGeneratorResolve(generator, resultValue, true)'); | ||
|
||
it.next().then(function(ret) { | ||
assert.sameValue(ret.value, undefined, 'Generator is closed'); | ||
assert.sameValue(ret.done, true, 'Generator is closed'); | ||
}).then($DONE, $DONE); | ||
|
||
}).catch($DONE); | ||
|
||
}).catch($DONE); | ||
|
||
}).catch($DONE); | ||
36 changes: 36 additions & 0 deletions
36
test/language/expressions/async-generators/return-suspendedYield.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2017 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
author: Caitlin Potter <[email protected]> | ||
esid: pending | ||
description: > | ||
AsyncGeneratorResumeNext: | ||
If completion.[[Type]] is return, and generator.[[AsyncGeneratorState]] is | ||
"suspendedYield", generator is resumed and immediately closes the generator | ||
and returns completion. | ||
flags: [async] | ||
---*/ | ||
|
||
var g = async function*() { | ||
yield 1; | ||
throw new Test262Error('Generator must not be resumed.'); | ||
}; | ||
|
||
var it = g(); | ||
it.next().then(function(ret) { | ||
assert.sameValue(ret.value, 1, 'Initial yield'); | ||
assert.sameValue(ret.done, false, 'Initial yield'); | ||
|
||
it.return('sent-value').then(function(ret) { | ||
assert.sameValue(ret.value, 'sent-value', 'AsyncGeneratorResolve(generator, resultValue, true)'); | ||
assert.sameValue(ret.done, true, 'AsyncGeneratorResolve(generator, resultValue, true)'); | ||
|
||
it.next().then(function(ret) { | ||
assert.sameValue(ret.value, undefined, 'Generator is closed'); | ||
assert.sameValue(ret.done, true, 'Generator is closed'); | ||
}).then($DONE, $DONE); | ||
|
||
}).catch($DONE); | ||
|
||
}).catch($DONE); |
30 changes: 30 additions & 0 deletions
30
test/language/expressions/async-generators/throw-suspendedStart-promise.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2017 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
author: Caitlin Potter <[email protected]> | ||
esid: pending | ||
description: > | ||
AsyncGeneratorResumeNext: | ||
If completion.[[Type]] is throw, and generator.[[AsyncGeneratorState]] is | ||
"suspendedStart", generator is closed without being resumed. | ||
|
||
AsyncGeneratorReject will not unwrap Promise values | ||
flags: [async] | ||
---*/ | ||
|
||
var g = async function*() { | ||
throw new Test262Error('Generator must not be resumed.'); | ||
}; | ||
|
||
var it = g(); | ||
var promise = new Promise(function() {}); | ||
|
||
it.throw(promise).then($DONE, function(err) { | ||
assert.sameValue(err, promise, 'AsyncGeneratorReject(generator, completion.[[Value]])'); | ||
|
||
it.next().then(function(ret) { | ||
assert.sameValue(ret.value, undefined, 'Generator is closed'); | ||
assert.sameValue(ret.done, true, 'Generator is closed'); | ||
}).then($DONE, $DONE); | ||
}).catch($DONE); |
27 changes: 27 additions & 0 deletions
27
test/language/expressions/async-generators/throw-suspendedStart.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2017 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
author: Caitlin Potter <[email protected]> | ||
esid: pending | ||
description: > | ||
AsyncGeneratorResumeNext: | ||
If completion.[[Type]] is throw, and generator.[[AsyncGeneratorState]] is | ||
"suspendedStart", generator is closed without being resumed. | ||
flags: [async] | ||
---*/ | ||
|
||
var error = new Error('boop'); | ||
var g = async function*() { | ||
throw new Test262Error('Generator must not be resumed.'); | ||
}; | ||
|
||
var it = g(); | ||
it.throw(error).then($DONE, function(err) { | ||
assert.sameValue(err, error, 'AsyncGeneratorReject(generator, completion.[[Value]])'); | ||
|
||
it.next().then(function(ret) { | ||
assert.sameValue(ret.value, undefined, 'Generator is closed'); | ||
assert.sameValue(ret.done, true, 'Generator is closed'); | ||
}).then($DONE, $DONE); | ||
}).catch($DONE); |
39 changes: 39 additions & 0 deletions
39
test/language/expressions/async-generators/throw-suspendedYield-promise.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2017 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
author: Caitlin Potter <[email protected]> | ||
esid: pending | ||
description: > | ||
AsyncGeneratorResumeNext: | ||
If completion.[[Type]] is throw, and generator.[[AsyncGeneratorState]] is | ||
"suspendedYield", generator is resumed and immediately and | ||
closes the generator and returns completion. | ||
|
||
AsyncGeneratorReject will not unwrap Promise values | ||
flags: [async] | ||
---*/ | ||
|
||
var g = async function*() { | ||
yield 1; | ||
throw new Test262Error('Generator must not be resumed.'); | ||
}; | ||
|
||
var it = g(); | ||
var promise = new Promise(function() {}); | ||
|
||
it.next().then(function(ret) { | ||
assert.sameValue(ret.value, 1, 'Initial yield'); | ||
assert.sameValue(ret.done, false, 'Initial yield'); | ||
|
||
it.throw(promise).then($DONE, function(err) { | ||
assert.sameValue(err, promise, 'AsyncGeneratorReject(generator, resultValue)'); | ||
|
||
it.next().then(function(ret) { | ||
assert.sameValue(ret.value, undefined, 'Generator is closed'); | ||
assert.sameValue(ret.done, true, 'Generator is closed'); | ||
}).then($DONE, $DONE); | ||
|
||
}).catch($DONE); | ||
|
||
}).catch($DONE); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish we could have
Promise#finally
alreadyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it would help with the nested Promises
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a specific reason these are nested instead of chained anyway?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(returning a Promise and chaining is) harder to read, less obvious, etc
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I very much disagree, 4 level nested callbacks are much less readable than chaining promises, but I also don't care enough to block, it seems you've reached "annoyed" point on this PR (been there myself, sorry if I'm projecting) and I don't want to add to it any more. Thanks for the contribution!