1 // Copyright 2013 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef GIN_V8_INITIALIZER_H_
6 #define GIN_V8_INITIALIZER_H_
10 #include "base/files/file.h"
11 #include "base/files/memory_mapped_file.h"
12 #include "build/build_config.h"
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"
17 #include "v8/include/v8-callbacks.h"
19 #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
20 #include "gin/public/v8_snapshot_file_type.h"
29 class GIN_EXPORT V8Initializer {
31 // This should be called by IsolateHolder::Initialize().
32 static void Initialize(IsolateHolder::ScriptMode mode,
33 const std::string js_command_line_flags = {},
34 v8::OOMErrorCallback oom_error_callback = nullptr);
36 // Get address and size information for currently loaded snapshot.
37 // If no snapshot is loaded, the return values are null for addresses
39 static void GetV8ExternalSnapshotData(v8::StartupData* snapshot);
40 static void GetV8ExternalSnapshotData(const char** snapshot_data_out,
41 int* snapshot_size_out);
43 #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
44 // Load V8 snapshot from default resources, if they are available.
45 static void LoadV8Snapshot(
46 V8SnapshotFileType snapshot_file_type = V8SnapshotFileType::kDefault);
48 // Load V8 snapshot from user provided file.
49 // The region argument, if non-zero, specifies the portions
50 // of the files to be mapped. Since the VM can boot with or without
51 // the snapshot, this function does not return a status.
52 static void LoadV8SnapshotFromFile(
53 base::File snapshot_file,
54 base::MemoryMappedFile::Region* snapshot_file_region,
55 V8SnapshotFileType snapshot_file_type);
57 #if BUILDFLAG(IS_ANDROID)
58 static base::FilePath GetSnapshotFilePath(
60 V8SnapshotFileType snapshot_file_type);
63 #endif // V8_USE_EXTERNAL_STARTUP_DATA
69 #endif // GIN_V8_INITIALIZER_H_