Skip to content
Closed
Changes from 1 commit
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
Next Next commit
src: elevate v8 namespaces referenced
  • Loading branch information
juanarbol authored and Trott committed Nov 29, 2018
commit 3eebb4b426eeef9c3656c6b33884951972e317ac
37 changes: 22 additions & 15 deletions src/async_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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<Value> 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));
Expand Down Expand Up @@ -341,8 +349,7 @@ class DestroyParam {
Persistent<Object> propBag;
};


void AsyncWrap::WeakCallback(const v8::WeakCallbackInfo<DestroyParam>& info) {
void AsyncWrap::WeakCallback(const WeakCallbackInfo<DestroyParam>& info) {
HandleScope scope(info.GetIsolate());

std::unique_ptr<DestroyParam> p{info.GetParameter()};
Expand Down Expand Up @@ -374,7 +381,7 @@ static void RegisterDestroyHook(const FunctionCallbackInfo<Value>& args) {
p->target.Reset(isolate, args[0].As<Object>());
p->propBag.Reset(isolate, args[2].As<Object>());
p->target.SetWeak(
p, AsyncWrap::WeakCallback, v8::WeakCallbackType::kParameter);
p, AsyncWrap::WeakCallback, WeakCallbackType::kParameter);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can now unwrap this into a single line.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know what is the max width of line? Linter could break this, no?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The max length is 80 and if you exceed that the linter will pick it up. You can run make lint-cpp to check any changes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased and wrapped!

}


Expand Down Expand Up @@ -448,8 +455,8 @@ void AsyncWrap::Initialize(Local<Object> target,
env->SetMethod(target, "disablePromiseHook", DisablePromiseHook);
env->SetMethod(target, "registerDestroyHook", RegisterDestroyHook);

v8::PropertyAttribute ReadOnlyDontDelete =
static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete);
PropertyAttribute ReadOnlyDontDelete =
static_cast<PropertyAttribute>(ReadOnly | DontDelete);

#define FORCE_SET_TARGET_FIELD(obj, str, field) \
(obj)->DefineOwnProperty(context, \
Expand Down Expand Up @@ -695,7 +702,7 @@ MaybeLocal<Value> AsyncWrap::MakeCallback(const Local<Function> 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();
Expand All @@ -704,7 +711,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();
Expand All @@ -715,18 +722,18 @@ async_context EmitAsyncInit(Isolate* isolate,
Local<Object> resource,
const char* name,
async_id trigger_async_id) {
v8::HandleScope handle_scope(isolate);
HandleScope handle_scope(isolate);
Local<String> 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<Object> resource,
v8::Local<v8::String> name,
Local<String> name,
async_id trigger_async_id) {
v8::HandleScope handle_scope(isolate);
HandleScope handle_scope(isolate);
Environment* env = Environment::GetCurrent(isolate);
CHECK_NOT_NULL(env);

Expand All @@ -748,7 +755,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);
}
Expand All @@ -767,10 +774,10 @@ Local<Object> AsyncWrap::GetOwner() {
}

Local<Object> AsyncWrap::GetOwner(Environment* env, Local<Object> 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<Value> owner;
if (!obj->Get(env->context(),
Expand Down