Reviewers: rossberg,
Message:
I looked into doing this in assembly, if there were a faster way, but no.
We
just have to turbofan %_GeneratorResume it seems.
Description:
Leaving a generator via an exception causes it to close
R=rossb...@chromium.org
BUG=v8:3096
LOG=Y
Please review this at https://codereview.chromium.org/717123002/
Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+25, -6 lines):
M src/generator.js
M src/runtime/runtime.h
M src/runtime/runtime-generator.cc
M test/mjsunit/es6/generators-iteration.js
Index: src/generator.js
diff --git a/src/generator.js b/src/generator.js
index
b35744a094f29ef0acd8baf3180bdfb7234a9084..49a1ed266cf173c9fe78a08ba058ad0015006cb3
100644
--- a/src/generator.js
+++ b/src/generator.js
@@ -21,7 +21,12 @@ function GeneratorObjectNext(value) {
}
if (DEBUG_IS_ACTIVE) %DebugPrepareStepInIfStepping(this);
- return %_GeneratorNext(this, value);
+ try {
+ return %_GeneratorNext(this, value);
+ } catch (e) {
+ %GeneratorClose(this);
+ throw e;
+ }
}
function GeneratorObjectThrow(exn) {
@@ -30,7 +35,12 @@ function GeneratorObjectThrow(exn) {
['[Generator].prototype.throw', this]);
}
- return %_GeneratorThrow(this, exn);
+ try {
+ return %_GeneratorThrow(this, exn);
+ } catch (e) {
+ %GeneratorClose(this);
+ throw e;
+ }
}
function GeneratorObjectIterator() {
Index: src/runtime/runtime-generator.cc
diff --git a/src/runtime/runtime-generator.cc
b/src/runtime/runtime-generator.cc
index
9c2add7413621f7253a4bc912ecf8b0a192ea1c7..071105f784c8b40618f960e79c9d04aced1d4ee1
100644
--- a/src/runtime/runtime-generator.cc
+++ b/src/runtime/runtime-generator.cc
@@ -135,6 +135,17 @@ RUNTIME_FUNCTION(Runtime_ResumeJSGeneratorObject) {
}
+RUNTIME_FUNCTION(Runtime_GeneratorClose) {
+ HandleScope scope(isolate);
+ DCHECK(args.length() == 1);
+ CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0);
+
+ generator->set_continuation(JSGeneratorObject::kGeneratorClosed);
+
+ return isolate->heap()->undefined_value();
+}
+
+
RUNTIME_FUNCTION(Runtime_ThrowGeneratorStateError) {
HandleScope scope(isolate);
DCHECK(args.length() == 1);
Index: src/runtime/runtime.h
diff --git a/src/runtime/runtime.h b/src/runtime/runtime.h
index
749c15f09950134bc05a07a6b918eb11afb89d7d..153d0f258fca8954ed1db980ca49ae8752a488d9
100644
--- a/src/runtime/runtime.h
+++ b/src/runtime/runtime.h
@@ -478,6 +478,7 @@ namespace internal {
F(SuspendJSGeneratorObject, 1, 1) \
F(ResumeJSGeneratorObject, 3, 1) \
F(ThrowGeneratorStateError, 1, 1) \
+ F(GeneratorClose, 1, 1) \
\
/* Arrays */ \
F(ArrayConstructor, -1, 1) \
Index: test/mjsunit/es6/generators-iteration.js
diff --git a/test/mjsunit/es6/generators-iteration.js
b/test/mjsunit/es6/generators-iteration.js
index
b6fcdaa48792d2d7b2d6fc7b486d746e9da8e99b..faeb68380fea4aa67a97ace057291d075e23a6c8
100644
--- a/test/mjsunit/es6/generators-iteration.js
+++ b/test/mjsunit/es6/generators-iteration.js
@@ -41,10 +41,7 @@ function assertIteratorIsClosed(iter) {
}
function assertThrownIteratorIsClosed(iter) {
- // TODO(yusukesuzuki): Since status of a thrown generator is "executing",
- // following tests are failed.
- // https://code.google.com/p/v8/issues/detail?id=3096
- // assertIteratorIsClosed(iter);
+ assertIteratorIsClosed(iter);
}
function TestGeneratorResultPrototype() {
--
--
v8-dev mailing list
v8-dev@googlegroups.com
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to v8-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.