Where Online Learning is simpler!
The C and C++ Include Header Files
/usr/include/node/v8-callbacks.h
$ cat -n /usr/include/node/v8-callbacks.h 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
9 10 #include
11 #include
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) 20 struct _EXCEPTION_POINTERS; 21 #endif 22 23 namespace v8 { 24 25 template
26 class FunctionCallbackInfo; 27 class Isolate; 28 class Message; 29 class Module; 30 class Object; 31 class Promise; 32 class ScriptOrModule; 33 class String; 34 class UnboundScript; 35 class Value; 36 37 /** 38 * A JIT code event is issued each time code is added, moved or removed. 39 * 40 * \note removal events are not currently issued. 41 */ 42 struct JitCodeEvent { 43 enum EventType { 44 CODE_ADDED, 45 CODE_MOVED, 46 CODE_REMOVED, 47 CODE_ADD_LINE_POS_INFO, 48 CODE_START_LINE_INFO_RECORDING, 49 CODE_END_LINE_INFO_RECORDING 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. 56 enum PositionType { POSITION, STATEMENT_POSITION }; 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. 64 enum CodeType { BYTE_CODE, JIT_CODE, WASM_CODE }; 65 66 // Type of event. 67 EventType type; 68 CodeType code_type; 69 // Start of the instructions. 70 void* code_start; 71 // Size of the instructions. 72 size_t code_len; 73 // Script info for CODE_ADDED event. 74 Local
script; 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. 95 PositionType position_type; 96 }; 97 98 struct wasm_source_info_t { 99 // Source file name. 100 const char* filename; 101 // Length of filename. 102 size_t filename_size; 103 // Line number table, which maps offsets of JITted code to line numbers of 104 // source file. 105 const line_info_t* line_number_table; 106 // Number of entries in the line number table. 107 size_t line_number_table_size; 108 }; 109 110 wasm_source_info_t* wasm_source_info = nullptr; 111 112 union { 113 // Only valid for CODE_ADDED. 114 struct name_t name; 115 116 // Only valid for CODE_ADD_LINE_POS_INFO 117 struct line_info_t line_info; 118 119 // New location of instructions. Only valid for CODE_MOVED. 120 void* new_code_start; 121 }; 122 123 Isolate* isolate; 124 }; 125 126 /** 127 * Option flags passed to the SetJitCodeEventHandler function. 128 */ 129 enum JitCodeEventOptions { 130 kJitCodeEventDefault = 0, 131 // Generate callbacks for already existent code. 132 kJitCodeEventEnumExisting = 1 133 }; 134 135 /** 136 * Callback function passed to SetJitCodeEventHandler. 137 * 138 * \param event code add, move or removal event. 139 */ 140 using JitCodeEventHandler = void (*)(const JitCodeEvent* event); 141 142 // --- Garbage Collection Callbacks --- 143 144 /** 145 * Applications can register callback functions which will be called before and 146 * after certain garbage collection operations. Allocations are not allowed in 147 * the callback functions, you therefore cannot manipulate objects (set or 148 * delete properties for example) since it is possible such operations will 149 * result in the allocation of objects. 150 * TODO(v8:12612): Deprecate kGCTypeMinorMarkSweep after updating blink. 151 */ 152 enum GCType { 153 kGCTypeScavenge = 1 << 0, 154 kGCTypeMinorMarkSweep = 1 << 1, 155 kGCTypeMinorMarkCompact V8_DEPRECATE_SOON( 156 "Use kGCTypeMinorMarkSweep instead of kGCTypeMinorMarkCompact.") = 157 kGCTypeMinorMarkSweep, 158 kGCTypeMarkSweepCompact = 1 << 2, 159 kGCTypeIncrementalMarking = 1 << 3, 160 kGCTypeProcessWeakCallbacks = 1 << 4, 161 kGCTypeAll = kGCTypeScavenge | kGCTypeMinorMarkSweep | 162 kGCTypeMarkSweepCompact | kGCTypeIncrementalMarking | 163 kGCTypeProcessWeakCallbacks 164 }; 165 166 /** 167 * GCCallbackFlags is used to notify additional information about the GC 168 * callback. 169 * - kGCCallbackFlagConstructRetainedObjectInfos: The GC callback is for 170 * constructing retained object infos. 171 * - kGCCallbackFlagForced: The GC callback is for a forced GC for testing. 172 * - kGCCallbackFlagSynchronousPhantomCallbackProcessing: The GC callback 173 * is called synchronously without getting posted to an idle task. 174 * - kGCCallbackFlagCollectAllAvailableGarbage: The GC callback is called 175 * in a phase where V8 is trying to collect all available garbage 176 * (e.g., handling a low memory notification). 177 * - kGCCallbackScheduleIdleGarbageCollection: The GC callback is called to 178 * trigger an idle garbage collection. 179 */ 180 enum GCCallbackFlags { 181 kNoGCCallbackFlags = 0, 182 kGCCallbackFlagConstructRetainedObjectInfos = 1 << 1, 183 kGCCallbackFlagForced = 1 << 2, 184 kGCCallbackFlagSynchronousPhantomCallbackProcessing = 1 << 3, 185 kGCCallbackFlagCollectAllAvailableGarbage = 1 << 4, 186 kGCCallbackFlagCollectAllExternalMemory = 1 << 5, 187 kGCCallbackScheduleIdleGarbageCollection = 1 << 6, 188 }; 189 190 using GCCallback = void (*)(GCType type, GCCallbackFlags flags); 191 192 using InterruptCallback = void (*)(Isolate* isolate, void* data); 193 194 /** 195 * This callback is invoked when the heap size is close to the heap limit and 196 * V8 is likely to abort with out-of-memory error. 197 * The callback can extend the heap limit by returning a value that is greater 198 * than the current_heap_limit. The initial heap limit is the limit that was 199 * set after heap setup. 200 */ 201 using NearHeapLimitCallback = size_t (*)(void* data, size_t current_heap_limit, 202 size_t initial_heap_limit); 203 204 /** 205 * Callback function passed to SetUnhandledExceptionCallback. 206 */ 207 #if defined(V8_OS_WIN) 208 using UnhandledExceptionCallback = 209 int (*)(_EXCEPTION_POINTERS* exception_pointers); 210 #endif 211 212 // --- Counters Callbacks --- 213 214 using CounterLookupCallback = int* (*)(const char* name); 215 216 using CreateHistogramCallback = void* (*)(const char* name, int min, int max, 217 size_t buckets); 218 219 using AddHistogramSampleCallback = void (*)(void* histogram, int sample); 220 221 // --- Exceptions --- 222 223 using FatalErrorCallback = void (*)(const char* location, const char* message); 224 225 struct OOMDetails { 226 bool is_heap_oom = false; 227 const char* detail = nullptr; 228 }; 229 230 using OOMErrorCallback = void (*)(const char* location, 231 const OOMDetails& details); 232 233 using MessageCallback = void (*)(Local
message, Local
data); 234 235 // --- Tracing --- 236 237 enum LogEventStatus : int { kStart = 0, kEnd = 1, kStamp = 2 }; 238 using LogEventCallback = void (*)(const char* name, 239 int /* LogEventStatus */ status); 240 241 // --- Crashkeys Callback --- 242 enum class CrashKeyId { 243 kIsolateAddress, 244 kReadonlySpaceFirstPageAddress, 245 kMapSpaceFirstPageAddress V8_ENUM_DEPRECATE_SOON("Map space got removed"), 246 kOldSpaceFirstPageAddress, 247 kCodeRangeBaseAddress, 248 kCodeSpaceFirstPageAddress, 249 kDumpType, 250 kSnapshotChecksumCalculated, 251 kSnapshotChecksumExpected, 252 }; 253 254 using AddCrashKeyCallback = void (*)(CrashKeyId id, const std::string& value); 255 256 // --- Enter/Leave Script Callback --- 257 using BeforeCallEnteredCallback = void (*)(Isolate*); 258 using CallCompletedCallback = void (*)(Isolate*); 259 260 // --- AllowCodeGenerationFromStrings callbacks --- 261 262 /** 263 * Callback to check if code generation from strings is allowed. See 264 * Context::AllowCodeGenerationFromStrings. 265 */ 266 using AllowCodeGenerationFromStringsCallback = bool (*)(Local
context, 267 Local
source); 268 269 struct ModifyCodeGenerationFromStringsResult { 270 // If true, proceed with the codegen algorithm. Otherwise, block it. 271 bool codegen_allowed = false; 272 // Overwrite the original source with this string, if present. 273 // Use the original source if empty. 274 // This field is considered only if codegen_allowed is true. 275 MaybeLocal
modified_source; 276 }; 277 278 /** 279 * Access type specification. 280 */ 281 enum AccessType { 282 ACCESS_GET, 283 ACCESS_SET, 284 ACCESS_HAS, 285 ACCESS_DELETE, 286 ACCESS_KEYS 287 }; 288 289 // --- Failed Access Check Callback --- 290 291 using FailedAccessCheckCallback = void (*)(Local
target, 292 AccessType type, Local
data); 293 294 /** 295 * Callback to check if codegen is allowed from a source object, and convert 296 * the source to string if necessary. See: ModifyCodeGenerationFromStrings. 297 */ 298 using ModifyCodeGenerationFromStringsCallback = 299 ModifyCodeGenerationFromStringsResult (*)(Local
context, 300 Local
source); 301 using ModifyCodeGenerationFromStringsCallback2 = 302 ModifyCodeGenerationFromStringsResult (*)(Local
context, 303 Local
source, 304 bool is_code_like); 305 306 // --- WebAssembly compilation callbacks --- 307 using ExtensionCallback = bool (*)(const FunctionCallbackInfo
&); 308 309 using AllowWasmCodeGenerationCallback = bool (*)(Local
context, 310 Local
source); 311 312 // --- Callback for APIs defined on v8-supported objects, but implemented 313 // by the embedder. Example: WebAssembly.{compile|instantiate}Streaming --- 314 using ApiImplementationCallback = void (*)(const FunctionCallbackInfo
&); 315 316 // --- Callback for WebAssembly.compileStreaming --- 317 using WasmStreamingCallback = void (*)(const FunctionCallbackInfo
&); 318 319 enum class WasmAsyncSuccess { kSuccess, kFail }; 320 321 // --- Callback called when async WebAssembly operations finish --- 322 using WasmAsyncResolvePromiseCallback = void (*)( 323 Isolate* isolate, Local
context, Local
resolver, 324 Local
result, WasmAsyncSuccess success); 325 326 // --- Callback for loading source map file for Wasm profiling support 327 using WasmLoadSourceMapCallback = Local
(*)(Isolate* isolate, 328 const char* name); 329 330 // --- Callback for checking if WebAssembly imported strings are enabled --- 331 using WasmImportedStringsEnabledCallback = bool (*)(Local
context); 332 333 // --- Callback for checking if the SharedArrayBuffer constructor is enabled --- 334 using SharedArrayBufferConstructorEnabledCallback = 335 bool (*)(Local
context); 336 337 // --- Callback for checking if the compile hints magic comments are enabled --- 338 using JavaScriptCompileHintsMagicEnabledCallback = 339 bool (*)(Local
context); 340 341 // --- Callback for checking if WebAssembly JSPI is enabled --- 342 using WasmJSPIEnabledCallback = bool (*)(Local
context); 343 344 /** 345 * HostImportModuleDynamicallyCallback is called when we 346 * require the embedder to load a module. This is used as part of the dynamic 347 * import syntax. 348 * 349 * The referrer contains metadata about the script/module that calls 350 * import. 351 * 352 * The specifier is the name of the module that should be imported. 353 * 354 * The import_attributes are import attributes for this request in the form: 355 * [key1, value1, key2, value2, ...] where the keys and values are of type 356 * v8::String. Note, unlike the FixedArray passed to ResolveModuleCallback and 357 * returned from ModuleRequest::GetImportAssertions(), this array does not 358 * contain the source Locations of the attributes. 359 * 360 * The embedder must compile, instantiate, evaluate the Module, and 361 * obtain its namespace object. 362 * 363 * The Promise returned from this function is forwarded to userland 364 * JavaScript. The embedder must resolve this promise with the module 365 * namespace object. In case of an exception, the embedder must reject 366 * this promise with the exception. If the promise creation itself 367 * fails (e.g. due to stack overflow), the embedder must propagate 368 * that exception by returning an empty MaybeLocal. 369 */ 370 using HostImportModuleDynamicallyCallback = MaybeLocal
(*)( 371 Local
context, Local
host_defined_options, 372 Local
resource_name, Local
specifier, 373 Local
import_attributes); 374 375 /** 376 * Callback for requesting a compile hint for a function from the embedder. The 377 * first parameter is the position of the function in source code and the second 378 * parameter is embedder data to be passed back. 379 */ 380 using CompileHintCallback = bool (*)(int, void*); 381 382 /** 383 * HostInitializeImportMetaObjectCallback is called the first time import.meta 384 * is accessed for a module. Subsequent access will reuse the same value. 385 * 386 * The method combines two implementation-defined abstract operations into one: 387 * HostGetImportMetaProperties and HostFinalizeImportMeta. 388 * 389 * The embedder should use v8::Object::CreateDataProperty to add properties on 390 * the meta object. 391 */ 392 using HostInitializeImportMetaObjectCallback = void (*)(Local
context, 393 Local
module, 394 Local
meta); 395 396 /** 397 * HostCreateShadowRealmContextCallback is called each time a ShadowRealm is 398 * being constructed in the initiator_context. 399 * 400 * The method combines Context creation and implementation defined abstract 401 * operation HostInitializeShadowRealm into one. 402 * 403 * The embedder should use v8::Context::New or v8::Context:NewFromSnapshot to 404 * create a new context. If the creation fails, the embedder must propagate 405 * that exception by returning an empty MaybeLocal. 406 */ 407 using HostCreateShadowRealmContextCallback = 408 MaybeLocal
(*)(Local
initiator_context); 409 410 /** 411 * PrepareStackTraceCallback is called when the stack property of an error is 412 * first accessed. The return value will be used as the stack value. If this 413 * callback is registed, the |Error.prepareStackTrace| API will be disabled. 414 * |sites| is an array of call sites, specified in 415 * https://v8.dev/docs/stack-trace-api 416 */ 417 using PrepareStackTraceCallback = MaybeLocal
(*)(Local
context, 418 Local
error, 419 Local
sites); 420 421 #if defined(V8_OS_WIN) 422 /** 423 * Callback to selectively enable ETW tracing based on the document URL. 424 * Implemented by the embedder, it should never call back into V8. 425 * 426 * Windows allows passing additional data to the ETW EnableCallback: 427 * https://learn.microsoft.com/en-us/windows/win32/api/evntprov/nc-evntprov-penablecallback 428 * 429 * This data can be configured in a WPR (Windows Performance Recorder) 430 * profile, adding a CustomFilter to an EventProvider like the following: 431 * 432 *
433 *
434 *
435 * 436 * Where: 437 * - Name="57277741-3638-4A4B-BDBA-0AC6E45DA56C" is the GUID of the V8 438 * ETW provider, (see src/libplatform/etw/etw-provider-win.h), 439 * - Type="0x80000000" is EVENT_FILTER_TYPE_SCHEMATIZED, 440 * - Value="AQABAAAAAA..." is a base64-encoded byte array that is 441 * base64-decoded by Windows and passed to the ETW enable callback in 442 * the 'PEVENT_FILTER_DESCRIPTOR FilterData' argument; see: 443 * https://learn.microsoft.com/en-us/windows/win32/api/evntprov/ns-evntprov-event_filter_descriptor. 444 * 445 * This array contains a struct EVENT_FILTER_HEADER followed by a 446 * variable length payload, and as payload we pass a string in JSON format, 447 * with a list of regular expressions that should match the document URL 448 * in order to enable ETW tracing: 449 * { 450 * "version": "1.0", 451 * "filtered_urls": [ 452 * "https:\/\/.*\.chromium\.org\/.*", "https://v8.dev/";, "..." 453 * ] 454 * } 455 */ 456 using FilterETWSessionByURLCallback = 457 bool (*)(Local
context, const std::string& etw_filter_payload); 458 #endif // V8_OS_WIN 459 460 } // namespace v8 461 462 #endif // INCLUDE_V8_ISOLATE_CALLBACKS_H_
Contact us
|
About us
|
Term of use
|
Copyright © 2000-2025 MyWebUniversity.com ™