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 #if defined(ENABLE_WRT_JS)
35 v8::OOMErrorCallback oom_error_callback = nullptr,
36 bool create_v8_platform = true);
38 v8::OOMErrorCallback oom_error_callback = nullptr);
41 // Get address and size information for currently loaded snapshot.
42 // If no snapshot is loaded, the return values are null for addresses
44 static void GetV8ExternalSnapshotData(v8::StartupData* snapshot);
45 static void GetV8ExternalSnapshotData(const char** snapshot_data_out,
46 int* snapshot_size_out);
48 #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
49 // Load V8 snapshot from default resources, if they are available.
50 static void LoadV8Snapshot(
51 V8SnapshotFileType snapshot_file_type = V8SnapshotFileType::kDefault);
53 // Load V8 snapshot from user provided file.
54 // The region argument, if non-zero, specifies the portions
55 // of the files to be mapped. Since the VM can boot with or without
56 // the snapshot, this function does not return a status.
57 static void LoadV8SnapshotFromFile(
58 base::File snapshot_file,
59 base::MemoryMappedFile::Region* snapshot_file_region,
60 V8SnapshotFileType snapshot_file_type);
62 #if BUILDFLAG(IS_ANDROID)
63 static base::FilePath GetSnapshotFilePath(
65 V8SnapshotFileType snapshot_file_type);
68 #endif // V8_USE_EXTERNAL_STARTUP_DATA
74 #endif // GIN_V8_INITIALIZER_H_