20std::shared_ptr<AsyncHooksWrap> UnwrapHook(
24 HandleScope scope(v8_isolate);
25 Local<Object> hook = info.This();
29 if (!hooks->async_hook_ctor.Get(v8_isolate)->HasInstance(hook)) {
31 "Invalid 'this' passed instead of AsyncHooks instance");
37 return Cast<i::Managed<AsyncHooksWrap>>(
handle)->get();
42 auto wrap = UnwrapHook(info);
43 if (wrap) wrap->Enable();
48 auto wrap = UnwrapHook(info);
49 if (wrap) wrap->Disable();
138 if (info.Length() != 1 || !info[0]->IsObject()) {
139 v8_isolate->
ThrowError(
"Invalid arguments passed to createHook");
143 std::shared_ptr<AsyncHooksWrap> wrap =
144 std::make_shared<AsyncHooksWrap>(v8_isolate);
149#define SET_HOOK_FN(name) \
150 MaybeLocal<Value> name##_maybe_func = fn_obj->Get( \
151 currentContext, String::NewFromUtf8Literal(v8_isolate, #name)); \
152 Local<Value> name##_func; \
153 if (name##_maybe_func.ToLocal(&name##_func) && name##_func->IsFunction()) { \
154 wrap->set_##name##_function(name##_func.As<Function>()); \
156 try_catch.ReThrow(); \
166 ->NewInstance(currentContext)
170 obj->SetInternalField(0, Utils::ToLocal(managed));
174 return handle_scope.
Escape(obj);
191 exception = direct_handle(i_isolate->
exception(), i_isolate);
205 ->HasPrivate(currentContext,
208 promise->SetPrivate(currentContext,
211 if (parent->IsPromise()) {
215 ->GetPrivate(currentContext,
218 promise->SetPrivate(currentContext,
222 CHECK(parent->IsUndefined());
223 promise->SetPrivate(currentContext,
231 ->GetPrivate(currentContext,
238 ->GetPrivate(currentContext,
249 std::shared_ptr<AsyncHooksWrap> wrap = hooks->
async_wraps_[
i];
256 if (!exception.is_null()) {
#define SET_HOOK_FN(name)
void set_before_function(v8::Local< v8::Function > value)
void set_after_function(v8::Local< v8::Function > value)
Persistent< v8::Function > after_function_
void set_promiseResolve_function(v8::Local< v8::Function > value)
v8::Local< v8::Function > after_function() const
v8::Local< v8::Function > before_function() const
v8::Local< v8::Function > promiseResolve_function() const
void set_init_function(v8::Local< v8::Function > value)
v8::Local< v8::Function > init_function() const
Persistent< v8::Function > init_function_
Persistent< v8::Function > promiseResolve_function_
Persistent< v8::Function > before_function_
std::stack< AsyncContext > asyncContexts
static void PromiseHookDispatch(PromiseHookType type, Local< Promise > promise, Local< Value > parent, const AsyncHooksWrap &wrap, AsyncHooks *hooks)
Persistent< ObjectTemplate > async_hooks_templ
v8::Isolate * v8_isolate_
bool skip_after_termination_
Persistent< FunctionTemplate > async_hook_ctor
async_id_t current_async_id
Persistent< Private > trigger_id_symbol
std::vector< std::shared_ptr< AsyncHooksWrap > > async_wraps_
async_id_t GetTriggerAsyncId() const
AsyncHooks(Isolate *isolate)
async_id_t GetExecutionAsyncId() const
Persistent< Private > async_id_symbol
static void ShellPromiseHook(PromiseHookType type, Local< Promise > promise, Local< Value > parent)
Local< Object > CreateHook(const v8::FunctionCallbackInfo< v8::Value > &info)
V8_INLINE Local< T > Escape(Local< T > value)
static Local< FunctionTemplate > New(Isolate *isolate, FunctionCallback callback=nullptr, Local< Value > data=Local< Value >(), Local< Signature > signature=Local< Signature >(), int length=0, ConstructorBehavior behavior=ConstructorBehavior::kAllow, SideEffectType side_effect_type=SideEffectType::kHasSideEffect, const CFunction *c_function=nullptr, uint16_t instance_type=0, uint16_t allowed_receiver_instance_type_range_start=0, uint16_t allowed_receiver_instance_type_range_end=0)
static Local< Integer > New(Isolate *isolate, int32_t value)
void SetPromiseHook(PromiseHook hook)
Local< Value > ThrowError(const char(&message)[N])
bool IsExecutionTerminating()
Local< Context > GetCurrentContext()
V8_INLINE Local< S > As() const
AsyncHooks * GetAsyncHooks()
static PerIsolateData * Get(Isolate *isolate)
V8_INLINE Local< T > Get(Isolate *isolate) const
static Local< Private > New(Isolate *isolate, Local< String > name=Local< String >())
static void ReportException(Isolate *isolate, Local< Message > message, Local< Value > exception)
static V8_WARN_UNUSED_RESULT Local< String > NewFromUtf8Literal(Isolate *isolate, const char(&literal)[N], NewStringType type=NewStringType::kNormal)
void SetVerbose(bool value)
static v8::internal::DirectHandle< To > OpenDirectHandle(v8::Local< From > handle)
V8_INLINE bool IsEmpty() const
Tagged< Object > exception()
void set_exception(Tagged< Object > exception_obj)
bool HasOverflowed() const
base::Vector< const DirectHandle< Object > > args
V8_INLINE IndirectHandle< T > handle(Tagged< T > object, Isolate *isolate)
bool V8_EXPORT ValidateCallbackInfo(const FunctionCallbackInfo< void > &info)
V8_INLINE Local< Primitive > Undefined(Isolate *isolate)
#define DCHECK(condition)
async_id_t execution_async_id
async_id_t trigger_async_id