v8 11.3.244 (node 20.3.0)
V8 is Google's open source JavaScript engine
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.
134
140using JitCodeEventHandler = void (*)(const JitCodeEvent* event);
141
142// --- Garbage Collection Callbacks ---
143
151enum GCType {
161
184};
185
186using GCCallback = void (*)(GCType type, GCCallbackFlags flags);
187
188using InterruptCallback = void (*)(Isolate* isolate, void* data);
189
197using NearHeapLimitCallback = size_t (*)(void* data, size_t current_heap_limit,
198 size_t initial_heap_limit);
199
203#if defined(V8_OS_WIN)
204using UnhandledExceptionCallback =
205 int (*)(_EXCEPTION_POINTERS* exception_pointers);
206#endif
207
208// --- Counters Callbacks ---
209
210using CounterLookupCallback = int* (*)(const char* name);
211
212using CreateHistogramCallback = void* (*)(const char* name, int min, int max,
213 size_t buckets);
214
215using AddHistogramSampleCallback = void (*)(void* histogram, int sample);
216
217// --- Exceptions ---
218
219using FatalErrorCallback = void (*)(const char* location, const char* message);
220
222 bool is_heap_oom = false;
223 const char* detail = nullptr;
224};
225
226using OOMErrorCallback = void (*)(const char* location,
227 const OOMDetails& details);
228
229using MessageCallback = void (*)(Local<Message> message, Local<Value> data);
230
231// --- Tracing ---
232
233enum LogEventStatus : int { kStart = 0, kEnd = 1, kStamp = 2 };
234using LogEventCallback = void (*)(const char* name,
235 int /* LogEventStatus */ status);
236
237// --- Crashkeys Callback ---
238enum class CrashKeyId {
241 kMapSpaceFirstPageAddress V8_ENUM_DEPRECATE_SOON("Map space got removed"),
245 kDumpType,
248};
249
250using AddCrashKeyCallback = void (*)(CrashKeyId id, const std::string& value);
251
252// --- Enter/Leave Script Callback ---
255
256// --- AllowCodeGenerationFromStrings callbacks ---
257
263 Local<String> source);
264
266 // If true, proceed with the codegen algorithm. Otherwise, block it.
267 bool codegen_allowed = false;
268 // Overwrite the original source with this string, if present.
269 // Use the original source if empty.
270 // This field is considered only if codegen_allowed is true.
272};
273
284
285// --- Failed Access Check Callback ---
286
288 AccessType type, Local<Value> data);
289
296 Local<Value> source);
299 Local<Value> source,
300 bool is_code_like);
301
302// --- WebAssembly compilation callbacks ---
304
306 Local<String> source);
307
308// --- Callback for APIs defined on v8-supported objects, but implemented
309// by the embedder. Example: WebAssembly.{compile|instantiate}Streaming ---
311
312// --- Callback for WebAssembly.compileStreaming ---
314
316
317// --- Callback called when async WebAssembly operations finish ---
319 Isolate* isolate, Local<Context> context, Local<Promise::Resolver> resolver,
320 Local<Value> result, WasmAsyncSuccess success);
321
322// --- Callback for loading source map file for Wasm profiling support
324 const char* name);
325
326// --- Callback for checking if WebAssembly Simd is enabled ---
327using WasmSimdEnabledCallback = bool (*)(Local<Context> context);
328
329// --- Callback for checking if WebAssembly exceptions are enabled ---
331
332// --- Callback for checking if WebAssembly GC is enabled ---
333// If the callback returns true, it will also enable Wasm stringrefs.
334using WasmGCEnabledCallback = bool (*)(Local<Context> context);
335
336// --- Callback for checking if the SharedArrayBuffer constructor is enabled ---
338 bool (*)(Local<Context> context);
339
368 Local<ScriptOrModule> referrer,
369 Local<String> specifier,
370 Local<FixedArray> import_assertions);
372 Local<Context> context, Local<Data> host_defined_options,
373 Local<Value> resource_name, Local<String> specifier,
374 Local<FixedArray> import_assertions);
375
381using CompileHintCallback = bool (*)(int, void*);
382
394 Local<Module> module,
395 Local<Object> meta);
396
409 MaybeLocal<Context> (*)(Local<Context> initiator_context);
410
419 Local<Value> error,
420 Local<Array> sites);
421
422} // namespace v8
423
424#endif // INCLUDE_V8_ISOLATE_CALLBACKS_H_
void(*)(const char *name, int status) LogEventCallback
bool(*)(const FunctionCallbackInfo< Value > &) ExtensionCallback
void(*)(Local< Message > message, Local< Value > data) MessageCallback
WasmAsyncSuccess
void(*)(CrashKeyId id, const std::string &value) AddCrashKeyCallback
bool(*)(Local< Context > context) WasmExceptionsEnabledCallback
bool(*)(Local< Context > context) WasmSimdEnabledCallback
bool(*)(Local< Context > context, Local< String > source) AllowWasmCodeGenerationCallback
bool(*)(Local< Context > context) WasmGCEnabledCallback
ModifyCodeGenerationFromStringsResult(*)(Local< Context > context, Local< Value > source, bool is_code_like) ModifyCodeGenerationFromStringsCallback2
GCCallbackFlags
@ kNoGCCallbackFlags
@ kGCCallbackFlagSynchronousPhantomCallbackProcessing
@ kGCCallbackFlagForced
@ kGCCallbackFlagConstructRetainedObjectInfos
@ kGCCallbackFlagCollectAllExternalMemory
@ kGCCallbackFlagCollectAllAvailableGarbage
@ kGCCallbackScheduleIdleGarbageCollection
void(*)(Isolate *) CallCompletedCallback
void(*)(GCType type, GCCallbackFlags flags) GCCallback
size_t(*)(void *data, size_t current_heap_limit, size_t initial_heap_limit) NearHeapLimitCallback
@ kGCTypeProcessWeakCallbacks
@ kGCTypeIncrementalMarking
@ kGCTypeMinorMarkCompact
@ kGCTypeMarkSweepCompact
@ kGCTypeScavenge
@ kGCTypeAll
JitCodeEventOptions
@ kJitCodeEventEnumExisting
@ kJitCodeEventDefault
void(*)(Local< Object > target, AccessType type, Local< Value > data) FailedAccessCheckCallback
void(*)(Isolate *isolate, void *data) InterruptCallback
bool(*)(Local< Context > context) SharedArrayBufferConstructorEnabledCallback
void(*)(const FunctionCallbackInfo< Value > &) ApiImplementationCallback
void(*)(const FunctionCallbackInfo< Value > &) WasmStreamingCallback
void(*)(const char *location, const char *message) FatalErrorCallback
void(*)(const char *location, const OOMDetails &details) OOMErrorCallback
bool(*)(Local< Context > context, Local< String > source) AllowCodeGenerationFromStringsCallback
ModifyCodeGenerationFromStringsResult(*)(Local< Context > context, Local< Value > source) ModifyCodeGenerationFromStringsCallback
void(*)(Isolate *isolate, Local< Context > context, Local< Promise::Resolver > resolver, Local< Value > result, WasmAsyncSuccess success) WasmAsyncResolvePromiseCallback
void(*)(Isolate *) BeforeCallEnteredCallback
void(*)(void *histogram, int sample) AddHistogramSampleCallback
bool(*)(int, void *) CompileHintCallback
@ ACCESS_KEYS
@ ACCESS_HAS
@ ACCESS_DELETE
@ ACCESS_GET
@ ACCESS_SET
int *(*)(const char *name) CounterLookupCallback
LogEventStatus
@ kStamp
@ kStart
@ kSnapshotChecksumCalculated
@ kCodeSpaceFirstPageAddress
@ kReadonlySpaceFirstPageAddress
void(*)(Local< Context > context, Local< Module > module, Local< Object > meta) HostInitializeImportMetaObjectCallback
void *(*)(const char *name, int min, int max, size_t buckets) CreateHistogramCallback
void(*)(const JitCodeEvent *event) JitCodeEventHandler
Local< UnboundScript > script
struct line_info_t line_info
wasm_source_info_t * wasm_source_info
struct name_t name
const char * detail