LCOV - code coverage report
Current view: top level - src/runtime - runtime-generator.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 29 56 51.8 %
Date: 2017-10-20 Functions: 3 26 11.5 %

          Line data    Source code
       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
       3             : // found in the LICENSE file.
       4             : 
       5             : #include "src/runtime/runtime-utils.h"
       6             : 
       7             : #include "src/arguments.h"
       8             : #include "src/factory.h"
       9             : #include "src/objects-inl.h"
      10             : 
      11             : namespace v8 {
      12             : namespace internal {
      13             : 
      14       33645 : RUNTIME_FUNCTION(Runtime_CreateJSGeneratorObject) {
      15       11215 :   HandleScope scope(isolate);
      16             :   DCHECK_EQ(2, args.length());
      17       22430 :   CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
      18       11215 :   CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 1);
      19       11215 :   CHECK(IsResumableFunction(function->shared()->kind()));
      20             : 
      21             :   // Underlying function needs to have bytecode available.
      22             :   DCHECK(function->shared()->HasBytecodeArray());
      23       11215 :   int size = function->shared()->bytecode_array()->register_count();
      24       11215 :   Handle<FixedArray> register_file = isolate->factory()->NewFixedArray(size);
      25             : 
      26             :   Handle<JSGeneratorObject> generator =
      27       11215 :       isolate->factory()->NewJSGeneratorObject(function);
      28       11215 :   generator->set_function(*function);
      29       22430 :   generator->set_context(isolate->context());
      30       11215 :   generator->set_receiver(*receiver);
      31       11215 :   generator->set_register_file(*register_file);
      32       11215 :   generator->set_continuation(JSGeneratorObject::kGeneratorExecuting);
      33       11215 :   return *generator;
      34             : }
      35             : 
      36           0 : RUNTIME_FUNCTION(Runtime_GeneratorClose) {
      37             :   // Runtime call is implemented in InterpreterIntrinsics and lowered in
      38             :   // JSIntrinsicLowering
      39           0 :   UNREACHABLE();
      40             : }
      41             : 
      42        3456 : RUNTIME_FUNCTION(Runtime_GeneratorGetFunction) {
      43        1728 :   HandleScope scope(isolate);
      44             :   DCHECK_EQ(1, args.length());
      45        3456 :   CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0);
      46             : 
      47        1728 :   return generator->function();
      48             : }
      49             : 
      50           0 : RUNTIME_FUNCTION(Runtime_GeneratorGetReceiver) {
      51           0 :   HandleScope scope(isolate);
      52             :   DCHECK_EQ(1, args.length());
      53           0 :   CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0);
      54             : 
      55           0 :   return generator->receiver();
      56             : }
      57             : 
      58           0 : RUNTIME_FUNCTION(Runtime_GeneratorGetContext) {
      59             :   // Runtime call is implemented in InterpreterIntrinsics and lowered in
      60             :   // JSIntrinsicLowering
      61           0 :   UNREACHABLE();
      62             : }
      63             : 
      64           0 : RUNTIME_FUNCTION(Runtime_GeneratorGetInputOrDebugPos) {
      65             :   // Runtime call is implemented in InterpreterIntrinsics and lowered in
      66             :   // JSIntrinsicLowering
      67           0 :   UNREACHABLE();
      68             : }
      69             : 
      70           0 : RUNTIME_FUNCTION(Runtime_AsyncGeneratorResolve) {
      71             :   // Runtime call is implemented in InterpreterIntrinsics and lowered in
      72             :   // JSIntrinsicLowering
      73           0 :   UNREACHABLE();
      74             : }
      75             : 
      76           0 : RUNTIME_FUNCTION(Runtime_AsyncGeneratorReject) {
      77             :   // Runtime call is implemented in InterpreterIntrinsics and lowered in
      78             :   // JSIntrinsicLowering
      79           0 :   UNREACHABLE();
      80             : }
      81             : 
      82           0 : RUNTIME_FUNCTION(Runtime_AsyncGeneratorYield) {
      83             :   // Runtime call is implemented in InterpreterIntrinsics and lowered in
      84             :   // JSIntrinsicLowering
      85           0 :   UNREACHABLE();
      86             : }
      87             : 
      88           0 : RUNTIME_FUNCTION(Runtime_GeneratorGetResumeMode) {
      89             :   // Runtime call is implemented in InterpreterIntrinsics and lowered in
      90             :   // JSIntrinsicLowering
      91           0 :   UNREACHABLE();
      92             : }
      93             : 
      94           0 : RUNTIME_FUNCTION(Runtime_GeneratorGetContinuation) {
      95           0 :   HandleScope scope(isolate);
      96             :   DCHECK_EQ(1, args.length());
      97           0 :   CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0);
      98             : 
      99           0 :   return Smi::FromInt(generator->continuation());
     100             : }
     101             : 
     102           0 : RUNTIME_FUNCTION(Runtime_GeneratorGetSourcePosition) {
     103           0 :   HandleScope scope(isolate);
     104             :   DCHECK_EQ(1, args.length());
     105           0 :   CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0);
     106             : 
     107           0 :   if (!generator->is_suspended()) return isolate->heap()->undefined_value();
     108           0 :   return Smi::FromInt(generator->source_position());
     109             : }
     110             : 
     111             : // Return true if {generator}'s PC has a catch handler. This allows
     112             : // catch prediction to happen from the AsyncGeneratorResumeNext stub.
     113         432 : RUNTIME_FUNCTION(Runtime_AsyncGeneratorHasCatchHandlerForPC) {
     114         216 :   DisallowHeapAllocation no_allocation_scope;
     115             :   DCHECK_EQ(1, args.length());
     116             :   DCHECK(args[0]->IsJSAsyncGeneratorObject());
     117         216 :   JSAsyncGeneratorObject* generator = JSAsyncGeneratorObject::cast(args[0]);
     118             : 
     119         216 :   int state = generator->continuation();
     120             :   DCHECK_NE(state, JSAsyncGeneratorObject::kGeneratorExecuting);
     121             : 
     122             :   // If state is 0 ("suspendedStart"), there is guaranteed to be no catch
     123             :   // handler. Otherwise, if state is below 0, the generator is closed and will
     124             :   // not reach a catch handler.
     125         216 :   if (state < 1) return isolate->heap()->false_value();
     126             : 
     127          63 :   SharedFunctionInfo* shared = generator->function()->shared();
     128             :   DCHECK(shared->HasBytecodeArray());
     129             :   HandlerTable* handler_table =
     130          63 :       HandlerTable::cast(shared->bytecode_array()->handler_table());
     131             : 
     132          63 :   int pc = Smi::cast(generator->input_or_debug_pos())->value();
     133          63 :   HandlerTable::CatchPrediction catch_prediction = HandlerTable::ASYNC_AWAIT;
     134          63 :   handler_table->LookupRange(pc, nullptr, &catch_prediction);
     135          63 :   return isolate->heap()->ToBoolean(catch_prediction == HandlerTable::CAUGHT);
     136             : }
     137             : 
     138             : }  // namespace internal
     139             : }  // namespace v8

Generated by: LCOV version 1.10