@@ -83,6 +83,12 @@ size_t SeaSerializer::Write(const SeaResource& sea) {
8383 written_total += WriteArithmetic<uint32_t >(flags);
8484 DCHECK_EQ (written_total, SeaResource::kHeaderSize );
8585
86+ Debug (" Write SEA code path %p, size=%zu\n " ,
87+ sea.code_path .data (),
88+ sea.code_path .size ());
89+ written_total +=
90+ WriteStringView (sea.code_path , StringLogMode::kAddressAndContent );
91+
8692 Debug (" Write SEA resource code %p, size=%zu\n " ,
8793 sea.code .data (),
8894 sea.code .size ());
@@ -117,14 +123,19 @@ SeaResource SeaDeserializer::Read() {
117123 Debug (" Read SEA flags %x\n " , static_cast <uint32_t >(flags));
118124 CHECK_EQ (read_total, SeaResource::kHeaderSize );
119125
126+ std::string_view code_path =
127+ ReadStringView (StringLogMode::kAddressAndContent );
128+ Debug (
129+ " Read SEA code path %p, size=%zu\n " , code_path.data (), code_path.size ());
130+
120131 std::string_view code = ReadStringView (StringLogMode::kAddressAndContent );
121132 Debug (" Read SEA resource code %p, size=%zu\n " , code.data (), code.size ());
122133
123134 std::string_view code_cache = ReadStringView (StringLogMode::kAddressOnly );
124135 Debug (" Read SEA resource code cache %p, size=%zu\n " ,
125136 code_cache.data (),
126137 code_cache.size ());
127- return {flags, code, code_cache};
138+ return {flags, code_path, code, code_cache};
128139}
129140
130141std::string_view FindSingleExecutableBlob () {
@@ -208,6 +219,26 @@ void GetCodeCache(const FunctionCallbackInfo<Value>& args) {
208219 args.GetReturnValue ().Set (buf);
209220}
210221
222+ void GetCodePath (const FunctionCallbackInfo<Value>& args) {
223+ if (!IsSingleExecutable ()) {
224+ return ;
225+ }
226+
227+ Environment* env = Environment::GetCurrent (args);
228+ Isolate* isolate = env->isolate ();
229+ HandleScope scope (isolate);
230+
231+ SeaResource sea_resource = FindSingleExecutableResource ();
232+
233+ Local<String> code_path;
234+ if (!String::NewFromUtf8 (isolate, sea_resource.code_path .data ())
235+ .ToLocal (&code_path)) {
236+ return ;
237+ }
238+
239+ args.GetReturnValue ().Set (code_path);
240+ }
241+
211242std::tuple<int , char **> FixupArgsForSEA (int argc, char ** argv) {
212243 // Repeats argv[0] at position 1 on argv as a replacement for the missing
213244 // entry point file path.
@@ -346,7 +377,7 @@ ExitCode GenerateSingleExecutableBlob(const SeaConfig& config) {
346377 }
347378 std::string code_cache = optional_code_cache.value ();
348379
349- SeaResource sea{config.flags , main_script, code_cache};
380+ SeaResource sea{config.flags , config. main_path , main_script, code_cache};
350381
351382 SeaSerializer serializer;
352383 serializer.Write (sea);
@@ -386,11 +417,13 @@ void Initialize(Local<Object> target,
386417 target,
387418 " isExperimentalSeaWarningNeeded" ,
388419 IsExperimentalSeaWarningNeeded);
420+ SetMethod (context, target, " getCodePath" , GetCodePath);
389421 SetMethod (context, target, " getCodeCache" , GetCodeCache);
390422}
391423
392424void RegisterExternalReferences (ExternalReferenceRegistry* registry) {
393425 registry->Register (IsExperimentalSeaWarningNeeded);
426+ registry->Register (GetCodePath);
394427 registry->Register (GetCodeCache);
395428}
396429
0 commit comments