From 2e49b99cc2f43684ed0903c5ae75a982c2e53bbc Mon Sep 17 00:00:00 2001 From: Clemens Backes Date: Mon, 13 Jun 2022 12:38:15 +0200 Subject: [PATCH] src,test: disable freezing V8 flags on initialization 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 Reviewed-By: Jiawen Geng Reviewed-By: James M Snell --- src/node.cc | 5 +++++ test/cctest/node_test_fixture.cc | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/node.cc b/src/node.cc index c7e20acfaf9aca..a9b909b74e0e6b 100644 --- a/src/node.cc +++ b/src/node.cc @@ -741,6 +741,11 @@ static ExitCode InitializeNodeWithArgsInternal( // used in diagnostic reports. per_process::cli_options->cmdline = *argv; + // Node provides a "v8.setFlagsFromString" method to dynamically change flags. + // Hence do not freeze flags when initializing V8. In a browser setting, this + // is security relevant, for Node it's less important. + V8::SetFlagsFromString("--no-freeze-flags-after-init"); + #if defined(NODE_V8_OPTIONS) // Should come before the call to V8::SetFlagsFromCommandLine() // so the user can disable a flag --foo at run-time by passing diff --git a/test/cctest/node_test_fixture.cc b/test/cctest/node_test_fixture.cc index 5cbbee8f1ece2c..59cf7eee49e530 100644 --- a/test/cctest/node_test_fixture.cc +++ b/test/cctest/node_test_fixture.cc @@ -24,6 +24,11 @@ void NodeTestEnvironment::SetUp() { #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(); }