Repository: electron/electron
File: shell/services/node/node_service.cc (C++)

Code before:
  // Append program path for process.argv0
  auto program = base::CommandLine::ForCurrentProcess()->GetProgram();
#if defined(OS_WIN)
  params->args.insert(params->args.begin(), base::WideToUTF8(program.value()));
#else
  params->args.insert(params->args.begin(), program.value());
#endif

  // Create the global environment.
  node_env_ = node_bindings_->CreateEnvironment(
      js_env_->isolate()->GetCurrentContext(), js_env_->platform(),
      js_env_->max_young_generation_size_in_bytes(), params->args,
      params->exec_args);

  // Override the default handler set by NodeBindings.
  node_env_->isolate()->SetFatalErrorHandler(V8FatalErrorCallback);

  node::SetProcessExitHandler(
      node_env_.get(), [this](node::Environment* env, int exit_code) {
        // Destroy node platform.
        node_env_stopped_ = true;
        ParentPort::GetInstance()->Close();
        js_env_->DestroyMicrotasksRunner();
        if (g_client_remote.is_bound()) {
          g_client_remote.reset();
        }
        receiver_.ResetWithReason(exit_code, "process_exit_termination");
        node::DefaultProcessExitHandler(env, exit_code);
      });

  node_env_->set_trace_sync_io(node_env_->options()->trace_sync_io);

  // We do not want to crash the utility process on unhandled rejections.
  node_env_->options()->unhandled_rejections = "warn-with-error-code";

  // Add Electron extended APIs.
  electron_bindings_->BindTo(node_env_->isolate(), node_env_->process_object());

  // Add entry script to process object.
  gin_helper::Dictionary process(node_env_->isolate(),
                                 node_env_->process_object());
  process.SetHidden("_serviceStartupScript", params->script);

  // Setup microtask runner.
  js_env_->CreateMicrotasksRunner();

  // Wrap the uv loop with global env.
  node_bindings_->set_uv_env(node_env_.get());

  // LoadEnvironment should be called after setting up
  // JavaScriptEnvironment including the microtask runner

Review comment (bug):
```suggestion
        g_client_remote.reset();
```

This is a little bikesheddy so OK to leave as-is if you disagree, but my sales pitch is: `Mojo::Remote::reset()` is cheap and the conditional isn't necessary. Removing unnecessary conditionals (1) can make life easier for anyone doing future postmortem debugging work and (2) can help the CPU with branch predictions.  (Though the second reason is maybe less important for `process.exit()` :smile_cat:)

Code after:
#if defined(OS_WIN)
  params->args.insert(params->args.begin(), base::WideToUTF8(program.value()));
#else
  params->args.insert(params->args.begin(), program.value());
#endif

  // Create the global environment.
  node_env_ = node_bindings_->CreateEnvironment(
      js_env_->isolate()->GetCurrentContext(), js_env_->platform(),
      js_env_->max_young_generation_size_in_bytes(), params->args,
      params->exec_args);

  // Override the default handler set by NodeBindings.
  node_env_->isolate()->SetFatalErrorHandler(V8FatalErrorCallback);

  node::SetProcessExitHandler(
      node_env_.get(), [this](node::Environment* env, int exit_code) {
        // Destroy node platform.
        node_env_stopped_ = true;
        ParentPort::GetInstance()->Close();
        js_env_->DestroyMicrotasksRunner();
        g_client_remote.reset();
        receiver_.ResetWithReason(exit_code, "process_exit_termination");
        node::DefaultProcessExitHandler(env, exit_code);
      });

  node_env_->set_trace_sync_io(node_env_->options()->trace_sync_io);

  // We do not want to crash the utility process on unhandled rejections.
  node_env_->options()->unhandled_rejections = "warn-with-error-code";

  // Add Electron extended APIs.
  electron_bindings_->BindTo(node_env_->isolate(), node_env_->process_object());

  // Add entry script to process object.
  gin_helper::Dictionary process(node_env_->isolate(),
                                 node_env_->process_object());
  process.SetHidden("_serviceStartupScript", params->script);

  // Setup microtask runner.
  js_env_->CreateMicrotasksRunner();

  // Wrap the uv loop with global env.
  node_bindings_->set_uv_env(node_env_.get());

  // LoadEnvironment should be called after setting up
  // JavaScriptEnvironment including the microtask runner
  // since this call will start compilation and execution
  // of the entry script. If there is an uncaught exception
  // the exit handler set above will be triggered and it expects
  // both Node Env and JavaScriptEnvironment are setup to perform