LCOV - code coverage report
Current view: top level - src - isolate-inl.h (source / functions) Hit Total Coverage
Test: app.info Lines: 78 78 100.0 %
Date: 2019-01-20 Functions: 112 114 98.2 %

          Line data    Source code
       1             : // Copyright 2015 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             : #ifndef V8_ISOLATE_INL_H_
       6             : #define V8_ISOLATE_INL_H_
       7             : 
       8             : #include "src/heap/heap-inl.h"  // Need MemoryChunk from heap/spaces.h
       9             : #include "src/isolate.h"
      10             : #include "src/objects-inl.h"
      11             : #include "src/objects/cell-inl.h"
      12             : #include "src/objects/regexp-match-info.h"
      13             : 
      14             : namespace v8 {
      15             : namespace internal {
      16             : 
      17             : IsolateAllocationMode Isolate::isolate_allocation_mode() {
      18           4 :   return isolate_allocator_->mode();
      19             : }
      20             : 
      21       76418 : bool Isolate::FromWritableHeapObject(HeapObject obj, Isolate** isolate) {
      22       16251 :   i::MemoryChunk* chunk = i::MemoryChunk::FromHeapObject(obj);
      23       76418 :   if (chunk->owner()->identity() == i::RO_SPACE) {
      24       60167 :     *isolate = nullptr;
      25       60167 :     return false;
      26             :   }
      27       16251 :   *isolate = chunk->heap()->isolate();
      28       16251 :   return true;
      29             : }
      30             : 
      31     1557589 : void Isolate::set_context(Context context) {
      32             :   DCHECK(context.is_null() || context->IsContext());
      33    35264747 :   thread_local_top_.context_ = context;
      34     1557589 : }
      35             : 
      36    23091054 : Handle<NativeContext> Isolate::native_context() {
      37    46182138 :   return handle(context()->native_context(), this);
      38             : }
      39             : 
      40             : NativeContext Isolate::raw_native_context() {
      41    35728179 :   return context()->native_context();
      42             : }
      43             : 
      44             : Object Isolate::pending_exception() {
      45             :   DCHECK(has_pending_exception());
      46             :   DCHECK(!thread_local_top_.pending_exception_->IsException(this));
      47             :   return thread_local_top_.pending_exception_;
      48             : }
      49             : 
      50          33 : void Isolate::set_pending_exception(Object exception_obj) {
      51             :   DCHECK(!exception_obj->IsException(this));
      52     1540442 :   thread_local_top_.pending_exception_ = exception_obj;
      53          33 : }
      54             : 
      55     1736910 : void Isolate::clear_pending_exception() {
      56             :   DCHECK(!thread_local_top_.pending_exception_->IsException(this));
      57     1736910 :   thread_local_top_.pending_exception_ = ReadOnlyRoots(this).the_hole_value();
      58     1736910 : }
      59             : 
      60             : 
      61    32646972 : bool Isolate::has_pending_exception() {
      62             :   DCHECK(!thread_local_top_.pending_exception_->IsException(this));
      63    65293951 :   return !thread_local_top_.pending_exception_->IsTheHole(this);
      64             : }
      65             : 
      66             : 
      67    24035095 : void Isolate::clear_pending_message() {
      68             :   thread_local_top_.pending_message_obj_ = ReadOnlyRoots(this).the_hole_value();
      69    24035092 : }
      70             : 
      71             : Object Isolate::scheduled_exception() {
      72             :   DCHECK(has_scheduled_exception());
      73             :   DCHECK(!thread_local_top_.scheduled_exception_->IsException(this));
      74             :   return thread_local_top_.scheduled_exception_;
      75             : }
      76             : 
      77    41763014 : bool Isolate::has_scheduled_exception() {
      78             :   DCHECK(!thread_local_top_.scheduled_exception_->IsException(this));
      79             :   return thread_local_top_.scheduled_exception_ !=
      80    41763050 :          ReadOnlyRoots(this).the_hole_value();
      81             : }
      82             : 
      83             : 
      84      119818 : void Isolate::clear_scheduled_exception() {
      85             :   DCHECK(!thread_local_top_.scheduled_exception_->IsException(this));
      86      119818 :   thread_local_top_.scheduled_exception_ = ReadOnlyRoots(this).the_hole_value();
      87      119818 : }
      88             : 
      89     2973909 : bool Isolate::is_catchable_by_javascript(Object exception) {
      90     5947818 :   return exception != ReadOnlyRoots(heap()).termination_exception();
      91             : }
      92             : 
      93             : void Isolate::FireBeforeCallEnteredCallback() {
      94     5407140 :   for (auto& callback : before_call_entered_callbacks_) {
      95          80 :     callback(reinterpret_cast<v8::Isolate*>(this));
      96             :   }
      97             : }
      98             : 
      99     9108760 : Handle<JSGlobalObject> Isolate::global_object() {
     100    18217497 :   return handle(context()->global_object(), this);
     101             : }
     102             : 
     103      271987 : Handle<JSObject> Isolate::global_proxy() {
     104      543974 :   return handle(context()->global_proxy(), this);
     105             : }
     106             : 
     107             : 
     108        7164 : Isolate::ExceptionScope::ExceptionScope(Isolate* isolate)
     109             :     : isolate_(isolate),
     110       14328 :       pending_exception_(isolate_->pending_exception(), isolate_) {}
     111             : 
     112             : 
     113             : Isolate::ExceptionScope::~ExceptionScope() {
     114        7164 :   isolate_->set_pending_exception(*pending_exception_);
     115             : }
     116             : 
     117             : #define NATIVE_CONTEXT_FIELD_ACCESSOR(index, type, name)     \
     118             :   Handle<type> Isolate::name() {                             \
     119             :     return Handle<type>(raw_native_context()->name(), this); \
     120             :   }                                                          \
     121             :   bool Isolate::is_##name(type value) {                      \
     122             :     return raw_native_context()->is_##name(value);           \
     123             :   }
     124    95062605 : NATIVE_CONTEXT_FIELDS(NATIVE_CONTEXT_FIELD_ACCESSOR)
     125             : #undef NATIVE_CONTEXT_FIELD_ACCESSOR
     126             : 
     127        2137 : bool Isolate::IsArrayConstructorIntact() {
     128        2137 :   Cell array_constructor_cell = heap()->array_constructor_protector();
     129        4274 :   return array_constructor_cell->value() == Smi::FromInt(kProtectorValid);
     130             : }
     131             : 
     132      425915 : bool Isolate::IsArraySpeciesLookupChainIntact() {
     133             :   // Note: It would be nice to have debug checks to make sure that the
     134             :   // species protector is accurate, but this would be hard to do for most of
     135             :   // what the protector stands for:
     136             :   // - You'd need to traverse the heap to check that no Array instance has
     137             :   //   a constructor property
     138             :   // - To check that Array[Symbol.species] == Array, JS code has to execute,
     139             :   //   but JS cannot be invoked in callstack overflow situations
     140             :   // All that could be checked reliably is that
     141             :   // Array.prototype.constructor == Array. Given that limitation, no check is
     142             :   // done here. In place, there are mjsunit tests harmony/array-species* which
     143             :   // ensure that behavior is correct in various invalid protector cases.
     144             : 
     145      425915 :   PropertyCell species_cell = heap()->array_species_protector();
     146     1277745 :   return species_cell->value()->IsSmi() &&
     147      851830 :          Smi::ToInt(species_cell->value()) == kProtectorValid;
     148             : }
     149             : 
     150        6406 : bool Isolate::IsTypedArraySpeciesLookupChainIntact() {
     151        6406 :   PropertyCell species_cell = heap()->typed_array_species_protector();
     152       19218 :   return species_cell->value()->IsSmi() &&
     153       12812 :          Smi::ToInt(species_cell->value()) == kProtectorValid;
     154             : }
     155             : 
     156       10817 : bool Isolate::IsRegExpSpeciesLookupChainIntact() {
     157       10817 :   PropertyCell species_cell = heap()->regexp_species_protector();
     158       32451 :   return species_cell->value()->IsSmi() &&
     159       21634 :          Smi::ToInt(species_cell->value()) == kProtectorValid;
     160             : }
     161             : 
     162       11770 : bool Isolate::IsPromiseSpeciesLookupChainIntact() {
     163       11770 :   PropertyCell species_cell = heap()->promise_species_protector();
     164       35310 :   return species_cell->value()->IsSmi() &&
     165       23540 :          Smi::ToInt(species_cell->value()) == kProtectorValid;
     166             : }
     167             : 
     168         471 : bool Isolate::IsStringLengthOverflowIntact() {
     169         471 :   Cell string_length_cell = heap()->string_length_protector();
     170         942 :   return string_length_cell->value() == Smi::FromInt(kProtectorValid);
     171             : }
     172             : 
     173       12924 : bool Isolate::IsArrayBufferDetachingIntact() {
     174       12924 :   PropertyCell buffer_detaching = heap()->array_buffer_detaching_protector();
     175       25848 :   return buffer_detaching->value() == Smi::FromInt(kProtectorValid);
     176             : }
     177             : 
     178        3490 : bool Isolate::IsArrayIteratorLookupChainIntact() {
     179        3490 :   PropertyCell array_iterator_cell = heap()->array_iterator_protector();
     180        6980 :   return array_iterator_cell->value() == Smi::FromInt(kProtectorValid);
     181             : }
     182             : 
     183         280 : bool Isolate::IsMapIteratorLookupChainIntact() {
     184         280 :   PropertyCell map_iterator_cell = heap()->map_iterator_protector();
     185         560 :   return map_iterator_cell->value() == Smi::FromInt(kProtectorValid);
     186             : }
     187             : 
     188         295 : bool Isolate::IsSetIteratorLookupChainIntact() {
     189         295 :   PropertyCell set_iterator_cell = heap()->set_iterator_protector();
     190         590 :   return set_iterator_cell->value() == Smi::FromInt(kProtectorValid);
     191             : }
     192             : 
     193         133 : bool Isolate::IsStringIteratorLookupChainIntact() {
     194         133 :   PropertyCell string_iterator_cell = heap()->string_iterator_protector();
     195         266 :   return string_iterator_cell->value() == Smi::FromInt(kProtectorValid);
     196             : }
     197             : 
     198             : }  // namespace internal
     199             : }  // namespace v8
     200             : 
     201             : #endif  // V8_ISOLATE_INL_H_

Generated by: LCOV version 1.10