Loading...
Searching...
No Matches
v8-callbacks.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_ISOLATE_CALLBACKS_H_
6#define INCLUDE_V8_ISOLATE_CALLBACKS_H_
7
8#include <stddef.h>
9
10#include <functional>
11#include <string>
12
13#include "cppgc/common.h"
14#include "v8-data.h" // NOLINT(build/include_directory)
15#include "v8-local-handle.h" // NOLINT(build/include_directory)
16#include "v8-promise.h" // NOLINT(build/include_directory)
17#include "v8config.h" // NOLINT(build/include_directory)
18
19#if defined(V8_OS_WIN)
20struct _EXCEPTION_POINTERS;
21#endif
22
23namespace v8 {
24
25class ArrayBuffer;
26template <typename T>
27class FunctionCallbackInfo;
28class Isolate;
29class Message;
30class Module;
31class Object;
32class Promise;
33class ScriptOrModule;
34class String;
35class UnboundScript;
36class Value;
37
44 enum EventType {
51 };
52 // Definition of the code position type. The "POSITION" type means the place
53 // in the source code which are of interest when making stack traces to
54 // pin-point the source location of a stack frame as close as possible.
55 // The "STATEMENT_POSITION" means the place at the beginning of each
56 // statement, and is used to indicate possible break locations.
58
59 // There are three different kinds of CodeType, one for JIT code generated
60 // by the optimizing compiler, one for byte code generated for the
61 // interpreter, and one for code generated from Wasm. For JIT_CODE and
62 // WASM_CODE, |code_start| points to the beginning of jitted assembly code,
63 // while for BYTE_CODE events, |code_start| points to the first bytecode of
64 // the interpreted function.
66
67 // Type of event.
70 // Start of the instructions.
72 // Size of the instructions.
73 size_t code_len;
74 // Script info for CODE_ADDED event.
76 // User-defined data for *_LINE_INFO_* event. It's used to hold the source
77 // code line information which is returned from the
78 // CODE_START_LINE_INFO_RECORDING event. And it's passed to subsequent
79 // CODE_ADD_LINE_POS_INFO and CODE_END_LINE_INFO_RECORDING events.
80 void* user_data;
81
82 struct name_t {
83 // Name of the object associated with the code, note that the string is not
84 // zero-terminated.
85 const char* str;
86 // Number of chars in str.
87 size_t len;
88 };
89
90 struct line_info_t {
91 // PC offset
92 size_t offset;
93 // Code position
94 size_t pos;
95 // The position type.
97 };
98
100 // Source file name.
101 const char* filename;
102 // Length of filename.
104 // Line number table, which maps offsets of JITted code to line numbers of
105 // source file.
107 // Number of entries in the line number table.
109 };
110
112
113 union {
114 // Only valid for CODE_ADDED.
115 struct name_t name;
116
117 // Only valid for CODE_ADD_LINE_POS_INFO
119
120 // New location of instructions. Only valid for CODE_MOVED.
122 };
123
125};
126
132 // Generate callbacks for already existent code.
134
137
143using JitCodeEventHandler = void (*)(const JitCodeEvent* event);
144
145// --- Garbage Collection Callbacks ---
146
155enum GCType {
165
189};
190
191using GCCallback = void (*)(GCType type, GCCallbackFlags flags);
192
193using InterruptCallback = void (*)(Isolate* isolate, void* data);
194
196 bool (*)(Isolate* isolate, Local<String> script_name);
197
205using NearHeapLimitCallback = size_t (*)(void* data, size_t current_heap_limit,
206 size_t initial_heap_limit);
207
211#if defined(V8_OS_WIN)
212using UnhandledExceptionCallback =
213 int (*)(_EXCEPTION_POINTERS* exception_pointers);
214#endif
215
216// --- Counters Callbacks ---
217
218using CounterLookupCallback = int* (*)(const char* name);
219
220using CreateHistogramCallback = void* (*)(const char* name, int min, int max,
221 size_t buckets);
222
223using AddHistogramSampleCallback = void (*)(void* histogram, int sample);
224
225// --- Exceptions ---
226
227using FatalErrorCallback = void (*)(const char* location, const char* message);
228
230 bool is_heap_oom = false;
231 const char* detail = nullptr;
232};
233
234using OOMErrorCallback = void (*)(const char* location,
235 const OOMDetails& details);
236
237using OOMErrorCallbackWithData = void (*)(const char* location,
238 const OOMDetails& details,
239 void* data);
240
241using MessageCallback = void (*)(Local<Message> message, Local<Value> data);
242
243// --- Tracing ---
244
245enum LogEventStatus : int { kStart = 0, kEnd = 1, kLog = 2 };
246using LogEventCallback = void (*)(const char* name,
247 int /* LogEventStatus */ status);
248
249// --- Crashkeys Callback ---
250enum class CrashKeyId {
253 kMapSpaceFirstPageAddress V8_ENUM_DEPRECATE_SOON("Map space got removed"),
257 kDumpType,
260};
261
262using AddCrashKeyCallback = void (*)(CrashKeyId id, const std::string& value);
263
264// --- CrashKeyString Callbacks ---
265using CrashKey = void*;
267
269 std::function<CrashKey(const char key[], CrashKeySize size)>;
271 std::function<void(CrashKey key, const std::string_view value)>;
272
273// --- Enter/Leave Script Callback ---
276
277// --- Modify Code Generation From Strings Callback ---
279 // If true, proceed with the codegen algorithm. Otherwise, block it.
280 bool codegen_allowed = false;
281 // Overwrite the original source with this string, if present.
282 // Use the original source if empty.
283 // This field is considered only if codegen_allowed is true.
285};
286
293 Local<Value> source);
296 Local<Value> source,
297 bool is_code_like);
298
299// --- Failed Access Check Callback ---
300
311
313 AccessType type, Local<Value> data);
314
315// --- WebAssembly compilation callbacks ---
317
319 Local<String> source);
320
321// --- Callback for APIs defined on v8-supported objects, but implemented
322// by the embedder. Example: WebAssembly.{compile|instantiate}Streaming ---
324
325// --- Callback for WebAssembly.compileStreaming ---
327
329
330// --- Callback called when async WebAssembly operations finish ---
332 Isolate* isolate, Local<Context> context, Local<Promise::Resolver> resolver,
333 Local<Value> result, WasmAsyncSuccess success);
334
335// --- Callback for loading source map file for Wasm profiling support
337 const char* name);
338
339// --- Callback for checking if WebAssembly Custom Descriptors are enabled ---
341
342// --- Callback for checking if the SharedArrayBuffer constructor is enabled ---
344 bool (*)(Local<Context> context);
345
346// --- Callback for getting high resolution timestamps in Temporal ---
348 int64_t (*)(Local<Context> context);
349
354 kSource,
355 kDefer,
357};
358
386 Local<Context> context, Local<Data> host_defined_options,
387 Local<Value> resource_name, Local<String> specifier,
388 Local<FixedArray> import_attributes);
389
427 Local<Context> context, Local<Data> host_defined_options,
428 Local<Value> resource_name, Local<String> specifier,
429 ModuleImportPhase phase, Local<FixedArray> import_attributes);
430
436using CompileHintCallback = bool (*)(int, void*);
437
449 Local<Module> module,
450 Local<Object> meta);
451
464 MaybeLocal<Context> (*)(Local<Context> initiator_context);
465
472 Local<Object> obj);
473
478using ArrayBufferDetachCallback = void (*)(Isolate* isolate,
479 Local<ArrayBuffer> buffer);
480
489 Local<Value> error,
490 Local<Array> sites);
491
498 void (*)(Local<Context> context, int script_id);
499
500#if defined(V8_OS_WIN)
537using FilterETWSessionByURLCallback =
538 bool (*)(Local<Context> context, const std::string& etw_filter_payload);
539
540struct FilterETWSessionByURLResult {
541 // If true, enable ETW tracing for the current isolate.
542 bool enable_etw_tracing;
543
544 // If true, also enables ETW tracing for interpreter stack frames.
545 bool trace_interpreter_frames;
546};
547using FilterETWSessionByURL2Callback = FilterETWSessionByURLResult (*)(
548 Local<Context> context, const std::string& etw_filter_payload);
549#endif // V8_OS_WIN
550
551} // namespace v8
552
553#endif // INCLUDE_V8_ISOLATE_CALLBACKS_H_
Definition: v8-function-callback.h:128
Definition: v8-isolate.h:298
Definition: v8-local-handle.h:360
Definition: v8-local-handle.h:728
Definition: libplatform.h:15
void(*)(const JitCodeEvent *event) JitCodeEventHandler
Definition: v8-callbacks.h:143
JitCodeEventOptions
Definition: v8-callbacks.h:130
@ kJitCodeEventEnumExisting
Definition: v8-callbacks.h:133
@ kLastJitCodeEventOption
Definition: v8-callbacks.h:135
@ kJitCodeEventDefault
Definition: v8-callbacks.h:131
void(*)(const char *location, const OOMDetails &details) OOMErrorCallback
Definition: v8-callbacks.h:235
ModifyCodeGenerationFromStringsResult(*)(Local< Context > context, Local< Value > source) ModifyCodeGenerationFromStringsCallback
Definition: v8-callbacks.h:293
void * CrashKey
Definition: v8-callbacks.h:265
bool(*)(Local< Context > context) SharedArrayBufferConstructorEnabledCallback
Definition: v8-callbacks.h:344
GCCallbackFlags
Definition: v8-callbacks.h:180
@ kGCCallbackScheduleIdleGarbageCollection
Definition: v8-callbacks.h:187
@ kGCCallbackFlagConstructRetainedObjectInfos
Definition: v8-callbacks.h:182
@ kGCCallbackFlagForced
Definition: v8-callbacks.h:183
@ kNoGCCallbackFlags
Definition: v8-callbacks.h:181
@ kGCCallbackFlagCollectAllExternalMemory
Definition: v8-callbacks.h:186
@ kGCCallbackFlagSynchronousPhantomCallbackProcessing
Definition: v8-callbacks.h:184
@ kGCCallbackFlagLastResort
Definition: v8-callbacks.h:188
@ kGCCallbackFlagCollectAllAvailableGarbage
Definition: v8-callbacks.h:185
CrashKeyId
Definition: v8-callbacks.h:250
@ kSnapshotChecksumCalculated
@ kCodeSpaceFirstPageAddress
@ kReadonlySpaceFirstPageAddress
LogEventStatus
Definition: v8-callbacks.h:245
@ kEnd
Definition: v8-callbacks.h:245
@ kStart
Definition: v8-callbacks.h:245
@ kLog
Definition: v8-callbacks.h:245
bool(*)(Local< Context > context) WasmCustomDescriptorsEnabledCallback
Definition: v8-callbacks.h:340
void(*)(Isolate *isolate, Local< ArrayBuffer > buffer) ArrayBufferDetachCallback
Definition: v8-callbacks.h:479
void(*)(Isolate *isolate, Local< Context > context, Local< Promise::Resolver > resolver, Local< Value > result, WasmAsyncSuccess success) WasmAsyncResolvePromiseCallback
Definition: v8-callbacks.h:333
bool(*)(const FunctionCallbackInfo< Value > &) ExtensionCallback
Definition: v8-callbacks.h:316
int64_t(*)(Local< Context > context) TemporalHostSystemUTCEpochNanosecondsCallback
Definition: v8-callbacks.h:348
void(*)(const FunctionCallbackInfo< Value > &) WasmStreamingCallback
Definition: v8-callbacks.h:326
void *(*)(const char *name, int min, int max, size_t buckets) CreateHistogramCallback
Definition: v8-callbacks.h:221
void(*)(Local< Context > context, Local< Module > module, Local< Object > meta) HostInitializeImportMetaObjectCallback
Definition: v8-callbacks.h:450
void(*)(Local< Message > message, Local< Value > data) MessageCallback
Definition: v8-callbacks.h:241
CrashKeySize
Definition: v8-callbacks.h:266
void(*)(const char *location, const OOMDetails &details, void *data) OOMErrorCallbackWithData
Definition: v8-callbacks.h:239
void(*)(GCType type, GCCallbackFlags flags) GCCallback
Definition: v8-callbacks.h:191
void(*)(CrashKeyId id, const std::string &value) AddCrashKeyCallback
Definition: v8-callbacks.h:262
void(*)(Isolate *isolate, void *data) InterruptCallback
Definition: v8-callbacks.h:193
void(*)(Isolate *) CallCompletedCallback
Definition: v8-callbacks.h:275
void(*)(void *histogram, int sample) AddHistogramSampleCallback
Definition: v8-callbacks.h:223
bool(*)(Isolate *isolate, Local< String > script_name) PrintCurrentStackTraceFilterCallback
Definition: v8-callbacks.h:196
size_t(*)(void *data, size_t current_heap_limit, size_t initial_heap_limit) NearHeapLimitCallback
Definition: v8-callbacks.h:206
void(*)(Isolate *) BeforeCallEnteredCallback
Definition: v8-callbacks.h:274
bool(*)(Local< Context > context, Local< String > source) AllowWasmCodeGenerationCallback
Definition: v8-callbacks.h:319
void(*)(const char *location, const char *message) FatalErrorCallback
Definition: v8-callbacks.h:227
WasmAsyncSuccess
Definition: v8-callbacks.h:328
GCType
Definition: v8-callbacks.h:155
@ kGCTypeMinorMarkSweep
Definition: v8-callbacks.h:157
@ kGCTypeScavenge
Definition: v8-callbacks.h:156
@ kGCTypeProcessWeakCallbacks
Definition: v8-callbacks.h:160
@ kGCTypeMarkSweepCompact
Definition: v8-callbacks.h:158
@ kGCTypeAll
Definition: v8-callbacks.h:161
@ kGCTypeIncrementalMarking
Definition: v8-callbacks.h:159
std::function< void(CrashKey key, const std::string_view value)> SetCrashKeyStringCallback
Definition: v8-callbacks.h:271
void(*)(Local< Context > context, int script_id) DynamicScriptCompiledFromEmbedderCallback
Definition: v8-callbacks.h:498
bool(*)(int, void *) CompileHintCallback
Definition: v8-callbacks.h:436
void(*)(const FunctionCallbackInfo< Value > &) ApiImplementationCallback
Definition: v8-callbacks.h:323
ModifyCodeGenerationFromStringsResult(*)(Local< Context > context, Local< Value > source, bool is_code_like) ModifyCodeGenerationFromStringsCallback2
Definition: v8-callbacks.h:297
void(*)(Local< Object > target, AccessType type, Local< Value > data) FailedAccessCheckCallback
Definition: v8-callbacks.h:313
AccessType
Definition: v8-callbacks.h:304
@ ACCESS_SET
Definition: v8-callbacks.h:306
@ ACCESS_HAS
Definition: v8-callbacks.h:307
@ ACCESS_KEYS
Definition: v8-callbacks.h:309
@ ACCESS_GET
Definition: v8-callbacks.h:305
@ ACCESS_DELETE
Definition: v8-callbacks.h:308
void(*)(const char *name, int status) LogEventCallback
Definition: v8-callbacks.h:247
std::function< CrashKey(const char key[], CrashKeySize size)> AllocateCrashKeyStringCallback
Definition: v8-callbacks.h:269
int *(*)(const char *name) CounterLookupCallback
Definition: v8-callbacks.h:218
bool(*)(Isolate *isolate, Local< Object > obj) IsJSApiWrapperNativeErrorCallback
Definition: v8-callbacks.h:472
ModuleImportPhase
Definition: v8-callbacks.h:353
Definition: v8-callbacks.h:90
size_t offset
Definition: v8-callbacks.h:92
size_t pos
Definition: v8-callbacks.h:94
PositionType position_type
Definition: v8-callbacks.h:96
Definition: v8-callbacks.h:82
const char * str
Definition: v8-callbacks.h:85
size_t len
Definition: v8-callbacks.h:87
Definition: v8-callbacks.h:99
const char * filename
Definition: v8-callbacks.h:101
const line_info_t * line_number_table
Definition: v8-callbacks.h:106
size_t filename_size
Definition: v8-callbacks.h:103
size_t line_number_table_size
Definition: v8-callbacks.h:108
Definition: v8-callbacks.h:43
PositionType
Definition: v8-callbacks.h:57
@ POSITION
Definition: v8-callbacks.h:57
@ STATEMENT_POSITION
Definition: v8-callbacks.h:57
CodeType
Definition: v8-callbacks.h:65
@ JIT_CODE
Definition: v8-callbacks.h:65
@ BYTE_CODE
Definition: v8-callbacks.h:65
@ WASM_CODE
Definition: v8-callbacks.h:65
struct name_t name
Definition: v8-callbacks.h:115
Local< UnboundScript > script
Definition: v8-callbacks.h:75
struct line_info_t line_info
Definition: v8-callbacks.h:118
Isolate * isolate
Definition: v8-callbacks.h:124
void * user_data
Definition: v8-callbacks.h:80
wasm_source_info_t * wasm_source_info
Definition: v8-callbacks.h:111
void * new_code_start
Definition: v8-callbacks.h:121
EventType
Definition: v8-callbacks.h:44
@ CODE_END_LINE_INFO_RECORDING
Definition: v8-callbacks.h:50
@ CODE_ADDED
Definition: v8-callbacks.h:45
@ CODE_MOVED
Definition: v8-callbacks.h:46
@ CODE_ADD_LINE_POS_INFO
Definition: v8-callbacks.h:48
@ CODE_REMOVED
Definition: v8-callbacks.h:47
@ CODE_START_LINE_INFO_RECORDING
Definition: v8-callbacks.h:49
EventType type
Definition: v8-callbacks.h:68
size_t code_len
Definition: v8-callbacks.h:73
void * code_start
Definition: v8-callbacks.h:71
CodeType code_type
Definition: v8-callbacks.h:69
Definition: v8-callbacks.h:278
bool codegen_allowed
Definition: v8-callbacks.h:280
MaybeLocal< String > modified_source
Definition: v8-callbacks.h:284
Definition: v8-callbacks.h:229
const char * detail
Definition: v8-callbacks.h:231
bool is_heap_oom
Definition: v8-callbacks.h:230
#define V8_ENUM_DEPRECATE_SOON(message)
Definition: v8config.h:668