From 70f23289aa020cd06d527744be75ce4f0f4c4427 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Wed, 19 Dec 2018 16:58:34 +0800 Subject: [PATCH] trace_events: move SetupTraceCategoryState into node_trace_events.cc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It makes more sense to put it in `internalBinding('trace_events')` instead of in the bootstrapper object. PR-URL: https://github.com/nodejs/node/pull/25128 Reviewed-By: Michaƫl Zasso Reviewed-By: Richard Lau Reviewed-By: James M Snell --- lib/internal/bootstrap/node.js | 8 +++++--- src/bootstrapper.cc | 7 ------- src/node_trace_events.cc | 11 +++++++++++ 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index c3753741641387..dcb0be8f7eb6ba 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -18,7 +18,6 @@ /* global isMainThread */ const { - _setupTraceCategoryState, _setupNextTick, _setupPromises } = bootstrappers; @@ -431,7 +430,10 @@ function readAndExecuteStdin() { } function setupTraceCategoryState() { - const { traceCategoryState } = internalBinding('trace_events'); + const { + traceCategoryState, + setTraceCategoryStateUpdateHandler + } = internalBinding('trace_events'); const kCategoryAsyncHooks = 0; let traceEventsAsyncHook; @@ -453,7 +455,7 @@ function setupTraceCategoryState() { } toggleTraceCategoryState(); - _setupTraceCategoryState(toggleTraceCategoryState); + setTraceCategoryStateUpdateHandler(toggleTraceCategoryState); } function setupProcessObject() { diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc index 60c05a58a6f47f..b46ba5badab226 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); } diff --git a/src/node_trace_events.cc b/src/node_trace_events.cc index 1dfb1de2fcea1e..3c0f1cf68f1db8 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,13 @@ void GetEnabledCategories(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()); +} + void NodeCategorySet::Initialize(Local target, Local unused, Local context, @@ -109,6 +117,9 @@ void NodeCategorySet::Initialize(Local target, Environment* env = Environment::GetCurrent(context); env->SetMethod(target, "getEnabledCategories", GetEnabledCategories); + env->SetMethod( + target, "setTraceCategoryStateUpdateHandler", + SetTraceCategoryStateUpdateHandler); Local category_set = env->NewFunctionTemplate(NodeCategorySet::New);