Skip to content

Commit

Permalink
src: add InitializeV8Platform function
Browse files Browse the repository at this point in the history
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: #69
  • Loading branch information
danbev authored and nodejs-ci committed Sep 6, 2018
1 parent 3291e5b commit b8f5893
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
9 changes: 7 additions & 2 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2990,6 +2990,12 @@ MultiIsolatePlatform* CreatePlatform(
}


MultiIsolatePlatform* InitializeV8Platform(int thread_pool_size) {
v8_platform.Initialize(thread_pool_size);
return v8_platform.Platform();
}


void FreePlatform(MultiIsolatePlatform* platform) {
delete platform;
}
Expand Down Expand Up @@ -3209,8 +3215,7 @@ int Start(int argc, char** argv) {
V8::SetEntropySource(crypto::EntropySource);
#endif // HAVE_OPENSSL

v8_platform.Initialize(
per_process_opts->v8_thread_pool_size);
InitializeV8Platform(per_process_opts->v8_thread_pool_size);
V8::Initialize();
performance::performance_v8_start = PERFORMANCE_NOW();
v8_initialized = true;
Expand Down
1 change: 1 addition & 0 deletions src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ NODE_EXTERN MultiIsolatePlatform* GetMainThreadMultiIsolatePlatform();
NODE_EXTERN MultiIsolatePlatform* CreatePlatform(
int thread_pool_size,
v8::TracingController* tracing_controller);
MultiIsolatePlatform* InitializeV8Platform(int thread_pool_size);
NODE_EXTERN void FreePlatform(MultiIsolatePlatform* platform);

NODE_EXTERN void EmitBeforeExit(Environment* env);
Expand Down
8 changes: 3 additions & 5 deletions test/cctest/node_test_fixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ class NodeTestFixture : public ::testing::Test {
tracing_controller.reset(new v8::TracingController());
node::tracing::TraceEventHelper::SetTracingController(
tracing_controller.get());
platform.reset(new node::NodePlatform(4, nullptr));
CHECK_EQ(0, uv_loop_init(&current_loop));
v8::V8::InitializePlatform(platform.get());
platform.reset(static_cast<node::NodePlatform*>(
node::InitializeV8Platform(4)));
v8::V8::Initialize();
}

Expand All @@ -88,10 +88,8 @@ class NodeTestFixture : public ::testing::Test {
virtual void SetUp() {
allocator = ArrayBufferUniquePtr(node::CreateArrayBufferAllocator(),
&node::FreeArrayBufferAllocator);
isolate_ = NewIsolate(allocator.get());
isolate_ = NewIsolate(allocator.get(), &current_loop);
CHECK_NE(isolate_, nullptr);
platform->RegisterIsolate(isolate_, &current_loop);
v8::Isolate::Initialize(isolate_, params);
}

virtual void TearDown() {
Expand Down

0 comments on commit b8f5893

Please sign in to comment.