★ wanayoo — archive 1999 https://github.com/nodejs/node/commit/bb766ae05aNouvelle recherche | Portail wanayoo
Skip to content
Permalink
Browse files
async_hooks: add HandleScopes to C++ embedder/addon API
Add `HandleScope`s to the public C++ API for embedders/addons,
since these methods create V8 handles that should not leak into
the outer scopes.

In particular, for some of the methods it was not clear from
the function signatures that these functions previously
needed to be invoked with a `HandleScope`.

PR-URL: #24285
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
  • Loading branch information
addaleax authored and BridgeAR committed Nov 13, 2018
1 parent b6d2819 commit bb766ae05a2a590c93767125cf73e0fa71a1991a
Showing with 10 additions and 0 deletions.
  1. +8 −0 src/async_wrap.cc
  2. +2 −0 test/addons/async-hello-world/binding.cc
@@ -706,13 +706,17 @@ MaybeLocal<Value> AsyncWrap::MakeCallback(const Local<Function> cb,


async_id AsyncHooksGetExecutionAsyncId(Isolate* isolate) {
// Environment::GetCurrent() allocates a Local<> handle.
v8::HandleScope handle_scope(isolate);
Environment* env = Environment::GetCurrent(isolate);
if (env == nullptr) return -1;
return env->execution_async_id();
}


async_id AsyncHooksGetTriggerAsyncId(Isolate* isolate) {
// Environment::GetCurrent() allocates a Local<> handle.
v8::HandleScope handle_scope(isolate);
Environment* env = Environment::GetCurrent(isolate);
if (env == nullptr) return -1;
return env->trigger_async_id();
@@ -723,6 +727,7 @@ async_context EmitAsyncInit(Isolate* isolate,
Local<Object> resource,
const char* name,
async_id trigger_async_id) {
v8::HandleScope handle_scope(isolate);
Local<String> type =
String::NewFromUtf8(isolate, name, v8::NewStringType::kInternalized)
.ToLocalChecked();
@@ -733,6 +738,7 @@ async_context EmitAsyncInit(Isolate* isolate,
Local<Object> resource,
v8::Local<v8::String> name,
async_id trigger_async_id) {
v8::HandleScope handle_scope(isolate);
Environment* env = Environment::GetCurrent(isolate);
CHECK_NOT_NULL(env);

@@ -753,6 +759,8 @@ async_context EmitAsyncInit(Isolate* isolate,
}

void EmitAsyncDestroy(Isolate* isolate, async_context asyncContext) {
// Environment::GetCurrent() allocates a Local<> handle.
v8::HandleScope handle_scope(isolate);
AsyncWrap::EmitDestroy(
Environment::GetCurrent(isolate), asyncContext.async_id);
}
@@ -57,6 +57,8 @@ void AfterAsync(uv_work_t* r) {
global, 2, argv).ToLocalChecked();
}

// None of the following operations should allocate handles into this scope.
v8::SealHandleScope seal_handle_scope(isolate);
// cleanup
node::EmitAsyncDestroy(isolate, req->context);
req->callback.Reset();

0 comments on commit bb766ae

Please sign in to comment.