v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
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
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
164
188
190
191using InterruptCallback = void (*)(Isolate* isolate, void* data);
192
194 bool (*)(Isolate* isolate, Local<String> script_name);
195
203using NearHeapLimitCallback = size_t (*)(void* data, size_t current_heap_limit,
204 size_t initial_heap_limit);
205
209#if defined(V8_OS_WIN)
210using UnhandledExceptionCallback =
211 int (*)(_EXCEPTION_POINTERS* exception_pointers);
212#endif
213
214// --- Counters Callbacks ---
215
216using CounterLookupCallback = int* (*)(const char* name);
217
218using CreateHistogramCallback = void* (*)(const char* name, int min, int max,
219 size_t buckets);
220
221using AddHistogramSampleCallback = void (*)(void* histogram, int sample);
222
223// --- Exceptions ---
224
225using FatalErrorCallback = void (*)(const char* location, const char* message);
226
228 bool is_heap_oom = false;
229 const char* detail = nullptr;
230};
231
232using OOMErrorCallback = void (*)(const char* location,
233 const OOMDetails& details);
234
236
237// --- Tracing ---
238
239enum LogEventStatus : int { kStart = 0, kEnd = 1, kLog = 2 };
240using LogEventCallback = void (*)(const char* name,
241 int /* LogEventStatus */ status);
242
243// --- Crashkeys Callback ---
255
256using AddCrashKeyCallback = void (*)(CrashKeyId id, const std::string& value);
257
258// --- Enter/Leave Script Callback ---
261
262// --- Modify Code Generation From Strings Callback ---
264 // If true, proceed with the codegen algorithm. Otherwise, block it.
265 bool codegen_allowed = false;
266 // Overwrite the original source with this string, if present.
267 // Use the original source if empty.
268 // This field is considered only if codegen_allowed is true.
270};
271
282 bool is_code_like);
283
284// --- Failed Access Check Callback ---
285
296
299
300// --- WebAssembly compilation callbacks ---
302
305
306// --- Callback for APIs defined on v8-supported objects, but implemented
307// by the embedder. Example: WebAssembly.{compile|instantiate}Streaming ---
309
310// --- Callback for WebAssembly.compileStreaming ---
312
314
315// --- Callback called when async WebAssembly operations finish ---
319
320// --- Callback for loading source map file for Wasm profiling support
322 const char* name);
323
324// --- Callback for checking if WebAssembly imported strings are enabled ---
326
327// --- Callback for checking if the SharedArrayBuffer constructor is enabled ---
329 bool (*)(Local<Context> context);
330
331// --- Callback for checking if the compile hints magic comments are enabled ---
333 bool (*)(Local<Context> context);
334
335// --- Callback for checking if WebAssembly JSPI is enabled ---
337
342 kSource,
344};
345
373 Local<Context> context, Local<Data> host_defined_options,
374 Local<Value> resource_name, Local<String> specifier,
375 Local<FixedArray> import_attributes);
376
414 Local<Context> context, Local<Data> host_defined_options,
415 Local<Value> resource_name, Local<String> specifier,
416 ModuleImportPhase phase, Local<FixedArray> import_attributes);
417
423using CompileHintCallback = bool (*)(int, void*);
424
436 Local<Module> module,
437 Local<Object> meta);
438
451 MaybeLocal<Context> (*)(Local<Context> initiator_context);
452
459 Local<Object> obj);
460
469 Local<Value> error,
470 Local<Array> sites);
471
472#if defined(V8_OS_WIN)
509using FilterETWSessionByURLCallback =
510 bool (*)(Local<Context> context, const std::string& etw_filter_payload);
511
512struct FilterETWSessionByURLResult {
513 // If true, enable ETW tracing for the current isolate.
514 bool enable_etw_tracing;
515
516 // If true, also enables ETW tracing for interpreter stack frames.
517 bool trace_interpreter_frames;
518};
519using FilterETWSessionByURL2Callback = FilterETWSessionByURLResult (*)(
520 Local<Context> context, const std::string& etw_filter_payload);
521#endif // V8_OS_WIN
522
523} // namespace v8
524
525#endif // INCLUDE_V8_ISOLATE_CALLBACKS_H_
const char * name
Definition builtins.cc:39
union v8::internal::@341::BuiltinMetadata::KindSpecificData data
other heap size flags(e.g. initial_heap_size) take precedence") DEFINE_SIZE_T( max_shared_heap_size
Isolate * isolate
TNode< Context > context
TNode< Object > target
ZoneVector< RpoNumber > & result
InstructionOperand source
v8_inspector::String16 String
Definition string-util.h:26
void(*)( Isolate *isolate, Local< Context > context, Local< Promise::Resolver > resolver, Local< Value > result, WasmAsyncSuccess success) WasmAsyncResolvePromiseCallback
bool(*)(Local< Context > context) WasmJSPIEnabledCallback
void(*)(GCType type, GCCallbackFlags flags) GCCallback
JitCodeEventOptions
@ kJitCodeEventEnumExisting
@ kLastJitCodeEventOption
@ kJitCodeEventDefault
bool(*)(Isolate *isolate, Local< Object > obj) IsJSApiWrapperNativeErrorCallback
bool(*)(Local< Context > context) JavaScriptCompileHintsMagicEnabledCallback
void(*)(const JitCodeEvent *event) JitCodeEventHandler
void(*)(CrashKeyId id, const std::string &value) AddCrashKeyCallback
GCCallbackFlags
@ kGCCallbackScheduleIdleGarbageCollection
@ kGCCallbackFlagConstructRetainedObjectInfos
@ kGCCallbackFlagForced
@ kNoGCCallbackFlags
@ kGCCallbackFlagCollectAllExternalMemory
@ kGCCallbackFlagSynchronousPhantomCallbackProcessing
@ kGCCallbackFlagCollectAllAvailableGarbage
@ kSnapshotChecksumCalculated
@ kCodeSpaceFirstPageAddress
@ kReadonlySpaceFirstPageAddress
LogEventStatus
@ kStart
ModifyCodeGenerationFromStringsResult(*)(Local< Context > context, Local< Value > source) ModifyCodeGenerationFromStringsCallback
bool(*)(const FunctionCallbackInfo< Value > &) ExtensionCallback
void(*)(void *histogram, int sample) AddHistogramSampleCallback
void(*)(const FunctionCallbackInfo< Value > &) WasmStreamingCallback
void(*)(const char *name, int status) LogEventCallback
void(*)(Isolate *) CallCompletedCallback
void(*)(const char *location, const char *message) FatalErrorCallback
void(*)(Local< Message > message, Local< Value > data) MessageCallback
void(*)(Local< Object > target, AccessType type, Local< Value > data) FailedAccessCheckCallback
void(*)(Local< Context > context, Local< Module > module, Local< Object > meta) HostInitializeImportMetaObjectCallback
void(*)(Isolate *isolate, void *data) InterruptCallback
int *(*)(const char *name) CounterLookupCallback
bool(*)(Local< Context > context) WasmImportedStringsEnabledCallback
void *(*)(const char *name, int min, int max, size_t buckets) CreateHistogramCallback
WasmAsyncSuccess
@ kGCTypeMinorMarkSweep
@ kGCTypeScavenge
@ kGCTypeProcessWeakCallbacks
@ kGCTypeMarkSweepCompact
@ kGCTypeAll
@ kGCTypeIncrementalMarking
bool(*)(Local< Context > context) SharedArrayBufferConstructorEnabledCallback
ModifyCodeGenerationFromStringsResult(*)(Local< Context > context, Local< Value > source, bool is_code_like) ModifyCodeGenerationFromStringsCallback2
size_t(*)(void *data, size_t current_heap_limit, size_t initial_heap_limit) NearHeapLimitCallback
@ ACCESS_SET
@ ACCESS_HAS
@ ACCESS_KEYS
@ ACCESS_GET
@ ACCESS_DELETE
bool(*)(Isolate *isolate, Local< String > script_name) PrintCurrentStackTraceFilterCallback
void(*)(Isolate *) BeforeCallEnteredCallback
void(*)(const char *location, const OOMDetails &details) OOMErrorCallback
void(*)(const FunctionCallbackInfo< Value > &) ApiImplementationCallback
bool(*)(int, void *) CompileHintCallback
ModuleImportPhase
bool(*)(Local< Context > context, Local< String > source) AllowWasmCodeGenerationCallback
Local< UnboundScript > script
struct line_info_t line_info
wasm_source_info_t * wasm_source_info
const char * detail
std::unique_ptr< ValueMirror > value
wasm::ValueType type