v8 10.2.154 (node 18.16.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 <string>
11
12#include "cppgc/common.h"
13#include "v8-data.h" // NOLINT(build/include_directory)
14#include "v8-local-handle.h" // NOLINT(build/include_directory)
15#include "v8config.h" // NOLINT(build/include_directory)
16
17#if defined(V8_OS_WIN)
18struct _EXCEPTION_POINTERS;
19#endif
20
21namespace v8 {
22
23template <typename T>
24class FunctionCallbackInfo;
25class Isolate;
26class Message;
27class Module;
28class Object;
29class Promise;
30class ScriptOrModule;
31class String;
32class UnboundScript;
33class Value;
34
41 enum EventType {
48 };
49 // Definition of the code position type. The "POSITION" type means the place
50 // in the source code which are of interest when making stack traces to
51 // pin-point the source location of a stack frame as close as possible.
52 // The "STATEMENT_POSITION" means the place at the beginning of each
53 // statement, and is used to indicate possible break locations.
55
56 // There are three different kinds of CodeType, one for JIT code generated
57 // by the optimizing compiler, one for byte code generated for the
58 // interpreter, and one for code generated from Wasm. For JIT_CODE and
59 // WASM_CODE, |code_start| points to the beginning of jitted assembly code,
60 // while for BYTE_CODE events, |code_start| points to the first bytecode of
61 // the interpreted function.
63
64 // Type of event.
67 // Start of the instructions.
69 // Size of the instructions.
70 size_t code_len;
71 // Script info for CODE_ADDED event.
73 // User-defined data for *_LINE_INFO_* event. It's used to hold the source
74 // code line information which is returned from the
75 // CODE_START_LINE_INFO_RECORDING event. And it's passed to subsequent
76 // CODE_ADD_LINE_POS_INFO and CODE_END_LINE_INFO_RECORDING events.
77 void* user_data;
78
79 struct name_t {
80 // Name of the object associated with the code, note that the string is not
81 // zero-terminated.
82 const char* str;
83 // Number of chars in str.
84 size_t len;
85 };
86
87 struct line_info_t {
88 // PC offset
89 size_t offset;
90 // Code position
91 size_t pos;
92 // The position type.
94 };
95
97 // Source file name.
98 const char* filename;
99 // Length of filename.
101 // Line number table, which maps offsets of JITted code to line numbers of
102 // source file.
104 // Number of entries in the line number table.
106 };
107
109
110 union {
111 // Only valid for CODE_ADDED.
112 struct name_t name;
113
114 // Only valid for CODE_ADD_LINE_POS_INFO
116
117 // New location of instructions. Only valid for CODE_MOVED.
119 };
120
122};
123
129 // Generate callbacks for already existent code.
132
138using JitCodeEventHandler = void (*)(const JitCodeEvent* event);
139
140// --- Garbage Collection Callbacks ---
141
149enum GCType {
159
182};
183
184using GCCallback = void (*)(GCType type, GCCallbackFlags flags);
185
186using InterruptCallback = void (*)(Isolate* isolate, void* data);
187
195using NearHeapLimitCallback = size_t (*)(void* data, size_t current_heap_limit,
196 size_t initial_heap_limit);
197
201#if defined(V8_OS_WIN)
202using UnhandledExceptionCallback =
203 int (*)(_EXCEPTION_POINTERS* exception_pointers);
204#endif
205
206// --- Counters Callbacks ---
207
208using CounterLookupCallback = int* (*)(const char* name);
209
210using CreateHistogramCallback = void* (*)(const char* name, int min, int max,
211 size_t buckets);
212
213using AddHistogramSampleCallback = void (*)(void* histogram, int sample);
214
215// --- Exceptions ---
216
217using FatalErrorCallback = void (*)(const char* location, const char* message);
218
219using OOMErrorCallback = void (*)(const char* location, bool is_heap_oom);
220
221using MessageCallback = void (*)(Local<Message> message, Local<Value> data);
222
223// --- Tracing ---
224
225enum LogEventStatus : int { kStart = 0, kEnd = 1, kStamp = 2 };
226using LogEventCallback = void (*)(const char* name,
227 int /* LogEventStatus */ status);
228
229// --- Crashkeys Callback ---
230enum class CrashKeyId {
235 kDumpType,
236};
237
238using AddCrashKeyCallback = void (*)(CrashKeyId id, const std::string& value);
239
240// --- Enter/Leave Script Callback ---
243
244// --- AllowCodeGenerationFromStrings callbacks ---
245
251 Local<String> source);
252
254 // If true, proceed with the codegen algorithm. Otherwise, block it.
255 bool codegen_allowed = false;
256 // Overwrite the original source with this string, if present.
257 // Use the original source if empty.
258 // This field is considered only if codegen_allowed is true.
260};
261
272
273// --- Failed Access Check Callback ---
274
276 AccessType type, Local<Value> data);
277
284 Local<Value> source);
287 Local<Value> source,
288 bool is_code_like);
289
290// --- WebAssembly compilation callbacks ---
292
294 Local<String> source);
295
296// --- Callback for APIs defined on v8-supported objects, but implemented
297// by the embedder. Example: WebAssembly.{compile|instantiate}Streaming ---
299
300// --- Callback for WebAssembly.compileStreaming ---
302
303// --- Callback for loading source map file for Wasm profiling support
305 const char* name);
306
307// --- Callback for checking if WebAssembly Simd is enabled ---
308using WasmSimdEnabledCallback = bool (*)(Local<Context> context);
309
310// --- Callback for checking if WebAssembly exceptions are enabled ---
312
313// --- Callback for checking if WebAssembly dynamic tiering is enabled ---
315
316// --- Callback for checking if the SharedArrayBuffer constructor is enabled ---
318 bool (*)(Local<Context> context);
319
348 Local<ScriptOrModule> referrer,
349 Local<String> specifier,
350 Local<FixedArray> import_assertions);
352 Local<Context> context, Local<Data> host_defined_options,
353 Local<Value> resource_name, Local<String> specifier,
354 Local<FixedArray> import_assertions);
355
367 Local<Module> module,
368 Local<Object> meta);
369
382 MaybeLocal<Context> (*)(Local<Context> initiator_context);
383
392 Local<Value> error,
393 Local<Array> sites);
394
395} // namespace v8
396
397#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
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
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
bool(*)(Local< Context > context, Local< String > source) AllowCodeGenerationFromStringsCallback
ModifyCodeGenerationFromStringsResult(*)(Local< Context > context, Local< Value > source) ModifyCodeGenerationFromStringsCallback
void(*)(Isolate *) BeforeCallEnteredCallback
void(*)(void *histogram, int sample) AddHistogramSampleCallback
@ ACCESS_KEYS
@ ACCESS_HAS
@ ACCESS_DELETE
@ ACCESS_GET
@ ACCESS_SET
int *(*)(const char *name) CounterLookupCallback
void(*)(const char *location, bool is_heap_oom) OOMErrorCallback
bool(*)(Local< Context > context) WasmDynamicTieringEnabledCallback
LogEventStatus
@ kStamp
@ kStart
@ 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