11cb0ef41Sopenharmony_ci// Copyright 2021 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#ifndef INCLUDE_V8_ISOLATE_CALLBACKS_H_
61cb0ef41Sopenharmony_ci#define INCLUDE_V8_ISOLATE_CALLBACKS_H_
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci#include <stddef.h>
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci#include <functional>
111cb0ef41Sopenharmony_ci#include <string>
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ci#include "cppgc/common.h"
141cb0ef41Sopenharmony_ci#include "v8-data.h"          // NOLINT(build/include_directory)
151cb0ef41Sopenharmony_ci#include "v8-local-handle.h"  // NOLINT(build/include_directory)
161cb0ef41Sopenharmony_ci#include "v8-promise.h"       // NOLINT(build/include_directory)
171cb0ef41Sopenharmony_ci#include "v8config.h"         // NOLINT(build/include_directory)
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ci#if defined(V8_OS_WIN)
201cb0ef41Sopenharmony_cistruct _EXCEPTION_POINTERS;
211cb0ef41Sopenharmony_ci#endif
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_cinamespace v8 {
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_citemplate <typename T>
261cb0ef41Sopenharmony_ciclass FunctionCallbackInfo;
271cb0ef41Sopenharmony_ciclass Isolate;
281cb0ef41Sopenharmony_ciclass Message;
291cb0ef41Sopenharmony_ciclass Module;
301cb0ef41Sopenharmony_ciclass Object;
311cb0ef41Sopenharmony_ciclass Promise;
321cb0ef41Sopenharmony_ciclass ScriptOrModule;
331cb0ef41Sopenharmony_ciclass String;
341cb0ef41Sopenharmony_ciclass UnboundScript;
351cb0ef41Sopenharmony_ciclass Value;
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_ci/**
381cb0ef41Sopenharmony_ci * A JIT code event is issued each time code is added, moved or removed.
391cb0ef41Sopenharmony_ci *
401cb0ef41Sopenharmony_ci * \note removal events are not currently issued.
411cb0ef41Sopenharmony_ci */
421cb0ef41Sopenharmony_cistruct JitCodeEvent {
431cb0ef41Sopenharmony_ci  enum EventType {
441cb0ef41Sopenharmony_ci    CODE_ADDED,
451cb0ef41Sopenharmony_ci    CODE_MOVED,
461cb0ef41Sopenharmony_ci    CODE_REMOVED,
471cb0ef41Sopenharmony_ci    CODE_ADD_LINE_POS_INFO,
481cb0ef41Sopenharmony_ci    CODE_START_LINE_INFO_RECORDING,
491cb0ef41Sopenharmony_ci    CODE_END_LINE_INFO_RECORDING
501cb0ef41Sopenharmony_ci  };
511cb0ef41Sopenharmony_ci  // Definition of the code position type. The "POSITION" type means the place
521cb0ef41Sopenharmony_ci  // in the source code which are of interest when making stack traces to
531cb0ef41Sopenharmony_ci  // pin-point the source location of a stack frame as close as possible.
541cb0ef41Sopenharmony_ci  // The "STATEMENT_POSITION" means the place at the beginning of each
551cb0ef41Sopenharmony_ci  // statement, and is used to indicate possible break locations.
561cb0ef41Sopenharmony_ci  enum PositionType { POSITION, STATEMENT_POSITION };
571cb0ef41Sopenharmony_ci
581cb0ef41Sopenharmony_ci  // There are three different kinds of CodeType, one for JIT code generated
591cb0ef41Sopenharmony_ci  // by the optimizing compiler, one for byte code generated for the
601cb0ef41Sopenharmony_ci  // interpreter, and one for code generated from Wasm. For JIT_CODE and
611cb0ef41Sopenharmony_ci  // WASM_CODE, |code_start| points to the beginning of jitted assembly code,
621cb0ef41Sopenharmony_ci  // while for BYTE_CODE events, |code_start| points to the first bytecode of
631cb0ef41Sopenharmony_ci  // the interpreted function.
641cb0ef41Sopenharmony_ci  enum CodeType { BYTE_CODE, JIT_CODE, WASM_CODE };
651cb0ef41Sopenharmony_ci
661cb0ef41Sopenharmony_ci  // Type of event.
671cb0ef41Sopenharmony_ci  EventType type;
681cb0ef41Sopenharmony_ci  CodeType code_type;
691cb0ef41Sopenharmony_ci  // Start of the instructions.
701cb0ef41Sopenharmony_ci  void* code_start;
711cb0ef41Sopenharmony_ci  // Size of the instructions.
721cb0ef41Sopenharmony_ci  size_t code_len;
731cb0ef41Sopenharmony_ci  // Script info for CODE_ADDED event.
741cb0ef41Sopenharmony_ci  Local<UnboundScript> script;
751cb0ef41Sopenharmony_ci  // User-defined data for *_LINE_INFO_* event. It's used to hold the source
761cb0ef41Sopenharmony_ci  // code line information which is returned from the
771cb0ef41Sopenharmony_ci  // CODE_START_LINE_INFO_RECORDING event. And it's passed to subsequent
781cb0ef41Sopenharmony_ci  // CODE_ADD_LINE_POS_INFO and CODE_END_LINE_INFO_RECORDING events.
791cb0ef41Sopenharmony_ci  void* user_data;
801cb0ef41Sopenharmony_ci
811cb0ef41Sopenharmony_ci  struct name_t {
821cb0ef41Sopenharmony_ci    // Name of the object associated with the code, note that the string is not
831cb0ef41Sopenharmony_ci    // zero-terminated.
841cb0ef41Sopenharmony_ci    const char* str;
851cb0ef41Sopenharmony_ci    // Number of chars in str.
861cb0ef41Sopenharmony_ci    size_t len;
871cb0ef41Sopenharmony_ci  };
881cb0ef41Sopenharmony_ci
891cb0ef41Sopenharmony_ci  struct line_info_t {
901cb0ef41Sopenharmony_ci    // PC offset
911cb0ef41Sopenharmony_ci    size_t offset;
921cb0ef41Sopenharmony_ci    // Code position
931cb0ef41Sopenharmony_ci    size_t pos;
941cb0ef41Sopenharmony_ci    // The position type.
951cb0ef41Sopenharmony_ci    PositionType position_type;
961cb0ef41Sopenharmony_ci  };
971cb0ef41Sopenharmony_ci
981cb0ef41Sopenharmony_ci  struct wasm_source_info_t {
991cb0ef41Sopenharmony_ci    // Source file name.
1001cb0ef41Sopenharmony_ci    const char* filename;
1011cb0ef41Sopenharmony_ci    // Length of filename.
1021cb0ef41Sopenharmony_ci    size_t filename_size;
1031cb0ef41Sopenharmony_ci    // Line number table, which maps offsets of JITted code to line numbers of
1041cb0ef41Sopenharmony_ci    // source file.
1051cb0ef41Sopenharmony_ci    const line_info_t* line_number_table;
1061cb0ef41Sopenharmony_ci    // Number of entries in the line number table.
1071cb0ef41Sopenharmony_ci    size_t line_number_table_size;
1081cb0ef41Sopenharmony_ci  };
1091cb0ef41Sopenharmony_ci
1101cb0ef41Sopenharmony_ci  wasm_source_info_t* wasm_source_info = nullptr;
1111cb0ef41Sopenharmony_ci
1121cb0ef41Sopenharmony_ci  union {
1131cb0ef41Sopenharmony_ci    // Only valid for CODE_ADDED.
1141cb0ef41Sopenharmony_ci    struct name_t name;
1151cb0ef41Sopenharmony_ci
1161cb0ef41Sopenharmony_ci    // Only valid for CODE_ADD_LINE_POS_INFO
1171cb0ef41Sopenharmony_ci    struct line_info_t line_info;
1181cb0ef41Sopenharmony_ci
1191cb0ef41Sopenharmony_ci    // New location of instructions. Only valid for CODE_MOVED.
1201cb0ef41Sopenharmony_ci    void* new_code_start;
1211cb0ef41Sopenharmony_ci  };
1221cb0ef41Sopenharmony_ci
1231cb0ef41Sopenharmony_ci  Isolate* isolate;
1241cb0ef41Sopenharmony_ci};
1251cb0ef41Sopenharmony_ci
1261cb0ef41Sopenharmony_ci/**
1271cb0ef41Sopenharmony_ci * Option flags passed to the SetJitCodeEventHandler function.
1281cb0ef41Sopenharmony_ci */
1291cb0ef41Sopenharmony_cienum JitCodeEventOptions {
1301cb0ef41Sopenharmony_ci  kJitCodeEventDefault = 0,
1311cb0ef41Sopenharmony_ci  // Generate callbacks for already existent code.
1321cb0ef41Sopenharmony_ci  kJitCodeEventEnumExisting = 1
1331cb0ef41Sopenharmony_ci};
1341cb0ef41Sopenharmony_ci
1351cb0ef41Sopenharmony_ci/**
1361cb0ef41Sopenharmony_ci * Callback function passed to SetJitCodeEventHandler.
1371cb0ef41Sopenharmony_ci *
1381cb0ef41Sopenharmony_ci * \param event code add, move or removal event.
1391cb0ef41Sopenharmony_ci */
1401cb0ef41Sopenharmony_ciusing JitCodeEventHandler = void (*)(const JitCodeEvent* event);
1411cb0ef41Sopenharmony_ci
1421cb0ef41Sopenharmony_ci// --- Garbage Collection Callbacks ---
1431cb0ef41Sopenharmony_ci
1441cb0ef41Sopenharmony_ci/**
1451cb0ef41Sopenharmony_ci * Applications can register callback functions which will be called before and
1461cb0ef41Sopenharmony_ci * after certain garbage collection operations.  Allocations are not allowed in
1471cb0ef41Sopenharmony_ci * the callback functions, you therefore cannot manipulate objects (set or
1481cb0ef41Sopenharmony_ci * delete properties for example) since it is possible such operations will
1491cb0ef41Sopenharmony_ci * result in the allocation of objects.
1501cb0ef41Sopenharmony_ci */
1511cb0ef41Sopenharmony_cienum GCType {
1521cb0ef41Sopenharmony_ci  kGCTypeScavenge = 1 << 0,
1531cb0ef41Sopenharmony_ci  kGCTypeMinorMarkCompact = 1 << 1,
1541cb0ef41Sopenharmony_ci  kGCTypeMarkSweepCompact = 1 << 2,
1551cb0ef41Sopenharmony_ci  kGCTypeIncrementalMarking = 1 << 3,
1561cb0ef41Sopenharmony_ci  kGCTypeProcessWeakCallbacks = 1 << 4,
1571cb0ef41Sopenharmony_ci  kGCTypeAll = kGCTypeScavenge | kGCTypeMinorMarkCompact |
1581cb0ef41Sopenharmony_ci               kGCTypeMarkSweepCompact | kGCTypeIncrementalMarking |
1591cb0ef41Sopenharmony_ci               kGCTypeProcessWeakCallbacks
1601cb0ef41Sopenharmony_ci};
1611cb0ef41Sopenharmony_ci
1621cb0ef41Sopenharmony_ci/**
1631cb0ef41Sopenharmony_ci * GCCallbackFlags is used to notify additional information about the GC
1641cb0ef41Sopenharmony_ci * callback.
1651cb0ef41Sopenharmony_ci *   - kGCCallbackFlagConstructRetainedObjectInfos: The GC callback is for
1661cb0ef41Sopenharmony_ci *     constructing retained object infos.
1671cb0ef41Sopenharmony_ci *   - kGCCallbackFlagForced: The GC callback is for a forced GC for testing.
1681cb0ef41Sopenharmony_ci *   - kGCCallbackFlagSynchronousPhantomCallbackProcessing: The GC callback
1691cb0ef41Sopenharmony_ci *     is called synchronously without getting posted to an idle task.
1701cb0ef41Sopenharmony_ci *   - kGCCallbackFlagCollectAllAvailableGarbage: The GC callback is called
1711cb0ef41Sopenharmony_ci *     in a phase where V8 is trying to collect all available garbage
1721cb0ef41Sopenharmony_ci *     (e.g., handling a low memory notification).
1731cb0ef41Sopenharmony_ci *   - kGCCallbackScheduleIdleGarbageCollection: The GC callback is called to
1741cb0ef41Sopenharmony_ci *     trigger an idle garbage collection.
1751cb0ef41Sopenharmony_ci */
1761cb0ef41Sopenharmony_cienum GCCallbackFlags {
1771cb0ef41Sopenharmony_ci  kNoGCCallbackFlags = 0,
1781cb0ef41Sopenharmony_ci  kGCCallbackFlagConstructRetainedObjectInfos = 1 << 1,
1791cb0ef41Sopenharmony_ci  kGCCallbackFlagForced = 1 << 2,
1801cb0ef41Sopenharmony_ci  kGCCallbackFlagSynchronousPhantomCallbackProcessing = 1 << 3,
1811cb0ef41Sopenharmony_ci  kGCCallbackFlagCollectAllAvailableGarbage = 1 << 4,
1821cb0ef41Sopenharmony_ci  kGCCallbackFlagCollectAllExternalMemory = 1 << 5,
1831cb0ef41Sopenharmony_ci  kGCCallbackScheduleIdleGarbageCollection = 1 << 6,
1841cb0ef41Sopenharmony_ci};
1851cb0ef41Sopenharmony_ci
1861cb0ef41Sopenharmony_ciusing GCCallback = void (*)(GCType type, GCCallbackFlags flags);
1871cb0ef41Sopenharmony_ci
1881cb0ef41Sopenharmony_ciusing InterruptCallback = void (*)(Isolate* isolate, void* data);
1891cb0ef41Sopenharmony_ci
1901cb0ef41Sopenharmony_ci/**
1911cb0ef41Sopenharmony_ci * This callback is invoked when the heap size is close to the heap limit and
1921cb0ef41Sopenharmony_ci * V8 is likely to abort with out-of-memory error.
1931cb0ef41Sopenharmony_ci * The callback can extend the heap limit by returning a value that is greater
1941cb0ef41Sopenharmony_ci * than the current_heap_limit. The initial heap limit is the limit that was
1951cb0ef41Sopenharmony_ci * set after heap setup.
1961cb0ef41Sopenharmony_ci */
1971cb0ef41Sopenharmony_ciusing NearHeapLimitCallback = size_t (*)(void* data, size_t current_heap_limit,
1981cb0ef41Sopenharmony_ci                                         size_t initial_heap_limit);
1991cb0ef41Sopenharmony_ci
2001cb0ef41Sopenharmony_ci/**
2011cb0ef41Sopenharmony_ci * Callback function passed to SetUnhandledExceptionCallback.
2021cb0ef41Sopenharmony_ci */
2031cb0ef41Sopenharmony_ci#if defined(V8_OS_WIN)
2041cb0ef41Sopenharmony_ciusing UnhandledExceptionCallback =
2051cb0ef41Sopenharmony_ci    int (*)(_EXCEPTION_POINTERS* exception_pointers);
2061cb0ef41Sopenharmony_ci#endif
2071cb0ef41Sopenharmony_ci
2081cb0ef41Sopenharmony_ci// --- Counters Callbacks ---
2091cb0ef41Sopenharmony_ci
2101cb0ef41Sopenharmony_ciusing CounterLookupCallback = int* (*)(const char* name);
2111cb0ef41Sopenharmony_ci
2121cb0ef41Sopenharmony_ciusing CreateHistogramCallback = void* (*)(const char* name, int min, int max,
2131cb0ef41Sopenharmony_ci                                          size_t buckets);
2141cb0ef41Sopenharmony_ci
2151cb0ef41Sopenharmony_ciusing AddHistogramSampleCallback = void (*)(void* histogram, int sample);
2161cb0ef41Sopenharmony_ci
2171cb0ef41Sopenharmony_ci// --- Exceptions ---
2181cb0ef41Sopenharmony_ci
2191cb0ef41Sopenharmony_ciusing FatalErrorCallback = void (*)(const char* location, const char* message);
2201cb0ef41Sopenharmony_ci
2211cb0ef41Sopenharmony_cistruct OOMDetails {
2221cb0ef41Sopenharmony_ci  bool is_heap_oom = false;
2231cb0ef41Sopenharmony_ci  const char* detail = nullptr;
2241cb0ef41Sopenharmony_ci};
2251cb0ef41Sopenharmony_ci
2261cb0ef41Sopenharmony_ciusing OOMErrorCallback = void (*)(const char* location,
2271cb0ef41Sopenharmony_ci                                  const OOMDetails& details);
2281cb0ef41Sopenharmony_ci
2291cb0ef41Sopenharmony_ciusing MessageCallback = void (*)(Local<Message> message, Local<Value> data);
2301cb0ef41Sopenharmony_ci
2311cb0ef41Sopenharmony_ci// --- Tracing ---
2321cb0ef41Sopenharmony_ci
2331cb0ef41Sopenharmony_cienum LogEventStatus : int { kStart = 0, kEnd = 1, kStamp = 2 };
2341cb0ef41Sopenharmony_ciusing LogEventCallback = void (*)(const char* name,
2351cb0ef41Sopenharmony_ci                                  int /* LogEventStatus */ status);
2361cb0ef41Sopenharmony_ci
2371cb0ef41Sopenharmony_ci// --- Crashkeys Callback ---
2381cb0ef41Sopenharmony_cienum class CrashKeyId {
2391cb0ef41Sopenharmony_ci  kIsolateAddress,
2401cb0ef41Sopenharmony_ci  kReadonlySpaceFirstPageAddress,
2411cb0ef41Sopenharmony_ci  kMapSpaceFirstPageAddress V8_ENUM_DEPRECATE_SOON("Map space got removed"),
2421cb0ef41Sopenharmony_ci  kOldSpaceFirstPageAddress,
2431cb0ef41Sopenharmony_ci  kCodeRangeBaseAddress,
2441cb0ef41Sopenharmony_ci  kCodeSpaceFirstPageAddress,
2451cb0ef41Sopenharmony_ci  kDumpType,
2461cb0ef41Sopenharmony_ci  kSnapshotChecksumCalculated,
2471cb0ef41Sopenharmony_ci  kSnapshotChecksumExpected,
2481cb0ef41Sopenharmony_ci};
2491cb0ef41Sopenharmony_ci
2501cb0ef41Sopenharmony_ciusing AddCrashKeyCallback = void (*)(CrashKeyId id, const std::string& value);
2511cb0ef41Sopenharmony_ci
2521cb0ef41Sopenharmony_ci// --- Enter/Leave Script Callback ---
2531cb0ef41Sopenharmony_ciusing BeforeCallEnteredCallback = void (*)(Isolate*);
2541cb0ef41Sopenharmony_ciusing CallCompletedCallback = void (*)(Isolate*);
2551cb0ef41Sopenharmony_ci
2561cb0ef41Sopenharmony_ci// --- AllowCodeGenerationFromStrings callbacks ---
2571cb0ef41Sopenharmony_ci
2581cb0ef41Sopenharmony_ci/**
2591cb0ef41Sopenharmony_ci * Callback to check if code generation from strings is allowed. See
2601cb0ef41Sopenharmony_ci * Context::AllowCodeGenerationFromStrings.
2611cb0ef41Sopenharmony_ci */
2621cb0ef41Sopenharmony_ciusing AllowCodeGenerationFromStringsCallback = bool (*)(Local<Context> context,
2631cb0ef41Sopenharmony_ci                                                        Local<String> source);
2641cb0ef41Sopenharmony_ci
2651cb0ef41Sopenharmony_cistruct ModifyCodeGenerationFromStringsResult {
2661cb0ef41Sopenharmony_ci  // If true, proceed with the codegen algorithm. Otherwise, block it.
2671cb0ef41Sopenharmony_ci  bool codegen_allowed = false;
2681cb0ef41Sopenharmony_ci  // Overwrite the original source with this string, if present.
2691cb0ef41Sopenharmony_ci  // Use the original source if empty.
2701cb0ef41Sopenharmony_ci  // This field is considered only if codegen_allowed is true.
2711cb0ef41Sopenharmony_ci  MaybeLocal<String> modified_source;
2721cb0ef41Sopenharmony_ci};
2731cb0ef41Sopenharmony_ci
2741cb0ef41Sopenharmony_ci/**
2751cb0ef41Sopenharmony_ci * Access type specification.
2761cb0ef41Sopenharmony_ci */
2771cb0ef41Sopenharmony_cienum AccessType {
2781cb0ef41Sopenharmony_ci  ACCESS_GET,
2791cb0ef41Sopenharmony_ci  ACCESS_SET,
2801cb0ef41Sopenharmony_ci  ACCESS_HAS,
2811cb0ef41Sopenharmony_ci  ACCESS_DELETE,
2821cb0ef41Sopenharmony_ci  ACCESS_KEYS
2831cb0ef41Sopenharmony_ci};
2841cb0ef41Sopenharmony_ci
2851cb0ef41Sopenharmony_ci// --- Failed Access Check Callback ---
2861cb0ef41Sopenharmony_ci
2871cb0ef41Sopenharmony_ciusing FailedAccessCheckCallback = void (*)(Local<Object> target,
2881cb0ef41Sopenharmony_ci                                           AccessType type, Local<Value> data);
2891cb0ef41Sopenharmony_ci
2901cb0ef41Sopenharmony_ci/**
2911cb0ef41Sopenharmony_ci * Callback to check if codegen is allowed from a source object, and convert
2921cb0ef41Sopenharmony_ci * the source to string if necessary. See: ModifyCodeGenerationFromStrings.
2931cb0ef41Sopenharmony_ci */
2941cb0ef41Sopenharmony_ciusing ModifyCodeGenerationFromStringsCallback =
2951cb0ef41Sopenharmony_ci    ModifyCodeGenerationFromStringsResult (*)(Local<Context> context,
2961cb0ef41Sopenharmony_ci                                              Local<Value> source);
2971cb0ef41Sopenharmony_ciusing ModifyCodeGenerationFromStringsCallback2 =
2981cb0ef41Sopenharmony_ci    ModifyCodeGenerationFromStringsResult (*)(Local<Context> context,
2991cb0ef41Sopenharmony_ci                                              Local<Value> source,
3001cb0ef41Sopenharmony_ci                                              bool is_code_like);
3011cb0ef41Sopenharmony_ci
3021cb0ef41Sopenharmony_ci// --- WebAssembly compilation callbacks ---
3031cb0ef41Sopenharmony_ciusing ExtensionCallback = bool (*)(const FunctionCallbackInfo<Value>&);
3041cb0ef41Sopenharmony_ci
3051cb0ef41Sopenharmony_ciusing AllowWasmCodeGenerationCallback = bool (*)(Local<Context> context,
3061cb0ef41Sopenharmony_ci                                                 Local<String> source);
3071cb0ef41Sopenharmony_ci
3081cb0ef41Sopenharmony_ci// --- Callback for APIs defined on v8-supported objects, but implemented
3091cb0ef41Sopenharmony_ci// by the embedder. Example: WebAssembly.{compile|instantiate}Streaming ---
3101cb0ef41Sopenharmony_ciusing ApiImplementationCallback = void (*)(const FunctionCallbackInfo<Value>&);
3111cb0ef41Sopenharmony_ci
3121cb0ef41Sopenharmony_ci// --- Callback for WebAssembly.compileStreaming ---
3131cb0ef41Sopenharmony_ciusing WasmStreamingCallback = void (*)(const FunctionCallbackInfo<Value>&);
3141cb0ef41Sopenharmony_ci
3151cb0ef41Sopenharmony_cienum class WasmAsyncSuccess { kSuccess, kFail };
3161cb0ef41Sopenharmony_ci
3171cb0ef41Sopenharmony_ci// --- Callback called when async WebAssembly operations finish ---
3181cb0ef41Sopenharmony_ciusing WasmAsyncResolvePromiseCallback = void (*)(
3191cb0ef41Sopenharmony_ci    Isolate* isolate, Local<Context> context, Local<Promise::Resolver> resolver,
3201cb0ef41Sopenharmony_ci    Local<Value> result, WasmAsyncSuccess success);
3211cb0ef41Sopenharmony_ci
3221cb0ef41Sopenharmony_ci// --- Callback for loading source map file for Wasm profiling support
3231cb0ef41Sopenharmony_ciusing WasmLoadSourceMapCallback = Local<String> (*)(Isolate* isolate,
3241cb0ef41Sopenharmony_ci                                                    const char* name);
3251cb0ef41Sopenharmony_ci
3261cb0ef41Sopenharmony_ci// --- Callback for checking if WebAssembly GC is enabled ---
3271cb0ef41Sopenharmony_ci// If the callback returns true, it will also enable Wasm stringrefs.
3281cb0ef41Sopenharmony_ciusing WasmGCEnabledCallback = bool (*)(Local<Context> context);
3291cb0ef41Sopenharmony_ci
3301cb0ef41Sopenharmony_ci// --- Callback for checking if the SharedArrayBuffer constructor is enabled ---
3311cb0ef41Sopenharmony_ciusing SharedArrayBufferConstructorEnabledCallback =
3321cb0ef41Sopenharmony_ci    bool (*)(Local<Context> context);
3331cb0ef41Sopenharmony_ci
3341cb0ef41Sopenharmony_ci/**
3351cb0ef41Sopenharmony_ci * HostImportModuleDynamicallyCallback is called when we
3361cb0ef41Sopenharmony_ci * require the embedder to load a module. This is used as part of the dynamic
3371cb0ef41Sopenharmony_ci * import syntax.
3381cb0ef41Sopenharmony_ci *
3391cb0ef41Sopenharmony_ci * The referrer contains metadata about the script/module that calls
3401cb0ef41Sopenharmony_ci * import.
3411cb0ef41Sopenharmony_ci *
3421cb0ef41Sopenharmony_ci * The specifier is the name of the module that should be imported.
3431cb0ef41Sopenharmony_ci *
3441cb0ef41Sopenharmony_ci * The import_assertions are import assertions for this request in the form:
3451cb0ef41Sopenharmony_ci * [key1, value1, key2, value2, ...] where the keys and values are of type
3461cb0ef41Sopenharmony_ci * v8::String. Note, unlike the FixedArray passed to ResolveModuleCallback and
3471cb0ef41Sopenharmony_ci * returned from ModuleRequest::GetImportAssertions(), this array does not
3481cb0ef41Sopenharmony_ci * contain the source Locations of the assertions.
3491cb0ef41Sopenharmony_ci *
3501cb0ef41Sopenharmony_ci * The embedder must compile, instantiate, evaluate the Module, and
3511cb0ef41Sopenharmony_ci * obtain its namespace object.
3521cb0ef41Sopenharmony_ci *
3531cb0ef41Sopenharmony_ci * The Promise returned from this function is forwarded to userland
3541cb0ef41Sopenharmony_ci * JavaScript. The embedder must resolve this promise with the module
3551cb0ef41Sopenharmony_ci * namespace object. In case of an exception, the embedder must reject
3561cb0ef41Sopenharmony_ci * this promise with the exception. If the promise creation itself
3571cb0ef41Sopenharmony_ci * fails (e.g. due to stack overflow), the embedder must propagate
3581cb0ef41Sopenharmony_ci * that exception by returning an empty MaybeLocal.
3591cb0ef41Sopenharmony_ci */
3601cb0ef41Sopenharmony_ciusing HostImportModuleDynamicallyWithImportAssertionsCallback =
3611cb0ef41Sopenharmony_ci    MaybeLocal<Promise> (*)(Local<Context> context,
3621cb0ef41Sopenharmony_ci                            Local<ScriptOrModule> referrer,
3631cb0ef41Sopenharmony_ci                            Local<String> specifier,
3641cb0ef41Sopenharmony_ci                            Local<FixedArray> import_assertions);
3651cb0ef41Sopenharmony_ciusing HostImportModuleDynamicallyCallback = MaybeLocal<Promise> (*)(
3661cb0ef41Sopenharmony_ci    Local<Context> context, Local<Data> host_defined_options,
3671cb0ef41Sopenharmony_ci    Local<Value> resource_name, Local<String> specifier,
3681cb0ef41Sopenharmony_ci    Local<FixedArray> import_assertions);
3691cb0ef41Sopenharmony_ci
3701cb0ef41Sopenharmony_ci/**
3711cb0ef41Sopenharmony_ci * Callback for requesting a compile hint for a function from the embedder. The
3721cb0ef41Sopenharmony_ci * first parameter is the position of the function in source code and the second
3731cb0ef41Sopenharmony_ci * parameter is embedder data to be passed back.
3741cb0ef41Sopenharmony_ci */
3751cb0ef41Sopenharmony_ciusing CompileHintCallback = bool (*)(int, void*);
3761cb0ef41Sopenharmony_ci
3771cb0ef41Sopenharmony_ci/**
3781cb0ef41Sopenharmony_ci * HostInitializeImportMetaObjectCallback is called the first time import.meta
3791cb0ef41Sopenharmony_ci * is accessed for a module. Subsequent access will reuse the same value.
3801cb0ef41Sopenharmony_ci *
3811cb0ef41Sopenharmony_ci * The method combines two implementation-defined abstract operations into one:
3821cb0ef41Sopenharmony_ci * HostGetImportMetaProperties and HostFinalizeImportMeta.
3831cb0ef41Sopenharmony_ci *
3841cb0ef41Sopenharmony_ci * The embedder should use v8::Object::CreateDataProperty to add properties on
3851cb0ef41Sopenharmony_ci * the meta object.
3861cb0ef41Sopenharmony_ci */
3871cb0ef41Sopenharmony_ciusing HostInitializeImportMetaObjectCallback = void (*)(Local<Context> context,
3881cb0ef41Sopenharmony_ci                                                        Local<Module> module,
3891cb0ef41Sopenharmony_ci                                                        Local<Object> meta);
3901cb0ef41Sopenharmony_ci
3911cb0ef41Sopenharmony_ci/**
3921cb0ef41Sopenharmony_ci * HostCreateShadowRealmContextCallback is called each time a ShadowRealm is
3931cb0ef41Sopenharmony_ci * being constructed in the initiator_context.
3941cb0ef41Sopenharmony_ci *
3951cb0ef41Sopenharmony_ci * The method combines Context creation and implementation defined abstract
3961cb0ef41Sopenharmony_ci * operation HostInitializeShadowRealm into one.
3971cb0ef41Sopenharmony_ci *
3981cb0ef41Sopenharmony_ci * The embedder should use v8::Context::New or v8::Context:NewFromSnapshot to
3991cb0ef41Sopenharmony_ci * create a new context. If the creation fails, the embedder must propagate
4001cb0ef41Sopenharmony_ci * that exception by returning an empty MaybeLocal.
4011cb0ef41Sopenharmony_ci */
4021cb0ef41Sopenharmony_ciusing HostCreateShadowRealmContextCallback =
4031cb0ef41Sopenharmony_ci    MaybeLocal<Context> (*)(Local<Context> initiator_context);
4041cb0ef41Sopenharmony_ci
4051cb0ef41Sopenharmony_ci/**
4061cb0ef41Sopenharmony_ci * PrepareStackTraceCallback is called when the stack property of an error is
4071cb0ef41Sopenharmony_ci * first accessed. The return value will be used as the stack value. If this
4081cb0ef41Sopenharmony_ci * callback is registed, the |Error.prepareStackTrace| API will be disabled.
4091cb0ef41Sopenharmony_ci * |sites| is an array of call sites, specified in
4101cb0ef41Sopenharmony_ci * https://v8.dev/docs/stack-trace-api
4111cb0ef41Sopenharmony_ci */
4121cb0ef41Sopenharmony_ciusing PrepareStackTraceCallback = MaybeLocal<Value> (*)(Local<Context> context,
4131cb0ef41Sopenharmony_ci                                                        Local<Value> error,
4141cb0ef41Sopenharmony_ci                                                        Local<Array> sites);
4151cb0ef41Sopenharmony_ci
4161cb0ef41Sopenharmony_ci}  // namespace v8
4171cb0ef41Sopenharmony_ci
4181cb0ef41Sopenharmony_ci#endif  // INCLUDE_V8_ISOLATE_CALLBACKS_H_
419