Skip to content
Permalink
Browse files

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.

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 Dec 19, 2018
1 parent de6f1f5 commit 19f1a506eebf25dfa3132c6612c5adf55f722df2
Showing with 16 additions and 10 deletions.
  1. +5 −3 lib/internal/bootstrap/node.js
  2. +0 −7 src/bootstrapper.cc
  3. +11 −0 src/node_trace_events.cc
@@ -18,7 +18,6 @@
/* global isMainThread */

const {
_setupTraceCategoryState,
_setupNextTick,
_setupPromises, _chdir, _cpuUsage,
_hrtime, _hrtimeBigInt,
@@ -401,7 +400,10 @@ function readAndExecuteStdin() {
}

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

@@ -423,7 +425,7 @@ function setupTraceCategoryState() {
}

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

function setupProcessObject() {
@@ -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();
@@ -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);
@@ -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,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);

0 comments on commit 19f1a50

Please sign in to comment.
You can’t perform that action at this time.