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#include <string_view>
13
14#include "cppgc/common.h"
15#include "v8-data.h" // NOLINT(build/include_directory)
16#include "v8-local-handle.h" // NOLINT(build/include_directory)
17#include "v8-promise.h" // NOLINT(build/include_directory)
18#include "v8config.h" // NOLINT(build/include_directory)
19
20#if defined(V8_OS_WIN)
21struct _EXCEPTION_POINTERS;
22#endif
23
24namespace v8 {
25
26class ArrayBuffer;
27template <typename T>
28class FunctionCallbackInfo;
29class Isolate;
30class Message;
31class Module;
32class Object;
33class Promise;
34class ScriptOrModule;
35class String;
36class UnboundScript;
37class Value;
38
45 enum EventType {
52 };
53 // Definition of the code position type. The "POSITION" type means the place
54 // in the source code which are of interest when making stack traces to
55 // pin-point the source location of a stack frame as close as possible.
56 // The "STATEMENT_POSITION" means the place at the beginning of each
57 // statement, and is used to indicate possible break locations.
59
60 // There are three different kinds of CodeType, one for JIT code generated
61 // by the optimizing compiler, one for byte code generated for the
62 // interpreter, and one for code generated from Wasm. For JIT_CODE and
63 // WASM_CODE, |code_start| points to the beginning of jitted assembly code,
64 // while for BYTE_CODE events, |code_start| points to the first bytecode of
65 // the interpreted function.
67
68 // Type of event.
71 // Start of the instructions.
73 // Size of the instructions.
74 size_t code_len;
75 // Script info for CODE_ADDED event.
77 // User-defined data for *_LINE_INFO_* event. It's used to hold the source
78 // code line information which is returned from the
79 // CODE_START_LINE_INFO_RECORDING event. And it's passed to subsequent
80 // CODE_ADD_LINE_POS_INFO and CODE_END_LINE_INFO_RECORDING events.
81 void* user_data;
82
83 struct name_t {
84 // Name of the object associated with the code, note that the string is not
85 // zero-terminated.
86 const char* str;
87 // Number of chars in str.
88 size_t len;
89 };
90
91 struct line_info_t {
92 // PC offset
93 size_t offset;
94 // Code position
95 size_t pos;
96 // The position type.
98 };
99
101 // Source file name.
102 const char* filename;
103 // Length of filename.
105 // Line number table, which maps offsets of JITted code to line numbers of
106 // source file.
108 // Number of entries in the line number table.
110 };
111
113
114 union {
115 // Only valid for CODE_ADDED.
116 struct name_t name;
117
118 // Only valid for CODE_ADD_LINE_POS_INFO
120
121 // New location of instructions. Only valid for CODE_MOVED.
123 };
124
126};
127
133 // Generate callbacks for already existent code.
135
138
144using JitCodeEventHandler = void (*)(const JitCodeEvent* event);
145
146// --- Garbage Collection Callbacks ---
147
156enum GCType {
166
190};
191
192using GCCallback = void (*)(GCType type, GCCallbackFlags flags);
193
194using InterruptCallback = void (*)(Isolate* isolate, void* data);
195
197 bool (*)(Isolate* isolate, Local<String> script_name);
198
206using NearHeapLimitCallback = size_t (*)(void* data, size_t current_heap_limit,
207 size_t initial_heap_limit);
208
212#if defined(V8_OS_WIN)
213using UnhandledExceptionCallback =
214 int (*)(_EXCEPTION_POINTERS* exception_pointers);
215#endif
216
217// --- Counters Callbacks ---
218
219using CounterLookupCallback = int* (*)(const char* name);
220
221using CreateHistogramCallback = void* (*)(const char* name, int min, int max,
222 size_t buckets);
223
224using AddHistogramSampleCallback = void (*)(void* histogram, int sample);
225
226// --- Exceptions ---
227
228using FatalErrorCallback = void (*)(const char* location, const char* message);
229
231 bool is_heap_oom = false;
232 const char* detail = nullptr;
233};
234
235using OOMErrorCallback = void (*)(const char* location,
236 const OOMDetails& details);
237
238using OOMErrorCallbackWithData = void (*)(const char* location,
239 const OOMDetails& details,
240 void* data);
241
242using MessageCallback = void (*)(Local<Message> message, Local<Value> data);
243
244// --- Tracing ---
245
246enum LogEventStatus : int { kStart = 0, kEnd = 1, kLog = 2 };
247using LogEventCallback = void (*)(const char* name,
248 int /* LogEventStatus */ status);
249
250// --- Crashkeys Callback ---
251enum class CrashKeyId {
254 kMapSpaceFirstPageAddress V8_ENUM_DEPRECATE_SOON("Map space got removed"),
258 kDumpType,
261};
262
263using AddCrashKeyCallback = void (*)(CrashKeyId id, const std::string& value);
264
265// --- CrashKey Callbacks ---
266using CrashKey = void*;
268
269// Allocates a new crash key with the given `key` name and maximum value `size`.
270// Embedders do not need to deduplicate by `key` name: V8 caches the returned
271// `CrashKey` handle in static storage whenever a key may be updated multiple
272// times. Returns nullptr if crash keys are not supported or initialized.
273using AllocateCrashKeyCallback = CrashKey (*)(const char key[],
274 CrashKeySize size);
275using SetCrashKeyCallback = void (*)(CrashKey key, std::string_view value);
276
277// Deprecated: use AllocateCrashKeyCallback / SetCrashKeyCallback with
278// V8::SetCrashKeyCallbacks instead.
280 std::function<CrashKey(const char key[], CrashKeySize size)>;
282 std::function<void(CrashKey key, const std::string_view value)>;
283
284// --- Enter/Leave Script Callback ---
287
288// --- Modify Code Generation From Strings Callback ---
290 // If true, proceed with the codegen algorithm. Otherwise, block it.
291 bool codegen_allowed = false;
292 // Overwrite the original source with this string, if present.
293 // Use the original source if empty.
294 // This field is considered only if codegen_allowed is true.
296};
297
304 Local<Value> source);
307 Local<Value> source,
308 bool is_code_like);
309
310// --- Failed Access Check Callback ---
311
322
324 AccessType type, Local<Value> data);
325
326// --- WebAssembly compilation callbacks ---
328using WasmModuleCallback = bool (*)(Isolate* isolate, Local<Value> source);
329using WasmInstanceCallback = bool (*)(Isolate* isolate, Local<Value> source);
330
332 Local<String> source);
333
334// --- Callback for APIs defined on v8-supported objects, but implemented
335// by the embedder. Example: WebAssembly.{compile|instantiate}Streaming ---
337
338// --- Callback for WebAssembly.compileStreaming ---
340
342
343// --- Callback called when async WebAssembly operations finish ---
345 Isolate* isolate, Local<Context> context, Local<Promise::Resolver> resolver,
346 Local<Value> result, WasmAsyncSuccess success);
347
348// --- Callback for loading source map file for Wasm profiling support
350 const char* name);
351
352// --- Callback for checking if WebAssembly Custom Descriptors are enabled ---
354
355// --- Callback for checking if the SharedArrayBuffer constructor is enabled ---
357 bool (*)(Local<Context> context);
358
359// --- Callback for getting high resolution timestamps in Temporal ---
361 int64_t (*)(Local<Context> context);
362
367 kSource,
368 kDefer,
370};
371
399 Local<Context> context, Local<Data> host_defined_options,
400 Local<Value> resource_name, Local<String> specifier,
401 Local<FixedArray> import_attributes);
402
440 Local<Context> context, Local<Data> host_defined_options,
441 Local<Value> resource_name, Local<String> specifier,
442 ModuleImportPhase phase, Local<FixedArray> import_attributes);
443
449using CompileHintCallback = bool (*)(int, void*);
450
462 Local<Module> module,
463 Local<Object> meta);
464
477 MaybeLocal<Context> (*)(Local<Context> initiator_context);
478
485 Local<Object> obj);
486
491using ArrayBufferDetachCallback = void (*)(Isolate* isolate,
492 Local<ArrayBuffer> buffer);
493
502 Local<Value> error,
503 Local<Array> sites);
504
511 void (*)(Local<Context> context, int script_id);
512
513#if defined(V8_OS_WIN)
550using FilterETWSessionByURLCallback =
551 bool (*)(Local<Context> context, const std::string& etw_filter_payload);
552
553struct FilterETWSessionByURLResult {
554 // If true, enable ETW tracing for the current isolate.
555 bool enable_etw_tracing;
556
557 // If true, also enables ETW tracing for interpreter stack frames.
558 bool trace_interpreter_frames;
559};
560using FilterETWSessionByURL2Callback = FilterETWSessionByURLResult (*)(
561 Local<Context> context, const std::string& etw_filter_payload);
562#endif // V8_OS_WIN
563
564} // namespace v8
565
566#endif // INCLUDE_V8_ISOLATE_CALLBACKS_H_
Definition: v8-function-callback.h:126
Definition: v8-isolate.h:305
Definition: v8-local-handle.h:359
Definition: v8-local-handle.h:730
Definition: libplatform.h:15
void(*)(const JitCodeEvent *event) JitCodeEventHandler
Definition: v8-callbacks.h:144
JitCodeEventOptions
Definition: v8-callbacks.h:131
@ kJitCodeEventEnumExisting
Definition: v8-callbacks.h:134
@ kLastJitCodeEventOption
Definition: v8-callbacks.h:136
@ kJitCodeEventDefault
Definition: v8-callbacks.h:132
void(*)(const char *location, const OOMDetails &details) OOMErrorCallback
Definition: v8-callbacks.h:236
ModifyCodeGenerationFromStringsResult(*)(Local< Context > context, Local< Value > source) ModifyCodeGenerationFromStringsCallback
Definition: v8-callbacks.h:304
void * CrashKey
Definition: v8-callbacks.h:266
bool(*)(Local< Context > context) SharedArrayBufferConstructorEnabledCallback
Definition: v8-callbacks.h:357
GCCallbackFlags
Definition: v8-callbacks.h:181
@ kGCCallbackScheduleIdleGarbageCollection
Definition: v8-callbacks.h:188
@ kGCCallbackFlagConstructRetainedObjectInfos
Definition: v8-callbacks.h:183
@ kGCCallbackFlagForced
Definition: v8-callbacks.h:184
@ kNoGCCallbackFlags
Definition: v8-callbacks.h:182
@ kGCCallbackFlagCollectAllExternalMemory
Definition: v8-callbacks.h:187
@ kGCCallbackFlagSynchronousPhantomCallbackProcessing
Definition: v8-callbacks.h:185
@ kGCCallbackFlagLastResort
Definition: v8-callbacks.h:189
@ kGCCallbackFlagCollectAllAvailableGarbage
Definition: v8-callbacks.h:186
CrashKeyId
Definition: v8-callbacks.h:251
@ kSnapshotChecksumCalculated
@ kCodeSpaceFirstPageAddress
@ kReadonlySpaceFirstPageAddress
LogEventStatus
Definition: v8-callbacks.h:246
@ kEnd
Definition: v8-callbacks.h:246
@ kStart
Definition: v8-callbacks.h:246
@ kLog
Definition: v8-callbacks.h:246
bool(*)(Local< Context > context) WasmCustomDescriptorsEnabledCallback
Definition: v8-callbacks.h:353
void(*)(Isolate *isolate, Local< ArrayBuffer > buffer) ArrayBufferDetachCallback
Definition: v8-callbacks.h:492
void(*)(Isolate *isolate, Local< Context > context, Local< Promise::Resolver > resolver, Local< Value > result, WasmAsyncSuccess success) WasmAsyncResolvePromiseCallback
Definition: v8-callbacks.h:346
bool(*)(Isolate *isolate, Local< Value > source) WasmInstanceCallback
Definition: v8-callbacks.h:329
bool(*)(const FunctionCallbackInfo< Value > &) ExtensionCallback
Definition: v8-callbacks.h:327
int64_t(*)(Local< Context > context) TemporalHostSystemUTCEpochNanosecondsCallback
Definition: v8-callbacks.h:361
bool(*)(Isolate *isolate, Local< Value > source) WasmModuleCallback
Definition: v8-callbacks.h:328
void(*)(const FunctionCallbackInfo< Value > &) WasmStreamingCallback
Definition: v8-callbacks.h:339
void *(*)(const char *name, int min, int max, size_t buckets) CreateHistogramCallback
Definition: v8-callbacks.h:222
void(*)(Local< Context > context, Local< Module > module, Local< Object > meta) HostInitializeImportMetaObjectCallback
Definition: v8-callbacks.h:463
void(*)(Local< Message > message, Local< Value > data) MessageCallback
Definition: v8-callbacks.h:242
CrashKeySize
Definition: v8-callbacks.h:267
void(*)(const char *location, const OOMDetails &details, void *data) OOMErrorCallbackWithData
Definition: v8-callbacks.h:240
void(*)(GCType type, GCCallbackFlags flags) GCCallback
Definition: v8-callbacks.h:192
void(*)(CrashKeyId id, const std::string &value) AddCrashKeyCallback
Definition: v8-callbacks.h:263
void(*)(Isolate *isolate, void *data) InterruptCallback
Definition: v8-callbacks.h:194
void(*)(Isolate *) CallCompletedCallback
Definition: v8-callbacks.h:286
void(*)(void *histogram, int sample) AddHistogramSampleCallback
Definition: v8-callbacks.h:224
bool(*)(Isolate *isolate, Local< String > script_name) PrintCurrentStackTraceFilterCallback
Definition: v8-callbacks.h:197
void(*)(CrashKey key, std::string_view value) SetCrashKeyCallback
Definition: v8-callbacks.h:275
CrashKey(*)(const char key[], CrashKeySize size) AllocateCrashKeyCallback
Definition: v8-callbacks.h:274
size_t(*)(void *data, size_t current_heap_limit, size_t initial_heap_limit) NearHeapLimitCallback
Definition: v8-callbacks.h:207
void(*)(Isolate *) BeforeCallEnteredCallback
Definition: v8-callbacks.h:285
bool(*)(Local< Context > context, Local< String > source) AllowWasmCodeGenerationCallback
Definition: v8-callbacks.h:332
void(*)(const char *location, const char *message) FatalErrorCallback
Definition: v8-callbacks.h:228
WasmAsyncSuccess
Definition: v8-callbacks.h:341
GCType
Definition: v8-callbacks.h:156
@ kGCTypeMinorMarkSweep
Definition: v8-callbacks.h:158
@ kGCTypeScavenge
Definition: v8-callbacks.h:157
@ kGCTypeProcessWeakCallbacks
Definition: v8-callbacks.h:161
@ kGCTypeMarkSweepCompact
Definition: v8-callbacks.h:159
@ kGCTypeAll
Definition: v8-callbacks.h:162
@ kGCTypeIncrementalMarking
Definition: v8-callbacks.h:160
std::function< void(CrashKey key, const std::string_view value)> SetCrashKeyStringCallback
Definition: v8-callbacks.h:282
void(*)(Local< Context > context, int script_id) DynamicScriptCompiledFromEmbedderCallback
Definition: v8-callbacks.h:511
bool(*)(int, void *) CompileHintCallback
Definition: v8-callbacks.h:449
void(*)(const FunctionCallbackInfo< Value > &) ApiImplementationCallback
Definition: v8-callbacks.h:336
ModifyCodeGenerationFromStringsResult(*)(Local< Context > context, Local< Value > source, bool is_code_like) ModifyCodeGenerationFromStringsCallback2
Definition: v8-callbacks.h:308
void(*)(Local< Object > target, AccessType type, Local< Value > data) FailedAccessCheckCallback
Definition: v8-callbacks.h:324
AccessType
Definition: v8-callbacks.h:315
@ ACCESS_SET
Definition: v8-callbacks.h:317
@ ACCESS_HAS
Definition: v8-callbacks.h:318
@ ACCESS_KEYS
Definition: v8-callbacks.h:320
@ ACCESS_GET
Definition: v8-callbacks.h:316
@ ACCESS_DELETE
Definition: v8-callbacks.h:319
void(*)(const char *name, int status) LogEventCallback
Definition: v8-callbacks.h:248
std::function< CrashKey(const char key[], CrashKeySize size)> AllocateCrashKeyStringCallback
Definition: v8-callbacks.h:280
int *(*)(const char *name) CounterLookupCallback
Definition: v8-callbacks.h:219
bool(*)(Isolate *isolate, Local< Object > obj) IsJSApiWrapperNativeErrorCallback
Definition: v8-callbacks.h:485
ModuleImportPhase
Definition: v8-callbacks.h:366
Definition: v8-callbacks.h:91
size_t offset
Definition: v8-callbacks.h:93
size_t pos
Definition: v8-callbacks.h:95
PositionType position_type
Definition: v8-callbacks.h:97
Definition: v8-callbacks.h:83
const char * str
Definition: v8-callbacks.h:86
size_t len
Definition: v8-callbacks.h:88
Definition: v8-callbacks.h:100
const char * filename
Definition: v8-callbacks.h:102
const line_info_t * line_number_table
Definition: v8-callbacks.h:107
size_t filename_size
Definition: v8-callbacks.h:104
size_t line_number_table_size
Definition: v8-callbacks.h:109
Definition: v8-callbacks.h:44
PositionType
Definition: v8-callbacks.h:58
@ POSITION
Definition: v8-callbacks.h:58
@ STATEMENT_POSITION
Definition: v8-callbacks.h:58
CodeType
Definition: v8-callbacks.h:66
@ JIT_CODE
Definition: v8-callbacks.h:66
@ BYTE_CODE
Definition: v8-callbacks.h:66
@ WASM_CODE
Definition: v8-callbacks.h:66
struct name_t name
Definition: v8-callbacks.h:116
Local< UnboundScript > script
Definition: v8-callbacks.h:76
struct line_info_t line_info
Definition: v8-callbacks.h:119
Isolate * isolate
Definition: v8-callbacks.h:125
void * user_data
Definition: v8-callbacks.h:81
wasm_source_info_t * wasm_source_info
Definition: v8-callbacks.h:112
void * new_code_start
Definition: v8-callbacks.h:122
EventType
Definition: v8-callbacks.h:45
@ CODE_END_LINE_INFO_RECORDING
Definition: v8-callbacks.h:51
@ CODE_ADDED
Definition: v8-callbacks.h:46
@ CODE_MOVED
Definition: v8-callbacks.h:47
@ CODE_ADD_LINE_POS_INFO
Definition: v8-callbacks.h:49
@ CODE_REMOVED
Definition: v8-callbacks.h:48
@ CODE_START_LINE_INFO_RECORDING
Definition: v8-callbacks.h:50
EventType type
Definition: v8-callbacks.h:69
size_t code_len
Definition: v8-callbacks.h:74
void * code_start
Definition: v8-callbacks.h:72
CodeType code_type
Definition: v8-callbacks.h:70
Definition: v8-callbacks.h:289
bool codegen_allowed
Definition: v8-callbacks.h:291
MaybeLocal< String > modified_source
Definition: v8-callbacks.h:295
Definition: v8-callbacks.h:230
const char * detail
Definition: v8-callbacks.h:232
bool is_heap_oom
Definition: v8-callbacks.h:231
#define V8_ENUM_DEPRECATE_SOON(message)
Definition: v8config.h:669