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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 (function(global, utils) { 5 (function(global, utils) {
6 6
7 "use strict"; 7 "use strict";
8 8
9 %CheckIsBootstrapping(); 9 %CheckIsBootstrapping();
10 10
(...skipping 21 matching lines...) Expand all
32 '[Generator].prototype.next', this); 32 '[Generator].prototype.next', this);
33 } 33 }
34 34
35 var continuation = %GeneratorGetContinuation(this); 35 var continuation = %GeneratorGetContinuation(this);
36 if (continuation > 0) { 36 if (continuation > 0) {
37 // Generator is suspended. 37 // Generator is suspended.
38 DEBUG_PREPARE_STEP_IN_IF_STEPPING(this); 38 DEBUG_PREPARE_STEP_IN_IF_STEPPING(this);
39 return %_GeneratorNext(this, value); 39 return %_GeneratorNext(this, value);
40 } else if (continuation == 0) { 40 } else if (continuation == 0) {
41 // Generator is already closed. 41 // Generator is already closed.
42 return { value: void 0, done: true }; 42 return %_CreateIterResultObject(UNDEFINED, true);
43 } else { 43 } else {
44 // Generator is running. 44 // Generator is running.
45 throw MakeTypeError(kGeneratorRunning); 45 throw MakeTypeError(kGeneratorRunning);
46 }
47 }
48
49
50 function GeneratorObjectReturn(value) {
51 if (!IS_GENERATOR(this)) {
52 throw MakeTypeError(kIncompatibleMethodReceiver,
53 '[Generator].prototype.return', this);
54 }
55
56 var continuation = %GeneratorGetContinuation(this);
57 if (continuation > 0) {
58 // Generator is suspended.
59 DEBUG_PREPARE_STEP_IN_IF_STEPPING(this);
60 return %_GeneratorReturn(this, value);
61 } else if (continuation == 0) {
62 // Generator is already closed.
63 return %_CreateIterResultObject(value, true);
64 } else {
65 // Generator is running.
66 throw MakeTypeError(kGeneratorRunning);
46 } 67 }
47 } 68 }
48 69
49 70
50 function GeneratorObjectThrow(exn) { 71 function GeneratorObjectThrow(exn) {
51 if (!IS_GENERATOR(this)) { 72 if (!IS_GENERATOR(this)) {
52 throw MakeTypeError(kIncompatibleMethodReceiver, 73 throw MakeTypeError(kIncompatibleMethodReceiver,
53 '[Generator].prototype.throw', this); 74 '[Generator].prototype.throw', this);
54 } 75 }
55 76
56 var continuation = %GeneratorGetContinuation(this); 77 var continuation = %GeneratorGetContinuation(this);
57 if (continuation > 0) { 78 if (continuation > 0) {
58 // Generator is suspended. 79 // Generator is suspended.
80 DEBUG_PREPARE_STEP_IN_IF_STEPPING(this);
59 return %_GeneratorThrow(this, exn); 81 return %_GeneratorThrow(this, exn);
60 } else if (continuation == 0) { 82 } else if (continuation == 0) {
61 // Generator is already closed. 83 // Generator is already closed.
62 throw exn; 84 throw exn;
63 } else { 85 } else {
64 // Generator is running. 86 // Generator is running.
65 throw MakeTypeError(kGeneratorRunning); 87 throw MakeTypeError(kGeneratorRunning);
66 } 88 }
67 } 89 }
68 90
69 // ---------------------------------------------------------------------------- 91 // ----------------------------------------------------------------------------
70 92
71 // Both Runtime_GeneratorNext and Runtime_GeneratorThrow are supported by 93 // None of the three resume operations (Runtime_GeneratorNext,
72 // neither Crankshaft nor TurboFan, disable optimization of wrappers here. 94 // Runtime_GeneratorReturn, Runtime_GeneratorThrow) is supported by
95 // Crankshaft or TurboFan. Disable optimization of wrappers here.
73 %NeverOptimizeFunction(GeneratorObjectNext); 96 %NeverOptimizeFunction(GeneratorObjectNext);
97 %NeverOptimizeFunction(GeneratorObjectReturn);
74 %NeverOptimizeFunction(GeneratorObjectThrow); 98 %NeverOptimizeFunction(GeneratorObjectThrow);
75 99
76 // Set up non-enumerable functions on the generator prototype object. 100 // Set up non-enumerable functions on the generator prototype object.
77 var GeneratorObjectPrototype = GeneratorFunctionPrototype.prototype; 101 var GeneratorObjectPrototype = GeneratorFunctionPrototype.prototype;
78 utils.InstallFunctions(GeneratorObjectPrototype, 102 utils.InstallFunctions(GeneratorObjectPrototype,
79 DONT_ENUM, 103 DONT_ENUM,
80 ["next", GeneratorObjectNext, 104 ["next", GeneratorObjectNext,
105 "return", GeneratorObjectReturn,
81 "throw", GeneratorObjectThrow]); 106 "throw", GeneratorObjectThrow]);
82 107
83 %AddNamedProperty(GeneratorObjectPrototype, "constructor", 108 %AddNamedProperty(GeneratorObjectPrototype, "constructor",
84 GeneratorFunctionPrototype, DONT_ENUM | READ_ONLY); 109 GeneratorFunctionPrototype, DONT_ENUM | READ_ONLY);
85 %AddNamedProperty(GeneratorObjectPrototype, 110 %AddNamedProperty(GeneratorObjectPrototype,
86 toStringTagSymbol, "Generator", DONT_ENUM | READ_ONLY); 111 toStringTagSymbol, "Generator", DONT_ENUM | READ_ONLY);
87 %InternalSetPrototype(GeneratorFunctionPrototype, GlobalFunction.prototype); 112 %InternalSetPrototype(GeneratorFunctionPrototype, GlobalFunction.prototype);
88 %AddNamedProperty(GeneratorFunctionPrototype, 113 %AddNamedProperty(GeneratorFunctionPrototype,
89 toStringTagSymbol, "GeneratorFunction", DONT_ENUM | READ_ONLY); 114 toStringTagSymbol, "GeneratorFunction", DONT_ENUM | READ_ONLY);
90 %AddNamedProperty(GeneratorFunctionPrototype, "constructor", 115 %AddNamedProperty(GeneratorFunctionPrototype, "constructor",
91 GeneratorFunction, DONT_ENUM | READ_ONLY); 116 GeneratorFunction, DONT_ENUM | READ_ONLY);
92 %InternalSetPrototype(GeneratorFunction, GlobalFunction); 117 %InternalSetPrototype(GeneratorFunction, GlobalFunction);
93 118
94 }) 119 })
OLDNEW
« 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