Skip to content

Commit cb5ccb0

Browse files
joyeecheungjuanarbol
authored andcommitted
bootstrap: run inspector and event loop in snapshot builder
This makes --inspect and stdin/out functional in the embedded snapshot, currently it's not guaranteed that these work perfectly, the plan is to investigate any out-of-sync states that might appear in user land snapshots with this while the it is a configure-time feature. PR-URL: #42466 Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Khaidi Chu <i@2333.moe> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
1 parent 542f5e7 commit cb5ccb0

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/node_snapshotable.cc

+17-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
#include "node_v8.h"
1616
#include "node_v8_platform-inl.h"
1717

18+
#if HAVE_INSPECTOR
19+
#include "inspector/worker_inspector.h" // ParentInspectorHandle
20+
#endif
21+
1822
namespace node {
1923

2024
using v8::Context;
@@ -136,7 +140,7 @@ void SnapshotBuilder::Generate(SnapshotData* out,
136140
nullptr,
137141
node::EnvironmentFlags::kDefaultFlags,
138142
{});
139-
// TODO(joyeecheung): run env->InitializeInspector({}) here.
143+
140144
// Run scripts in lib/internal/bootstrap/
141145
{
142146
TryCatch bootstrapCatch(isolate);
@@ -153,6 +157,9 @@ void SnapshotBuilder::Generate(SnapshotData* out,
153157
// could also explore snapshotting other kinds of execution modes
154158
// in the future).
155159
if (per_process::cli_options->build_snapshot) {
160+
#if HAVE_INSPECTOR
161+
env->InitializeInspector({});
162+
#endif
156163
TryCatch bootstrapCatch(isolate);
157164
// TODO(joyeecheung): we could use the result for something special,
158165
// like setting up initializers that should be invoked at snapshot
@@ -163,7 +170,15 @@ void SnapshotBuilder::Generate(SnapshotData* out,
163170
PrintCaughtException(isolate, context, bootstrapCatch);
164171
}
165172
result.ToLocalChecked();
166-
// TODO(joyeecheung): run SpinEventLoop here.
173+
// FIXME(joyeecheung): right now running the loop in the snapshot
174+
// builder seems to introduces inconsistencies in JS land that need to
175+
// be synchronized again after snapshot restoration.
176+
int exit_code = SpinEventLoop(env).FromMaybe(1);
177+
CHECK_EQ(exit_code, 0);
178+
if (bootstrapCatch.HasCaught()) {
179+
PrintCaughtException(isolate, context, bootstrapCatch);
180+
abort();
181+
}
167182
}
168183

169184
if (per_process::enabled_debug_list.enabled(DebugCategory::MKSNAPSHOT)) {

0 commit comments

Comments
 (0)