src: make build_snapshot a per-Isolate option, rather than a global one

PR-URL: https://github.com/nodejs/node/pull/45888
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
This commit is contained in:
Anna Henningsen
2023-01-24 21:35:27 +01:00
committed by Node.js GitHub Bot
parent 06bb6b42b3
commit 02fad4f40a
5 changed files with 10 additions and 10 deletions

View File

@@ -307,7 +307,7 @@ MaybeLocal<Value> StartExecution(Environment* env, StartExecutionCallback cb) {
return StartExecution(env, "internal/main/inspect");
}
if (per_process::cli_options->build_snapshot) {
if (env->isolate_data()->options()->build_snapshot) {
return StartExecution(env, "internal/main/mksnapshot");
}
@@ -1227,7 +1227,7 @@ static ExitCode StartInternal(int argc, char** argv) {
uv_loop_configure(uv_default_loop(), UV_METRICS_IDLE_TIME);
// --build-snapshot indicates that we are in snapshot building mode.
if (per_process::cli_options->build_snapshot) {
if (per_process::cli_options->per_isolate->build_snapshot) {
if (result->args().size() < 2) {
fprintf(stderr,
"--build-snapshot must be used with an entry point script.\n"

View File

@@ -777,6 +777,11 @@ PerIsolateOptionsParser::PerIsolateOptionsParser(
Implies("--experimental-shadow-realm", "--harmony-shadow-realm");
Implies("--harmony-shadow-realm", "--experimental-shadow-realm");
ImpliesNot("--no-harmony-shadow-realm", "--experimental-shadow-realm");
AddOption("--build-snapshot",
"Generate a snapshot blob when the process exits."
" Currently only supported in the node_mksnapshot binary.",
&PerIsolateOptions::build_snapshot,
kDisallowedInEnvvar);
Insert(eop, &PerIsolateOptions::get_per_env_options);
}
@@ -815,11 +820,6 @@ PerProcessOptionsParser::PerProcessOptionsParser(
"disable Object.prototype.__proto__",
&PerProcessOptions::disable_proto,
kAllowedInEnvvar);
AddOption("--build-snapshot",
"Generate a snapshot blob when the process exits."
" Currently only supported in the node_mksnapshot binary.",
&PerProcessOptions::build_snapshot,
kDisallowedInEnvvar);
AddOption("--node-snapshot",
"", // It's a debug-only option.
&PerProcessOptions::node_snapshot,

View File

@@ -224,6 +224,7 @@ class PerIsolateOptions : public Options {
bool report_on_signal = false;
bool experimental_shadow_realm = false;
std::string report_signal = "SIGUSR2";
bool build_snapshot = false;
inline EnvironmentOptions* get_per_env_options();
void CheckOptions(std::vector<std::string>* errors,
std::vector<std::string>* argv) override;
@@ -248,7 +249,6 @@ class PerProcessOptions : public Options {
bool zero_fill_all_buffers = false;
bool debug_arraybuffer_allocations = false;
std::string disable_proto;
bool build_snapshot = false;
// We enable the shared read-only heap which currently requires that the
// snapshot used in different isolates in the same process to be the same.
// Therefore --node-snapshot is a per-process option.

View File

@@ -1136,7 +1136,7 @@ ExitCode SnapshotBuilder::Generate(SnapshotData* out,
// It's only possible to be kDefault in node_mksnapshot.
SnapshotMetadata::Type snapshot_type =
per_process::cli_options->build_snapshot
per_process::cli_options->per_isolate->build_snapshot
? SnapshotMetadata::Type::kFullyCustomized
: SnapshotMetadata::Type::kDefault;

View File

@@ -72,7 +72,7 @@ int BuildSnapshot(int argc, char* argv[]) {
CHECK_EQ(result->exit_code(), 0);
std::string out_path;
if (node::per_process::cli_options->build_snapshot) {
if (node::per_process::cli_options->per_isolate->build_snapshot) {
out_path = result->args()[2];
} else {
out_path = result->args()[1];