v8 10.2.154 (node 18.16.0)
V8 is Google's open source JavaScript engine
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
59 public:
75 static void SetSnapshotDataBlob(StartupData* startup_blob);
76
79
83 static void SetFlagsFromString(const char* str);
84 static void SetFlagsFromString(const char* str, size_t length);
85
89 static void SetFlagsFromCommandLine(int* argc, char** argv,
90 bool remove_flags);
91
93 static const char* GetVersion();
94
99 V8_INLINE static bool Initialize() {
100 const int kBuildConfiguration =
101 (internal::PointerCompressionIsEnabled() ? kPointerCompression : 0) |
102 (internal::SmiValuesAre31Bits() ? k31BitSmis : 0) |
103 (internal::SandboxedExternalPointersAreEnabled()
104 ? kSandboxedExternalPointers
105 : 0) |
106 (internal::SandboxIsEnabled() ? kSandbox : 0);
107 return Initialize(kBuildConfiguration);
108 }
109
114 static void SetEntropySource(EntropySource source);
115
121 ReturnAddressLocationResolver return_address_resolver);
122
132 static bool Dispose();
133
141 static bool InitializeICU(const char* icu_data_file = nullptr);
142
155 static bool InitializeICUDefaultLocation(const char* exec_path,
156 const char* icu_data_file = nullptr);
157
173 static void InitializeExternalStartupData(const char* directory_path);
174 static void InitializeExternalStartupDataFromFile(const char* snapshot_blob);
175
180 static void InitializePlatform(Platform* platform);
181
186 static void DisposePlatform();
187 V8_DEPRECATED("Use DisposePlatform()")
188 static void ShutdownPlatform() { DisposePlatform(); }
189
190#ifdef V8_SANDBOX
191 //
192 // Sandbox related API.
193 //
194 // This API is not yet stable and subject to changes in the future.
195 //
196
208 static bool InitializeSandbox();
209 V8_DEPRECATE_SOON("Use InitializeSandbox()")
210 static bool InitializeVirtualMemoryCage() { return InitializeSandbox(); }
211
226 static VirtualAddressSpace* GetSandboxAddressSpace();
227 V8_DEPRECATE_SOON("Use GetSandboxAddressSpace()")
228 static PageAllocator* GetVirtualMemoryCagePageAllocator();
229
236 static size_t GetSandboxSizeInBytes();
237 V8_DEPRECATE_SOON("Use GetSandboxSizeInBytes()")
238 static size_t GetVirtualMemoryCageSizeInBytes() {
239 return GetSandboxSizeInBytes();
240 }
241
250 static bool IsSandboxConfiguredSecurely();
251 V8_DEPRECATE_SOON("Use IsSandboxConfiguredSecurely()")
252 static bool IsUsingSecureVirtualMemoryCage() {
253 return IsSandboxConfiguredSecurely();
254 }
255#endif
256
263 static bool EnableWebAssemblyTrapHandler(bool use_v8_signal_handler);
264
265#if defined(V8_OS_WIN)
275 static void SetUnhandledExceptionCallback(
276 UnhandledExceptionCallback unhandled_exception_callback);
277#endif
278
285 static void SetFatalMemoryErrorCallback(OOMErrorCallback oom_error_callback);
286
291
292 private:
293 V8();
294
295 enum BuildConfigurationFeatures {
296 kPointerCompression = 1 << 0,
297 k31BitSmis = 1 << 1,
298 kSandboxedExternalPointers = 1 << 2,
299 kSandbox = 1 << 3,
300 };
301
306 static bool Initialize(int build_config);
307
308 friend class Context;
309 template <class K, class V, class T>
311};
312
313} // namespace v8
314
315#endif // INCLUDE_V8_INITIALIZATION_H_
static void InitializeExternalStartupDataFromFile(const char *snapshot_blob)
static void SetReturnAddressLocationResolver(ReturnAddressLocationResolver return_address_resolver)
static const char * GetVersion()
static void InitializeExternalStartupData(const char *directory_path)
static V8_INLINE bool Initialize()
static void SetDcheckErrorHandler(DcheckErrorCallback that)
static void SetFatalMemoryErrorCallback(OOMErrorCallback oom_error_callback)
static void SetFlagsFromString(const char *str, size_t length)
static void GetSharedMemoryStatistics(SharedMemoryStatistics *statistics)
static bool Dispose()
static bool InitializeICU(const char *icu_data_file=nullptr)
static bool InitializeICUDefaultLocation(const char *exec_path, const char *icu_data_file=nullptr)
static void SetFlagsFromCommandLine(int *argc, char **argv, bool remove_flags)
static void SetFlagsFromString(const char *str)
static void SetEntropySource(EntropySource source)
static void InitializePlatform(Platform *platform)
static bool EnableWebAssemblyTrapHandler(bool use_v8_signal_handler)
static void DisposePlatform()
static void SetSnapshotDataBlob(StartupData *startup_blob)
v8::PageAllocator PageAllocator
Definition platform.h:22
bool(*)(unsigned char *buffer, size_t length) EntropySource
uintptr_t(*)(uintptr_t return_addr_location) ReturnAddressLocationResolver
void(*)(const char *location, bool is_heap_oom) OOMErrorCallback
void(*)(const char *file, int line, const char *message) DcheckErrorCallback
#define V8_EXPORT
Definition v8config.h:578
#define V8_INLINE
Definition v8config.h:425
#define V8_DEPRECATE_SOON(message)
Definition v8config.h:470
#define V8_DEPRECATED(message)
Definition v8config.h:462