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
25template <typename T>
26class FunctionCallbackInfo;
27class Isolate;
28class Message;
29class Module;
30class Object;
31class Promise;
32class ScriptOrModule;
33class String;
34class UnboundScript;
35class Value;
36
43 enum EventType {
50 };
51 // Definition of the code position type. The "POSITION" type means the place
52 // in the source code which are of interest when making stack traces to
53 // pin-point the source location of a stack frame as close as possible.
54 // The "STATEMENT_POSITION" means the place at the beginning of each
55 // statement, and is used to indicate possible break locations.
57
58 // There are three different kinds of CodeType, one for JIT code generated
59 // by the optimizing compiler, one for byte code generated for the
60 // interpreter, and one for code generated from Wasm. For JIT_CODE and
61 // WASM_CODE, |code_start| points to the beginning of jitted assembly code,
62 // while for BYTE_CODE events, |code_start| points to the first bytecode of
63 // the interpreted function.
65
66 // Type of event.
69 // Start of the instructions.
71 // Size of the instructions.
72 size_t code_len;
73 // Script info for CODE_ADDED event.
75 // User-defined data for *_LINE_INFO_* event. It's used to hold the source
76 // code line information which is returned from the
77 // CODE_START_LINE_INFO_RECORDING event. And it's passed to subsequent
78 // CODE_ADD_LINE_POS_INFO and CODE_END_LINE_INFO_RECORDING events.
79 void* user_data;
80
81 struct name_t {
82 // Name of the object associated with the code, note that the string is not
83 // zero-terminated.
84 const char* str;
85 // Number of chars in str.
86 size_t len;
87 };
88
89 struct line_info_t {
90 // PC offset
91 size_t offset;
92 // Code position
93 size_t pos;
94 // The position type.
96 };
97
99 // Source file name.
100 const char* filename;
101 // Length of filename.
103 // Line number table, which maps offsets of JITted code to line numbers of
104 // source file.
106 // Number of entries in the line number table.
108 };
109
111
112 union {
113 // Only valid for CODE_ADDED.
114 struct name_t name;
115
116 // Only valid for CODE_ADD_LINE_POS_INFO
118
119 // New location of instructions. Only valid for CODE_MOVED.
121 };
122
124};
125
131 // Generate callbacks for already existent code.
133
136
142using JitCodeEventHandler = void (*)(const JitCodeEvent* event);
143
144// --- Garbage Collection Callbacks ---
145
154enum GCType {
164
188};
189
190using GCCallback = void (*)(GCType type, GCCallbackFlags flags);
191
192using InterruptCallback = void (*)(Isolate* isolate, void* data);
193
195 bool (*)(Isolate* isolate, Local<String> script_name);
196
204using NearHeapLimitCallback = size_t (*)(void* data, size_t current_heap_limit,
205 size_t initial_heap_limit);
206
210#if defined(V8_OS_WIN)
211using UnhandledExceptionCallback =
212 int (*)(_EXCEPTION_POINTERS* exception_pointers);
213#endif
214
215// --- Counters Callbacks ---
216
217using CounterLookupCallback = int* (*)(const char* name);
218
219using CreateHistogramCallback = void* (*)(const char* name, int min, int max,
220 size_t buckets);
221
222using AddHistogramSampleCallback = void (*)(void* histogram, int sample);
223
224// --- Exceptions ---
225
226using FatalErrorCallback = void (*)(const char* location, const char* message);
227
229 bool is_heap_oom = false;
230 const char* detail = nullptr;
231};
232
233using OOMErrorCallback = void (*)(const char* location,
234 const OOMDetails& details);
235
236using OOMErrorCallbackWithData = void (*)(const char* location,
237 const OOMDetails& details,
238 void* data);
239
240using MessageCallback = void (*)(Local<Message> message, Local<Value> data);
241
242// --- Tracing ---
243
244enum LogEventStatus : int { kStart = 0, kEnd = 1, kLog = 2 };
245using LogEventCallback = void (*)(const char* name,
246 int /* LogEventStatus */ status);
247
248// --- Crashkeys Callback ---
249enum class CrashKeyId {
252 kMapSpaceFirstPageAddress V8_ENUM_DEPRECATE_SOON("Map space got removed"),
256 kDumpType,
259};
260
261using AddCrashKeyCallback = void (*)(CrashKeyId id, const std::string& value);
262
263// --- Enter/Leave Script Callback ---
266
267// --- Modify Code Generation From Strings Callback ---
269 // If true, proceed with the codegen algorithm. Otherwise, block it.
270 bool codegen_allowed = false;
271 // Overwrite the original source with this string, if present.
272 // Use the original source if empty.
273 // This field is considered only if codegen_allowed is true.
275};
276
283 Local<Value> source);
286 Local<Value> source,
287 bool is_code_like);
288
289// --- Failed Access Check Callback ---
290
301
303 AccessType type, Local<Value> data);
304
305// --- WebAssembly compilation callbacks ---
307
309 Local<String> source);
310
311// --- Callback for APIs defined on v8-supported objects, but implemented
312// by the embedder. Example: WebAssembly.{compile|instantiate}Streaming ---
314
315// --- Callback for WebAssembly.compileStreaming ---
317
319
320// --- Callback called when async WebAssembly operations finish ---
322 Isolate* isolate, Local<Context> context, Local<Promise::Resolver> resolver,
323 Local<Value> result, WasmAsyncSuccess success);
324
325// --- Callback for loading source map file for Wasm profiling support
327 const char* name);
328
329// --- Callback for checking if WebAssembly Custom Descriptors are enabled ---
331
332// --- Callback for checking if the SharedArrayBuffer constructor is enabled ---
334 bool (*)(Local<Context> context);
335
340 kSource,
342};
343
371 Local<Context> context, Local<Data> host_defined_options,
372 Local<Value> resource_name, Local<String> specifier,
373 Local<FixedArray> import_attributes);
374
412 Local<Context> context, Local<Data> host_defined_options,
413 Local<Value> resource_name, Local<String> specifier,
414 ModuleImportPhase phase, Local<FixedArray> import_attributes);
415
421using CompileHintCallback = bool (*)(int, void*);
422
434 Local<Module> module,
435 Local<Object> meta);
436
449 MaybeLocal<Context> (*)(Local<Context> initiator_context);
450
457 Local<Object> obj);
458
467 Local<Value> error,
468 Local<Array> sites);
469
470#if defined(V8_OS_WIN)
507using FilterETWSessionByURLCallback =
508 bool (*)(Local<Context> context, const std::string& etw_filter_payload);
509
510struct FilterETWSessionByURLResult {
511 // If true, enable ETW tracing for the current isolate.
512 bool enable_etw_tracing;
513
514 // If true, also enables ETW tracing for interpreter stack frames.
515 bool trace_interpreter_frames;
516};
517using FilterETWSessionByURL2Callback = FilterETWSessionByURLResult (*)(
518 Local<Context> context, const std::string& etw_filter_payload);
519#endif // V8_OS_WIN
520
521} // namespace v8
522
523#endif // INCLUDE_V8_ISOLATE_CALLBACKS_H_
Definition: v8-function-callback.h:118
Definition: v8-isolate.h:290
Definition: v8-local-handle.h:366
Definition: v8-local-handle.h:734
Definition: libplatform.h:15
void(*)(const JitCodeEvent *event) JitCodeEventHandler
Definition: v8-callbacks.h:142
JitCodeEventOptions
Definition: v8-callbacks.h:129
@ kJitCodeEventEnumExisting
Definition: v8-callbacks.h:132
@ kLastJitCodeEventOption
Definition: v8-callbacks.h:134
@ kJitCodeEventDefault
Definition: v8-callbacks.h:130
void(*)(const char *location, const OOMDetails &details) OOMErrorCallback
Definition: v8-callbacks.h:234
ModifyCodeGenerationFromStringsResult(*)(Local< Context > context, Local< Value > source) ModifyCodeGenerationFromStringsCallback
Definition: v8-callbacks.h:283
bool(*)(Local< Context > context) SharedArrayBufferConstructorEnabledCallback
Definition: v8-callbacks.h:334
GCCallbackFlags
Definition: v8-callbacks.h:179
@ kGCCallbackScheduleIdleGarbageCollection
Definition: v8-callbacks.h:186
@ kGCCallbackFlagConstructRetainedObjectInfos
Definition: v8-callbacks.h:181
@ kGCCallbackFlagForced
Definition: v8-callbacks.h:182
@ kNoGCCallbackFlags
Definition: v8-callbacks.h:180
@ kGCCallbackFlagCollectAllExternalMemory
Definition: v8-callbacks.h:185
@ kGCCallbackFlagSynchronousPhantomCallbackProcessing
Definition: v8-callbacks.h:183
@ kGCCallbackFlagLastResort
Definition: v8-callbacks.h:187
@ kGCCallbackFlagCollectAllAvailableGarbage
Definition: v8-callbacks.h:184
CrashKeyId
Definition: v8-callbacks.h:249
@ kSnapshotChecksumCalculated
@ kCodeSpaceFirstPageAddress
@ kReadonlySpaceFirstPageAddress
LogEventStatus
Definition: v8-callbacks.h:244
@ kEnd
Definition: v8-callbacks.h:244
@ kStart
Definition: v8-callbacks.h:244
@ kLog
Definition: v8-callbacks.h:244
bool(*)(Local< Context > context) WasmCustomDescriptorsEnabledCallback
Definition: v8-callbacks.h:330
void(*)(Isolate *isolate, Local< Context > context, Local< Promise::Resolver > resolver, Local< Value > result, WasmAsyncSuccess success) WasmAsyncResolvePromiseCallback
Definition: v8-callbacks.h:323
bool(*)(const FunctionCallbackInfo< Value > &) ExtensionCallback
Definition: v8-callbacks.h:306
void(*)(const FunctionCallbackInfo< Value > &) WasmStreamingCallback
Definition: v8-callbacks.h:316
void *(*)(const char *name, int min, int max, size_t buckets) CreateHistogramCallback
Definition: v8-callbacks.h:220
void(*)(Local< Context > context, Local< Module > module, Local< Object > meta) HostInitializeImportMetaObjectCallback
Definition: v8-callbacks.h:435
void(*)(Local< Message > message, Local< Value > data) MessageCallback
Definition: v8-callbacks.h:240
void(*)(const char *location, const OOMDetails &details, void *data) OOMErrorCallbackWithData
Definition: v8-callbacks.h:238
void(*)(GCType type, GCCallbackFlags flags) GCCallback
Definition: v8-callbacks.h:190
void(*)(CrashKeyId id, const std::string &value) AddCrashKeyCallback
Definition: v8-callbacks.h:261
void(*)(Isolate *isolate, void *data) InterruptCallback
Definition: v8-callbacks.h:192
void(*)(Isolate *) CallCompletedCallback
Definition: v8-callbacks.h:265
void(*)(void *histogram, int sample) AddHistogramSampleCallback
Definition: v8-callbacks.h:222
bool(*)(Isolate *isolate, Local< String > script_name) PrintCurrentStackTraceFilterCallback
Definition: v8-callbacks.h:195
size_t(*)(void *data, size_t current_heap_limit, size_t initial_heap_limit) NearHeapLimitCallback
Definition: v8-callbacks.h:205
void(*)(Isolate *) BeforeCallEnteredCallback
Definition: v8-callbacks.h:264
bool(*)(Local< Context > context, Local< String > source) AllowWasmCodeGenerationCallback
Definition: v8-callbacks.h:309
void(*)(const char *location, const char *message) FatalErrorCallback
Definition: v8-callbacks.h:226
WasmAsyncSuccess
Definition: v8-callbacks.h:318
GCType
Definition: v8-callbacks.h:154
@ kGCTypeMinorMarkSweep
Definition: v8-callbacks.h:156
@ kGCTypeScavenge
Definition: v8-callbacks.h:155
@ kGCTypeProcessWeakCallbacks
Definition: v8-callbacks.h:159
@ kGCTypeMarkSweepCompact
Definition: v8-callbacks.h:157
@ kGCTypeAll
Definition: v8-callbacks.h:160
@ kGCTypeIncrementalMarking
Definition: v8-callbacks.h:158
bool(*)(int, void *) CompileHintCallback
Definition: v8-callbacks.h:421
void(*)(const FunctionCallbackInfo< Value > &) ApiImplementationCallback
Definition: v8-callbacks.h:313
ModifyCodeGenerationFromStringsResult(*)(Local< Context > context, Local< Value > source, bool is_code_like) ModifyCodeGenerationFromStringsCallback2
Definition: v8-callbacks.h:287
void(*)(Local< Object > target, AccessType type, Local< Value > data) FailedAccessCheckCallback
Definition: v8-callbacks.h:303
AccessType
Definition: v8-callbacks.h:294
@ ACCESS_SET
Definition: v8-callbacks.h:296
@ ACCESS_HAS
Definition: v8-callbacks.h:297
@ ACCESS_KEYS
Definition: v8-callbacks.h:299
@ ACCESS_GET
Definition: v8-callbacks.h:295
@ ACCESS_DELETE
Definition: v8-callbacks.h:298
void(*)(const char *name, int status) LogEventCallback
Definition: v8-callbacks.h:246
int *(*)(const char *name) CounterLookupCallback
Definition: v8-callbacks.h:217
bool(*)(Isolate *isolate, Local< Object > obj) IsJSApiWrapperNativeErrorCallback
Definition: v8-callbacks.h:457
ModuleImportPhase
Definition: v8-callbacks.h:339
Definition: v8-callbacks.h:89
size_t offset
Definition: v8-callbacks.h:91
size_t pos
Definition: v8-callbacks.h:93
PositionType position_type
Definition: v8-callbacks.h:95
Definition: v8-callbacks.h:81
const char * str
Definition: v8-callbacks.h:84
size_t len
Definition: v8-callbacks.h:86
Definition: v8-callbacks.h:98
const char * filename
Definition: v8-callbacks.h:100
const line_info_t * line_number_table
Definition: v8-callbacks.h:105
size_t filename_size
Definition: v8-callbacks.h:102
size_t line_number_table_size
Definition: v8-callbacks.h:107
Definition: v8-callbacks.h:42
PositionType
Definition: v8-callbacks.h:56
@ POSITION
Definition: v8-callbacks.h:56
@ STATEMENT_POSITION
Definition: v8-callbacks.h:56
CodeType
Definition: v8-callbacks.h:64
@ JIT_CODE
Definition: v8-callbacks.h:64
@ BYTE_CODE
Definition: v8-callbacks.h:64
@ WASM_CODE
Definition: v8-callbacks.h:64
struct name_t name
Definition: v8-callbacks.h:114
Local< UnboundScript > script
Definition: v8-callbacks.h:74
struct line_info_t line_info
Definition: v8-callbacks.h:117
Isolate * isolate
Definition: v8-callbacks.h:123
void * user_data
Definition: v8-callbacks.h:79
wasm_source_info_t * wasm_source_info
Definition: v8-callbacks.h:110
void * new_code_start
Definition: v8-callbacks.h:120
EventType
Definition: v8-callbacks.h:43
@ CODE_END_LINE_INFO_RECORDING
Definition: v8-callbacks.h:49
@ CODE_ADDED
Definition: v8-callbacks.h:44
@ CODE_MOVED
Definition: v8-callbacks.h:45
@ CODE_ADD_LINE_POS_INFO
Definition: v8-callbacks.h:47
@ CODE_REMOVED
Definition: v8-callbacks.h:46
@ CODE_START_LINE_INFO_RECORDING
Definition: v8-callbacks.h:48
EventType type
Definition: v8-callbacks.h:67
size_t code_len
Definition: v8-callbacks.h:72
void * code_start
Definition: v8-callbacks.h:70
CodeType code_type
Definition: v8-callbacks.h:68
Definition: v8-callbacks.h:268
bool codegen_allowed
Definition: v8-callbacks.h:270
MaybeLocal< String > modified_source
Definition: v8-callbacks.h:274
Definition: v8-callbacks.h:228
const char * detail
Definition: v8-callbacks.h:230
bool is_heap_oom
Definition: v8-callbacks.h:229
#define V8_ENUM_DEPRECATE_SOON(message)
Definition: v8config.h:659