@@ -137,6 +137,20 @@ void GetV8FilePath(const char* file_name, base::FilePath* path_out) {
137137#endif
138138}
139139
140+ #if BUILDFLAG(IS_MAC)
141+ bool FakeMapV8File (const char * aPath, base::MemoryMappedFile** mmapped_file_out) {
142+ std::unique_ptr<base::MemoryMappedFile> mmapped_file (
143+ new base::MemoryMappedFile ());
144+ size_t length;
145+ uint8_t * data = reinterpret_cast <uint8_t *>(recordreplay::ReadSystemFileContents (false , aPath, &length));
146+ if (data) {
147+ mmapped_file->FakeFromData (data, length);
148+ *mmapped_file_out = mmapped_file.release ();
149+ return true ;
150+ }
151+ return false ;
152+ }
153+ #else
140154bool MapV8File (base::File file,
141155 base::MemoryMappedFile::Region region,
142156 base::MemoryMappedFile** mmapped_file_out) {
@@ -203,6 +217,7 @@ base::File OpenV8File(const char* file_name,
203217 OpenV8FileResult::MAX_VALUE);
204218 return file;
205219}
220+ #endif
206221
207222#endif // defined(V8_USE_EXTERNAL_STARTUP_DATA)
208223
@@ -504,12 +519,23 @@ void V8Initializer::LoadV8Snapshot(V8SnapshotFileType snapshot_file_type) {
504519 return ;
505520 }
506521
522+ #if BUILDFLAG(IS_MAC)
523+ if (g_mapped_snapshot) {
524+ return ;
525+ }
526+ g_snapshot_file_type = snapshot_file_type;
527+ if (!FakeMapV8File (GetSnapshotFileName (snapshot_file_type), &g_mapped_snapshot)) {
528+ LOG (FATAL) << " Error loading V8 startup snapshot file" ;
529+ }
530+ #else
507531 base::MemoryMappedFile::Region file_region;
508532 base::File file =
509533 OpenV8File (GetSnapshotFileName (snapshot_file_type), &file_region);
510534 LoadV8SnapshotFromFile (std::move (file), &file_region, snapshot_file_type);
535+ #endif
511536}
512537
538+ #if !BUILDFLAG(IS_MAC)
513539// static
514540void V8Initializer::LoadV8SnapshotFromFile (
515541 base::File snapshot_file,
@@ -537,6 +563,7 @@ void V8Initializer::LoadV8SnapshotFromFile(
537563 return ;
538564 }
539565}
566+ #endif
540567
541568#if BUILDFLAG(IS_ANDROID)
542569// static
0 commit comments