From dde727e72f9b06f3287d9940d5bb14763d12e08f 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 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 PR-URL: https://github.com/nodejs/node/pull/36068 Reviewed-By: Juan José Arboleda Reviewed-By: Gabriel Schulhof Reviewed-By: Benjamin Gruenbaum Reviewed-By: Rich Trott Reviewed-By: Chengzhong Wu --- 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 0a3494ce700c93..64e4298e122f43 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);