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: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
c131fbb652
commit
01f6b9543f
@ -15,6 +15,10 @@
|
|||||||
#include "node_v8.h"
|
#include "node_v8.h"
|
||||||
#include "node_v8_platform-inl.h"
|
#include "node_v8_platform-inl.h"
|
||||||
|
|
||||||
|
#if HAVE_INSPECTOR
|
||||||
|
#include "inspector/worker_inspector.h" // ParentInspectorHandle
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace node {
|
namespace node {
|
||||||
|
|
||||||
using v8::Context;
|
using v8::Context;
|
||||||
@ -136,7 +140,7 @@ void SnapshotBuilder::Generate(SnapshotData* out,
|
|||||||
nullptr,
|
nullptr,
|
||||||
node::EnvironmentFlags::kDefaultFlags,
|
node::EnvironmentFlags::kDefaultFlags,
|
||||||
{});
|
{});
|
||||||
// TODO(joyeecheung): run env->InitializeInspector({}) here.
|
|
||||||
// Run scripts in lib/internal/bootstrap/
|
// Run scripts in lib/internal/bootstrap/
|
||||||
{
|
{
|
||||||
TryCatch bootstrapCatch(isolate);
|
TryCatch bootstrapCatch(isolate);
|
||||||
@ -153,6 +157,9 @@ void SnapshotBuilder::Generate(SnapshotData* out,
|
|||||||
// could also explore snapshotting other kinds of execution modes
|
// could also explore snapshotting other kinds of execution modes
|
||||||
// in the future).
|
// in the future).
|
||||||
if (per_process::cli_options->build_snapshot) {
|
if (per_process::cli_options->build_snapshot) {
|
||||||
|
#if HAVE_INSPECTOR
|
||||||
|
env->InitializeInspector({});
|
||||||
|
#endif
|
||||||
TryCatch bootstrapCatch(isolate);
|
TryCatch bootstrapCatch(isolate);
|
||||||
// TODO(joyeecheung): we could use the result for something special,
|
// TODO(joyeecheung): we could use the result for something special,
|
||||||
// like setting up initializers that should be invoked at snapshot
|
// like setting up initializers that should be invoked at snapshot
|
||||||
@ -163,7 +170,15 @@ void SnapshotBuilder::Generate(SnapshotData* out,
|
|||||||
PrintCaughtException(isolate, context, bootstrapCatch);
|
PrintCaughtException(isolate, context, bootstrapCatch);
|
||||||
}
|
}
|
||||||
result.ToLocalChecked();
|
result.ToLocalChecked();
|
||||||
// TODO(joyeecheung): run SpinEventLoop here.
|
// FIXME(joyeecheung): right now running the loop in the snapshot
|
||||||
|
// builder seems to introduces inconsistencies in JS land that need to
|
||||||
|
// be synchronized again after snapshot restoration.
|
||||||
|
int exit_code = SpinEventLoop(env).FromMaybe(1);
|
||||||
|
CHECK_EQ(exit_code, 0);
|
||||||
|
if (bootstrapCatch.HasCaught()) {
|
||||||
|
PrintCaughtException(isolate, context, bootstrapCatch);
|
||||||
|
abort();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (per_process::enabled_debug_list.enabled(DebugCategory::MKSNAPSHOT)) {
|
if (per_process::enabled_debug_list.enabled(DebugCategory::MKSNAPSHOT)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user