[go: nahoru, domu]

blob: a749ccbecfc8b82217d4ed48dcf8a5d9ceba052c [file] [log] [blame]
oth05c26fde2015-04-05 14:30:571// Copyright 2013 The Chromium Authors. All rights reserved.
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
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"
oth05c26fde2015-04-05 14:30:5712#include "gin/array_buffer.h"
13#include "gin/gin_export.h"
14#include "gin/public/isolate_holder.h"
15#include "gin/public/v8_platform.h"
16#include "v8/include/v8.h"
17
18namespace gin {
19
20class GIN_EXPORT V8Initializer {
21 public:
oth05c26fde2015-04-05 14:30:5722 // This should be called by IsolateHolder::Initialize().
yhirano93150242015-12-07 12:28:3323 static void Initialize(IsolateHolder::ScriptMode mode,
24 IsolateHolder::V8ExtrasMode v8_extras_mode);
oth05c26fde2015-04-05 14:30:5725
26 // Get address and size information for currently loaded snapshot.
27 // If no snapshot is loaded, the return values are null for addresses
28 // and 0 for sizes.
Hitoshi Yoshidad88a223e2017-09-10 05:55:2529 static void GetV8ExternalSnapshotData(v8::StartupData* natives,
30 v8::StartupData* snapshot);
oth05c26fde2015-04-05 14:30:5731 static void GetV8ExternalSnapshotData(const char** natives_data_out,
32 int* natives_size_out,
33 const char** snapshot_data_out,
34 int* snapshot_size_out);
35
36#if defined(V8_USE_EXTERNAL_STARTUP_DATA)
Hitoshi Yoshida9aff02e2018-01-19 16:55:0337 // Indicates which file to load as a snapshot blob image.
38 enum class V8SnapshotFileType {
39 kDefault,
40
41 // Snapshot augmented with customized contexts, which can be deserialized
42 // using v8::Context::FromSnapshot.
43 kWithAdditionalContext,
44 };
oth05c26fde2015-04-05 14:30:5745
Hitoshi Yoshidaba9c2f0f2017-11-27 03:11:4646 // Load V8 snapshot from default resources, if they are available.
Hitoshi Yoshida9aff02e2018-01-19 16:55:0347 static void LoadV8Snapshot(
48 V8SnapshotFileType snapshot_file_type = V8SnapshotFileType::kDefault);
Hitoshi Yoshidaba9c2f0f2017-11-27 03:11:4649 // Load V8 natives source from default resources. Contains asserts
50 // so that it will not return if natives cannot be loaded.
51 static void LoadV8Natives();
Hitoshi Yoshidaba9c2f0f2017-11-27 03:11:4652
Josh Gao79f75272018-10-04 18:37:4553 // 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
erikcorryc94eff12015-06-08 11:29:1656 // the snapshot, this function does not return a status.
Josh Gao79f75272018-10-04 18:37:4557 static void LoadV8SnapshotFromFile(
58 base::File snapshot_file,
59 base::MemoryMappedFile::Region* snapshot_file_region,
60 V8SnapshotFileType snapshot_file_type);
61 // Similar to LoadV8SnapshotFromFile, but for the source of the natives.
erikcorryc94eff12015-06-08 11:29:1662 // Without the natives we cannot continue, so this function contains
63 // release mode asserts and won't return if it fails.
Josh Gao79f75272018-10-04 18:37:4564 static void LoadV8NativesFromFile(
65 base::File natives_file,
66 base::MemoryMappedFile::Region* natives_file_region);
oth05c26fde2015-04-05 14:30:5767
tobiasjsb20016272016-02-10 11:54:1268#if defined(OS_ANDROID)
michaelbai020375882016-06-21 16:08:1569 static base::FilePath GetNativesFilePath();
Hitoshi Yoshida06697232018-03-05 04:09:1570 static base::FilePath GetSnapshotFilePath(
71 bool abi_32_bit,
72 V8SnapshotFileType snapshot_file_type);
tobiasjsb20016272016-02-10 11:54:1273#endif
74
oth05c26fde2015-04-05 14:30:5775#endif // V8_USE_EXTERNAL_STARTUP_DATA
Hitoshi Yoshidaf2f50de2017-08-22 13:23:5576
oth05c26fde2015-04-05 14:30:5777};
78
79} // namespace gin
80
81#endif // GIN_V8_INITIALIZER_H_