/
fix_allow_preventing_initializeinspector_in_env.patch
81 lines (76 loc) · 3.3 KB
/
fix_allow_preventing_initializeinspector_in_env.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Shelley Vohr <shelley.vohr@gmail.com>
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 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.
diff --git a/src/api/environment.cc b/src/api/environment.cc
index 523d252e08974a10f9a53fb46d3345669cec3380..5bf19a0dda42849159d954181058897c45d280fd 100644
--- a/src/api/environment.cc
+++ b/src/api/environment.cc
@@ -344,12 +344,14 @@ Environment* CreateEnvironment(
Environment* env = new Environment(
isolate_data, context, args, exec_args, nullptr, flags, thread_id);
#if HAVE_INSPECTOR
- if (inspector_parent_handle) {
- env->InitializeInspector(
- std::move(static_cast<InspectorParentHandleImpl*>(
- inspector_parent_handle.get())->impl));
- } else {
- env->InitializeInspector({});
+ if (env->should_initialize_inspector()) {
+ if (inspector_parent_handle) {
+ env->InitializeInspector(
+ std::move(static_cast<InspectorParentHandleImpl*>(
+ inspector_parent_handle.get())->impl));
+ } else {
+ env->InitializeInspector({});
+ }
}
#endif
diff --git a/src/env-inl.h b/src/env-inl.h
index 061897d95d8b5f61968c59260e609d7be724b88f..7c7ee3207089bf3e51db646a367bdd6deba18628 100644
--- a/src/env-inl.h
+++ b/src/env-inl.h
@@ -881,6 +881,10 @@ inline bool Environment::hide_console_windows() const {
return flags_ & EnvironmentFlags::kHideConsoleWindows;
}
+inline bool Environment::should_initialize_inspector() const {
+ return (flags_ & EnvironmentFlags::kNoInitializeInspector) == 0;
+}
+
bool Environment::filehandle_close_warning() const {
return emit_filehandle_warning_;
}
diff --git a/src/env.h b/src/env.h
index 8760bc4361f199a2e3471c4ca435f8e178c78e7e..33f34ed79452b004b5fb40e70cda6e3d0ee2d1e2 100644
--- a/src/env.h
+++ b/src/env.h
@@ -1199,6 +1199,7 @@ class Environment : public MemoryRetainer {
inline bool owns_inspector() const;
inline bool tracks_unmanaged_fds() const;
inline bool hide_console_windows() 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 b7f3e97873ef90b635e0648639f1a287a0bd88fa..48e378079f6d05e7cc1141a8875450b125028789 100644
--- a/src/node.h
+++ b/src/node.h
@@ -409,7 +409,11 @@ enum Flags : uint64_t {
// Set this flag to force hiding console windows when spawning child
// processes. This is usually used when embedding Node.js in GUI programs on
// Windows.
- kHideConsoleWindows = 1 << 5
+ kHideConsoleWindows = 1 << 5,
+ // 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 << 6
};
} // namespace EnvironmentFlags