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

Unified Diff: src/js/generator.js

Issue 1639343005: [generators] Implement Generator.prototype.return. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@yield-star
Patch Set: Another rebase Created 4 years, 10 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 63ec99ee4bf4f04874ad58a277b8984972a4b0cd..3dcdcc0ffa1aeafee85384f345a4c4bd5587fefa 100644
--- a/src/js/generator.js
+++ b/src/js/generator.js
@@ -39,7 +39,28 @@ function GeneratorObjectNext(value) {
return %_GeneratorNext(this, value);
} 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);
+ return %_GeneratorReturn(this, value);
+ } else if (continuation == 0) {
+ // Generator is already closed.
+ return %_CreateIterResultObject(value, true);
} else {
// Generator is running.
throw MakeTypeError(kGeneratorRunning);
@@ -56,6 +77,7 @@ function GeneratorObjectThrow(exn) {
var continuation = %GeneratorGetContinuation(this);
if (continuation > 0) {
// Generator is suspended.
+ DEBUG_PREPARE_STEP_IN_IF_STEPPING(this);
return %_GeneratorThrow(this, exn);
} else if (continuation == 0) {
// Generator is already closed.
@@ -68,9 +90,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.
@@ -78,6 +102,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