Skip to content

Commit 90ae4bd

Browse files
danbevtargos
authored andcommitted
src: add InitializeV8Platform function
This commit adds an InitializeV8Platform function which calls v8_platform's Initialize to create the NodePlatform and also set the structs members. When running cctests this functions was not being called (it is called from the Start function but that function is not called by the test fixture. The motivation for adding this is that I'm guessing that embedders would might need the ability to do the same thing. Refs: nodejs/node-v8#69 PR-URL: nodejs#21983 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent d5e7294 commit 90ae4bd

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

src/node.cc

+7-2
Original file line numberDiff line numberDiff line change
@@ -2990,6 +2990,12 @@ MultiIsolatePlatform* CreatePlatform(
29902990
}
29912991

29922992

2993+
MultiIsolatePlatform* InitializeV8Platform(int thread_pool_size) {
2994+
v8_platform.Initialize(thread_pool_size);
2995+
return v8_platform.Platform();
2996+
}
2997+
2998+
29932999
void FreePlatform(MultiIsolatePlatform* platform) {
29943000
delete platform;
29953001
}
@@ -3209,8 +3215,7 @@ int Start(int argc, char** argv) {
32093215
V8::SetEntropySource(crypto::EntropySource);
32103216
#endif // HAVE_OPENSSL
32113217

3212-
v8_platform.Initialize(
3213-
per_process_opts->v8_thread_pool_size);
3218+
InitializeV8Platform(per_process_opts->v8_thread_pool_size);
32143219
V8::Initialize();
32153220
performance::performance_v8_start = PERFORMANCE_NOW();
32163221
v8_initialized = true;

src/node.h

+1
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ NODE_EXTERN MultiIsolatePlatform* GetMainThreadMultiIsolatePlatform();
291291
NODE_EXTERN MultiIsolatePlatform* CreatePlatform(
292292
int thread_pool_size,
293293
v8::TracingController* tracing_controller);
294+
MultiIsolatePlatform* InitializeV8Platform(int thread_pool_size);
294295
NODE_EXTERN void FreePlatform(MultiIsolatePlatform* platform);
295296

296297
NODE_EXTERN void EmitBeforeExit(Environment* env);

test/cctest/node_test_fixture.h

+3-5
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ class NodeTestFixture : public ::testing::Test {
7070
tracing_controller.reset(new v8::TracingController());
7171
node::tracing::TraceEventHelper::SetTracingController(
7272
tracing_controller.get());
73-
platform.reset(new node::NodePlatform(4, nullptr));
7473
CHECK_EQ(0, uv_loop_init(&current_loop));
75-
v8::V8::InitializePlatform(platform.get());
74+
platform.reset(static_cast<node::NodePlatform*>(
75+
node::InitializeV8Platform(4)));
7676
v8::V8::Initialize();
7777
}
7878

@@ -88,10 +88,8 @@ class NodeTestFixture : public ::testing::Test {
8888
virtual void SetUp() {
8989
allocator = ArrayBufferUniquePtr(node::CreateArrayBufferAllocator(),
9090
&node::FreeArrayBufferAllocator);
91-
isolate_ = NewIsolate(allocator.get());
91+
isolate_ = NewIsolate(allocator.get(), &current_loop);
9292
CHECK_NE(isolate_, nullptr);
93-
platform->RegisterIsolate(isolate_, &current_loop);
94-
v8::Isolate::Initialize(isolate_, params);
9593
}
9694

9795
virtual void TearDown() {

0 commit comments

Comments
 (0)