v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
isolate-inl.h
Go to the documentation of this file.
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
9// Include the non-inl header before the rest of the headers.
10
15#include "src/objects/oddball.h"
20
21#ifdef DEBUG
24#endif
25
26namespace v8::internal {
27
28// static
29V8_INLINE Isolate::PerIsolateThreadData*
31 return g_current_per_isolate_thread_data_;
32}
33
34// static
36 Isolate* isolate = TryGetCurrent();
37 DCHECK_NOT_NULL(isolate);
38 return isolate;
39}
40
41bool Isolate::IsCurrent() const { return this == TryGetCurrent(); }
42
44 DCHECK(context.is_null() || IsContext(context));
46}
47
52
54 DCHECK(!context().is_null());
55 return context()->native_context();
56}
57
59 DCHECK(context.is_null() || IsContext(context));
61}
62
67
69 Tagged<Context> maybe_topmost_script_having_context =
71 if (V8_LIKELY(!maybe_topmost_script_having_context.is_null())) {
72 // The topmost script-having context value is guaranteed to be valid only
73 // inside the Api callback however direct calls of Api callbacks from
74 // builtins or optimized code do not change the current VM state, so we
75 // allow JS VM state too.
76 DCHECK(current_vm_state() == EXTERNAL || // called from C++ code
77 current_vm_state() == JS); // called from JS code directly
78
79 Tagged<NativeContext> incumbent_context =
80 maybe_topmost_script_having_context->native_context();
81 DCHECK_EQ(incumbent_context, *GetIncumbentContextSlow());
82 return direct_handle(incumbent_context, this);
83 }
85}
86
88 DCHECK(IsTheHole(message_obj, this) || IsJSMessageObject(message_obj));
89 thread_local_top()->pending_message_ = message_obj;
90}
91
95
97 set_pending_message(ReadOnlyRoots(this).the_hole_value());
98}
99
101 return !IsTheHole(pending_message(), this);
102}
103
106 DCHECK(!IsException(thread_local_top()->exception_, this));
108}
109
111 DCHECK(!IsException(exception_obj, this));
112 thread_local_top()->exception_ = exception_obj;
113}
114
116 DCHECK(!IsException(thread_local_top()->exception_, this));
117 thread_local_top()->exception_ = ReadOnlyRoots(this).the_hole_value();
118}
119
124
127 DCHECK(!IsException(top->exception_, this));
128 return !IsTheHole(top->exception_, this);
129}
130
132 return thread_local_top()->exception_ ==
133 i::ReadOnlyRoots(this).termination_exception();
134}
135
136#ifdef DEBUG
137Tagged<Object> Isolate::VerifyBuiltinsResult(Tagged<Object> result) {
138 if (is_execution_terminating() && !v8_flags.strict_termination_checks) {
139 // We may be missing places where termination checks are handled properly.
140 // If that's the case, it's likely that we'll have one sitting around when
141 // we return from a builtin. If we're not looking to find such bugs
142 // (strict_termination_checks is false), simply return the exception marker.
143 return ReadOnlyRoots(this).exception();
144 }
145
146 // Here we use full pointer comparison as the result might be an object
147 // outside of the main pointer compression heap (e.g. in trusted space).
149 result.SafeEquals(ReadOnlyRoots(this).exception()));
150
151#ifdef V8_COMPRESS_POINTERS
152 // Check that the returned pointer is actually part of the current isolate (or
153 // the shared isolate), because that's the assumption in generated code (which
154 // might call this builtin).
156 if (!IsSmi(result) &&
158 DCHECK(isolate == this || isolate == shared_space_isolate());
159 }
160#endif
161
162 return result;
163}
164
165ObjectPair Isolate::VerifyBuiltinsResult(ObjectPair pair) {
166#ifdef V8_HOST_ARCH_64_BIT
167 Tagged<Object> x(pair.x), y(pair.y);
168
169 // Here we use full pointer comparison as the result might be an object
170 // outside of the main pointer compression heap (e.g. in trusted space).
171 DCHECK_EQ(has_exception(), x.SafeEquals(ReadOnlyRoots(this).exception()));
172
173#ifdef V8_COMPRESS_POINTERS
174 // Check that the returned pointer is actually part of the current isolate (or
175 // the shared isolate), because that's the assumption in generated code (which
176 // might call this builtin).
178 if (!IsSmi(x) && GetIsolateFromHeapObject(Cast<HeapObject>(x), &isolate)) {
179 DCHECK(isolate == this || isolate == shared_space_isolate());
180 }
181 if (!IsSmi(y) && GetIsolateFromHeapObject(Cast<HeapObject>(y), &isolate)) {
182 DCHECK(isolate == this || isolate == shared_space_isolate());
183 }
184#endif
185#endif // V8_HOST_ARCH_64_BIT
186 return pair;
187}
188#endif // DEBUG
189
191 return exception != ReadOnlyRoots(heap()).termination_exception();
192}
193
195 return isolate_data()->fast_c_call_caller_fp() != kNullAddress;
196}
197
199 if (!is_catchable_by_javascript(exception)) return false;
200 if (!IsJSObject(exception)) return true;
202 this, Cast<JSReceiver>(exception), factory()->wasm_uncatchable_symbol());
203}
204
207 callback(reinterpret_cast<v8::Isolate*>(this));
208 }
209}
210
214
218
220 : isolate_(isolate), exception_(isolate_->exception(), isolate_) {
222}
223
225 isolate_->set_exception(*exception_);
226}
227
230 return IsInCreationContext(array, Context::INITIAL_ARRAY_PROTOTYPE_INDEX);
231}
232
233#define NATIVE_CONTEXT_FIELD_ACCESSOR(index, type, name) \
234 Handle<UNPAREN(type)> Isolate::name() { \
235 return Handle<UNPAREN(type)>(raw_native_context()->name(), this); \
236 } \
237 bool Isolate::is_##name(Tagged<UNPAREN(type)> value) { \
238 return raw_native_context()->is_##name(value); \
239 }
241#undef NATIVE_CONTEXT_FIELD_ACCESSOR
242
244 : ptr_compr_cage_access_scope_(isolate),
245 previous_isolate_(Isolate::TryGetCurrent()) {
246 Isolate::SetCurrent(isolate);
247}
248
252
253} // namespace v8::internal
254
255#endif // V8_EXECUTION_ISOLATE_INL_H_
Isolate * isolate_
void Reset()
Definition api.cc:2839
static const int kNoContext
Definition contexts.h:577
Isolate * isolate() const
Definition factory.h:1281
void set_topmost_script_having_context(Tagged< Context > context)
Definition isolate-inl.h:58
Isolate(const Isolate &)=delete
Handle< JSGlobalObject > global_object()
v8::TryCatch * try_catch_handler()
Definition isolate.h:850
void FireBeforeCallEnteredCallback()
static void SetCurrent(Isolate *isolate)
Definition isolate.cc:528
static V8_INLINE Isolate * Current()
Definition isolate-inl.h:35
const IsolateData * isolate_data() const
Definition isolate.h:1207
bool IsInCreationContext(Tagged< JSObject > object, uint32_t index)
Definition isolate.cc:6228
bool InFastCCall() const
void set_pending_message(Tagged< Object > message_obj)
Definition isolate-inl.h:87
Tagged< Context > context() const
Definition isolate.h:800
void set_context(Tagged< Context > context)
Definition isolate-inl.h:43
Tagged< NativeContext > raw_native_context()
Definition isolate-inl.h:53
Tagged< Object > exception()
bool is_catchable_by_javascript(Tagged< Object > exception)
bool IsCurrent() const
Definition isolate-inl.h:41
Handle< NativeContext > native_context()
Definition isolate-inl.h:48
bool is_catchable_by_wasm(Tagged< Object > exception)
DirectHandle< NativeContext > GetIncumbentContextSlow()
Definition isolate.cc:3713
Tagged< Object > pending_message()
Definition isolate-inl.h:92
v8::internal::Factory * factory()
Definition isolate.h:1527
void set_exception(Tagged< Object > exception_obj)
DirectHandle< NativeContext > GetIncumbentContext()
Definition isolate-inl.h:68
Tagged< Context > topmost_script_having_context() const
Definition isolate.h:808
Handle< JSGlobalProxy > global_proxy()
static V8_INLINE PerIsolateThreadData * CurrentPerIsolateThreadData()
Definition isolate-inl.h:30
bool IsInitialArrayPrototype(Tagged< JSArray > array)
Isolate * shared_space_isolate() const
Definition isolate.h:2295
std::vector< BeforeCallEnteredCallback > before_call_entered_callbacks_
Definition isolate.h:2762
void clear_topmost_script_having_context()
Definition isolate-inl.h:63
ThreadLocalTop * thread_local_top()
Definition isolate.h:1331
static bool HasInternalMarkerProperty(Isolate *isolate, Tagged< JSReceiver > object, DirectHandle< Symbol > marker)
Definition lookup.cc:1395
V8_INLINE constexpr bool is_null() const
Definition tagged.h:502
Tagged< Context > topmost_script_having_context_
#define NATIVE_CONTEXT_FIELDS(V)
Definition contexts.h:46
#define NATIVE_CONTEXT_FIELD_ACCESSOR(index, type, name)
TNode< Object > callback
ZoneVector< RpoNumber > & result
int x
V8_INLINE IndirectHandle< T > handle(Tagged< T > object, Isolate *isolate)
Definition handles-inl.h:72
V8_INLINE bool GetIsolateFromHeapObject(Tagged< HeapObject > object, Isolate **isolate)
V8_INLINE constexpr bool IsSmi(TaggedImpl< kRefType, StorageType > obj)
Definition objects.h:665
V8_INLINE DirectHandle< T > direct_handle(Tagged< T > object, Isolate *isolate)
V8_EXPORT_PRIVATE FlagValues v8_flags
uint64_t ObjectPair
static constexpr Address kNullAddress
Definition v8-internal.h:53
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
Definition casting.h:150
@ EXTERNAL
Definition v8-unwinder.h:43
#define CHECK(condition)
Definition logging.h:124
#define DCHECK_NOT_NULL(val)
Definition logging.h:492
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_EQ(v1, v2)
Definition logging.h:485
#define V8_INLINE
Definition v8config.h:500
#define V8_LIKELY(condition)
Definition v8config.h:661