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_EXECUTION_ISOLATE_INL_H_
6 #define V8_EXECUTION_ISOLATE_INL_H_
7
8 #include "src/execution/isolate.h"
9 #include "src/objects/cell-inl.h"
10 #include "src/objects/js-function.h"
11 #include "src/objects/objects-inl.h"
12 #include "src/objects/oddball.h"
13 #include "src/objects/property-cell.h"
14 #include "src/objects/regexp-match-info.h"
15 #include "src/objects/shared-function-info.h"
16
17 namespace v8 {
18 namespace internal {
19
set_context(Context context)20 void Isolate::set_context(Context context) {
21 DCHECK(context.is_null() || context.IsContext());
22 thread_local_top()->context_ = context;
23 }
24
native_context()25 Handle<NativeContext> Isolate::native_context() {
26 DCHECK(!context().is_null());
27 return handle(context().native_context(), this);
28 }
29
raw_native_context()30 NativeContext Isolate::raw_native_context() {
31 DCHECK(!context().is_null());
32 return context().native_context();
33 }
34
pending_exception()35 Object Isolate::pending_exception() {
36 DCHECK(has_pending_exception());
37 DCHECK(!thread_local_top()->pending_exception_.IsException(this));
38 return thread_local_top()->pending_exception_;
39 }
40
set_pending_exception(Object exception_obj)41 void Isolate::set_pending_exception(Object exception_obj) {
42 DCHECK(!exception_obj.IsException(this));
43 thread_local_top()->pending_exception_ = exception_obj;
44 }
45
clear_pending_exception()46 void Isolate::clear_pending_exception() {
47 DCHECK(!thread_local_top()->pending_exception_.IsException(this));
48 thread_local_top()->pending_exception_ = ReadOnlyRoots(this).the_hole_value();
49 }
50
has_pending_exception()51 bool Isolate::has_pending_exception() {
52 DCHECK(!thread_local_top()->pending_exception_.IsException(this));
53 return !thread_local_top()->pending_exception_.IsTheHole(this);
54 }
55
clear_pending_message()56 void Isolate::clear_pending_message() {
57 thread_local_top()->pending_message_obj_ =
58 ReadOnlyRoots(this).the_hole_value();
59 }
60
scheduled_exception()61 Object Isolate::scheduled_exception() {
62 DCHECK(has_scheduled_exception());
63 DCHECK(!thread_local_top()->scheduled_exception_.IsException(this));
64 return thread_local_top()->scheduled_exception_;
65 }
66
has_scheduled_exception()67 bool Isolate::has_scheduled_exception() {
68 DCHECK(!thread_local_top()->scheduled_exception_.IsException(this));
69 return thread_local_top()->scheduled_exception_ !=
70 ReadOnlyRoots(this).the_hole_value();
71 }
72
clear_scheduled_exception()73 void Isolate::clear_scheduled_exception() {
74 DCHECK(!thread_local_top()->scheduled_exception_.IsException(this));
75 thread_local_top()->scheduled_exception_ =
76 ReadOnlyRoots(this).the_hole_value();
77 }
78
is_catchable_by_javascript(Object exception)79 bool Isolate::is_catchable_by_javascript(Object exception) {
80 return exception != ReadOnlyRoots(heap()).termination_exception();
81 }
82
is_catchable_by_wasm(Object exception)83 bool Isolate::is_catchable_by_wasm(Object exception) {
84 if (!is_catchable_by_javascript(exception)) return false;
85 if (!exception.IsJSObject()) return true;
86 // We don't allocate, but the LookupIterator interface expects a handle.
87 DisallowHeapAllocation no_gc;
88 HandleScope handle_scope(this);
89 LookupIterator it(this, handle(JSReceiver::cast(exception), this),
90 factory()->wasm_uncatchable_symbol(),
91 LookupIterator::OWN_SKIP_INTERCEPTOR);
92 return !JSReceiver::HasProperty(&it).FromJust();
93 }
94
FireBeforeCallEnteredCallback()95 void Isolate::FireBeforeCallEnteredCallback() {
96 for (auto& callback : before_call_entered_callbacks_) {
97 callback(reinterpret_cast<v8::Isolate*>(this));
98 }
99 }
100
global_object()101 Handle<JSGlobalObject> Isolate::global_object() {
102 return handle(context().global_object(), this);
103 }
104
global_proxy()105 Handle<JSGlobalProxy> Isolate::global_proxy() {
106 return handle(context().global_proxy(), this);
107 }
108
ExceptionScope(Isolate * isolate)109 Isolate::ExceptionScope::ExceptionScope(Isolate* isolate)
110 : isolate_(isolate),
111 pending_exception_(isolate_->pending_exception(), isolate_) {}
112
~ExceptionScope()113 Isolate::ExceptionScope::~ExceptionScope() {
114 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 NATIVE_CONTEXT_FIELDS(NATIVE_CONTEXT_FIELD_ACCESSOR)
125 #undef NATIVE_CONTEXT_FIELD_ACCESSOR
126
127 } // namespace internal
128 } // namespace v8
129
130 #endif // V8_EXECUTION_ISOLATE_INL_H_
131