Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
n-api: add napi_get_uv_event_loop for JSRT
Browse files Browse the repository at this point in the history
  • Loading branch information
kfarnung committed Mar 7, 2018
1 parent dc0de49 commit 5bed491
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/node_api_jsrt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,12 @@ struct CallbackInfo {
};

struct napi_env__ {
explicit napi_env__(v8::Isolate* _isolate): isolate(_isolate) {}
explicit napi_env__(v8::Isolate* _isolate, uv_loop_t* _loop)
: isolate(_isolate),
loop(_loop) {}
~napi_env__() {}
v8::Isolate* isolate;
uv_loop_t* loop;
};

namespace {
Expand Down Expand Up @@ -527,7 +530,8 @@ void napi_module_register_cb(v8::Local<v8::Object> exports,

// Create a new napi_env for this module. Once module unloading is supported
// we shall have to call delete on this object from there.
napi_env env = new napi_env__(context->GetIsolate());
v8::Isolate* isolate = context->GetIsolate();
napi_env env = new napi_env__(isolate, node::GetCurrentEventLoop(isolate));

napi_value _exports =
mod->nm_register_func(env, v8impl::JsValueFromV8LocalValue(exports));
Expand Down Expand Up @@ -2895,3 +2899,12 @@ NAPI_EXTERN napi_status napi_is_promise(napi_env env,

return napi_ok;
}

NAPI_EXTERN napi_status napi_get_uv_event_loop(napi_env env, uv_loop_t** loop) {
CHECK_ENV(env);
CHECK_ARG(loop);
*loop = env->loop;

napi_clear_last_error();
return napi_ok;
}

0 comments on commit 5bed491

Please sign in to comment.