• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/isolate.h"
9 #include "src/objects-inl.h"
10 
11 namespace v8 {
12 namespace internal {
13 
14 
set_context(Context * context)15 void Isolate::set_context(Context* context) {
16   DCHECK(context == NULL || context->IsContext());
17   thread_local_top_.context_ = context;
18 }
19 
native_context()20 Handle<Context> Isolate::native_context() {
21   return handle(context()->native_context(), this);
22 }
23 
raw_native_context()24 Context* Isolate::raw_native_context() { return context()->native_context(); }
25 
pending_exception()26 Object* Isolate::pending_exception() {
27   DCHECK(has_pending_exception());
28   DCHECK(!thread_local_top_.pending_exception_->IsException(this));
29   return thread_local_top_.pending_exception_;
30 }
31 
32 
set_pending_exception(Object * exception_obj)33 void Isolate::set_pending_exception(Object* exception_obj) {
34   DCHECK(!exception_obj->IsException(this));
35   thread_local_top_.pending_exception_ = exception_obj;
36 }
37 
38 
clear_pending_exception()39 void Isolate::clear_pending_exception() {
40   DCHECK(!thread_local_top_.pending_exception_->IsException(this));
41   thread_local_top_.pending_exception_ = heap_.the_hole_value();
42 }
43 
44 
has_pending_exception()45 bool Isolate::has_pending_exception() {
46   DCHECK(!thread_local_top_.pending_exception_->IsException(this));
47   return !thread_local_top_.pending_exception_->IsTheHole(this);
48 }
49 
50 
clear_pending_message()51 void Isolate::clear_pending_message() {
52   thread_local_top_.pending_message_obj_ = heap_.the_hole_value();
53 }
54 
55 
scheduled_exception()56 Object* Isolate::scheduled_exception() {
57   DCHECK(has_scheduled_exception());
58   DCHECK(!thread_local_top_.scheduled_exception_->IsException(this));
59   return thread_local_top_.scheduled_exception_;
60 }
61 
62 
has_scheduled_exception()63 bool Isolate::has_scheduled_exception() {
64   DCHECK(!thread_local_top_.scheduled_exception_->IsException(this));
65   return thread_local_top_.scheduled_exception_ != heap_.the_hole_value();
66 }
67 
68 
clear_scheduled_exception()69 void Isolate::clear_scheduled_exception() {
70   DCHECK(!thread_local_top_.scheduled_exception_->IsException(this));
71   thread_local_top_.scheduled_exception_ = heap_.the_hole_value();
72 }
73 
74 
is_catchable_by_javascript(Object * exception)75 bool Isolate::is_catchable_by_javascript(Object* exception) {
76   return exception != heap()->termination_exception();
77 }
78 
is_catchable_by_wasm(Object * exception)79 bool Isolate::is_catchable_by_wasm(Object* exception) {
80   return is_catchable_by_javascript(exception) &&
81          (exception->IsNumber() || exception->IsSmi());
82 }
83 
FireBeforeCallEnteredCallback()84 void Isolate::FireBeforeCallEnteredCallback() {
85   for (int i = 0; i < before_call_entered_callbacks_.length(); i++) {
86     before_call_entered_callbacks_.at(i)(reinterpret_cast<v8::Isolate*>(this));
87   }
88 }
89 
global_object()90 Handle<JSGlobalObject> Isolate::global_object() {
91   return handle(context()->global_object(), this);
92 }
93 
global_proxy()94 Handle<JSObject> Isolate::global_proxy() {
95   return handle(context()->global_proxy(), this);
96 }
97 
98 
ExceptionScope(Isolate * isolate)99 Isolate::ExceptionScope::ExceptionScope(Isolate* isolate)
100     : isolate_(isolate),
101       pending_exception_(isolate_->pending_exception(), isolate_) {}
102 
103 
~ExceptionScope()104 Isolate::ExceptionScope::~ExceptionScope() {
105   isolate_->set_pending_exception(*pending_exception_);
106 }
107 
108 #define NATIVE_CONTEXT_FIELD_ACCESSOR(index, type, name)     \
109   Handle<type> Isolate::name() {                             \
110     return Handle<type>(raw_native_context()->name(), this); \
111   }                                                          \
112   bool Isolate::is_##name(type* value) {                     \
113     return raw_native_context()->is_##name(value);           \
114   }
NATIVE_CONTEXT_FIELDS(NATIVE_CONTEXT_FIELD_ACCESSOR)115 NATIVE_CONTEXT_FIELDS(NATIVE_CONTEXT_FIELD_ACCESSOR)
116 #undef NATIVE_CONTEXT_FIELD_ACCESSOR
117 
118 bool Isolate::IsArraySpeciesLookupChainIntact() {
119   // Note: It would be nice to have debug checks to make sure that the
120   // species protector is accurate, but this would be hard to do for most of
121   // what the protector stands for:
122   // - You'd need to traverse the heap to check that no Array instance has
123   //   a constructor property
124   // - To check that Array[Symbol.species] == Array, JS code has to execute,
125   //   but JS cannot be invoked in callstack overflow situations
126   // All that could be checked reliably is that
127   // Array.prototype.constructor == Array. Given that limitation, no check is
128   // done here. In place, there are mjsunit tests harmony/array-species* which
129   // ensure that behavior is correct in various invalid protector cases.
130 
131   Cell* species_cell = heap()->species_protector();
132   return species_cell->value()->IsSmi() &&
133          Smi::cast(species_cell->value())->value() == kProtectorValid;
134 }
135 
IsStringLengthOverflowIntact()136 bool Isolate::IsStringLengthOverflowIntact() {
137   PropertyCell* string_length_cell = heap()->string_length_protector();
138   return string_length_cell->value() == Smi::FromInt(kProtectorValid);
139 }
140 
IsFastArrayIterationIntact()141 bool Isolate::IsFastArrayIterationIntact() {
142   Cell* fast_iteration_cell = heap()->fast_array_iteration_protector();
143   return fast_iteration_cell->value() == Smi::FromInt(kProtectorValid);
144 }
145 
IsArrayBufferNeuteringIntact()146 bool Isolate::IsArrayBufferNeuteringIntact() {
147   PropertyCell* buffer_neutering = heap()->array_buffer_neutering_protector();
148   return buffer_neutering->value() == Smi::FromInt(kProtectorValid);
149 }
150 
IsArrayIteratorLookupChainIntact()151 bool Isolate::IsArrayIteratorLookupChainIntact() {
152   PropertyCell* array_iterator_cell = heap()->array_iterator_protector();
153   return array_iterator_cell->value() == Smi::FromInt(kProtectorValid);
154 }
155 
156 }  // namespace internal
157 }  // namespace v8
158 
159 #endif  // V8_ISOLATE_INL_H_
160