Skip to content

Commit

Permalink
chore: remove custom Node.js debugger (#25587)
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Sep 24, 2020
1 parent b980d1b commit b807cab
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 206 deletions.
2 changes: 0 additions & 2 deletions filenames.gni
Expand Up @@ -256,8 +256,6 @@ filenames = {
"shell/browser/net/web_request_api_interface.h",
"shell/browser/network_hints_handler_impl.cc",
"shell/browser/network_hints_handler_impl.h",
"shell/browser/node_debugger.cc",
"shell/browser/node_debugger.h",
"shell/browser/notifications/linux/libnotify_notification.cc",
"shell/browser/notifications/linux/libnotify_notification.h",
"shell/browser/notifications/linux/notification_presenter_linux.cc",
Expand Down
3 changes: 1 addition & 2 deletions patches/node/.patches
Expand Up @@ -4,7 +4,6 @@ refactor_alter_child_process_fork_to_use_execute_script_with.patch
feat_add_uv_loop_watcher_queue_code.patch
feat_initialize_asar_support.patch
expose_get_builtin_module_function.patch
fix_build_and_expose_inspector_agent.patch
fix_expose_internalcallbackscope.patch
build_add_gn_build_files.patch
fix_add_default_values_for_enable_lto_and_build_v8_with_gn_in.patch
Expand All @@ -30,5 +29,5 @@ update_tests_after_increasing_typed_array_size.patch
feat_add_implementation_of_v8_platform_postjob.patch
crypto_update_certdata_to_nss_3_56.patch
fix_-wincompatible-pointer-types-discards-qualifiers_error.patch
fix_allow_preventing_initializeinspector_in_env.patch
fix_add_v8_enable_reverse_jsargs_defines_in_common_gypi.patch
fix_allow_preventing_initializeinspector_in_env.patch
47 changes: 23 additions & 24 deletions patches/node/fix_allow_preventing_initializeinspector_in_env.patch
@@ -1,18 +1,17 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Shelley Vohr <shelley.vohr@gmail.com>
Date: Tue, 1 Sep 2020 19:30:08 -0700
Date: Tue, 22 Sep 2020 19:44:30 -0700
Subject: fix: allow preventing InitializeInspector in env

https://github.com/nodejs/node/commit/8c5ad1392f30cfe6b107e9bd85f4cb918ba04aab
made it such that env->InitializeInspector was called in CreateEnvironment
no matter what, which creates an issue for embedders seeking to manage
the InspectorAgent themselves as Electron does. This adds a new
no matter what, which creates an issue for Electron, as the V8 inspector
already exists in the renderer process and therefore we only want to
initialize it in the browser process. This adds a new
EnvironmentFlags option which allows preventing that invocation.

This will be upstreamed.

diff --git a/src/api/environment.cc b/src/api/environment.cc
index 4fa2d4175fb318f560b7b9a8ed8baa091d3ed6a2..7bd899c5933ac2e6178d650632699e19e85c00c9 100644
index 4fa2d4175fb318f560b7b9a8ed8baa091d3ed6a2..cf6115d04ba3c184937c5db85c9d7ebc78ed3db7 100644
--- a/src/api/environment.cc
+++ b/src/api/environment.cc
@@ -358,12 +358,14 @@ Environment* CreateEnvironment(
Expand All @@ -25,7 +24,7 @@ index 4fa2d4175fb318f560b7b9a8ed8baa091d3ed6a2..7bd899c5933ac2e6178d650632699e19
- inspector_parent_handle.get())->impl));
- } else {
- env->InitializeInspector({});
+ if (!env->should_not_initialize_inspector()) {
+ if (env->should_initialize_inspector()) {
+ if (inspector_parent_handle) {
+ env->InitializeInspector(
+ std::move(static_cast<InspectorParentHandleImpl*>(
Expand All @@ -37,34 +36,34 @@ index 4fa2d4175fb318f560b7b9a8ed8baa091d3ed6a2..7bd899c5933ac2e6178d650632699e19
#endif

diff --git a/src/env-inl.h b/src/env-inl.h
index 623e9d4e429c03bb267539a318166f3ef3b9c501..8fc5f720764dd4ca536ae01ca78b2c7e3e9fd007 100644
index 623e9d4e429c03bb267539a318166f3ef3b9c501..52a122a51049238547ff662bed1a10b346f3af00 100644
--- a/src/env-inl.h
+++ b/src/env-inl.h
@@ -833,6 +833,10 @@ inline bool Environment::owns_inspector() const {
return flags_ & EnvironmentFlags::kOwnsInspector;
@@ -837,6 +837,10 @@ inline bool Environment::tracks_unmanaged_fds() const {
return flags_ & EnvironmentFlags::kTrackUnmanagedFds;
}

+inline bool Environment::should_not_initialize_inspector() const {
+ return flags_ & EnvironmentFlags::kNoInitializeInspector;
+inline bool Environment::should_initialize_inspector() const {
+ return (flags_ & EnvironmentFlags::kNoInitializeInspector) == 0;
+}
+
inline bool Environment::tracks_unmanaged_fds() const {
return flags_ & EnvironmentFlags::kTrackUnmanagedFds;
bool Environment::filehandle_close_warning() const {
return emit_filehandle_warning_;
}
diff --git a/src/env.h b/src/env.h
index 38d17f4e18aa38fde2c2f59a9816c8fb0f65fd51..4b9c2780f9736cb8bde60f40abb9aac9d53160a1 100644
index 38d17f4e18aa38fde2c2f59a9816c8fb0f65fd51..4fe2eb3b7699efcab87c377743a955effbbfd9de 100644
--- a/src/env.h
+++ b/src/env.h
@@ -1019,6 +1019,7 @@ class Environment : public MemoryRetainer {

inline bool is_main_thread() const;
inline bool should_not_register_esm_loader() const;
+ inline bool should_not_initialize_inspector() const;
@@ -1022,6 +1022,7 @@ class Environment : public MemoryRetainer {
inline bool owns_process_state() const;
inline bool owns_inspector() const;
inline bool tracks_unmanaged_fds() const;
+ inline bool should_initialize_inspector() const;
inline uint64_t thread_id() const;
inline worker::Worker* worker_context() const;
Environment* worker_parent_env() const;
diff --git a/src/node.h b/src/node.h
index 80acb3f9f04ef8e6c363cf31384af4037abeeb87..6b657f6941b8f96da08b6397e01e19a2763edf8f 100644
index 80acb3f9f04ef8e6c363cf31384af4037abeeb87..22f037b0b26f39f9ce94c4a364b27cf204366cb9 100644
--- a/src/node.h
+++ b/src/node.h
@@ -424,7 +424,11 @@ enum Flags : uint64_t {
Expand All @@ -73,9 +72,9 @@ index 80acb3f9f04ef8e6c363cf31384af4037abeeb87..6b657f6941b8f96da08b6397e01e19a2
// by fs.open() and fs.close(), and close them during FreeEnvironment().
- kTrackUnmanagedFds = 1 << 4
+ kTrackUnmanagedFds = 1 << 4,
+ // This flag should be set to prevent InspectorAgent initialization from
+ // within the environment. This is used by embedders who wish to manage the
+ // InspectorAgent themselves.
+ // Controls whether or not the Environment should call InitializeInspector.
+ // This control is needed by embedders who may not want to initialize the V8
+ // inspector in situations where it already exists.
+ kNoInitializeInspector = 1 << 5
};
} // namespace EnvironmentFlags
Expand Down
65 changes: 0 additions & 65 deletions patches/node/fix_build_and_expose_inspector_agent.patch

This file was deleted.

13 changes: 1 addition & 12 deletions shell/app/node_main.cc
Expand Up @@ -25,7 +25,6 @@
#include "gin/v8_initializer.h"
#include "shell/app/uv_task_runner.h"
#include "shell/browser/javascript_environment.h"
#include "shell/browser/node_debugger.h"
#include "shell/common/api/electron_bindings.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/node_bindings.h"
Expand Down Expand Up @@ -202,15 +201,11 @@ int NodeMain(int argc, char* argv[]) {
isolate_data = node::CreateIsolateData(isolate, loop, gin_env.platform());
CHECK_NE(nullptr, isolate_data);

uint64_t flags = node::EnvironmentFlags::kDefaultFlags |
node::EnvironmentFlags::kNoInitializeInspector;

std::vector<std::string> args(argv, argv + argc); // NOLINT
std::vector<std::string> exec_args(exec_argv,
exec_argv + exec_argc); // NOLINT
env = node::CreateEnvironment(isolate_data, gin_env.context(), args,
exec_args,
(node::EnvironmentFlags::Flags)flags);
exec_args);
CHECK_NE(nullptr, env);

node::IsolateSettings is;
Expand Down Expand Up @@ -247,10 +242,6 @@ int NodeMain(int argc, char* argv[]) {
}
}

// Enable support for v8 inspector.
NodeDebugger node_debugger(env);
node_debugger.Start();

// TODO(codebytere): we should try to handle this upstream.
{
v8::HandleScope scope(isolate);
Expand Down Expand Up @@ -288,8 +279,6 @@ int NodeMain(int argc, char* argv[]) {
node::performance::NODE_PERFORMANCE_MILESTONE_LOOP_EXIT);
}

node_debugger.Stop();

env->set_trace_sync_io(false);

exit_code = node::EmitExit(env);
Expand Down
6 changes: 0 additions & 6 deletions shell/browser/electron_browser_main_parts.cc
Expand Up @@ -41,7 +41,6 @@
#include "shell/browser/feature_list.h"
#include "shell/browser/javascript_environment.h"
#include "shell/browser/media/media_capture_devices_dispatcher.h"
#include "shell/browser/node_debugger.h"
#include "shell/browser/ui/devtools_manager_delegate.h"
#include "shell/common/api/electron_bindings.h"
#include "shell/common/application_info.h"
Expand Down Expand Up @@ -322,10 +321,6 @@ void ElectronBrowserMainParts::PostEarlyInitialization() {
js_env_->context(), js_env_->platform());
node_env_ = std::make_unique<NodeEnvironment>(env);

// Enable support for v8 inspector
node_debugger_ = std::make_unique<NodeDebugger>(env);
node_debugger_->Start();

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

// Add Electron extended APIs.
Expand Down Expand Up @@ -550,7 +545,6 @@ void ElectronBrowserMainParts::PostMainMessageLoopRun() {

// Destroy node platform after all destructors_ are executed, as they may
// invoke Node/V8 APIs inside them.
node_debugger_->Stop();
node_env_->env()->set_trace_sync_io(false);
js_env_->OnMessageLoopDestroying();
node::Stop(node_env_->env());
Expand Down
2 changes: 0 additions & 2 deletions shell/browser/electron_browser_main_parts.h
Expand Up @@ -42,7 +42,6 @@ class Browser;
class ElectronBindings;
class JavascriptEnvironment;
class NodeBindings;
class NodeDebugger;
class NodeEnvironment;
class BridgeTaskRunner;

Expand Down Expand Up @@ -151,7 +150,6 @@ class ElectronBrowserMainParts : public content::BrowserMainParts {
std::unique_ptr<NodeBindings> node_bindings_;
std::unique_ptr<ElectronBindings> electron_bindings_;
std::unique_ptr<NodeEnvironment> node_env_;
std::unique_ptr<NodeDebugger> node_debugger_;
std::unique_ptr<IconManager> icon_manager_;
std::unique_ptr<base::FieldTrialList> field_trial_list_;

Expand Down
55 changes: 0 additions & 55 deletions shell/browser/node_debugger.cc

This file was deleted.

33 changes: 0 additions & 33 deletions shell/browser/node_debugger.h

This file was deleted.

9 changes: 4 additions & 5 deletions shell/common/node_bindings.cc
Expand Up @@ -392,13 +392,13 @@ node::Environment* NodeBindings::CreateEnvironment(
node::CreateIsolateData(context->GetIsolate(), uv_loop_, platform);

node::Environment* env;
uint64_t flags = node::EnvironmentFlags::kDefaultFlags |
node::EnvironmentFlags::kNoInitializeInspector;
if (browser_env_ != BrowserEnvironment::BROWSER) {
// 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;
uint64_t flags = node::EnvironmentFlags::kDefaultFlags |
node::EnvironmentFlags::kNoRegisterESMLoader |
node::EnvironmentFlags::kNoInitializeInspector;
v8::TryCatch try_catch(context->GetIsolate());
env = node::CreateEnvironment(isolate_data_, context, args, exec_args,
(node::EnvironmentFlags::Flags)flags);
Expand All @@ -411,8 +411,7 @@ node::Environment* NodeBindings::CreateEnvironment(
<< process_type;
}
} else {
env = node::CreateEnvironment(isolate_data_, context, args, exec_args,
(node::EnvironmentFlags::Flags)flags);
env = node::CreateEnvironment(isolate_data_, context, args, exec_args);
DCHECK(env);
}

Expand Down

0 comments on commit b807cab

Please sign in to comment.