Skip to content

Commit

Permalink
src: add flags for controlling process behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere authored and electron-roller[bot] committed Feb 16, 2022
1 parent 9f88ee4 commit 6838727
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 162 deletions.
2 changes: 0 additions & 2 deletions patches/node/.patches
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ feat_initialize_asar_support.patch
expose_get_builtin_module_function.patch
build_add_gn_build_files.patch
fix_add_default_values_for_variables_in_common_gypi.patch
feat_add_flags_for_low-level_hooks_and_exceptions.patch
fix_expose_tracing_agent_and_use_tracing_tracingcontroller_instead.patch
pass_all_globals_through_require.patch
build_modify_js2c_py_to_allow_injection_of_original-fs_and_custom_embedder_js.patch
Expand All @@ -19,7 +18,6 @@ fix_allow_preventing_initializeinspector_in_env.patch
src_allow_embedders_to_provide_a_custom_pageallocator_to.patch
fix_crypto_tests_to_run_with_bssl.patch
fix_account_for_debugger_agent_race_condition.patch
add_should_read_node_options_from_env_option_to_disable_node_options.patch
repl_fix_crash_when_sharedarraybuffer_disabled.patch
fix_readbarrier_undefined_symbol_error_on_woa_arm64.patch
chore_fix_-wimplicit-fallthrough.patch
Expand Down

This file was deleted.

This file was deleted.

24 changes: 13 additions & 11 deletions shell/common/node_bindings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ bool NodeBindings::IsInitialized() {
void NodeBindings::Initialize() {
TRACE_EVENT0("electron", "NodeBindings::Initialize");
// Open node's error reporting system for browser process.
node::g_upstream_node_mode = false;

#if BUILDFLAG(IS_LINUX)
// Get real command line in renderer process forked by zygote.
Expand All @@ -381,14 +380,17 @@ void NodeBindings::Initialize() {

auto env = base::Environment::Create();
SetNodeOptions(env.get());
node::Environment::should_read_node_options_from_env_ =
fuses::IsNodeOptionsEnabled();

std::vector<std::string> argv = {"electron"};
std::vector<std::string> exec_argv;
std::vector<std::string> errors;
uint64_t process_flags = node::ProcessFlags::kEnableStdioInheritance;
if (!fuses::IsNodeOptionsEnabled())
process_flags |= node::ProcessFlags::kDisableNodeOptionsEnv;

int exit_code = node::InitializeNodeWithArgs(&argv, &exec_argv, &errors);
int exit_code = node::InitializeNodeWithArgs(
&argv, &exec_argv, &errors,
static_cast<node::ProcessFlags::Flags>(process_flags));

for (const std::string& error : errors)
fprintf(stderr, "%s: %s\n", argv[0].c_str(), error.c_str());
Expand Down Expand Up @@ -466,20 +468,20 @@ node::Environment* NodeBindings::CreateEnvironment(
node::CreateIsolateData(context->GetIsolate(), uv_loop_, platform);

node::Environment* env;
uint64_t flags = node::EnvironmentFlags::kDefaultFlags |
node::EnvironmentFlags::kHideConsoleWindows |
node::EnvironmentFlags::kNoGlobalSearchPaths;
uint64_t env_flags = node::EnvironmentFlags::kDefaultFlags |
node::EnvironmentFlags::kHideConsoleWindows |
node::EnvironmentFlags::kNoGlobalSearchPaths;

if (browser_env_ != BrowserEnvironment::kBrowser) {
// Only one ESM loader can be registered per isolate -
// in renderer processes this should be blink. We need to tell Node.js
// not to register its handler (overriding blinks) in non-browser processes.
flags |= node::EnvironmentFlags::kNoRegisterESMLoader |
node::EnvironmentFlags::kNoInitializeInspector;
env_flags |= node::EnvironmentFlags::kNoRegisterESMLoader |
node::EnvironmentFlags::kNoInitializeInspector;
v8::TryCatch try_catch(context->GetIsolate());
env = node::CreateEnvironment(
isolate_data_, context, args, exec_args,
static_cast<node::EnvironmentFlags::Flags>(flags));
static_cast<node::EnvironmentFlags::Flags>(env_flags));
DCHECK(env);

// This will only be caught when something has gone terrible wrong as all
Expand All @@ -491,7 +493,7 @@ node::Environment* NodeBindings::CreateEnvironment(
} else {
env = node::CreateEnvironment(
isolate_data_, context, args, exec_args,
static_cast<node::EnvironmentFlags::Flags>(flags));
static_cast<node::EnvironmentFlags::Flags>(env_flags));
DCHECK(env);
}

Expand Down

0 comments on commit 6838727

Please sign in to comment.