From 9f559af8c9b9664b3f592eb374ec25128309f7a1 Mon Sep 17 00:00:00 2001 From: Michael Dawson Date: Tue, 10 Nov 2020 10:20:28 -0500 Subject: [PATCH] n-api: improve consistency of how we get context Refs: https://github.com/nodejs/node-addon-api/issues/764 Improve the consistency of how we get a context when needed. We generally used env->context() in N-API but there were are few exceptions that this PR addresses. Signed-off-by: Michael Dawson --- src/js_native_api_v8.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/js_native_api_v8.cc b/src/js_native_api_v8.cc index e7a16401369f42..c4df11916e7ace 100644 --- a/src/js_native_api_v8.cc +++ b/src/js_native_api_v8.cc @@ -169,7 +169,7 @@ inline static napi_status ConcludeDeferred(napi_env env, NAPI_PREAMBLE(env); CHECK_ARG(env, result); - v8::Local context = env->isolate->GetCurrentContext(); + v8::Local context = env->context(); v8impl::Persistent* deferred_ref = NodePersistentFromJsDeferred(deferred); v8::Local v8_deferred = @@ -385,8 +385,7 @@ inline static napi_status Unwrap(napi_env env, CHECK_ARG(env, result); } - v8::Isolate* isolate = env->isolate; - v8::Local context = isolate->GetCurrentContext(); + v8::Local context = env->context(); v8::Local value = v8impl::V8LocalValueFromJsValue(js_object); RETURN_STATUS_IF_FALSE(env, value->IsObject(), napi_invalid_arg);