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
199// Returns true to print a stack frame, or false to print "<redacted>" instead.
200// See the origin-aware overload of Message::PrintCurrentStackTrace for which
201// script is passed in.
203 Isolate* isolate, Local<String> script_name, bool is_shared_cross_origin);
204
212using NearHeapLimitCallback = size_t (*)(void* data, size_t current_heap_limit,
213 size_t initial_heap_limit);
214
218#if defined(V8_OS_WIN)
219using UnhandledExceptionCallback =
220 int (*)(_EXCEPTION_POINTERS* exception_pointers);
221#endif
222
223// --- Counters Callbacks ---
224
225using CounterLookupCallback = int* (*)(const char* name);
226
227using CreateHistogramCallback = void* (*)(const char* name, int min, int max,
228 size_t buckets);
229
230using AddHistogramSampleCallback = void (*)(void* histogram, int sample);
231
232// --- Exceptions ---
233
234using FatalErrorCallback = void (*)(const char* location, const char* message);
235
237 bool is_heap_oom = false;
238 const char* detail = nullptr;
239};
240
241using OOMErrorCallback = void (*)(const char* location,
242 const OOMDetails& details);
243
244using OOMErrorCallbackWithData = void (*)(const char* location,
245 const OOMDetails& details,
246 void* data);
247
248using MessageCallback = void (*)(Local<Message> message, Local<Value> data);
249
250// --- Tracing ---
251
252enum LogEventStatus : int { kStart = 0, kEnd = 1, kLog = 2 };
253using LogEventCallback = void (*)(const char* name,
254 int /* LogEventStatus */ status);
255
256// --- Crashkeys Callback ---
257// Deprecated: use V8::SetCrashKeyCallbacks instead.
258enum class CrashKeyId {
261 kMapSpaceFirstPageAddress V8_ENUM_DEPRECATE_SOON("Map space got removed"),
265 kDumpType,
268};
269
270using AddCrashKeyCallback = void (*)(CrashKeyId id, const std::string& value);
271
272// --- CrashKey Callbacks ---
273using CrashKey = void*;
275
276// Allocates a new crash key with the given `key` name and maximum value `size`.
277// Embedders do not need to deduplicate by `key` name: V8 caches the returned
278// `CrashKey` handle in static storage whenever a key may be updated multiple
279// times. Returns nullptr if crash keys are not supported or initialized.
280using AllocateCrashKeyCallback = CrashKey (*)(const char key[],
281 CrashKeySize size);
282using SetCrashKeyCallback = void (*)(CrashKey key, std::string_view value);
283
284// Deprecated: use AllocateCrashKeyCallback / SetCrashKeyCallback with
285// V8::SetCrashKeyCallbacks instead.
287 std::function<CrashKey(const char key[], CrashKeySize size)>;
289 std::function<void(CrashKey key, const std::string_view value)>;
290
291// --- Enter/Leave Script Callback ---
294
295// --- Modify Code Generation From Strings Callback ---
297 // If true, proceed with the codegen algorithm. Otherwise, block it.
298 bool codegen_allowed = false;
299 // Overwrite the original source with this string, if present.
300 // Use the original source if empty.
301 // This field is considered only if codegen_allowed is true.
303};
304
311 Local<Value> source);
314 Local<Value> source,
315 bool is_code_like);
316
317// --- Failed Access Check Callback ---
318
329
331 AccessType type, Local<Value> data);
332
333// --- WebAssembly compilation callbacks ---
335 "Use WasmModuleCallback or WasmInstanceCallback instead") =
336 bool (*)(const FunctionCallbackInfo<Value>&);
337using WasmModuleCallback = bool (*)(Isolate* isolate, Local<Value> source);
338using WasmInstanceCallback = bool (*)(Isolate* isolate, Local<Value> source);
339
341 Local<String> source);
342
343// --- Callback for APIs defined on v8-supported objects, but implemented
344// by the embedder. Example: WebAssembly.{compile|instantiate}Streaming ---
346
347// --- Callback for WebAssembly.compileStreaming ---
349
351
352// --- Callback called when async WebAssembly operations finish ---
354 Isolate* isolate, Local<Context> context, Local<Promise::Resolver> resolver,
355 Local<Value> result, WasmAsyncSuccess success);
356
357// --- Callback for loading source map file for Wasm profiling support
359 const char* name);
360
361// --- Callback for checking if WebAssembly Custom Descriptors are enabled ---
363
364// --- Callback for checking if the SharedArrayBuffer constructor is enabled ---
366 bool (*)(Local<Context> context);
367
368// --- Callback for getting high resolution timestamps in Temporal ---
370 int64_t (*)(Local<Context> context);
371
376 kSource,
377 kDefer,
379};
380
408 Local<Context> context, Local<Data> host_defined_options,
409 Local<Value> resource_name, Local<String> specifier,
410 Local<FixedArray> import_attributes);
411
449 Local<Context> context, Local<Data> host_defined_options,
450 Local<Value> resource_name, Local<String> specifier,
451 ModuleImportPhase phase, Local<FixedArray> import_attributes);
452
458using CompileHintCallback = bool (*)(int, void*);
459
471 Local<Module> module,
472 Local<Object> meta);
473
486 MaybeLocal<Context> (*)(Local<Context> initiator_context);
487
494 Local<Object> obj);
495
500using ArrayBufferDetachCallback = void (*)(Isolate* isolate,
501 Local<ArrayBuffer> buffer);
502
511 Local<Value> error,
512 Local<Array> sites);
513
520 void (*)(Local<Context> context, int script_id);
521
522#if defined(V8_OS_WIN)
559using FilterETWSessionByURLCallback =
560 bool (*)(Local<Context> context, const std::string& etw_filter_payload);
561
562struct FilterETWSessionByURLResult {
563 // If true, enable ETW tracing for the current isolate.
564 bool enable_etw_tracing;
565
566 // If true, also enables ETW tracing for interpreter stack frames.
567 bool trace_interpreter_frames;
568};
569using FilterETWSessionByURL2Callback = FilterETWSessionByURLResult (*)(
570 Local<Context> context, const std::string& etw_filter_payload);
571#endif // V8_OS_WIN
572
573} // namespace v8
574
575#endif // INCLUDE_V8_ISOLATE_CALLBACKS_H_
Definition: v8-function-callback.h:126
Definition: v8-isolate.h:305
Definition: v8-local-handle.h:356
Definition: v8-local-handle.h:724
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:242
ModifyCodeGenerationFromStringsResult(*)(Local< Context > context, Local< Value > source) ModifyCodeGenerationFromStringsCallback
Definition: v8-callbacks.h:311
void * CrashKey
Definition: v8-callbacks.h:273
bool(*)(Local< Context > context) SharedArrayBufferConstructorEnabledCallback
Definition: v8-callbacks.h:366
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:258
@ kSnapshotChecksumCalculated
@ kCodeSpaceFirstPageAddress
@ kReadonlySpaceFirstPageAddress
LogEventStatus
Definition: v8-callbacks.h:252
@ kEnd
Definition: v8-callbacks.h:252
@ kStart
Definition: v8-callbacks.h:252
@ kLog
Definition: v8-callbacks.h:252
bool(*)(Local< Context > context) WasmCustomDescriptorsEnabledCallback
Definition: v8-callbacks.h:362
void(*)(Isolate *isolate, Local< ArrayBuffer > buffer) ArrayBufferDetachCallback
Definition: v8-callbacks.h:501
void(*)(Isolate *isolate, Local< Context > context, Local< Promise::Resolver > resolver, Local< Value > result, WasmAsyncSuccess success) WasmAsyncResolvePromiseCallback
Definition: v8-callbacks.h:355
bool(*)(Isolate *isolate, Local< Value > source) WasmInstanceCallback
Definition: v8-callbacks.h:338
bool(*)(const FunctionCallbackInfo< Value > &) ExtensionCallback
Definition: v8-callbacks.h:336
int64_t(*)(Local< Context > context) TemporalHostSystemUTCEpochNanosecondsCallback
Definition: v8-callbacks.h:370
bool(*)(Isolate *isolate, Local< Value > source) WasmModuleCallback
Definition: v8-callbacks.h:337
void(*)(const FunctionCallbackInfo< Value > &) WasmStreamingCallback
Definition: v8-callbacks.h:348
void *(*)(const char *name, int min, int max, size_t buckets) CreateHistogramCallback
Definition: v8-callbacks.h:228
void(*)(Local< Context > context, Local< Module > module, Local< Object > meta) HostInitializeImportMetaObjectCallback
Definition: v8-callbacks.h:472
void(*)(Local< Message > message, Local< Value > data) MessageCallback
Definition: v8-callbacks.h:248
CrashKeySize
Definition: v8-callbacks.h:274
void(*)(const char *location, const OOMDetails &details, void *data) OOMErrorCallbackWithData
Definition: v8-callbacks.h:246
bool(*)(Isolate *isolate, Local< String > script_name, bool is_shared_cross_origin) PrintCurrentStackTraceWithOriginFilterCallback
Definition: v8-callbacks.h:203
void(*)(GCType type, GCCallbackFlags flags) GCCallback
Definition: v8-callbacks.h:192
void(*)(CrashKeyId id, const std::string &value) AddCrashKeyCallback
Definition: v8-callbacks.h:270
void(*)(Isolate *isolate, void *data) InterruptCallback
Definition: v8-callbacks.h:194
void(*)(Isolate *) CallCompletedCallback
Definition: v8-callbacks.h:293
void(*)(void *histogram, int sample) AddHistogramSampleCallback
Definition: v8-callbacks.h:230
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:282
CrashKey(*)(const char key[], CrashKeySize size) AllocateCrashKeyCallback
Definition: v8-callbacks.h:281
size_t(*)(void *data, size_t current_heap_limit, size_t initial_heap_limit) NearHeapLimitCallback
Definition: v8-callbacks.h:213
void(*)(Isolate *) BeforeCallEnteredCallback
Definition: v8-callbacks.h:292
bool(*)(Local< Context > context, Local< String > source) AllowWasmCodeGenerationCallback
Definition: v8-callbacks.h:341
void(*)(const char *location, const char *message) FatalErrorCallback
Definition: v8-callbacks.h:234
WasmAsyncSuccess
Definition: v8-callbacks.h:350
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:289
void(*)(Local< Context > context, int script_id) DynamicScriptCompiledFromEmbedderCallback
Definition: v8-callbacks.h:520
bool(*)(int, void *) CompileHintCallback
Definition: v8-callbacks.h:458
void(*)(const FunctionCallbackInfo< Value > &) ApiImplementationCallback
Definition: v8-callbacks.h:345
ModifyCodeGenerationFromStringsResult(*)(Local< Context > context, Local< Value > source, bool is_code_like) ModifyCodeGenerationFromStringsCallback2
Definition: v8-callbacks.h:315
void(*)(Local< Object > target, AccessType type, Local< Value > data) FailedAccessCheckCallback
Definition: v8-callbacks.h:331
AccessType
Definition: v8-callbacks.h:322
@ ACCESS_SET
Definition: v8-callbacks.h:324
@ ACCESS_HAS
Definition: v8-callbacks.h:325
@ ACCESS_KEYS
Definition: v8-callbacks.h:327
@ ACCESS_GET
Definition: v8-callbacks.h:323
@ ACCESS_DELETE
Definition: v8-callbacks.h:326
void(*)(const char *name, int status) LogEventCallback
Definition: v8-callbacks.h:254
std::function< CrashKey(const char key[], CrashKeySize size)> AllocateCrashKeyStringCallback
Definition: v8-callbacks.h:287
int *(*)(const char *name) CounterLookupCallback
Definition: v8-callbacks.h:225
bool(*)(Isolate *isolate, Local< Object > obj) IsJSApiWrapperNativeErrorCallback
Definition: v8-callbacks.h:494
ModuleImportPhase
Definition: v8-callbacks.h:375
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:296
bool codegen_allowed
Definition: v8-callbacks.h:298
MaybeLocal< String > modified_source
Definition: v8-callbacks.h:302
Definition: v8-callbacks.h:236
const char * detail
Definition: v8-callbacks.h:238
bool is_heap_oom
Definition: v8-callbacks.h:237
#define V8_DEPRECATE_SOON(message)
Definition: v8config.h:632
#define V8_ENUM_DEPRECATE_SOON(message)
Definition: v8config.h:669