@@ -295,6 +295,31 @@ MaybeLocal<Value> StartExecution(Environment* env, StartExecutionCallback cb) {
295295 }));
296296 }
297297
298+ #ifndef DISABLE_SINGLE_EXECUTABLE_APPLICATION
299+ if (sea::IsSingleExecutable ()) {
300+ const std::string_view sea_code = sea::FindSingleExecutableCode ();
301+ if (SnapshotData::IsSnapshotBlob (sea_code)) {
302+ if (env->snapshot_deserialize_main ().IsEmpty ()) {
303+ fprintf (
304+ stderr,
305+ " No deserialized main function found for the snapshot blob found"
306+ " in single executable binary.\n " );
307+ return MaybeLocal<Value>();
308+ } else {
309+ return env->RunSnapshotDeserializeMain ();
310+ }
311+ }
312+
313+ // TODO(addaleax): Find a way to reuse:
314+ //
315+ // LoadEnvironment(Environment*, const char*)
316+ //
317+ // instead and not add yet another main entry point here because this
318+ // already duplicates existing code.
319+ return StartExecution (env, " internal/main/single_executable_application" );
320+ }
321+ #endif
322+
298323 // TODO(joyeecheung): move these conditions into JS land and let the
299324 // deserialize main function take precedence. For workers, we need to
300325 // move the pre-execution part into a different file that can be
@@ -312,18 +337,6 @@ MaybeLocal<Value> StartExecution(Environment* env, StartExecutionCallback cb) {
312337 first_argv = env->argv ()[1 ];
313338 }
314339
315- #ifndef DISABLE_SINGLE_EXECUTABLE_APPLICATION
316- if (sea::IsSingleExecutable ()) {
317- // TODO(addaleax): Find a way to reuse:
318- //
319- // LoadEnvironment(Environment*, const char*)
320- //
321- // instead and not add yet another main entry point here because this
322- // already duplicates existing code.
323- return StartExecution (env, " internal/main/single_executable_application" );
324- }
325- #endif
326-
327340 if (first_argv == " inspect" ) {
328341 return StartExecution (env, " internal/main/inspect" );
329342 }
@@ -1177,8 +1190,25 @@ ExitCode LoadSnapshotDataAndRun(const SnapshotData** snapshot_data_ptr,
11771190 ExitCode exit_code = result->exit_code_enum ();
11781191 // nullptr indicates there's no snapshot data.
11791192 DCHECK_NULL (*snapshot_data_ptr);
1180- // --snapshot-blob indicates that we are reading a customized snapshot.
1181- if (!per_process::cli_options->snapshot_blob .empty ()) {
1193+
1194+ bool has_cli_snapshot_blob = !per_process::cli_options->snapshot_blob .empty ();
1195+ #ifndef DISABLE_SINGLE_EXECUTABLE_APPLICATION
1196+ if (sea::IsSingleExecutable ()) {
1197+ const std::string_view sea_code = sea::FindSingleExecutableCode ();
1198+ if (SnapshotData::IsSnapshotBlob (sea_code)) {
1199+ std::unique_ptr<SnapshotData> read_data =
1200+ std::make_unique<SnapshotData>();
1201+ if (SnapshotData::FromBlob (read_data.get (), sea_code)) {
1202+ *snapshot_data_ptr = read_data.release ();
1203+ } else {
1204+ fprintf (stderr, " Invalid snapshot data in single executable binary\n " );
1205+ return ExitCode::kGenericUserError ;
1206+ }
1207+ }
1208+ } else if (has_cli_snapshot_blob) {
1209+ #else
1210+ if (has_cli_snapshot_blob) {
1211+ #endif
11821212 std::string filename = per_process::cli_options->snapshot_blob ;
11831213 FILE* fp = fopen (filename.c_str (), " rb" );
11841214 if (fp == nullptr ) {
0 commit comments