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

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

Issue 1895603002: [esnext] prototype runtime implementation for async functions (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@AsyncFunction
Patch Set: fix some nits Created 4 years, 7 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/parsing/preparser.cc ('k') | src/v8.gyp » ('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 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"
11 11
12 namespace v8 { 12 namespace v8 {
13 namespace internal { 13 namespace internal {
14 14
15 RUNTIME_FUNCTION(Runtime_CreateJSGeneratorObject) { 15 RUNTIME_FUNCTION(Runtime_CreateJSGeneratorObject) {
16 HandleScope scope(isolate); 16 HandleScope scope(isolate);
17 DCHECK(args.length() == 2); 17 DCHECK(args.length() == 2);
18 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); 18 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
19 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 1); 19 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 1);
20 RUNTIME_ASSERT(function->shared()->is_generator()); 20 RUNTIME_ASSERT(function->shared()->is_resumable());
21 21
22 Handle<FixedArray> operand_stack; 22 Handle<FixedArray> operand_stack;
23 if (FLAG_ignition && FLAG_ignition_generators) { 23 if (FLAG_ignition && FLAG_ignition_generators) {
24 int size = function->shared()->bytecode_array()->register_count(); 24 int size = function->shared()->bytecode_array()->register_count();
25 operand_stack = isolate->factory()->NewFixedArray(size); 25 operand_stack = isolate->factory()->NewFixedArray(size);
26 } else { 26 } else {
27 DCHECK(!function->shared()->HasBytecodeArray()); 27 DCHECK(!function->shared()->HasBytecodeArray());
28 operand_stack = handle(isolate->heap()->empty_fixed_array()); 28 operand_stack = handle(isolate->heap()->empty_fixed_array());
29 } 29 }
30 30
31 Handle<JSGeneratorObject> generator = 31 Handle<JSGeneratorObject> generator =
32 isolate->factory()->NewJSGeneratorObject(function); 32 isolate->factory()->NewJSGeneratorObject(function);
33 generator->set_function(*function); 33 generator->set_function(*function);
34 generator->set_context(isolate->context()); 34 generator->set_context(isolate->context());
35 generator->set_receiver(*receiver); 35 generator->set_receiver(*receiver);
36 generator->set_operand_stack(*operand_stack); 36 generator->set_operand_stack(*operand_stack);
37 generator->set_continuation(JSGeneratorObject::kGeneratorExecuting); 37 generator->set_continuation(JSGeneratorObject::kGeneratorExecuting);
38 return *generator; 38 return *generator;
39 } 39 }
40 40
41 41
42 RUNTIME_FUNCTION(Runtime_SuspendJSGeneratorObject) { 42 RUNTIME_FUNCTION(Runtime_SuspendJSGeneratorObject) {
43 HandleScope handle_scope(isolate); 43 HandleScope handle_scope(isolate);
44 DCHECK(args.length() == 1); 44 DCHECK(args.length() == 1);
45 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator_object, 0); 45 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator_object, 0);
46 46
47 JavaScriptFrameIterator stack_iterator(isolate); 47 JavaScriptFrameIterator stack_iterator(isolate);
48 JavaScriptFrame* frame = stack_iterator.frame(); 48 JavaScriptFrame* frame = stack_iterator.frame();
49 RUNTIME_ASSERT(frame->function()->shared()->is_generator()); 49 RUNTIME_ASSERT(frame->function()->shared()->is_resumable());
50 DCHECK_EQ(frame->function(), generator_object->function()); 50 DCHECK_EQ(frame->function(), generator_object->function());
51 DCHECK(frame->function()->shared()->is_compiled()); 51 DCHECK(frame->function()->shared()->is_compiled());
52 DCHECK(!frame->function()->IsOptimized()); 52 DCHECK(!frame->function()->IsOptimized());
53 53
54 // The caller should have saved the context and continuation already. 54 // The caller should have saved the context and continuation already.
55 DCHECK_EQ(generator_object->context(), Context::cast(frame->context())); 55 DCHECK_EQ(generator_object->context(), Context::cast(frame->context()));
56 DCHECK_LT(0, generator_object->continuation()); 56 DCHECK_LT(0, generator_object->continuation());
57 57
58 // We expect there to be at least two values on the operand stack: the return 58 // We expect there to be at least two values on the operand stack: the return
59 // value of the yield expression, and the arguments to this runtime call. 59 // value of the yield expression, and the arguments to this runtime call.
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 int offset = generator->continuation(); 197 int offset = generator->continuation();
198 RUNTIME_ASSERT(0 <= offset && offset < code->instruction_size()); 198 RUNTIME_ASSERT(0 <= offset && offset < code->instruction_size());
199 return Smi::FromInt(code->SourcePosition(offset)); 199 return Smi::FromInt(code->SourcePosition(offset));
200 } 200 }
201 201
202 return isolate->heap()->undefined_value(); 202 return isolate->heap()->undefined_value();
203 } 203 }
204 204
205 } // namespace internal 205 } // namespace internal
206 } // namespace v8 206 } // namespace v8
OLDNEW
« no previous file with comments | « src/parsing/preparser.cc ('k') | src/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698