summaryrefslogtreecommitdiff
path: root/src/node_snapshotable.cc
diff options
context:
space:
mode:
authorAnna Henningsen <anna.henningsen@mongodb.com>2023-03-02 15:31:08 +0100
committerGitHub <noreply@github.com>2023-03-02 14:31:08 +0000
commit3803b028dda9d7f3bf06836b5ad4522ff1ae0cb3 (patch)
tree933a7fce2a16acb666cb5c83247ef6e5666098c0 /src/node_snapshotable.cc
parent7bd909b603475aeba1d97da3e08cdcde3339fc19 (diff)
downloadnode-new-3803b028dda9d7f3bf06836b5ad4522ff1ae0cb3.tar.gz
src: share common code paths for SEA and embedder script
Since SEA is very similar in principle to embedding functionality, it makes sense to share code paths where possible. This commit does so and addresses a `TODO` while doing so. It also adds a utility to directly run CJS code to the embedder startup callback, which comes in handy for this purpose. Finally, this commit is breaking because it aligns the behavior of `require()`ing internal modules; previously, embedders could use the `require` function that they received to do so. (If this is not considered breaking because accessing internals is not covered by the API, then this would need ABI compatibility patches for becoming fully non-breaking.) PR-URL: https://github.com/nodejs/node/pull/46825 Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Diffstat (limited to 'src/node_snapshotable.cc')
-rw-r--r--src/node_snapshotable.cc14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/node_snapshotable.cc b/src/node_snapshotable.cc
index e6323a128f..ee32786737 100644
--- a/src/node_snapshotable.cc
+++ b/src/node_snapshotable.cc
@@ -1444,19 +1444,25 @@ void SerializeSnapshotableObjects(Realm* realm,
namespace mksnapshot {
+// NB: This is also used by the regular embedding codepath.
void GetEmbedderEntryFunction(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
Isolate* isolate = env->isolate();
- if (!env->embedder_mksnapshot_entry_point()) return;
+ if (!env->embedder_entry_point()) return;
MaybeLocal<Function> jsfn =
Function::New(isolate->GetCurrentContext(),
[](const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
Local<Value> require_fn = args[0];
+ Local<Value> runcjs_fn = args[1];
CHECK(require_fn->IsFunction());
- CHECK(env->embedder_mksnapshot_entry_point());
- env->embedder_mksnapshot_entry_point()(
- {env->process_object(), require_fn.As<Function>()});
+ CHECK(runcjs_fn->IsFunction());
+ MaybeLocal<Value> retval = env->embedder_entry_point()(
+ {env->process_object(),
+ require_fn.As<Function>(),
+ runcjs_fn.As<Function>()});
+ if (!retval.IsEmpty())
+ args.GetReturnValue().Set(retval.ToLocalChecked());
});
if (!jsfn.IsEmpty()) args.GetReturnValue().Set(jsfn.ToLocalChecked());
}