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

Side by Side Diff: src/runtime/runtime-generator.cc

Issue 1606273002: Implement [Generator].prototype.return. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix bug in old code; add more tests 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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 #include "src/runtime/runtime-utils.h" 5 #include "src/runtime/runtime-utils.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/factory.h" 8 #include "src/factory.h"
9 #include "src/frames-inl.h" 9 #include "src/frames-inl.h"
10 #include "src/objects-inl.h" 10 #include "src/objects-inl.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 } 80 }
81 81
82 return isolate->heap()->undefined_value(); 82 return isolate->heap()->undefined_value();
83 } 83 }
84 84
85 85
86 // Note that this function is the slow path for resuming generators. It is only 86 // Note that this function is the slow path for resuming generators. It is only
87 // called if the suspended activation had operands on the stack, stack handlers 87 // called if the suspended activation had operands on the stack, stack handlers
88 // needing rewinding, or if the resume should throw an exception. The fast path 88 // needing rewinding, or if the resume should throw an exception. The fast path
89 // is handled directly in FullCodeGenerator::EmitGeneratorResume(), which is 89 // is handled directly in FullCodeGenerator::EmitGeneratorResume(), which is
90 // inlined into GeneratorNext and GeneratorThrow. EmitGeneratorResumeResume is 90 // inlined into GeneratorNext, GeneratorReturn, and GeneratorThrow.
91 // called in any case, as it needs to reconstruct the stack frame and make space 91 // EmitGeneratorResume is called in any case, as it needs to reconstruct the
92 // for arguments and operands. 92 // stack frame and make space for arguments and operands.
93 RUNTIME_FUNCTION(Runtime_ResumeJSGeneratorObject) { 93 RUNTIME_FUNCTION(Runtime_ResumeJSGeneratorObject) {
94 SealHandleScope shs(isolate); 94 SealHandleScope shs(isolate);
95 DCHECK(args.length() == 3); 95 DCHECK(args.length() == 3);
96 CONVERT_ARG_CHECKED(JSGeneratorObject, generator_object, 0); 96 CONVERT_ARG_CHECKED(JSGeneratorObject, generator_object, 0);
97 CONVERT_ARG_CHECKED(Object, value, 1); 97 CONVERT_ARG_CHECKED(Object, value, 1);
98 CONVERT_SMI_ARG_CHECKED(resume_mode_int, 2); 98 CONVERT_SMI_ARG_CHECKED(resume_mode_int, 2);
99 JavaScriptFrameIterator stack_iterator(isolate); 99 JavaScriptFrameIterator stack_iterator(isolate);
100 JavaScriptFrame* frame = stack_iterator.frame(); 100 JavaScriptFrame* frame = stack_iterator.frame();
101 101
102 DCHECK_EQ(frame->function(), generator_object->function()); 102 DCHECK_EQ(frame->function(), generator_object->function());
(...skipping 15 matching lines...) Expand all
118 FixedArray* operand_stack = generator_object->operand_stack(); 118 FixedArray* operand_stack = generator_object->operand_stack();
119 int operands_count = operand_stack->length(); 119 int operands_count = operand_stack->length();
120 if (operands_count != 0) { 120 if (operands_count != 0) {
121 frame->RestoreOperandStack(operand_stack); 121 frame->RestoreOperandStack(operand_stack);
122 generator_object->set_operand_stack(isolate->heap()->empty_fixed_array()); 122 generator_object->set_operand_stack(isolate->heap()->empty_fixed_array());
123 } 123 }
124 124
125 JSGeneratorObject::ResumeMode resume_mode = 125 JSGeneratorObject::ResumeMode resume_mode =
126 static_cast<JSGeneratorObject::ResumeMode>(resume_mode_int); 126 static_cast<JSGeneratorObject::ResumeMode>(resume_mode_int);
127 switch (resume_mode) { 127 switch (resume_mode) {
128 // Note: this looks like NEXT and RETURN are the same but RETURN receives
129 // special treatment in the generator code (to which we return here).
128 case JSGeneratorObject::NEXT: 130 case JSGeneratorObject::NEXT:
131 case JSGeneratorObject::RETURN:
129 return value; 132 return value;
130 case JSGeneratorObject::THROW: 133 case JSGeneratorObject::THROW:
131 return isolate->Throw(value); 134 return isolate->Throw(value);
132 } 135 }
133 136
134 UNREACHABLE(); 137 UNREACHABLE();
135 return isolate->ThrowIllegalOperation(); 138 return isolate->ThrowIllegalOperation();
136 } 139 }
137 140
138 141
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 RUNTIME_ASSERT(0 <= offset && offset < code->Size()); 202 RUNTIME_ASSERT(0 <= offset && offset < code->Size());
200 Address pc = code->address() + offset; 203 Address pc = code->address() + offset;
201 204
202 return Smi::FromInt(code->SourcePosition(pc)); 205 return Smi::FromInt(code->SourcePosition(pc));
203 } 206 }
204 207
205 return isolate->heap()->undefined_value(); 208 return isolate->heap()->undefined_value();
206 } 209 }
207 210
208 211
212 // Optimization for the following three functions is disabled in
213 // js/generator.js and compiler/ast-graph-builder.cc.
214
215
209 RUNTIME_FUNCTION(Runtime_GeneratorNext) { 216 RUNTIME_FUNCTION(Runtime_GeneratorNext) {
210 UNREACHABLE(); // Optimization disabled in SetUpGenerators(). 217 UNREACHABLE();
218 return NULL;
Jarin 2016/01/22 13:42:48 NULL -> nullptr.
219 }
220
221
222 RUNTIME_FUNCTION(Runtime_GeneratorReturn) {
223 UNREACHABLE();
211 return NULL; 224 return NULL;
212 } 225 }
213 226
214 227
215 RUNTIME_FUNCTION(Runtime_GeneratorThrow) { 228 RUNTIME_FUNCTION(Runtime_GeneratorThrow) {
216 UNREACHABLE(); // Optimization disabled in SetUpGenerators(). 229 UNREACHABLE();
217 return NULL; 230 return NULL;
218 } 231 }
219 } // namespace internal 232 } // namespace internal
220 } // namespace v8 233 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698