blob: 1341b77198431e1c426bff043bdb2bbcf202c8ca [file] [log] [blame]
Avi Drissman468e51b62022-09-13 20:47:011// Copyright 2013 The Chromium Authors
oth05c26fde2015-04-05 14:30:572// 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
avi90e658dd2015-12-21 07:16:198#include <stdint.h>
9
oth05c26fde2015-04-05 14:30:5710#include "base/files/file.h"
agrievefd2d44ab2015-06-19 04:33:0311#include "base/files/memory_mapped_file.h"
Dan Elphick05acd602021-08-30 15:22:0712#include "build/build_config.h"
oth05c26fde2015-04-05 14:30:5713#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 Babbitt7b2d15e2022-04-08 00:35:4217#include "v8/include/v8-callbacks.h"
Dan Elphick05acd602021-08-30 15:22:0718
Scott Violet592f4f72021-10-12 16:01:5519#if defined(V8_USE_EXTERNAL_STARTUP_DATA)
20#include "gin/public/v8_snapshot_file_type.h"
21#endif
22
Dan Elphick05acd602021-08-30 15:22:0723namespace v8 {
24class StartupData;
25}
oth05c26fde2015-04-05 14:30:5726
27namespace gin {
28
29class GIN_EXPORT V8Initializer {
30 public:
oth05c26fde2015-04-05 14:30:5731 // This should be called by IsolateHolder::Initialize().
Clemens Backesa1ff90ca2022-05-17 11:18:5032 static void Initialize(IsolateHolder::ScriptMode mode,
Thomas Lukaszewicz47141e82025-01-16 20:00:4233 const std::string& js_command_line_flags,
34 bool disallow_v8_feature_flag_overrides,
35 v8::OOMErrorCallback oom_error_callback);
oth05c26fde2015-04-05 14:30:5736
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 Gruberdfa064172019-10-22 04:40:3940 static void GetV8ExternalSnapshotData(v8::StartupData* snapshot);
41 static void GetV8ExternalSnapshotData(const char** snapshot_data_out,
oth05c26fde2015-04-05 14:30:5742 int* snapshot_size_out);
43
44#if defined(V8_USE_EXTERNAL_STARTUP_DATA)
Hitoshi Yoshidaba9c2f0f2017-11-27 03:11:4645 // Load V8 snapshot from default resources, if they are available.
Hitoshi Yoshida9aff02e2018-01-19 16:55:0346 static void LoadV8Snapshot(
47 V8SnapshotFileType snapshot_file_type = V8SnapshotFileType::kDefault);
Hitoshi Yoshidaba9c2f0f2017-11-27 03:11:4648
Josh Gao79f752792018-10-04 18:37:4549 // 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
erikcorryc94eff12015-06-08 11:29:1652 // the snapshot, this function does not return a status.
Josh Gao79f752792018-10-04 18:37:4553 static void LoadV8SnapshotFromFile(
54 base::File snapshot_file,
55 base::MemoryMappedFile::Region* snapshot_file_region,
56 V8SnapshotFileType snapshot_file_type);
oth05c26fde2015-04-05 14:30:5757
Xiaohan Wangc696a4742022-01-08 01:20:4658#if BUILDFLAG(IS_ANDROID)
Hitoshi Yoshida06697232018-03-05 04:09:1559 static base::FilePath GetSnapshotFilePath(
60 bool abi_32_bit,
61 V8SnapshotFileType snapshot_file_type);
tobiasjsb20016272016-02-10 11:54:1262#endif
63
oth05c26fde2015-04-05 14:30:5764#endif // V8_USE_EXTERNAL_STARTUP_DATA
Hitoshi Yoshidaf2f50de2017-08-22 13:23:5565
oth05c26fde2015-04-05 14:30:5766};
67
68} // namespace gin
69
70#endif // GIN_V8_INITIALIZER_H_