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 : #include "src/objects/cell-inl.h"
11 : #include "src/objects/oddball.h"
12 : #include "src/objects/property-cell.h"
13 : #include "src/objects/regexp-match-info.h"
14 : #include "src/objects/shared-function-info.h"
15 :
16 : namespace v8 {
17 : namespace internal {
18 :
19 : IsolateAllocationMode Isolate::isolate_allocation_mode() {
20 4 : return isolate_allocator_->mode();
21 : }
22 :
23 1354848 : void Isolate::set_context(Context context) {
24 : DCHECK(context.is_null() || context->IsContext());
25 34738930 : thread_local_top()->context_ = context;
26 1354848 : }
27 :
28 20980636 : Handle<NativeContext> Isolate::native_context() {
29 41961284 : return handle(context()->native_context(), this);
30 : }
31 :
32 : NativeContext Isolate::raw_native_context() {
33 32150099 : return context()->native_context();
34 : }
35 :
36 : Object Isolate::pending_exception() {
37 : DCHECK(has_pending_exception());
38 : DCHECK(!thread_local_top()->pending_exception_->IsException(this));
39 1942528 : return thread_local_top()->pending_exception_;
40 : }
41 :
42 33 : void Isolate::set_pending_exception(Object exception_obj) {
43 : DCHECK(!exception_obj->IsException(this));
44 1530852 : thread_local_top()->pending_exception_ = exception_obj;
45 33 : }
46 :
47 1724223 : void Isolate::clear_pending_exception() {
48 : DCHECK(!thread_local_top()->pending_exception_->IsException(this));
49 1724223 : thread_local_top()->pending_exception_ = ReadOnlyRoots(this).the_hole_value();
50 1724223 : }
51 :
52 :
53 29740840 : bool Isolate::has_pending_exception() {
54 : DCHECK(!thread_local_top()->pending_exception_->IsException(this));
55 59481682 : return !thread_local_top()->pending_exception_->IsTheHole(this);
56 : }
57 :
58 :
59 23729777 : void Isolate::clear_pending_message() {
60 : thread_local_top()->pending_message_obj_ =
61 23729771 : ReadOnlyRoots(this).the_hole_value();
62 23729771 : }
63 :
64 : Object Isolate::scheduled_exception() {
65 : DCHECK(has_scheduled_exception());
66 : DCHECK(!thread_local_top()->scheduled_exception_->IsException(this));
67 30866 : return thread_local_top()->scheduled_exception_;
68 : }
69 :
70 39200974 : bool Isolate::has_scheduled_exception() {
71 : DCHECK(!thread_local_top()->scheduled_exception_->IsException(this));
72 : return thread_local_top()->scheduled_exception_ !=
73 39200983 : ReadOnlyRoots(this).the_hole_value();
74 : }
75 :
76 :
77 115065 : void Isolate::clear_scheduled_exception() {
78 : DCHECK(!thread_local_top()->scheduled_exception_->IsException(this));
79 : thread_local_top()->scheduled_exception_ =
80 115065 : ReadOnlyRoots(this).the_hole_value();
81 115065 : }
82 :
83 2949434 : bool Isolate::is_catchable_by_javascript(Object exception) {
84 5898868 : return exception != ReadOnlyRoots(heap()).termination_exception();
85 : }
86 :
87 : void Isolate::FireBeforeCallEnteredCallback() {
88 5437127 : for (auto& callback : before_call_entered_callbacks_) {
89 80 : callback(reinterpret_cast<v8::Isolate*>(this));
90 : }
91 : }
92 :
93 9259337 : Handle<JSGlobalObject> Isolate::global_object() {
94 18518672 : return handle(context()->global_object(), this);
95 : }
96 :
97 267556 : Handle<JSObject> Isolate::global_proxy() {
98 535113 : return handle(context()->global_proxy(), this);
99 : }
100 :
101 :
102 7976 : Isolate::ExceptionScope::ExceptionScope(Isolate* isolate)
103 : : isolate_(isolate),
104 15952 : pending_exception_(isolate_->pending_exception(), isolate_) {}
105 :
106 :
107 7976 : Isolate::ExceptionScope::~ExceptionScope() {
108 7976 : isolate_->set_pending_exception(*pending_exception_);
109 7976 : }
110 :
111 : #define NATIVE_CONTEXT_FIELD_ACCESSOR(index, type, name) \
112 : Handle<type> Isolate::name() { \
113 : return Handle<type>(raw_native_context()->name(), this); \
114 : } \
115 : bool Isolate::is_##name(type value) { \
116 : return raw_native_context()->is_##name(value); \
117 : }
118 87877589 : NATIVE_CONTEXT_FIELDS(NATIVE_CONTEXT_FIELD_ACCESSOR)
119 : #undef NATIVE_CONTEXT_FIELD_ACCESSOR
120 :
121 2206 : bool Isolate::IsArrayConstructorIntact() {
122 : Cell array_constructor_cell =
123 : Cell::cast(root(RootIndex::kArrayConstructorProtector));
124 2206 : return array_constructor_cell->value() == Smi::FromInt(kProtectorValid);
125 : }
126 :
127 422887 : bool Isolate::IsArraySpeciesLookupChainIntact() {
128 : // Note: It would be nice to have debug checks to make sure that the
129 : // species protector is accurate, but this would be hard to do for most of
130 : // what the protector stands for:
131 : // - You'd need to traverse the heap to check that no Array instance has
132 : // a constructor property
133 : // - To check that Array[Symbol.species] == Array, JS code has to execute,
134 : // but JS cannot be invoked in callstack overflow situations
135 : // All that could be checked reliably is that
136 : // Array.prototype.constructor == Array. Given that limitation, no check is
137 : // done here. In place, there are mjsunit tests harmony/array-species* which
138 : // ensure that behavior is correct in various invalid protector cases.
139 :
140 : PropertyCell species_cell =
141 : PropertyCell::cast(root(RootIndex::kArraySpeciesProtector));
142 1268661 : return species_cell->value()->IsSmi() &&
143 845774 : Smi::ToInt(species_cell->value()) == kProtectorValid;
144 : }
145 :
146 6386 : bool Isolate::IsTypedArraySpeciesLookupChainIntact() {
147 : PropertyCell species_cell =
148 : PropertyCell::cast(root(RootIndex::kTypedArraySpeciesProtector));
149 19158 : return species_cell->value()->IsSmi() &&
150 12772 : Smi::ToInt(species_cell->value()) == kProtectorValid;
151 : }
152 :
153 10817 : bool Isolate::IsRegExpSpeciesLookupChainIntact() {
154 : PropertyCell species_cell =
155 : PropertyCell::cast(root(RootIndex::kRegExpSpeciesProtector));
156 32451 : return species_cell->value()->IsSmi() &&
157 21634 : Smi::ToInt(species_cell->value()) == kProtectorValid;
158 : }
159 :
160 11588 : bool Isolate::IsPromiseSpeciesLookupChainIntact() {
161 : PropertyCell species_cell =
162 : PropertyCell::cast(root(RootIndex::kPromiseSpeciesProtector));
163 34764 : return species_cell->value()->IsSmi() &&
164 23176 : Smi::ToInt(species_cell->value()) == kProtectorValid;
165 : }
166 :
167 474 : bool Isolate::IsStringLengthOverflowIntact() {
168 : Cell string_length_cell = Cell::cast(root(RootIndex::kStringLengthProtector));
169 474 : return string_length_cell->value() == Smi::FromInt(kProtectorValid);
170 : }
171 :
172 12636 : bool Isolate::IsArrayBufferDetachingIntact() {
173 : PropertyCell buffer_detaching =
174 : PropertyCell::cast(root(RootIndex::kArrayBufferDetachingProtector));
175 12636 : return buffer_detaching->value() == Smi::FromInt(kProtectorValid);
176 : }
177 :
178 3545 : bool Isolate::IsArrayIteratorLookupChainIntact() {
179 : PropertyCell array_iterator_cell =
180 : PropertyCell::cast(root(RootIndex::kArrayIteratorProtector));
181 3545 : return array_iterator_cell->value() == Smi::FromInt(kProtectorValid);
182 : }
183 :
184 280 : bool Isolate::IsMapIteratorLookupChainIntact() {
185 : PropertyCell map_iterator_cell =
186 : PropertyCell::cast(root(RootIndex::kMapIteratorProtector));
187 280 : return map_iterator_cell->value() == Smi::FromInt(kProtectorValid);
188 : }
189 :
190 295 : bool Isolate::IsSetIteratorLookupChainIntact() {
191 : PropertyCell set_iterator_cell =
192 : PropertyCell::cast(root(RootIndex::kSetIteratorProtector));
193 295 : return set_iterator_cell->value() == Smi::FromInt(kProtectorValid);
194 : }
195 :
196 133 : bool Isolate::IsStringIteratorLookupChainIntact() {
197 : PropertyCell string_iterator_cell =
198 : PropertyCell::cast(root(RootIndex::kStringIteratorProtector));
199 133 : return string_iterator_cell->value() == Smi::FromInt(kProtectorValid);
200 : }
201 :
202 : } // namespace internal
203 : } // namespace v8
204 :
205 : #endif // V8_ISOLATE_INL_H_
|