From 90ae4bd0c987479ff364a469e6f2fcc83baba66c Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Tue, 3 Jul 2018 09:37:07 +0200 Subject: [PATCH] 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 Reviewed-By: Gus Caplan Reviewed-By: Ujjwal Sharma Reviewed-By: Matteo Collina --- src/node.cc | 9 +++++++-- src/node.h | 1 + test/cctest/node_test_fixture.h | 8 +++----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/node.cc b/src/node.cc index 68f23888799018..89e4f76caca049 100644 --- a/src/node.cc +++ b/src/node.cc @@ -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; } @@ -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; diff --git a/src/node.h b/src/node.h index 8bd4bd1549bbc3..9b4dfa6e149db7 100644 --- a/src/node.h +++ b/src/node.h @@ -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); diff --git a/test/cctest/node_test_fixture.h b/test/cctest/node_test_fixture.h index 4a729be09c2d0b..775a211f54380a 100644 --- a/test/cctest/node_test_fixture.h +++ b/test/cctest/node_test_fixture.h @@ -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(¤t_loop)); - v8::V8::InitializePlatform(platform.get()); + platform.reset(static_cast( + node::InitializeV8Platform(4))); v8::V8::Initialize(); } @@ -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(), ¤t_loop); CHECK_NE(isolate_, nullptr); - platform->RegisterIsolate(isolate_, ¤t_loop); - v8::Isolate::Initialize(isolate_, params); } virtual void TearDown() {