Avi Drissman | 468e51b6 | 2022-09-13 20:47:01 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors |
oth | 05c26fde | 2015-04-05 14:30:57 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef GIN_V8_INITIALIZER_H_ |
| 6 | #define GIN_V8_INITIALIZER_H_ |
| 7 | |
avi | 90e658dd | 2015-12-21 07:16:19 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
oth | 05c26fde | 2015-04-05 14:30:57 | [diff] [blame] | 10 | #include "base/files/file.h" |
agrieve | fd2d44ab | 2015-06-19 04:33:03 | [diff] [blame] | 11 | #include "base/files/memory_mapped_file.h" |
Dan Elphick | 05acd60 | 2021-08-30 15:22:07 | [diff] [blame] | 12 | #include "build/build_config.h" |
oth | 05c26fde | 2015-04-05 14:30:57 | [diff] [blame] | 13 | #include "gin/array_buffer.h" |
| 14 | #include "gin/gin_export.h" |
| 15 | #include "gin/public/isolate_holder.h" |
| 16 | #include "gin/public/v8_platform.h" |
Kevin Babbitt | 7b2d15e | 2022-04-08 00:35:42 | [diff] [blame] | 17 | #include "v8/include/v8-callbacks.h" |
Dan Elphick | 05acd60 | 2021-08-30 15:22:07 | [diff] [blame] | 18 | |
Scott Violet | 592f4f7 | 2021-10-12 16:01:55 | [diff] [blame] | 19 | #if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
| 20 | #include "gin/public/v8_snapshot_file_type.h" |
| 21 | #endif |
| 22 | |
Dan Elphick | 05acd60 | 2021-08-30 15:22:07 | [diff] [blame] | 23 | namespace v8 { |
| 24 | class StartupData; |
| 25 | } |
oth | 05c26fde | 2015-04-05 14:30:57 | [diff] [blame] | 26 | |
| 27 | namespace gin { |
| 28 | |
| 29 | class GIN_EXPORT V8Initializer { |
| 30 | public: |
oth | 05c26fde | 2015-04-05 14:30:57 | [diff] [blame] | 31 | // This should be called by IsolateHolder::Initialize(). |
Clemens Backes | a1ff90ca | 2022-05-17 11:18:50 | [diff] [blame] | 32 | static void Initialize(IsolateHolder::ScriptMode mode, |
Thomas Lukaszewicz | 47141e8 | 2025-01-16 20:00:42 | [diff] [blame] | 33 | const std::string& js_command_line_flags, |
| 34 | bool disallow_v8_feature_flag_overrides, |
| 35 | v8::OOMErrorCallback oom_error_callback); |
oth | 05c26fde | 2015-04-05 14:30:57 | [diff] [blame] | 36 | |
| 37 | // Get address and size information for currently loaded snapshot. |
| 38 | // If no snapshot is loaded, the return values are null for addresses |
| 39 | // and 0 for sizes. |
Jakob Gruber | dfa06417 | 2019-10-22 04:40:39 | [diff] [blame] | 40 | static void GetV8ExternalSnapshotData(v8::StartupData* snapshot); |
| 41 | static void GetV8ExternalSnapshotData(const char** snapshot_data_out, |
oth | 05c26fde | 2015-04-05 14:30:57 | [diff] [blame] | 42 | int* snapshot_size_out); |
| 43 | |
| 44 | #if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
Hitoshi Yoshida | ba9c2f0f | 2017-11-27 03:11:46 | [diff] [blame] | 45 | // Load V8 snapshot from default resources, if they are available. |
Hitoshi Yoshida | 9aff02e | 2018-01-19 16:55:03 | [diff] [blame] | 46 | static void LoadV8Snapshot( |
| 47 | V8SnapshotFileType snapshot_file_type = V8SnapshotFileType::kDefault); |
Hitoshi Yoshida | ba9c2f0f | 2017-11-27 03:11:46 | [diff] [blame] | 48 | |
Josh Gao | 79f75279 | 2018-10-04 18:37:45 | [diff] [blame] | 49 | // Load V8 snapshot from user provided file. |
| 50 | // The region argument, if non-zero, specifies the portions |
| 51 | // of the files to be mapped. Since the VM can boot with or without |
erikcorry | c94eff1 | 2015-06-08 11:29:16 | [diff] [blame] | 52 | // the snapshot, this function does not return a status. |
Josh Gao | 79f75279 | 2018-10-04 18:37:45 | [diff] [blame] | 53 | static void LoadV8SnapshotFromFile( |
| 54 | base::File snapshot_file, |
| 55 | base::MemoryMappedFile::Region* snapshot_file_region, |
| 56 | V8SnapshotFileType snapshot_file_type); |
oth | 05c26fde | 2015-04-05 14:30:57 | [diff] [blame] | 57 | |
Xiaohan Wang | c696a474 | 2022-01-08 01:20:46 | [diff] [blame] | 58 | #if BUILDFLAG(IS_ANDROID) |
Hitoshi Yoshida | 0669723 | 2018-03-05 04:09:15 | [diff] [blame] | 59 | static base::FilePath GetSnapshotFilePath( |
| 60 | bool abi_32_bit, |
| 61 | V8SnapshotFileType snapshot_file_type); |
tobiasjs | b2001627 | 2016-02-10 11:54:12 | [diff] [blame] | 62 | #endif |
| 63 | |
oth | 05c26fde | 2015-04-05 14:30:57 | [diff] [blame] | 64 | #endif // V8_USE_EXTERNAL_STARTUP_DATA |
Hitoshi Yoshida | f2f50de | 2017-08-22 13:23:55 | [diff] [blame] | 65 | |
oth | 05c26fde | 2015-04-05 14:30:57 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | } // namespace gin |
| 69 | |
| 70 | #endif // GIN_V8_INITIALIZER_H_ |