v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
v8-initialization.h
Go to the documentation of this file.
1// Copyright 2021 the V8 project 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 INCLUDE_V8_INITIALIZATION_H_
6#define INCLUDE_V8_INITIALIZATION_H_
7
8#include <stddef.h>
9#include <stdint.h>
10
11#include "v8-callbacks.h" // NOLINT(build/include_directory)
12#include "v8-internal.h" // NOLINT(build/include_directory)
13#include "v8-isolate.h" // NOLINT(build/include_directory)
14#include "v8-platform.h" // NOLINT(build/include_directory)
15#include "v8config.h" // NOLINT(build/include_directory)
16
17// We reserve the V8_* prefix for macros defined in V8 public API and
18// assume there are no name conflicts with the embedder's code.
19
23namespace v8 {
24
25class PageAllocator;
26class Platform;
27template <class K, class V, class T>
28class PersistentValueMapBase;
29
34using EntropySource = bool (*)(unsigned char* buffer, size_t length);
35
50 uintptr_t (*)(uintptr_t return_addr_location);
51
52using DcheckErrorCallback = void (*)(const char* file, int line,
53 const char* message);
54
55using V8FatalErrorCallback = void (*)(const char* file, int line,
56 const char* message);
57
62 public:
78 static void SetSnapshotDataBlob(StartupData* startup_blob);
79
81 static void SetDcheckErrorHandler(DcheckErrorCallback that);
82
87 static void SetFatalErrorHandler(V8FatalErrorCallback that);
88
92 static void SetFlagsFromString(const char* str);
93 static void SetFlagsFromString(const char* str, size_t length);
94
98 static void SetFlagsFromCommandLine(int* argc, char** argv,
99 bool remove_flags);
100
102 static const char* GetVersion();
103
108 V8_INLINE static bool Initialize() {
109#ifdef V8_TARGET_OS_ANDROID
110 const bool kV8TargetOsIsAndroid = true;
111#else
112 const bool kV8TargetOsIsAndroid = false;
113#endif
114
115#ifdef V8_ENABLE_CHECKS
116 const bool kV8EnableChecks = true;
117#else
118 const bool kV8EnableChecks = false;
119#endif
120
121 const int kBuildConfiguration =
122 (internal::PointerCompressionIsEnabled() ? kPointerCompression : 0) |
123 (internal::SmiValuesAre31Bits() ? k31BitSmis : 0) |
124 (internal::SandboxIsEnabled() ? kSandbox : 0) |
125 (kV8TargetOsIsAndroid ? kTargetOsIsAndroid : 0) |
126 (kV8EnableChecks ? kEnableChecks : 0);
127 return Initialize(kBuildConfiguration);
128 }
129
134 static void SetEntropySource(EntropySource source);
135
140 static void SetReturnAddressLocationResolver(
141 ReturnAddressLocationResolver return_address_resolver);
142
152 static bool Dispose();
153
161 static bool InitializeICU(const char* icu_data_file = nullptr);
162
175 static bool InitializeICUDefaultLocation(const char* exec_path,
176 const char* icu_data_file = nullptr);
177
193 static void InitializeExternalStartupData(const char* directory_path);
194 static void InitializeExternalStartupDataFromFile(const char* snapshot_blob);
195
200 static void InitializePlatform(Platform* platform);
201
206 static void DisposePlatform();
207
208#if defined(V8_ENABLE_SANDBOX)
219 static bool IsSandboxConfiguredSecurely();
220
233 static VirtualAddressSpace* GetSandboxAddressSpace();
234
241 static size_t GetSandboxSizeInBytes();
242
253 static size_t GetSandboxReservationSizeInBytes();
254#endif // V8_ENABLE_SANDBOX
255
262 static bool EnableWebAssemblyTrapHandler(bool use_v8_signal_handler);
263
264#if defined(V8_OS_WIN)
274 static void SetUnhandledExceptionCallback(
275 UnhandledExceptionCallback callback);
276#endif
277
283 static void SetFatalMemoryErrorCallback(OOMErrorCallback callback);
284
288 static void GetSharedMemoryStatistics(SharedMemoryStatistics* statistics);
289
290 private:
291 V8();
292
294 kPointerCompression = 1 << 0,
295 k31BitSmis = 1 << 1,
296 kSandbox = 1 << 2,
297 kTargetOsIsAndroid = 1 << 3,
298 kEnableChecks = 1 << 4,
299 };
300
305 static bool Initialize(int build_config);
306
307 friend class Context;
308 template <class K, class V, class T>
310};
311
312} // namespace v8
313
314#endif // INCLUDE_V8_INITIALIZATION_H_
static V8_INLINE bool Initialize()
TNode< Object > callback
v8::PageAllocator PageAllocator
Definition platform.h:22
void(*)(const char *file, int line, const char *message) DcheckErrorCallback
void(*)(const char *file, int line, const char *message) V8FatalErrorCallback
uintptr_t(*)(uintptr_t return_addr_location) ReturnAddressLocationResolver
bool(*)(unsigned char *buffer, size_t length) EntropySource
void(*)(const char *location, const OOMDetails &details) OOMErrorCallback
Symbol file
#define V8_EXPORT
Definition v8config.h:800
#define V8_INLINE
Definition v8config.h:500