Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions nan.h
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,12 @@ v8::Local<v8::Value> MakeCallback(v8::Local<v8::Object> target,

// === AsyncResource ===========================================================

// node::MakeCallback() taking the Environment (nodejs/node#66510).
// Placeholder version, to be set to the first release that has it.
#if NODE_MAJOR_VERSION >= 27
# define NAN_MAKECALLBACK_ENV 1
#endif

class AsyncResource {
public:
AsyncResource(
Expand All @@ -595,6 +601,9 @@ class AsyncResource {
}

context = node::EmitAsyncInit(isolate, resource, name);
#if defined(NAN_MAKECALLBACK_ENV)
env = node::GetCurrentEnvironment(isolate->GetCurrentContext());
#endif
#endif
}

Expand All @@ -611,6 +620,9 @@ class AsyncResource {
v8::Local<v8::String> name_string =
New<v8::String>(name).ToLocalChecked();
context = node::EmitAsyncInit(isolate, resource, name_string);
#if defined(NAN_MAKECALLBACK_ENV)
env = node::GetCurrentEnvironment(isolate->GetCurrentContext());
#endif
#endif
}

Expand All @@ -628,6 +640,9 @@ class AsyncResource {
, v8::Local<v8::Value>* argv) {
#if NODE_MODULE_VERSION < NODE_9_0_MODULE_VERSION
return MakeCallback(target, func, argc, argv);
#elif defined(NAN_MAKECALLBACK_ENV)
// taken once in the constructor, so Node does not look it up per call
return node::MakeCallback(env, target, func, argc, argv, context);
#else
return node::MakeCallback(
v8::Isolate::GetCurrent(), target, func, argc, argv, context);
Expand Down Expand Up @@ -671,6 +686,9 @@ class AsyncResource {
#if NODE_MODULE_VERSION >= NODE_9_0_MODULE_VERSION
node::async_context context;
#endif
#if defined(NAN_MAKECALLBACK_ENV)
node::Environment* env;
#endif
};

inline uv_loop_t* GetCurrentEventLoop() {
Expand Down
Loading