File tree Expand file tree Collapse file tree 7 files changed +43
-6
lines changed Open diff view settings
Expand file tree Collapse file tree 7 files changed +43
-6
lines changed Open diff view settings
Original file line number Diff line number Diff line change @@ -496,6 +496,15 @@ NODE_EXTERN MultiIsolatePlatform* CreatePlatform(
496496 v8::TracingController* tracing_controller);
497497NODE_EXTERN void FreePlatform (MultiIsolatePlatform* platform);
498498
499+ // Get/set the currently active tracing controller. Using CreatePlatform()
500+ // will implicitly set this by default. This is global and should be initialized
501+ // along with the v8::Platform instance that is being used. `controller`
502+ // is allowed to be `nullptr`.
503+ // This is used for tracing events from Node.js itself. V8 uses the tracing
504+ // controller returned from the active `v8::Platform` instance.
505+ NODE_EXTERN v8::TracingController* GetTracingController ();
506+ NODE_EXTERN void SetTracingController (v8::TracingController* controller);
507+
499508NODE_EXTERN void EmitBeforeExit (Environment* env);
500509NODE_EXTERN int EmitExit (Environment* env);
501510NODE_EXTERN void RunAtExit (Environment* env);
Original file line number Diff line number Diff line change @@ -328,7 +328,8 @@ NodePlatform::NodePlatform(int thread_pool_size,
328328 // TODO(addaleax): It's a bit icky that we use global state here, but we can't
329329 // really do anything about it unless V8 starts exposing a way to access the
330330 // current v8::Platform instance.
331- tracing::TraceEventHelper::SetTracingController (tracing_controller_);
331+ SetTracingController (tracing_controller_);
332+ DCHECK_EQ (GetTracingController (), tracing_controller_);
332333 worker_thread_task_runner_ =
333334 std::make_shared<WorkerThreadsTaskRunner>(thread_pool_size);
334335}
Original file line number Diff line number Diff line change 1111#include " libplatform/libplatform.h"
1212#include " node.h"
1313#include " node_mutex.h"
14- #include " tracing/agent.h"
1514#include " uv.h"
1615
1716namespace node {
Original file line number Diff line number Diff line change 88#include " env-inl.h"
99#include " node.h"
1010#include " node_metadata.h"
11+ #include " node_platform.h"
1112#include " node_options.h"
1213#include " tracing/node_trace_writer.h"
1314#include " tracing/trace_event.h"
Original file line number Diff line number Diff line change 11#include " tracing/trace_event.h"
2+ #include " node.h"
23
34namespace node {
45namespace tracing {
@@ -24,4 +25,13 @@ void TraceEventHelper::SetTracingController(v8::TracingController* controller) {
2425}
2526
2627} // namespace tracing
28+
29+ v8::TracingController* GetTracingController () {
30+ return tracing::TraceEventHelper::GetTracingController ();
31+ }
32+
33+ void SetTracingController (v8::TracingController* controller) {
34+ tracing::TraceEventHelper::SetTracingController (controller);
35+ }
36+
2737} // namespace node
Original file line number Diff line number Diff line change 55#ifndef SRC_TRACING_TRACE_EVENT_H_
66#define SRC_TRACING_TRACE_EVENT_H_
77
8- #include " node_platform.h"
98#include " v8-platform.h"
9+ #include " tracing/agent.h"
1010#include " trace_event_common.h"
1111#include < atomic>
1212
@@ -310,9 +310,7 @@ const int kZeroNumArgs = 0;
310310const decltype (nullptr ) kGlobalScope = nullptr;
311311const uint64_t kNoId = 0 ;
312312
313- // Extern (for now) because embedders need access to TraceEventHelper.
314- // Refs: https://github.com/nodejs/node/pull/28724
315- class NODE_EXTERN TraceEventHelper {
313+ class TraceEventHelper {
316314 public:
317315 static v8::TracingController* GetTracingController ();
318316 static void SetTracingController (v8::TracingController* controller);
Original file line number Diff line number Diff line change @@ -57,3 +57,22 @@ TEST_F(PlatformTest, SkipNewTasksInFlushForegroundTasks) {
5757 EXPECT_EQ (3 , run_count);
5858 EXPECT_FALSE (platform->FlushForegroundTasks (isolate_));
5959}
60+
61+ TEST_F (PlatformTest, TracingControllerNullptr) {
62+ v8::TracingController* orig_controller = node::GetTracingController ();
63+ node::SetTracingController (nullptr );
64+ EXPECT_EQ (node::GetTracingController (), nullptr );
65+
66+ v8::Isolate::Scope isolate_scope (isolate_);
67+ const v8::HandleScope handle_scope (isolate_);
68+ const Argv argv;
69+ Env env {handle_scope, argv};
70+
71+ node::LoadEnvironment (*env, [&](const node::StartExecutionCallbackInfo& info)
72+ -> v8::MaybeLocal<v8::Value> {
73+ return v8::Null (isolate_);
74+ });
75+
76+ node::SetTracingController (orig_controller);
77+ EXPECT_EQ (node::GetTracingController (), orig_controller);
78+ }
You can’t perform that action at this time.
0 commit comments