mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
vm: include vm context in the embedded snapshot
Include a minimally initialized contextify context in the embedded snapshot. This paves the way for user-land vm context snapshots. PR-URL: https://github.com/nodejs/node/pull/44252 Refs: https://github.com/nodejs/node/issues/44014 Refs: https://github.com/nodejs/node/issues/37476 Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
This commit is contained in:
4 files changed
+45
-11
No files matched your search
+24
-9
@@ -28,6 +28,7 @@
|
||||
#include "node_errors.h"
|
||||
#include "node_external_reference.h"
|
||||
#include "node_internals.h"
|
||||
#include "node_snapshot_builder.h"
|
||||
#include "node_watchdog.h"
|
||||
#include "util-inl.h"
|
||||
|
||||
@@ -118,6 +119,9 @@ ContextifyContext::ContextifyContext(
|
||||
object_template = CreateGlobalTemplate(env->isolate());
|
||||
env->set_contextify_global_template(object_template);
|
||||
}
|
||||
bool use_node_snapshot = per_process::cli_options->node_snapshot;
|
||||
const SnapshotData* snapshot_data =
|
||||
use_node_snapshot ? SnapshotBuilder::GetEmbeddedSnapshotData() : nullptr;
|
||||
|
||||
MicrotaskQueue* queue =
|
||||
microtask_queue()
|
||||
@@ -125,7 +129,7 @@ ContextifyContext::ContextifyContext(
|
||||
: env->isolate()->GetCurrentContext()->GetMicrotaskQueue();
|
||||
|
||||
Local<Context> v8_context;
|
||||
if (!(CreateV8Context(env->isolate(), object_template, queue)
|
||||
if (!(CreateV8Context(env->isolate(), object_template, snapshot_data, queue)
|
||||
.ToLocal(&v8_context)) ||
|
||||
!InitializeContext(v8_context, env, sandbox_obj, options)) {
|
||||
// Allocation failure, maximum call stack size reached, termination, etc.
|
||||
@@ -190,17 +194,28 @@ Local<ObjectTemplate> ContextifyContext::CreateGlobalTemplate(
|
||||
MaybeLocal<Context> ContextifyContext::CreateV8Context(
|
||||
Isolate* isolate,
|
||||
Local<ObjectTemplate> object_template,
|
||||
const SnapshotData* snapshot_data,
|
||||
MicrotaskQueue* queue) {
|
||||
EscapableHandleScope scope(isolate);
|
||||
|
||||
Local<Context> ctx = Context::New(isolate,
|
||||
nullptr, // extensions
|
||||
object_template,
|
||||
{}, // global object
|
||||
{}, // deserialization callback
|
||||
queue);
|
||||
if (ctx.IsEmpty()) return MaybeLocal<Context>();
|
||||
|
||||
Local<Context> ctx;
|
||||
if (snapshot_data == nullptr) {
|
||||
ctx = Context::New(isolate,
|
||||
nullptr, // extensions
|
||||
object_template,
|
||||
{}, // global object
|
||||
{}, // deserialization callback
|
||||
queue);
|
||||
if (ctx.IsEmpty()) return MaybeLocal<Context>();
|
||||
} else if (!Context::FromSnapshot(isolate,
|
||||
SnapshotData::kNodeVMContextIndex,
|
||||
{}, // deserialization callback
|
||||
nullptr, // extensions
|
||||
{}, // global object
|
||||
queue)
|
||||
.ToLocal(&ctx)) {
|
||||
return MaybeLocal<Context>();
|
||||
}
|
||||
return scope.Escape(ctx);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user