9 #include "src/handles-inl.h" 10 #include "src/objects-inl.h" 11 #include "src/objects/stack-frame-info.h" 18 if (obj == v8::internal::Smi::kZero)
return nullptr;
19 return reinterpret_cast<T
>(
20 v8::internal::Foreign::cast(obj)->foreign_address());
25 if (obj == v8::internal::Smi::kZero)
return v8::internal::kNullAddress;
26 return v8::internal::Foreign::cast(obj)->foreign_address();
33 if (obj ==
nullptr)
return handle(v8::internal::Smi::kZero, isolate);
34 return isolate->factory()->NewForeign(
35 reinterpret_cast<v8::internal::Address>(obj));
41 if (obj == v8::internal::kNullAddress) {
42 return handle(v8::internal::Smi::kZero, isolate);
44 return isolate->factory()->NewForeign(obj);
47 template <
class From,
class To>
49 DCHECK(obj.is_null() || (obj->IsSmi() || !obj->IsTheHole()));
50 return Local<To>(
reinterpret_cast<To*
>(obj.location()));
55 #define MAKE_TO_LOCAL(Name, From, To) \ 56 Local<v8::To> Utils::Name(v8::internal::Handle<v8::internal::From> obj) { \ 57 return Convert<v8::internal::From, v8::To>(obj); \ 60 #define MAKE_TO_LOCAL_TYPED_ARRAY(Type, typeName, TYPE, ctype) \ 61 Local<v8::Type##Array> Utils::ToLocal##Type##Array( \ 62 v8::internal::Handle<v8::internal::JSTypedArray> obj) { \ 63 DCHECK(obj->type() == v8::internal::kExternal##Type##Array); \ 64 return Convert<v8::internal::JSTypedArray, v8::Type##Array>(obj); \ 67 MAKE_TO_LOCAL(ToLocal, Context, Context)
68 MAKE_TO_LOCAL(ToLocal, Object,
Value)
69 MAKE_TO_LOCAL(ToLocal, Module, Module)
70 MAKE_TO_LOCAL(ToLocal, Name, Name)
71 MAKE_TO_LOCAL(ToLocal, String, String)
72 MAKE_TO_LOCAL(ToLocal, Symbol, Symbol)
73 MAKE_TO_LOCAL(ToLocal, JSRegExp, RegExp)
74 MAKE_TO_LOCAL(ToLocal, JSReceiver, Object)
75 MAKE_TO_LOCAL(ToLocal, JSObject, Object)
76 MAKE_TO_LOCAL(ToLocal, JSFunction, Function)
77 MAKE_TO_LOCAL(ToLocal, JSArray, Array)
78 MAKE_TO_LOCAL(ToLocal, JSMap, Map)
79 MAKE_TO_LOCAL(ToLocal, JSSet, Set)
80 MAKE_TO_LOCAL(ToLocal, JSProxy, Proxy)
81 MAKE_TO_LOCAL(ToLocal, JSArrayBuffer, ArrayBuffer)
82 MAKE_TO_LOCAL(ToLocal, JSArrayBufferView, ArrayBufferView)
83 MAKE_TO_LOCAL(ToLocal, JSDataView, DataView)
84 MAKE_TO_LOCAL(ToLocal, JSTypedArray, TypedArray)
85 MAKE_TO_LOCAL(ToLocalShared, JSArrayBuffer, SharedArrayBuffer)
87 TYPED_ARRAYS(MAKE_TO_LOCAL_TYPED_ARRAY)
89 MAKE_TO_LOCAL(ToLocal, FunctionTemplateInfo, FunctionTemplate)
90 MAKE_TO_LOCAL(ToLocal, ObjectTemplateInfo, ObjectTemplate)
91 MAKE_TO_LOCAL(SignatureToLocal, FunctionTemplateInfo, Signature)
92 MAKE_TO_LOCAL(AccessorSignatureToLocal, FunctionTemplateInfo, AccessorSignature)
93 MAKE_TO_LOCAL(MessageToLocal, Object, Message)
94 MAKE_TO_LOCAL(PromiseToLocal, JSObject, Promise)
95 MAKE_TO_LOCAL(StackTraceToLocal, FixedArray, StackTrace)
96 MAKE_TO_LOCAL(StackFrameToLocal, StackFrameInfo, StackFrame)
97 MAKE_TO_LOCAL(NumberToLocal, Object, Number)
98 MAKE_TO_LOCAL(IntegerToLocal, Object, Integer)
99 MAKE_TO_LOCAL(Uint32ToLocal, Object, Uint32)
100 MAKE_TO_LOCAL(ToLocal, BigInt, BigInt);
101 MAKE_TO_LOCAL(ExternalToLocal, JSObject, External)
102 MAKE_TO_LOCAL(CallableToLocal, JSReceiver, Function)
103 MAKE_TO_LOCAL(ToLocalPrimitive, Object, Primitive)
104 MAKE_TO_LOCAL(ToLocal, FixedArray, PrimitiveArray)
105 MAKE_TO_LOCAL(ScriptOrModuleToLocal, Script, ScriptOrModule)
107 #undef MAKE_TO_LOCAL_TYPED_ARRAY 112 #define MAKE_OPEN_HANDLE(From, To) \ 113 v8::internal::Handle<v8::internal::To> Utils::OpenHandle( \ 114 const v8::From* that, bool allow_empty_handle) { \ 115 DCHECK(allow_empty_handle || that != nullptr); \ 116 DCHECK(that == nullptr || \ 117 (*reinterpret_cast<v8::internal::Object* const*>(that))->Is##To()); \ 118 return v8::internal::Handle<v8::internal::To>( \ 119 reinterpret_cast<v8::internal::Address*>( \ 120 const_cast<v8::From*>(that))); \ 123 OPEN_HANDLE_LIST(MAKE_OPEN_HANDLE)
125 #undef MAKE_OPEN_HANDLE 126 #undef OPEN_HANDLE_LIST 130 Handle<Context> HandleScopeImplementer::MicrotaskContext() {
131 if (!microtask_context_.is_null()) {
132 return Handle<Context>(microtask_context_, isolate_);
134 return Handle<Context>::null();
137 Handle<Context> HandleScopeImplementer::LastEnteredContext() {
138 if (entered_contexts_.empty())
return Handle<Context>::null();
139 return Handle<Context>(entered_contexts_.back(), isolate_);
142 Handle<Context> HandleScopeImplementer::LastEnteredOrMicrotaskContext() {
143 if (MicrotaskContextIsLastEnteredContext())
return MicrotaskContext();
144 if (entered_contexts_.empty())
return Handle<Context>::null();
145 return Handle<Context>(entered_contexts_.back(), isolate_);
151 #endif // V8_API_INL_H_