From 0148c1d4f9c0055370ab86b976d2b67378d5ea24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Arboleda?= Date: Mon, 26 Nov 2018 06:54:05 -0500 Subject: [PATCH] src: elevate v8 namespaces referenced PR-URL: https://github.com/nodejs/node/pull/24657 Reviewed-By: Colin Ihrig Reviewed-By: Luigi Pinca Reviewed-By: Gireesh Punathil Reviewed-By: Minwoo Jung Reviewed-By: Franziska Hinkelmann --- src/async_wrap.cc | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/async_wrap.cc b/src/async_wrap.cc index f3bd59d4ac30bc..a8458f4265ff21 100644 --- a/src/async_wrap.cc +++ b/src/async_wrap.cc @@ -30,6 +30,8 @@ #include "v8-profiler.h" using v8::Context; +using v8::DontDelete; +using v8::EscapableHandleScope; using v8::Function; using v8::FunctionCallbackInfo; using v8::FunctionTemplate; @@ -38,16 +40,22 @@ using v8::Integer; using v8::Isolate; using v8::Local; using v8::MaybeLocal; +using v8::NewStringType; using v8::Number; using v8::Object; using v8::ObjectTemplate; using v8::Promise; using v8::PromiseHookType; +using v8::PropertyAttribute; using v8::PropertyCallbackInfo; +using v8::ReadOnly; using v8::String; +using v8::TryCatch; using v8::Uint32; using v8::Undefined; using v8::Value; +using v8::WeakCallbackInfo; +using v8::WeakCallbackType; using AsyncHooks = node::Environment::AsyncHooks; @@ -117,7 +125,7 @@ void Emit(Environment* env, double async_id, AsyncHooks::Fields type, if (async_hooks->fields()[type] == 0 || !env->can_call_into_js()) return; - v8::HandleScope handle_scope(env->isolate()); + HandleScope handle_scope(env->isolate()); Local async_id_value = Number::New(env->isolate(), async_id); FatalTryCatch try_catch(env); USE(fn->Call(env->context(), Undefined(env->isolate()), 1, &async_id_value)); @@ -353,8 +361,7 @@ class DestroyParam { Persistent propBag; }; - -void AsyncWrap::WeakCallback(const v8::WeakCallbackInfo& info) { +void AsyncWrap::WeakCallback(const WeakCallbackInfo& info) { HandleScope scope(info.GetIsolate()); std::unique_ptr p{info.GetParameter()}; @@ -385,8 +392,7 @@ static void RegisterDestroyHook(const FunctionCallbackInfo& args) { p->env = Environment::GetCurrent(args); p->target.Reset(isolate, args[0].As()); p->propBag.Reset(isolate, args[2].As()); - p->target.SetWeak( - p, AsyncWrap::WeakCallback, v8::WeakCallbackType::kParameter); + p->target.SetWeak(p, AsyncWrap::WeakCallback, WeakCallbackType::kParameter); } @@ -460,8 +466,8 @@ void AsyncWrap::Initialize(Local target, env->SetMethod(target, "disablePromiseHook", DisablePromiseHook); env->SetMethod(target, "registerDestroyHook", RegisterDestroyHook); - v8::PropertyAttribute ReadOnlyDontDelete = - static_cast(v8::ReadOnly | v8::DontDelete); + PropertyAttribute ReadOnlyDontDelete = + static_cast(ReadOnly | DontDelete); #define FORCE_SET_TARGET_FIELD(obj, str, field) \ (obj)->DefineOwnProperty(context, \ @@ -707,7 +713,7 @@ MaybeLocal AsyncWrap::MakeCallback(const Local cb, async_id AsyncHooksGetExecutionAsyncId(Isolate* isolate) { // Environment::GetCurrent() allocates a Local<> handle. - v8::HandleScope handle_scope(isolate); + HandleScope handle_scope(isolate); Environment* env = Environment::GetCurrent(isolate); if (env == nullptr) return -1; return env->execution_async_id(); @@ -716,7 +722,7 @@ async_id AsyncHooksGetExecutionAsyncId(Isolate* isolate) { async_id AsyncHooksGetTriggerAsyncId(Isolate* isolate) { // Environment::GetCurrent() allocates a Local<> handle. - v8::HandleScope handle_scope(isolate); + HandleScope handle_scope(isolate); Environment* env = Environment::GetCurrent(isolate); if (env == nullptr) return -1; return env->trigger_async_id(); @@ -727,18 +733,18 @@ async_context EmitAsyncInit(Isolate* isolate, Local resource, const char* name, async_id trigger_async_id) { - v8::HandleScope handle_scope(isolate); + HandleScope handle_scope(isolate); Local type = - String::NewFromUtf8(isolate, name, v8::NewStringType::kInternalized) + String::NewFromUtf8(isolate, name, NewStringType::kInternalized) .ToLocalChecked(); return EmitAsyncInit(isolate, resource, type, trigger_async_id); } async_context EmitAsyncInit(Isolate* isolate, Local resource, - v8::Local name, + Local name, async_id trigger_async_id) { - v8::HandleScope handle_scope(isolate); + HandleScope handle_scope(isolate); Environment* env = Environment::GetCurrent(isolate); CHECK_NOT_NULL(env); @@ -760,7 +766,7 @@ async_context EmitAsyncInit(Isolate* isolate, void EmitAsyncDestroy(Isolate* isolate, async_context asyncContext) { // Environment::GetCurrent() allocates a Local<> handle. - v8::HandleScope handle_scope(isolate); + HandleScope handle_scope(isolate); AsyncWrap::EmitDestroy( Environment::GetCurrent(isolate), asyncContext.async_id); } @@ -779,10 +785,10 @@ Local AsyncWrap::GetOwner() { } Local AsyncWrap::GetOwner(Environment* env, Local obj) { - v8::EscapableHandleScope handle_scope(env->isolate()); + EscapableHandleScope handle_scope(env->isolate()); CHECK(!obj.IsEmpty()); - v8::TryCatch ignore_exceptions(env->isolate()); + TryCatch ignore_exceptions(env->isolate()); while (true) { Local owner; if (!obj->Get(env->context(),