Skip to content
Prev Previous commit
Next Next commit
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.
  • Loading branch information
joyeecheung committed Mar 25, 2022
commit 39cd563e9abc95762033ed741d9effbdb2b693ca
20 changes: 18 additions & 2 deletions src/node_snapshotable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#include "node_v8.h"
#include "node_v8_platform-inl.h"

#if HAVE_INSPECTOR
#include "inspector/worker_inspector.h" // ParentInspectorHandle
#endif

Comment thread
RaisinTen marked this conversation as resolved.
namespace node {

using v8::Context;
Expand Down Expand Up @@ -137,7 +141,7 @@ void SnapshotBuilder::Generate(SnapshotData* out,
nullptr,
node::EnvironmentFlags::kDefaultFlags,
{});
// TODO(joyeecheung): run env->InitializeInspector({}) here.

// Run scripts in lib/internal/bootstrap/
{
TryCatch bootstrapCatch(isolate);
Expand All @@ -150,6 +154,10 @@ void SnapshotBuilder::Generate(SnapshotData* out,

// Run the entry point file
Comment thread
joyeecheung marked this conversation as resolved.
Outdated
if (!entry_file.empty()) {
#if HAVE_INSPECTOR
env->InitializeInspector({});
#endif

TryCatch bootstrapCatch(isolate);
// TODO(joyee): we could use the result for something special, like
// setting up initializers that should be invoked at snapshot
Expand All @@ -160,7 +168,15 @@ void SnapshotBuilder::Generate(SnapshotData* out,
PrintCaughtException(isolate, context, bootstrapCatch);
Comment thread
RaisinTen marked this conversation as resolved.
}
result.ToLocalChecked();
// TODO(joyeecheung): run SpinEventLoop here.
// FIXME(joyee): right now running the loop in the snapshot builder
// seems to intrudoces inconsistencies in JS land that need to be
// synchronized again after snapshot restoration.
Comment thread
joyeecheung marked this conversation as resolved.
Outdated
int exit_code = SpinEventLoop(env).FromMaybe(1);
CHECK_EQ(exit_code, 0);
Comment thread
RaisinTen marked this conversation as resolved.
if (bootstrapCatch.HasCaught()) {
PrintCaughtException(isolate, context, bootstrapCatch);
abort();
}
}

if (per_process::enabled_debug_list.enabled(DebugCategory::MKSNAPSHOT)) {
Expand Down