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 authored and addaleax committed Jan 14, 2019
1 parent de6f1f5 commit 19f1a50
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, _chdir, _cpuUsage,
_hrtime, _hrtimeBigInt,
Expand Down Expand Up @@ -401,7 +400,10 @@ function readAndExecuteStdin() {
}

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

Expand All @@ -423,7 +425,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);
BOOTSTRAP_METHOD(_chdir, Chdir);
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 19f1a50

Please sign in to comment.