Skip to content

Commit

Permalink
trace_events: move SetupTraceCategoryState into node_trace_events.cc
Browse files Browse the repository at this point in the history
It makes more sense to put it in `internalBinding('trace_events')`
instead of in the bootstrapper object.

PR-URL: #25128
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
joyeecheung committed Dec 21, 2018
1 parent 75d0a93 commit 70f2328
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
8 changes: 5 additions & 3 deletions lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
/* global isMainThread */

const {
_setupTraceCategoryState,
_setupNextTick,
_setupPromises
} = bootstrappers;
Expand Down Expand Up @@ -431,7 +430,10 @@ function readAndExecuteStdin() {
}

function setupTraceCategoryState() {
const { traceCategoryState } = internalBinding('trace_events');
const {
traceCategoryState,
setTraceCategoryStateUpdateHandler
} = internalBinding('trace_events');
const kCategoryAsyncHooks = 0;
let traceEventsAsyncHook;

Expand All @@ -453,7 +455,7 @@ function setupTraceCategoryState() {
}

toggleTraceCategoryState();
_setupTraceCategoryState(toggleTraceCategoryState);
setTraceCategoryStateUpdateHandler(toggleTraceCategoryState);
}

function setupProcessObject() {
Expand Down
7 changes: 0 additions & 7 deletions src/bootstrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ void RunMicrotasks(const FunctionCallbackInfo<Value>& args) {
args.GetIsolate()->RunMicrotasks();
}

void SetupTraceCategoryState(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
CHECK(args[0]->IsFunction());
env->set_trace_category_state_function(args[0].As<Function>());
}

void SetupNextTick(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
Isolate* isolate = env->isolate();
Expand Down Expand Up @@ -136,7 +130,6 @@ void SetupPromises(const FunctionCallbackInfo<Value>& args) {
// completes so that it can be gc'd as soon as possible.
void SetupBootstrapObject(Environment* env,
Local<Object> bootstrapper) {
BOOTSTRAP_METHOD(_setupTraceCategoryState, SetupTraceCategoryState);
BOOTSTRAP_METHOD(_setupNextTick, SetupNextTick);
BOOTSTRAP_METHOD(_setupPromises, SetupPromises);
}
Expand Down
11 changes: 11 additions & 0 deletions src/node_trace_events.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace node {

using v8::Array;
using v8::Context;
using v8::Function;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
using v8::Local;
Expand Down Expand Up @@ -102,13 +103,23 @@ void GetEnabledCategories(const FunctionCallbackInfo<Value>& args) {
}
}

static void SetTraceCategoryStateUpdateHandler(
const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
CHECK(args[0]->IsFunction());
env->set_trace_category_state_function(args[0].As<Function>());
}

void NodeCategorySet::Initialize(Local<Object> target,
Local<Value> unused,
Local<Context> context,
void* priv) {
Environment* env = Environment::GetCurrent(context);

env->SetMethod(target, "getEnabledCategories", GetEnabledCategories);
env->SetMethod(
target, "setTraceCategoryStateUpdateHandler",
SetTraceCategoryStateUpdateHandler);

Local<FunctionTemplate> category_set =
env->NewFunctionTemplate(NodeCategorySet::New);
Expand Down

0 comments on commit 70f2328

Please sign in to comment.