mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
2e49b99cc2
Node.js still changes flags after initializationg; either because tests need to set their own flags (which V8 tests also still allow), or because it's explicitly requested via the "v8.setFlagsFromString" method that Node.js provides. PR-URL: https://github.com/nodejs/node/pull/44741 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
45 lines
1.7 KiB
C++
45 lines
1.7 KiB
C++
#include "node_test_fixture.h"
|
|
#include "cppgc/platform.h"
|
|
|
|
ArrayBufferUniquePtr NodeZeroIsolateTestFixture::allocator{nullptr, nullptr};
|
|
uv_loop_t NodeZeroIsolateTestFixture::current_loop;
|
|
NodePlatformUniquePtr NodeZeroIsolateTestFixture::platform;
|
|
TracingAgentUniquePtr NodeZeroIsolateTestFixture::tracing_agent;
|
|
bool NodeZeroIsolateTestFixture::node_initialized = false;
|
|
|
|
|
|
void NodeTestEnvironment::SetUp() {
|
|
NodeZeroIsolateTestFixture::tracing_agent =
|
|
std::make_unique<node::tracing::Agent>();
|
|
node::tracing::TraceEventHelper::SetAgent(
|
|
NodeZeroIsolateTestFixture::tracing_agent.get());
|
|
node::tracing::TracingController* tracing_controller =
|
|
NodeZeroIsolateTestFixture::tracing_agent->GetTracingController();
|
|
static constexpr int kV8ThreadPoolSize = 4;
|
|
NodeZeroIsolateTestFixture::platform.reset(
|
|
new node::NodePlatform(kV8ThreadPoolSize, tracing_controller));
|
|
v8::V8::InitializePlatform(NodeZeroIsolateTestFixture::platform.get());
|
|
#ifdef V8_ENABLE_SANDBOX
|
|
ASSERT_TRUE(v8::V8::InitializeSandbox());
|
|
#endif
|
|
cppgc::InitializeProcess(
|
|
NodeZeroIsolateTestFixture::platform->GetPageAllocator());
|
|
|
|
// Before initializing V8, disable the --freeze-flags-after-init flag, so
|
|
// individual tests can set their own flags.
|
|
v8::V8::SetFlagsFromString("--no-freeze-flags-after-init");
|
|
|
|
v8::V8::Initialize();
|
|
}
|
|
|
|
void NodeTestEnvironment::TearDown() {
|
|
v8::V8::Dispose();
|
|
v8::V8::DisposePlatform();
|
|
NodeZeroIsolateTestFixture::platform->Shutdown();
|
|
NodeZeroIsolateTestFixture::platform.reset(nullptr);
|
|
NodeZeroIsolateTestFixture::tracing_agent.reset(nullptr);
|
|
}
|
|
|
|
::testing::Environment* const node_env =
|
|
::testing::AddGlobalTestEnvironment(new NodeTestEnvironment());
|