Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

n-api: remove napi_env::CallIntoModuleThrow #33570

Closed
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/js_native_api_v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ class RefBase : protected Finalizer, RefTracker {
protected:
inline void Finalize(bool is_env_teardown = false) override {
if (_finalize_callback != nullptr) {
_env->CallIntoModuleThrow([&](napi_env env) {
_env->CallIntoModule([&](napi_env env) {
_finalize_callback(
env,
_finalize_data,
Expand Down Expand Up @@ -475,7 +475,7 @@ class CallbackWrapperBase : public CallbackWrapper {
napi_callback cb = _bundle->*FunctionField;

napi_value result;
env->CallIntoModuleThrow([&](napi_env env) {
env->CallIntoModule([&](napi_env env) {
result = cb(env, cbinfo_wrapper);
});

Expand Down
16 changes: 7 additions & 9 deletions src/js_native_api_v8.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,13 @@ struct napi_env__ {
return v8::Just(true);
}

template <typename T, typename U>
void CallIntoModule(T&& call, U&& handle_exception) {
static inline void
HandleThrow(napi_env env, v8::Local<v8::Value> value) {
env->isolate->ThrowException(value);
}

template <typename T, typename U = decltype(HandleThrow)>
inline void CallIntoModule(T&& call, U&& handle_exception = HandleThrow) {
int open_handle_scopes_before = open_handle_scopes;
int open_callback_scopes_before = open_callback_scopes;
napi_clear_last_error(this);
Expand All @@ -96,13 +101,6 @@ struct napi_env__ {
}
}

template <typename T>
void CallIntoModuleThrow(T&& call) {
CallIntoModule(call, [&](napi_env env, v8::Local<v8::Value> value) {
env->isolate->ThrowException(value);
});
}

v8impl::Persistent<v8::Value> last_exception;

// We store references in two different lists, depending on whether they have
Expand Down
8 changes: 4 additions & 4 deletions src/node_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class BufferFinalizer : private Finalizer {
v8::HandleScope handle_scope(finalizer->_env->isolate);
v8::Context::Scope context_scope(finalizer->_env->context());

finalizer->_env->CallIntoModuleThrow([&](napi_env env) {
finalizer->_env->CallIntoModule([&](napi_env env) {
finalizer->_finalize_callback(
env,
finalizer->_finalize_data,
Expand Down Expand Up @@ -308,7 +308,7 @@ class ThreadSafeFunction : public node::AsyncResource {
v8::Local<v8::Function>::New(env->isolate, ref);
js_callback = v8impl::JsValueFromV8LocalValue(js_cb);
}
env->CallIntoModuleThrow([&](napi_env env) {
env->CallIntoModule([&](napi_env env) {
call_js_cb(env, js_callback, context, data);
});
}
Expand All @@ -318,7 +318,7 @@ class ThreadSafeFunction : public node::AsyncResource {
v8::HandleScope scope(env->isolate);
if (finalize_cb) {
CallbackScope cb_scope(this);
env->CallIntoModuleThrow([&](napi_env env) {
env->CallIntoModule([&](napi_env env) {
finalize_cb(env, finalize_data, context);
});
}
Expand Down Expand Up @@ -455,7 +455,7 @@ void napi_module_register_by_symbol(v8::Local<v8::Object> exports,
napi_env env = v8impl::NewEnv(context);

napi_value _exports;
env->CallIntoModuleThrow([&](napi_env env) {
env->CallIntoModule([&](napi_env env) {
_exports = init(env, v8impl::JsValueFromV8LocalValue(exports));
});

Expand Down