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

Unified Diff: src/js/generator.js

Issue 1606273002: Implement [Generator].prototype.return. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Port changes to other architectures. Created 4 years, 11 months 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/full-codegen/x64/full-codegen-x64.cc ('k') | src/objects.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/js/generator.js
diff --git a/src/js/generator.js b/src/js/generator.js
index 7f43656ebcf5c1fb4cfb5eca311e8381082f5c33..6aad8e1624e7abe9b9fa687d497b2e25e1ce87dc 100644
--- a/src/js/generator.js
+++ b/src/js/generator.js
@@ -37,14 +37,44 @@ function GeneratorObjectNext(value) {
// Generator is suspended.
DEBUG_PREPARE_STEP_IN_IF_STEPPING(this);
try {
- return %_GeneratorNext(this, value);
+ let result = %_GeneratorNext(this, value);
+ if (result.done) %GeneratorClose(this);
+ return result;
} catch (e) {
%GeneratorClose(this);
throw e;
}
} else if (continuation == 0) {
// Generator is already closed.
- return { value: void 0, done: true };
+ return %_CreateIterResultObject(UNDEFINED, true);
+ } else {
+ // Generator is running.
+ throw MakeTypeError(kGeneratorRunning);
+ }
+}
+
+
+function GeneratorObjectReturn(value) {
+ if (!IS_GENERATOR(this)) {
+ throw MakeTypeError(kIncompatibleMethodReceiver,
+ '[Generator].prototype.return', this);
+ }
+
+ var continuation = %GeneratorGetContinuation(this);
+ if (continuation > 0) {
+ // Generator is suspended.
+ DEBUG_PREPARE_STEP_IN_IF_STEPPING(this);
+ try {
+ let result = %_GeneratorReturn(this, value);
+ if (result.done) %GeneratorClose(this);
+ return result;
+ } catch (e) {
+ %GeneratorClose(this);
+ throw e;
+ }
+ } else if (continuation == 0) {
+ // Generator is already closed.
+ return %_CreateIterResultObject(value, true);
} else {
// Generator is running.
throw MakeTypeError(kGeneratorRunning);
@@ -62,7 +92,9 @@ function GeneratorObjectThrow(exn) {
if (continuation > 0) {
// Generator is suspended.
try {
- return %_GeneratorThrow(this, exn);
+ let result = %_GeneratorThrow(this, exn);
+ if (result.done) %GeneratorClose(this);
+ return result;
} catch (e) {
%GeneratorClose(this);
throw e;
@@ -78,9 +110,11 @@ function GeneratorObjectThrow(exn) {
// ----------------------------------------------------------------------------
-// Both Runtime_GeneratorNext and Runtime_GeneratorThrow are supported by
-// neither Crankshaft nor TurboFan, disable optimization of wrappers here.
+// None of the three resume operations (Runtime_GeneratorNext,
+// Runtime_GeneratorReturn, Runtime_GeneratorThrow) is supported by
+// Crankshaft or TurboFan. Disable optimization of wrappers here.
%NeverOptimizeFunction(GeneratorObjectNext);
+%NeverOptimizeFunction(GeneratorObjectReturn);
%NeverOptimizeFunction(GeneratorObjectThrow);
// Set up non-enumerable functions on the generator prototype object.
@@ -88,6 +122,7 @@ var GeneratorObjectPrototype = GeneratorFunctionPrototype.prototype;
utils.InstallFunctions(GeneratorObjectPrototype,
DONT_ENUM,
["next", GeneratorObjectNext,
+ "return", GeneratorObjectReturn,
"throw", GeneratorObjectThrow]);
%AddNamedProperty(GeneratorObjectPrototype, "constructor",
« no previous file with comments | « src/full-codegen/x64/full-codegen-x64.cc ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698