-
Notifications
You must be signed in to change notification settings - Fork 15k
/
fix_allow_preventing_initializeinspector_in_env.patch
81 lines (75 loc) · 3.23 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 bc1ab0bfcf87936b8d8156172319283704b05da8..08e0da9ba08b933036623ae288b9b1f89efeed8b 100644
--- a/src/api/environment.cc
+++ b/src/api/environment.cc
@@ -358,12 +358,14 @@ Environment* CreateEnvironment(
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 623e9d4e429c03bb267539a318166f3ef3b9c501..52a122a51049238547ff662bed1a10b346f3af00 100644
--- a/src/env-inl.h
+++ b/src/env-inl.h
@@ -837,6 +837,10 @@ inline bool Environment::tracks_unmanaged_fds() const {
return flags_ & EnvironmentFlags::kTrackUnmanagedFds;
}
+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 38d17f4e18aa38fde2c2f59a9816c8fb0f65fd51..4fe2eb3b7699efcab87c377743a955effbbfd9de 100644
--- a/src/env.h
+++ b/src/env.h
@@ -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 d051b422d7c5a51a8590abda382676d3f661b532..180e876f21f55826ea280b8d0f0d5b4ee8cf87b2 100644
--- a/src/node.h
+++ b/src/node.h
@@ -423,7 +423,11 @@ enum Flags : uint64_t {
kNoRegisterESMLoader = 1 << 3,
// Set this flag to make Node.js track "raw" file descriptors, i.e. managed
// by fs.open() and fs.close(), and close them during FreeEnvironment().
- kTrackUnmanagedFds = 1 << 4
+ kTrackUnmanagedFds = 1 << 4,
+ // 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