Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Unified Diff: src/generator.js

Issue 717123002: Leaving a generator via an exception causes it to close (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Remove state checking from full-codegen and associated runtime functions Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/arm64/full-codegen-arm64.cc ('k') | src/ia32/full-codegen-ia32.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/generator.js
diff --git a/src/generator.js b/src/generator.js
index b35744a094f29ef0acd8baf3180bdfb7234a9084..2e2c84a943497323f184cda36223360b9948db12 100644
--- a/src/generator.js
+++ b/src/generator.js
@@ -20,8 +20,23 @@ function GeneratorObjectNext(value) {
['[Generator].prototype.next', this]);
}
- if (DEBUG_IS_ACTIVE) %DebugPrepareStepInIfStepping(this);
- return %_GeneratorNext(this, value);
+ var continuation = %GeneratorGetContinuation(this);
+ if (continuation > 0) {
+ // Generator is suspended.
+ if (DEBUG_IS_ACTIVE) %DebugPrepareStepInIfStepping(this);
+ try {
+ return %_GeneratorNext(this, value);
+ } catch (e) {
+ %GeneratorClose(this);
+ throw e;
+ }
+ } else if (continuation == 0) {
+ // Generator is already closed.
+ return { value: void 0, done: true };
+ } else {
+ // Generator is running.
+ throw MakeTypeError('generator_running', []);
+ }
}
function GeneratorObjectThrow(exn) {
@@ -30,7 +45,22 @@ function GeneratorObjectThrow(exn) {
['[Generator].prototype.throw', this]);
}
- return %_GeneratorThrow(this, exn);
+ var continuation = %GeneratorGetContinuation(this);
+ if (continuation > 0) {
+ // Generator is suspended.
+ try {
+ return %_GeneratorThrow(this, exn);
+ } catch (e) {
+ %GeneratorClose(this);
+ throw e;
+ }
+ } else if (continuation == 0) {
+ // Generator is already closed.
+ throw exn;
+ } else {
+ // Generator is running.
+ throw MakeTypeError('generator_running', []);
+ }
}
function GeneratorObjectIterator() {
« no previous file with comments | « src/arm64/full-codegen-arm64.cc ('k') | src/ia32/full-codegen-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698