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: https://github.com/nodejs/node-v8/issues/69

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Daniel Bevenius 2018-07-03 09:37:07 +02:00 committed by Michaël Zasso
parent d5e7294445
commit 90ae4bd0c9
No known key found for this signature in database
GPG Key ID: 770F7A9A5AE15600
3 changed files with 11 additions and 7 deletions

View File

@ -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) { void FreePlatform(MultiIsolatePlatform* platform) {
delete platform; delete platform;
} }
@ -3209,8 +3215,7 @@ int Start(int argc, char** argv) {
V8::SetEntropySource(crypto::EntropySource); V8::SetEntropySource(crypto::EntropySource);
#endif // HAVE_OPENSSL #endif // HAVE_OPENSSL
v8_platform.Initialize( InitializeV8Platform(per_process_opts->v8_thread_pool_size);
per_process_opts->v8_thread_pool_size);
V8::Initialize(); V8::Initialize();
performance::performance_v8_start = PERFORMANCE_NOW(); performance::performance_v8_start = PERFORMANCE_NOW();
v8_initialized = true; v8_initialized = true;

View File

@ -291,6 +291,7 @@ NODE_EXTERN MultiIsolatePlatform* GetMainThreadMultiIsolatePlatform();
NODE_EXTERN MultiIsolatePlatform* CreatePlatform( NODE_EXTERN MultiIsolatePlatform* CreatePlatform(
int thread_pool_size, int thread_pool_size,
v8::TracingController* tracing_controller); v8::TracingController* tracing_controller);
MultiIsolatePlatform* InitializeV8Platform(int thread_pool_size);
NODE_EXTERN void FreePlatform(MultiIsolatePlatform* platform); NODE_EXTERN void FreePlatform(MultiIsolatePlatform* platform);
NODE_EXTERN void EmitBeforeExit(Environment* env); NODE_EXTERN void EmitBeforeExit(Environment* env);

View File

@ -70,9 +70,9 @@ class NodeTestFixture : public ::testing::Test {
tracing_controller.reset(new v8::TracingController()); tracing_controller.reset(new v8::TracingController());
node::tracing::TraceEventHelper::SetTracingController( node::tracing::TraceEventHelper::SetTracingController(
tracing_controller.get()); tracing_controller.get());
platform.reset(new node::NodePlatform(4, nullptr));
CHECK_EQ(0, uv_loop_init(&current_loop)); 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(); v8::V8::Initialize();
} }
@ -88,10 +88,8 @@ class NodeTestFixture : public ::testing::Test {
virtual void SetUp() { virtual void SetUp() {
allocator = ArrayBufferUniquePtr(node::CreateArrayBufferAllocator(), allocator = ArrayBufferUniquePtr(node::CreateArrayBufferAllocator(),
&node::FreeArrayBufferAllocator); &node::FreeArrayBufferAllocator);
isolate_ = NewIsolate(allocator.get()); isolate_ = NewIsolate(allocator.get(), &current_loop);
CHECK_NE(isolate_, nullptr); CHECK_NE(isolate_, nullptr);
platform->RegisterIsolate(isolate_, &current_loop);
v8::Isolate::Initialize(isolate_, params);
} }
virtual void TearDown() { virtual void TearDown() {