From 1b4448169b580e2cea920b551924a94db31f3633 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Wed, 19 Dec 2018 16:58:34 +0800 Subject: [PATCH 1/2] trace_events: move SetupTraceCategoryState into node_trace_events.cc It makes more sense to put it in `internalBinding('trace_events')` instead of in the bootstrapper object. --- lib/internal/bootstrap/node.js | 8 +++++--- src/bootstrapper.cc | 7 ------- src/node_trace_events.cc | 8 ++++++++ 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index 33d79689d0993f..a89f68797e3d53 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -18,7 +18,6 @@ /* global isMainThread */ const { - _setupTraceCategoryState, _setupNextTick, _setupPromises, _chdir, _cpuUsage, _hrtime, _hrtimeBigInt, @@ -384,7 +383,10 @@ function readAndExecuteStdin() { } function setupTraceCategoryState() { - const { traceCategoryState } = internalBinding('trace_events'); + const { + traceCategoryState, + setupTraceCategoryState + } = internalBinding('trace_events'); const kCategoryAsyncHooks = 0; let traceEventsAsyncHook; @@ -406,7 +408,7 @@ function setupTraceCategoryState() { } toggleTraceCategoryState(); - _setupTraceCategoryState(toggleTraceCategoryState); + setupTraceCategoryState(toggleTraceCategoryState); } function setupProcessObject() { diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc index 0a1cfed2109e5c..de3eca8ba464a2 100644 --- a/src/bootstrapper.cc +++ b/src/bootstrapper.cc @@ -30,12 +30,6 @@ void RunMicrotasks(const FunctionCallbackInfo& args) { args.GetIsolate()->RunMicrotasks(); } -void SetupTraceCategoryState(const FunctionCallbackInfo& args) { - Environment* env = Environment::GetCurrent(args); - CHECK(args[0]->IsFunction()); - env->set_trace_category_state_function(args[0].As()); -} - void SetupNextTick(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); Isolate* isolate = env->isolate(); @@ -136,7 +130,6 @@ void SetupPromises(const FunctionCallbackInfo& args) { // completes so that it can be gc'd as soon as possible. void SetupBootstrapObject(Environment* env, Local bootstrapper) { - BOOTSTRAP_METHOD(_setupTraceCategoryState, SetupTraceCategoryState); BOOTSTRAP_METHOD(_setupNextTick, SetupNextTick); BOOTSTRAP_METHOD(_setupPromises, SetupPromises); BOOTSTRAP_METHOD(_chdir, Chdir); diff --git a/src/node_trace_events.cc b/src/node_trace_events.cc index 1dfb1de2fcea1e..9f588297d61dd1 100644 --- a/src/node_trace_events.cc +++ b/src/node_trace_events.cc @@ -11,6 +11,7 @@ namespace node { using v8::Array; using v8::Context; +using v8::Function; using v8::FunctionCallbackInfo; using v8::FunctionTemplate; using v8::Local; @@ -102,6 +103,12 @@ void GetEnabledCategories(const FunctionCallbackInfo& args) { } } +static void SetupTraceCategoryState(const FunctionCallbackInfo& args) { + Environment* env = Environment::GetCurrent(args); + CHECK(args[0]->IsFunction()); + env->set_trace_category_state_function(args[0].As()); +} + void NodeCategorySet::Initialize(Local target, Local unused, Local context, @@ -109,6 +116,7 @@ void NodeCategorySet::Initialize(Local target, Environment* env = Environment::GetCurrent(context); env->SetMethod(target, "getEnabledCategories", GetEnabledCategories); + env->SetMethod(target, "setupTraceCategoryState", SetupTraceCategoryState); Local category_set = env->NewFunctionTemplate(NodeCategorySet::New); From a7005a8483fd209b0be0bde5e026d551b3d0bc8d Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Wed, 19 Dec 2018 20:45:23 +0800 Subject: [PATCH 2/2] fixup! trace_events: move SetupTraceCategoryState into node_trace_events.cc --- lib/internal/bootstrap/node.js | 4 ++-- src/node_trace_events.cc | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index a89f68797e3d53..ca44196e88e8e3 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -385,7 +385,7 @@ function readAndExecuteStdin() { function setupTraceCategoryState() { const { traceCategoryState, - setupTraceCategoryState + setTraceCategoryStateUpdateHandler } = internalBinding('trace_events'); const kCategoryAsyncHooks = 0; let traceEventsAsyncHook; @@ -408,7 +408,7 @@ function setupTraceCategoryState() { } toggleTraceCategoryState(); - setupTraceCategoryState(toggleTraceCategoryState); + setTraceCategoryStateUpdateHandler(toggleTraceCategoryState); } function setupProcessObject() { diff --git a/src/node_trace_events.cc b/src/node_trace_events.cc index 9f588297d61dd1..3c0f1cf68f1db8 100644 --- a/src/node_trace_events.cc +++ b/src/node_trace_events.cc @@ -103,7 +103,8 @@ void GetEnabledCategories(const FunctionCallbackInfo& args) { } } -static void SetupTraceCategoryState(const FunctionCallbackInfo& args) { +static void SetTraceCategoryStateUpdateHandler( + const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); CHECK(args[0]->IsFunction()); env->set_trace_category_state_function(args[0].As()); @@ -116,7 +117,9 @@ void NodeCategorySet::Initialize(Local target, Environment* env = Environment::GetCurrent(context); env->SetMethod(target, "getEnabledCategories", GetEnabledCategories); - env->SetMethod(target, "setupTraceCategoryState", SetupTraceCategoryState); + env->SetMethod( + target, "setTraceCategoryStateUpdateHandler", + SetTraceCategoryStateUpdateHandler); Local category_set = env->NewFunctionTemplate(NodeCategorySet::New);