-
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 53b07052e43a09f29f863ee1b2287bdebe7b7a7f..c08fe4b32d4155badb572f15529f903c0ec63146 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 9b2f82cc00e661f139611dd2de53598d6d8ff210..006bcaf4a9a864438cd447dc4235b3a5257cd2a5 100644
--- a/src/env-inl.h
+++ b/src/env-inl.h
@@ -829,6 +829,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 9c435f12db0e2d0a13ebd2b01810f0857c55fe2e..1ea1caf0e327719c39f91ce3c0897dde5034c904 100644
--- a/src/env.h
+++ b/src/env.h
@@ -1026,6 +1026,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 a649f52403659fd18898e1e813f97e32f33784e7..b646fdda58ebcbf2dd92ee4fc9cb0d9c039174d1 100644
--- a/src/node.h
+++ b/src/node.h
@@ -426,7 +426,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