From dffb2c891b0cc926dfa38f78a86d74164ef70288 Mon Sep 17 00:00:00 2001 From: Archkon <180910180+Archkon@users.noreply.github.com> Date: Thu, 30 Jul 2026 21:05:53 +0800 Subject: [PATCH] src: return empty pointer without builtin snapshot Avoid creating an EmbedderSnapshotData wrapper with null implementation when Node.js is built without a builtin snapshot. This ensures callers can reliably detect the unavailable snapshot through the public API. Signed-off-by: Archkon <180910180+Archkon@users.noreply.github.com> --- src/api/embed_helpers.cc | 9 +++++++-- src/node.h | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/api/embed_helpers.cc b/src/api/embed_helpers.cc index c1bcb3948c4c..391ffe2b334b 100644 --- a/src/api/embed_helpers.cc +++ b/src/api/embed_helpers.cc @@ -317,8 +317,13 @@ void EmbedderSnapshotData::DeleteSnapshotData::operator()( } EmbedderSnapshotData::Pointer EmbedderSnapshotData::BuiltinSnapshotData() { - return EmbedderSnapshotData::Pointer{new EmbedderSnapshotData( - SnapshotBuilder::GetEmbeddedSnapshotData(), false)}; + const SnapshotData* snapshot_data = + SnapshotBuilder::GetEmbeddedSnapshotData(); + if (snapshot_data == nullptr) { + return {}; + } + return EmbedderSnapshotData::Pointer{ + new EmbedderSnapshotData(snapshot_data, false)}; } EmbedderSnapshotData::Pointer EmbedderSnapshotData::FromBlob( diff --git a/src/node.h b/src/node.h index 32a9806ae848..887f2acdee2b 100644 --- a/src/node.h +++ b/src/node.h @@ -492,7 +492,8 @@ class EmbedderSnapshotData { // Return an EmbedderSnapshotData object that refers to the built-in // snapshot of Node.js. This can have been configured through e.g. - // --node-snapshot-main=entry.js. + // --node-snapshot-main=entry.js. If Node.js was built without a built-in + // snapshot, this returns an empty pointer. static Pointer BuiltinSnapshotData(); // Return an EmbedderSnapshotData object that is based on an input file.