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/isolate.h"
9 : #include "src/objects-inl.h"
10 :
11 : namespace v8 {
12 : namespace internal {
13 :
14 :
15 6948924 : void Isolate::set_context(Context* context) {
16 : DCHECK(context == NULL || context->IsContext());
17 84713873 : thread_local_top_.context_ = context;
18 6948924 : }
19 :
20 22535820 : Handle<Context> Isolate::native_context() {
21 22535827 : return handle(context()->native_context(), this);
22 : }
23 :
24 32542640 : Context* Isolate::raw_native_context() { return context()->native_context(); }
25 :
26 84 : Object* Isolate::pending_exception() {
27 : DCHECK(has_pending_exception());
28 : DCHECK(!thread_local_top_.pending_exception_->IsException(this));
29 84 : return thread_local_top_.pending_exception_;
30 : }
31 :
32 :
33 : void Isolate::set_pending_exception(Object* exception_obj) {
34 : DCHECK(!exception_obj->IsException(this));
35 1524353 : thread_local_top_.pending_exception_ = exception_obj;
36 : }
37 :
38 :
39 84 : void Isolate::clear_pending_exception() {
40 : DCHECK(!thread_local_top_.pending_exception_->IsException(this));
41 1470050 : thread_local_top_.pending_exception_ = heap_.the_hole_value();
42 84 : }
43 :
44 :
45 6443163 : bool Isolate::has_pending_exception() {
46 : DCHECK(!thread_local_top_.pending_exception_->IsException(this));
47 12886327 : return !thread_local_top_.pending_exception_->IsTheHole(this);
48 : }
49 :
50 :
51 : void Isolate::clear_pending_message() {
52 64275518 : thread_local_top_.pending_message_obj_ = heap_.the_hole_value();
53 : }
54 :
55 :
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 :
63 39487748 : bool Isolate::has_scheduled_exception() {
64 : DCHECK(!thread_local_top_.scheduled_exception_->IsException(this));
65 337126826 : return thread_local_top_.scheduled_exception_ != heap_.the_hole_value();
66 : }
67 :
68 :
69 : void Isolate::clear_scheduled_exception() {
70 : DCHECK(!thread_local_top_.scheduled_exception_->IsException(this));
71 104389 : thread_local_top_.scheduled_exception_ = heap_.the_hole_value();
72 : }
73 :
74 :
75 : bool Isolate::is_catchable_by_javascript(Object* exception) {
76 2946874 : return exception != heap()->termination_exception();
77 : }
78 :
79 1860 : bool Isolate::is_catchable_by_wasm(Object* exception) {
80 3720 : return is_catchable_by_javascript(exception) &&
81 30 : (exception->IsNumber() || exception->IsSmi());
82 : }
83 :
84 : void Isolate::FireBeforeCallEnteredCallback() {
85 30038678 : for (int i = 0; i < before_call_entered_callbacks_.length(); i++) {
86 30038678 : before_call_entered_callbacks_.at(i)(reinterpret_cast<v8::Isolate*>(this));
87 : }
88 : }
89 :
90 4744252 : Handle<JSGlobalObject> Isolate::global_object() {
91 9488509 : return handle(context()->global_object(), this);
92 : }
93 :
94 345078 : Handle<JSObject> Isolate::global_proxy() {
95 690156 : return handle(context()->global_proxy(), this);
96 : }
97 :
98 :
99 13763 : Isolate::ExceptionScope::ExceptionScope(Isolate* isolate)
100 : : isolate_(isolate),
101 27526 : pending_exception_(isolate_->pending_exception(), isolate_) {}
102 :
103 :
104 : Isolate::ExceptionScope::~ExceptionScope() {
105 13763 : 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 : }
115 64972040 : NATIVE_CONTEXT_FIELDS(NATIVE_CONTEXT_FIELD_ACCESSOR)
116 : #undef NATIVE_CONTEXT_FIELD_ACCESSOR
117 :
118 112 : 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 1103400 : Cell* species_cell = heap()->species_protector();
132 2206800 : return species_cell->value()->IsSmi() &&
133 112 : Smi::cast(species_cell->value())->value() == kProtectorValid;
134 : }
135 :
136 : bool Isolate::IsStringLengthOverflowIntact() {
137 15535 : PropertyCell* string_length_cell = heap()->string_length_protector();
138 : return string_length_cell->value() == Smi::FromInt(kProtectorValid);
139 : }
140 :
141 : bool Isolate::IsFastArrayIterationIntact() {
142 1412 : Cell* fast_iteration_cell = heap()->fast_array_iteration_protector();
143 : return fast_iteration_cell->value() == Smi::FromInt(kProtectorValid);
144 : }
145 :
146 : bool Isolate::IsArrayBufferNeuteringIntact() {
147 8376 : PropertyCell* buffer_neutering = heap()->array_buffer_neutering_protector();
148 : return buffer_neutering->value() == Smi::FromInt(kProtectorValid);
149 : }
150 :
151 : bool Isolate::IsArrayIteratorLookupChainIntact() {
152 49439 : 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_
|