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

Side by Side Diff: src/runtime.cc

Issue 13704010: Generator objects can suspend (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: Tighten typing on generator object contexts Created 7 years, 8 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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 2276 matching lines...) Expand 10 before | Expand all | Expand 10 after
2287 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); 2287 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
2288 CONVERT_SMI_ARG_CHECKED(num, 1); 2288 CONVERT_SMI_ARG_CHECKED(num, 1);
2289 RUNTIME_ASSERT(num >= 0); 2289 RUNTIME_ASSERT(num >= 0);
2290 SetExpectedNofProperties(function, num); 2290 SetExpectedNofProperties(function, num);
2291 return isolate->heap()->undefined_value(); 2291 return isolate->heap()->undefined_value();
2292 } 2292 }
2293 2293
2294 2294
2295 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateJSGeneratorObject) { 2295 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateJSGeneratorObject) {
2296 NoHandleAllocation ha(isolate); 2296 NoHandleAllocation ha(isolate);
2297 ASSERT(args.length() == 0); 2297 ASSERT(args.length() == 0);
Michael Starzinger 2013/04/17 13:43:48 nit: Let's add an empty newline after the assert a
2298 JavaScriptFrameIterator it(isolate); 2298 JavaScriptFrameIterator it(isolate);
2299 JavaScriptFrame* frame = it.frame(); 2299 JavaScriptFrame* frame = it.frame();
2300 JSFunction* function = JSFunction::cast(frame->function()); 2300 JSFunction* function = JSFunction::cast(frame->function());
2301 RUNTIME_ASSERT(function->shared()->is_generator()); 2301 RUNTIME_ASSERT(function->shared()->is_generator());
2302 2302
2303 JSGeneratorObject* generator; 2303 JSGeneratorObject* generator;
2304 if (frame->IsConstructor()) { 2304 if (frame->IsConstructor()) {
2305 generator = JSGeneratorObject::cast(frame->receiver()); 2305 generator = JSGeneratorObject::cast(frame->receiver());
2306 } else { 2306 } else {
2307 MaybeObject* maybe_generator = 2307 MaybeObject* maybe_generator =
2308 isolate->heap()->AllocateJSGeneratorObject(function); 2308 isolate->heap()->AllocateJSGeneratorObject(function);
2309 if (!maybe_generator->To(&generator)) return maybe_generator; 2309 if (!maybe_generator->To(&generator)) return maybe_generator;
2310 } 2310 }
2311 generator->set_function(function); 2311 generator->set_function(function);
2312 generator->set_context(isolate->heap()->undefined_value()); 2312 generator->set_context(Context::cast(frame->context()));
2313 generator->set_continuation(0); 2313 generator->set_continuation(0);
2314 generator->set_operand_stack(isolate->heap()->empty_fixed_array()); 2314 generator->set_operand_stack(isolate->heap()->empty_fixed_array());
2315 2315
2316 return generator; 2316 return generator;
2317 } 2317 }
2318 2318
2319 2319
2320 RUNTIME_FUNCTION(MaybeObject*, Runtime_SuspendJSGeneratorObject) {
2321 HandleScope scope(isolate);
2322 ASSERT(args.length() == 1);
2323 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator_object, 0);
2324
2325 JavaScriptFrameIterator stack_iterator(isolate);
2326 JavaScriptFrame *frame = stack_iterator.frame();
2327 Handle<JSFunction> function(JSFunction::cast(frame->function()));
Michael Starzinger 2013/04/17 13:43:48 Let's play it safe for now and add the following h
2328
2329 intptr_t offset = frame->pc() - function->code()->instruction_start();
2330 ASSERT(*function == generator_object->function());
2331 ASSERT(offset >= 0 && Smi::IsValid(offset));
2332 generator_object->set_continuation(offset);
2333
2334 // Generator functions force context allocation for locals, so Local0 points
2335 // to the bottom of the operand stack. Assume the stack grows down.
2336 intptr_t stack_size_in_bytes =
2337 (frame->fp() + JavaScriptFrameConstants::kLocal0Offset) -
2338 (frame->sp() - kPointerSize);
Michael Starzinger 2013/04/17 13:43:48 Just for the record: This magic computation needs
2339 ASSERT(IsAddressAligned(frame->fp(), kPointerSize));
2340 ASSERT(IsAligned(stack_size_in_bytes, kPointerSize));
2341 ASSERT(stack_size_in_bytes >= 0);
2342 ASSERT(Smi::IsValid(stack_size_in_bytes));
2343 unsigned stack_size = stack_size_in_bytes >> kPointerSizeLog2;
2344
2345 // We expect there to be at least two values on the stack: the return value of
2346 // the yield expression, and the argument to this runtime call. Neither of
2347 // those should be saved.
2348 ASSERT(stack_size >= 2);
2349 stack_size -= 2;
2350
Michael Starzinger 2013/04/17 13:43:48 IIUC the current implementation relies and the con
Michael Starzinger 2013/04/17 13:49:02 That should have been "generator_object->context()
2351 if (stack_size == 0) {
2352 ASSERT(generator_object->operand_stack() ==
2353 isolate->heap()->empty_fixed_array());
2354 // If there are no operands on the stack, there shouldn't be a handler
2355 // active either. Also, the active context will be the same as the function
2356 // itself, so there is no need to save the context.
2357 ASSERT_EQ(frame->context(), generator_object->context());
2358 ASSERT(!frame->HasHandler());
2359 } else {
2360 generator_object->set_context(Context::cast(frame->context()));
2361 // Saving the operand stack or stack handlers is not currently implemented.
Michael Starzinger 2013/04/17 13:43:48 Let's turn this comment into a TODO.
2362 UNIMPLEMENTED();
2363 }
2364
2365 // The return value is the hole for a suspend return, and anything else for a
2366 // resume return.
2367 return *isolate->factory()->the_hole_value();
Michael Starzinger 2013/04/17 13:43:48 Use "isolate->heap()->the_hole_value()" here inste
2368 }
2369
2370
2320 MUST_USE_RESULT static MaybeObject* CharFromCode(Isolate* isolate, 2371 MUST_USE_RESULT static MaybeObject* CharFromCode(Isolate* isolate,
2321 Object* char_code) { 2372 Object* char_code) {
2322 uint32_t code; 2373 uint32_t code;
2323 if (char_code->ToArrayIndex(&code)) { 2374 if (char_code->ToArrayIndex(&code)) {
2324 if (code <= 0xffff) { 2375 if (code <= 0xffff) {
2325 return isolate->heap()->LookupSingleCharacterStringFromCode(code); 2376 return isolate->heap()->LookupSingleCharacterStringFromCode(code);
2326 } 2377 }
2327 } 2378 }
2328 return isolate->heap()->empty_string(); 2379 return isolate->heap()->empty_string();
2329 } 2380 }
(...skipping 10779 matching lines...) Expand 10 before | Expand all | Expand 10 after
13109 // Handle last resort GC and make sure to allow future allocations 13160 // Handle last resort GC and make sure to allow future allocations
13110 // to grow the heap without causing GCs (if possible). 13161 // to grow the heap without causing GCs (if possible).
13111 isolate->counters()->gc_last_resort_from_js()->Increment(); 13162 isolate->counters()->gc_last_resort_from_js()->Increment();
13112 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 13163 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
13113 "Runtime::PerformGC"); 13164 "Runtime::PerformGC");
13114 } 13165 }
13115 } 13166 }
13116 13167
13117 13168
13118 } } // namespace v8::internal 13169 } } // namespace v8::internal
OLDNEW
« src/parser.cc ('K') | « src/runtime.h ('k') | src/x64/full-codegen-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698