Skip to content

Commit 19f1a50

Browse files
joyeecheungaddaleax
authored andcommitted
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 <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent de6f1f5 commit 19f1a50

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

lib/internal/bootstrap/node.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
/* global isMainThread */
1919

2020
const {
21-
_setupTraceCategoryState,
2221
_setupNextTick,
2322
_setupPromises, _chdir, _cpuUsage,
2423
_hrtime, _hrtimeBigInt,
@@ -401,7 +400,10 @@ function readAndExecuteStdin() {
401400
}
402401

403402
function setupTraceCategoryState() {
404-
const { traceCategoryState } = internalBinding('trace_events');
403+
const {
404+
traceCategoryState,
405+
setTraceCategoryStateUpdateHandler
406+
} = internalBinding('trace_events');
405407
const kCategoryAsyncHooks = 0;
406408
let traceEventsAsyncHook;
407409

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

425427
toggleTraceCategoryState();
426-
_setupTraceCategoryState(toggleTraceCategoryState);
428+
setTraceCategoryStateUpdateHandler(toggleTraceCategoryState);
427429
}
428430

429431
function setupProcessObject() {

src/bootstrapper.cc

-7
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ void RunMicrotasks(const FunctionCallbackInfo<Value>& args) {
3030
args.GetIsolate()->RunMicrotasks();
3131
}
3232

33-
void SetupTraceCategoryState(const FunctionCallbackInfo<Value>& args) {
34-
Environment* env = Environment::GetCurrent(args);
35-
CHECK(args[0]->IsFunction());
36-
env->set_trace_category_state_function(args[0].As<Function>());
37-
}
38-
3933
void SetupNextTick(const FunctionCallbackInfo<Value>& args) {
4034
Environment* env = Environment::GetCurrent(args);
4135
Isolate* isolate = env->isolate();
@@ -136,7 +130,6 @@ void SetupPromises(const FunctionCallbackInfo<Value>& args) {
136130
// completes so that it can be gc'd as soon as possible.
137131
void SetupBootstrapObject(Environment* env,
138132
Local<Object> bootstrapper) {
139-
BOOTSTRAP_METHOD(_setupTraceCategoryState, SetupTraceCategoryState);
140133
BOOTSTRAP_METHOD(_setupNextTick, SetupNextTick);
141134
BOOTSTRAP_METHOD(_setupPromises, SetupPromises);
142135
BOOTSTRAP_METHOD(_chdir, Chdir);

src/node_trace_events.cc

+11
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace node {
1111

1212
using v8::Array;
1313
using v8::Context;
14+
using v8::Function;
1415
using v8::FunctionCallbackInfo;
1516
using v8::FunctionTemplate;
1617
using v8::Local;
@@ -102,13 +103,23 @@ void GetEnabledCategories(const FunctionCallbackInfo<Value>& args) {
102103
}
103104
}
104105

106+
static void SetTraceCategoryStateUpdateHandler(
107+
const FunctionCallbackInfo<Value>& args) {
108+
Environment* env = Environment::GetCurrent(args);
109+
CHECK(args[0]->IsFunction());
110+
env->set_trace_category_state_function(args[0].As<Function>());
111+
}
112+
105113
void NodeCategorySet::Initialize(Local<Object> target,
106114
Local<Value> unused,
107115
Local<Context> context,
108116
void* priv) {
109117
Environment* env = Environment::GetCurrent(context);
110118

111119
env->SetMethod(target, "getEnabledCategories", GetEnabledCategories);
120+
env->SetMethod(
121+
target, "setTraceCategoryStateUpdateHandler",
122+
SetTraceCategoryStateUpdateHandler);
112123

113124
Local<FunctionTemplate> category_set =
114125
env->NewFunctionTemplate(NodeCategorySet::New);

0 commit comments

Comments
 (0)