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_H_
61cb0ef41Sopenharmony_ci#define INCLUDE_V8_ISOLATE_H_
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci#include <stddef.h>
91cb0ef41Sopenharmony_ci#include <stdint.h>
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ci#include <memory>
121cb0ef41Sopenharmony_ci#include <utility>
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ci#include "cppgc/common.h"
151cb0ef41Sopenharmony_ci#include "v8-array-buffer.h"       // NOLINT(build/include_directory)
161cb0ef41Sopenharmony_ci#include "v8-callbacks.h"          // NOLINT(build/include_directory)
171cb0ef41Sopenharmony_ci#include "v8-data.h"               // NOLINT(build/include_directory)
181cb0ef41Sopenharmony_ci#include "v8-debug.h"              // NOLINT(build/include_directory)
191cb0ef41Sopenharmony_ci#include "v8-embedder-heap.h"      // NOLINT(build/include_directory)
201cb0ef41Sopenharmony_ci#include "v8-function-callback.h"  // NOLINT(build/include_directory)
211cb0ef41Sopenharmony_ci#include "v8-internal.h"           // NOLINT(build/include_directory)
221cb0ef41Sopenharmony_ci#include "v8-local-handle.h"       // NOLINT(build/include_directory)
231cb0ef41Sopenharmony_ci#include "v8-microtask.h"          // NOLINT(build/include_directory)
241cb0ef41Sopenharmony_ci#include "v8-persistent-handle.h"  // NOLINT(build/include_directory)
251cb0ef41Sopenharmony_ci#include "v8-primitive.h"          // NOLINT(build/include_directory)
261cb0ef41Sopenharmony_ci#include "v8-statistics.h"         // NOLINT(build/include_directory)
271cb0ef41Sopenharmony_ci#include "v8-unwinder.h"           // NOLINT(build/include_directory)
281cb0ef41Sopenharmony_ci#include "v8config.h"              // NOLINT(build/include_directory)
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_cinamespace v8 {
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ciclass CppHeap;
331cb0ef41Sopenharmony_ciclass HeapProfiler;
341cb0ef41Sopenharmony_ciclass MicrotaskQueue;
351cb0ef41Sopenharmony_ciclass StartupData;
361cb0ef41Sopenharmony_ciclass ScriptOrModule;
371cb0ef41Sopenharmony_ciclass SharedArrayBuffer;
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_cinamespace internal {
401cb0ef41Sopenharmony_ciclass MicrotaskQueue;
411cb0ef41Sopenharmony_ciclass ThreadLocalTop;
421cb0ef41Sopenharmony_ci}  // namespace internal
431cb0ef41Sopenharmony_ci
441cb0ef41Sopenharmony_cinamespace metrics {
451cb0ef41Sopenharmony_ciclass Recorder;
461cb0ef41Sopenharmony_ci}  // namespace metrics
471cb0ef41Sopenharmony_ci
481cb0ef41Sopenharmony_ci/**
491cb0ef41Sopenharmony_ci * A set of constraints that specifies the limits of the runtime's memory use.
501cb0ef41Sopenharmony_ci * You must set the heap size before initializing the VM - the size cannot be
511cb0ef41Sopenharmony_ci * adjusted after the VM is initialized.
521cb0ef41Sopenharmony_ci *
531cb0ef41Sopenharmony_ci * If you are using threads then you should hold the V8::Locker lock while
541cb0ef41Sopenharmony_ci * setting the stack limit and you must set a non-default stack limit separately
551cb0ef41Sopenharmony_ci * for each thread.
561cb0ef41Sopenharmony_ci *
571cb0ef41Sopenharmony_ci * The arguments for set_max_semi_space_size, set_max_old_space_size,
581cb0ef41Sopenharmony_ci * set_max_executable_size, set_code_range_size specify limits in MB.
591cb0ef41Sopenharmony_ci *
601cb0ef41Sopenharmony_ci * The argument for set_max_semi_space_size_in_kb is in KB.
611cb0ef41Sopenharmony_ci */
621cb0ef41Sopenharmony_ciclass V8_EXPORT ResourceConstraints {
631cb0ef41Sopenharmony_ci public:
641cb0ef41Sopenharmony_ci  /**
651cb0ef41Sopenharmony_ci   * Configures the constraints with reasonable default values based on the
661cb0ef41Sopenharmony_ci   * provided heap size limit. The heap size includes both the young and
671cb0ef41Sopenharmony_ci   * the old generation.
681cb0ef41Sopenharmony_ci   *
691cb0ef41Sopenharmony_ci   * \param initial_heap_size_in_bytes The initial heap size or zero.
701cb0ef41Sopenharmony_ci   *    By default V8 starts with a small heap and dynamically grows it to
711cb0ef41Sopenharmony_ci   *    match the set of live objects. This may lead to ineffective
721cb0ef41Sopenharmony_ci   *    garbage collections at startup if the live set is large.
731cb0ef41Sopenharmony_ci   *    Setting the initial heap size avoids such garbage collections.
741cb0ef41Sopenharmony_ci   *    Note that this does not affect young generation garbage collections.
751cb0ef41Sopenharmony_ci   *
761cb0ef41Sopenharmony_ci   * \param maximum_heap_size_in_bytes The hard limit for the heap size.
771cb0ef41Sopenharmony_ci   *    When the heap size approaches this limit, V8 will perform series of
781cb0ef41Sopenharmony_ci   *    garbage collections and invoke the NearHeapLimitCallback. If the garbage
791cb0ef41Sopenharmony_ci   *    collections do not help and the callback does not increase the limit,
801cb0ef41Sopenharmony_ci   *    then V8 will crash with V8::FatalProcessOutOfMemory.
811cb0ef41Sopenharmony_ci   */
821cb0ef41Sopenharmony_ci  void ConfigureDefaultsFromHeapSize(size_t initial_heap_size_in_bytes,
831cb0ef41Sopenharmony_ci                                     size_t maximum_heap_size_in_bytes);
841cb0ef41Sopenharmony_ci
851cb0ef41Sopenharmony_ci  /**
861cb0ef41Sopenharmony_ci   * Configures the constraints with reasonable default values based on the
871cb0ef41Sopenharmony_ci   * capabilities of the current device the VM is running on.
881cb0ef41Sopenharmony_ci   *
891cb0ef41Sopenharmony_ci   * \param physical_memory The total amount of physical memory on the current
901cb0ef41Sopenharmony_ci   *   device, in bytes.
911cb0ef41Sopenharmony_ci   * \param virtual_memory_limit The amount of virtual memory on the current
921cb0ef41Sopenharmony_ci   *   device, in bytes, or zero, if there is no limit.
931cb0ef41Sopenharmony_ci   */
941cb0ef41Sopenharmony_ci  void ConfigureDefaults(uint64_t physical_memory,
951cb0ef41Sopenharmony_ci                         uint64_t virtual_memory_limit);
961cb0ef41Sopenharmony_ci
971cb0ef41Sopenharmony_ci  /**
981cb0ef41Sopenharmony_ci   * The address beyond which the VM's stack may not grow.
991cb0ef41Sopenharmony_ci   */
1001cb0ef41Sopenharmony_ci  uint32_t* stack_limit() const { return stack_limit_; }
1011cb0ef41Sopenharmony_ci  void set_stack_limit(uint32_t* value) { stack_limit_ = value; }
1021cb0ef41Sopenharmony_ci
1031cb0ef41Sopenharmony_ci  /**
1041cb0ef41Sopenharmony_ci   * The amount of virtual memory reserved for generated code. This is relevant
1051cb0ef41Sopenharmony_ci   * for 64-bit architectures that rely on code range for calls in code.
1061cb0ef41Sopenharmony_ci   *
1071cb0ef41Sopenharmony_ci   * When V8_COMPRESS_POINTERS_IN_SHARED_CAGE is defined, there is a shared
1081cb0ef41Sopenharmony_ci   * process-wide code range that is lazily initialized. This value is used to
1091cb0ef41Sopenharmony_ci   * configure that shared code range when the first Isolate is
1101cb0ef41Sopenharmony_ci   * created. Subsequent Isolates ignore this value.
1111cb0ef41Sopenharmony_ci   */
1121cb0ef41Sopenharmony_ci  size_t code_range_size_in_bytes() const { return code_range_size_; }
1131cb0ef41Sopenharmony_ci  void set_code_range_size_in_bytes(size_t limit) { code_range_size_ = limit; }
1141cb0ef41Sopenharmony_ci
1151cb0ef41Sopenharmony_ci  /**
1161cb0ef41Sopenharmony_ci   * The maximum size of the old generation.
1171cb0ef41Sopenharmony_ci   * When the old generation approaches this limit, V8 will perform series of
1181cb0ef41Sopenharmony_ci   * garbage collections and invoke the NearHeapLimitCallback.
1191cb0ef41Sopenharmony_ci   * If the garbage collections do not help and the callback does not
1201cb0ef41Sopenharmony_ci   * increase the limit, then V8 will crash with V8::FatalProcessOutOfMemory.
1211cb0ef41Sopenharmony_ci   */
1221cb0ef41Sopenharmony_ci  size_t max_old_generation_size_in_bytes() const {
1231cb0ef41Sopenharmony_ci    return max_old_generation_size_;
1241cb0ef41Sopenharmony_ci  }
1251cb0ef41Sopenharmony_ci  void set_max_old_generation_size_in_bytes(size_t limit) {
1261cb0ef41Sopenharmony_ci    max_old_generation_size_ = limit;
1271cb0ef41Sopenharmony_ci  }
1281cb0ef41Sopenharmony_ci
1291cb0ef41Sopenharmony_ci  /**
1301cb0ef41Sopenharmony_ci   * The maximum size of the young generation, which consists of two semi-spaces
1311cb0ef41Sopenharmony_ci   * and a large object space. This affects frequency of Scavenge garbage
1321cb0ef41Sopenharmony_ci   * collections and should be typically much smaller that the old generation.
1331cb0ef41Sopenharmony_ci   */
1341cb0ef41Sopenharmony_ci  size_t max_young_generation_size_in_bytes() const {
1351cb0ef41Sopenharmony_ci    return max_young_generation_size_;
1361cb0ef41Sopenharmony_ci  }
1371cb0ef41Sopenharmony_ci  void set_max_young_generation_size_in_bytes(size_t limit) {
1381cb0ef41Sopenharmony_ci    max_young_generation_size_ = limit;
1391cb0ef41Sopenharmony_ci  }
1401cb0ef41Sopenharmony_ci
1411cb0ef41Sopenharmony_ci  size_t initial_old_generation_size_in_bytes() const {
1421cb0ef41Sopenharmony_ci    return initial_old_generation_size_;
1431cb0ef41Sopenharmony_ci  }
1441cb0ef41Sopenharmony_ci  void set_initial_old_generation_size_in_bytes(size_t initial_size) {
1451cb0ef41Sopenharmony_ci    initial_old_generation_size_ = initial_size;
1461cb0ef41Sopenharmony_ci  }
1471cb0ef41Sopenharmony_ci
1481cb0ef41Sopenharmony_ci  size_t initial_young_generation_size_in_bytes() const {
1491cb0ef41Sopenharmony_ci    return initial_young_generation_size_;
1501cb0ef41Sopenharmony_ci  }
1511cb0ef41Sopenharmony_ci  void set_initial_young_generation_size_in_bytes(size_t initial_size) {
1521cb0ef41Sopenharmony_ci    initial_young_generation_size_ = initial_size;
1531cb0ef41Sopenharmony_ci  }
1541cb0ef41Sopenharmony_ci
1551cb0ef41Sopenharmony_ci private:
1561cb0ef41Sopenharmony_ci  static constexpr size_t kMB = 1048576u;
1571cb0ef41Sopenharmony_ci  size_t code_range_size_ = 0;
1581cb0ef41Sopenharmony_ci  size_t max_old_generation_size_ = 0;
1591cb0ef41Sopenharmony_ci  size_t max_young_generation_size_ = 0;
1601cb0ef41Sopenharmony_ci  size_t initial_old_generation_size_ = 0;
1611cb0ef41Sopenharmony_ci  size_t initial_young_generation_size_ = 0;
1621cb0ef41Sopenharmony_ci  uint32_t* stack_limit_ = nullptr;
1631cb0ef41Sopenharmony_ci};
1641cb0ef41Sopenharmony_ci
1651cb0ef41Sopenharmony_ci/**
1661cb0ef41Sopenharmony_ci * Option flags passed to the SetRAILMode function.
1671cb0ef41Sopenharmony_ci * See documentation https://developers.google.com/web/tools/chrome-devtools/
1681cb0ef41Sopenharmony_ci * profile/evaluate-performance/rail
1691cb0ef41Sopenharmony_ci */
1701cb0ef41Sopenharmony_cienum RAILMode : unsigned {
1711cb0ef41Sopenharmony_ci  // Response performance mode: In this mode very low virtual machine latency
1721cb0ef41Sopenharmony_ci  // is provided. V8 will try to avoid JavaScript execution interruptions.
1731cb0ef41Sopenharmony_ci  // Throughput may be throttled.
1741cb0ef41Sopenharmony_ci  PERFORMANCE_RESPONSE,
1751cb0ef41Sopenharmony_ci  // Animation performance mode: In this mode low virtual machine latency is
1761cb0ef41Sopenharmony_ci  // provided. V8 will try to avoid as many JavaScript execution interruptions
1771cb0ef41Sopenharmony_ci  // as possible. Throughput may be throttled. This is the default mode.
1781cb0ef41Sopenharmony_ci  PERFORMANCE_ANIMATION,
1791cb0ef41Sopenharmony_ci  // Idle performance mode: The embedder is idle. V8 can complete deferred work
1801cb0ef41Sopenharmony_ci  // in this mode.
1811cb0ef41Sopenharmony_ci  PERFORMANCE_IDLE,
1821cb0ef41Sopenharmony_ci  // Load performance mode: In this mode high throughput is provided. V8 may
1831cb0ef41Sopenharmony_ci  // turn off latency optimizations.
1841cb0ef41Sopenharmony_ci  PERFORMANCE_LOAD
1851cb0ef41Sopenharmony_ci};
1861cb0ef41Sopenharmony_ci
1871cb0ef41Sopenharmony_ci/**
1881cb0ef41Sopenharmony_ci * Memory pressure level for the MemoryPressureNotification.
1891cb0ef41Sopenharmony_ci * kNone hints V8 that there is no memory pressure.
1901cb0ef41Sopenharmony_ci * kModerate hints V8 to speed up incremental garbage collection at the cost of
1911cb0ef41Sopenharmony_ci * of higher latency due to garbage collection pauses.
1921cb0ef41Sopenharmony_ci * kCritical hints V8 to free memory as soon as possible. Garbage collection
1931cb0ef41Sopenharmony_ci * pauses at this level will be large.
1941cb0ef41Sopenharmony_ci */
1951cb0ef41Sopenharmony_cienum class MemoryPressureLevel { kNone, kModerate, kCritical };
1961cb0ef41Sopenharmony_ci
1971cb0ef41Sopenharmony_ci/**
1981cb0ef41Sopenharmony_ci * Isolate represents an isolated instance of the V8 engine.  V8 isolates have
1991cb0ef41Sopenharmony_ci * completely separate states.  Objects from one isolate must not be used in
2001cb0ef41Sopenharmony_ci * other isolates.  The embedder can create multiple isolates and use them in
2011cb0ef41Sopenharmony_ci * parallel in multiple threads.  An isolate can be entered by at most one
2021cb0ef41Sopenharmony_ci * thread at any given time.  The Locker/Unlocker API must be used to
2031cb0ef41Sopenharmony_ci * synchronize.
2041cb0ef41Sopenharmony_ci */
2051cb0ef41Sopenharmony_ciclass V8_EXPORT Isolate {
2061cb0ef41Sopenharmony_ci public:
2071cb0ef41Sopenharmony_ci  /**
2081cb0ef41Sopenharmony_ci   * Initial configuration parameters for a new Isolate.
2091cb0ef41Sopenharmony_ci   */
2101cb0ef41Sopenharmony_ci  struct V8_EXPORT CreateParams {
2111cb0ef41Sopenharmony_ci    CreateParams();
2121cb0ef41Sopenharmony_ci    ~CreateParams();
2131cb0ef41Sopenharmony_ci
2141cb0ef41Sopenharmony_ci    /**
2151cb0ef41Sopenharmony_ci     * Allows the host application to provide the address of a function that is
2161cb0ef41Sopenharmony_ci     * notified each time code is added, moved or removed.
2171cb0ef41Sopenharmony_ci     */
2181cb0ef41Sopenharmony_ci    JitCodeEventHandler code_event_handler = nullptr;
2191cb0ef41Sopenharmony_ci
2201cb0ef41Sopenharmony_ci    /**
2211cb0ef41Sopenharmony_ci     * ResourceConstraints to use for the new Isolate.
2221cb0ef41Sopenharmony_ci     */
2231cb0ef41Sopenharmony_ci    ResourceConstraints constraints;
2241cb0ef41Sopenharmony_ci
2251cb0ef41Sopenharmony_ci    /**
2261cb0ef41Sopenharmony_ci     * Explicitly specify a startup snapshot blob. The embedder owns the blob.
2271cb0ef41Sopenharmony_ci     * The embedder *must* ensure that the snapshot is from a trusted source.
2281cb0ef41Sopenharmony_ci     */
2291cb0ef41Sopenharmony_ci    StartupData* snapshot_blob = nullptr;
2301cb0ef41Sopenharmony_ci
2311cb0ef41Sopenharmony_ci    /**
2321cb0ef41Sopenharmony_ci     * Enables the host application to provide a mechanism for recording
2331cb0ef41Sopenharmony_ci     * statistics counters.
2341cb0ef41Sopenharmony_ci     */
2351cb0ef41Sopenharmony_ci    CounterLookupCallback counter_lookup_callback = nullptr;
2361cb0ef41Sopenharmony_ci
2371cb0ef41Sopenharmony_ci    /**
2381cb0ef41Sopenharmony_ci     * Enables the host application to provide a mechanism for recording
2391cb0ef41Sopenharmony_ci     * histograms. The CreateHistogram function returns a
2401cb0ef41Sopenharmony_ci     * histogram which will later be passed to the AddHistogramSample
2411cb0ef41Sopenharmony_ci     * function.
2421cb0ef41Sopenharmony_ci     */
2431cb0ef41Sopenharmony_ci    CreateHistogramCallback create_histogram_callback = nullptr;
2441cb0ef41Sopenharmony_ci    AddHistogramSampleCallback add_histogram_sample_callback = nullptr;
2451cb0ef41Sopenharmony_ci
2461cb0ef41Sopenharmony_ci    /**
2471cb0ef41Sopenharmony_ci     * The ArrayBuffer::Allocator to use for allocating and freeing the backing
2481cb0ef41Sopenharmony_ci     * store of ArrayBuffers.
2491cb0ef41Sopenharmony_ci     *
2501cb0ef41Sopenharmony_ci     * If the shared_ptr version is used, the Isolate instance and every
2511cb0ef41Sopenharmony_ci     * |BackingStore| allocated using this allocator hold a std::shared_ptr
2521cb0ef41Sopenharmony_ci     * to the allocator, in order to facilitate lifetime
2531cb0ef41Sopenharmony_ci     * management for the allocator instance.
2541cb0ef41Sopenharmony_ci     */
2551cb0ef41Sopenharmony_ci    ArrayBuffer::Allocator* array_buffer_allocator = nullptr;
2561cb0ef41Sopenharmony_ci    std::shared_ptr<ArrayBuffer::Allocator> array_buffer_allocator_shared;
2571cb0ef41Sopenharmony_ci
2581cb0ef41Sopenharmony_ci    /**
2591cb0ef41Sopenharmony_ci     * Specifies an optional nullptr-terminated array of raw addresses in the
2601cb0ef41Sopenharmony_ci     * embedder that V8 can match against during serialization and use for
2611cb0ef41Sopenharmony_ci     * deserialization. This array and its content must stay valid for the
2621cb0ef41Sopenharmony_ci     * entire lifetime of the isolate.
2631cb0ef41Sopenharmony_ci     */
2641cb0ef41Sopenharmony_ci    const intptr_t* external_references = nullptr;
2651cb0ef41Sopenharmony_ci
2661cb0ef41Sopenharmony_ci    /**
2671cb0ef41Sopenharmony_ci     * Whether calling Atomics.wait (a function that may block) is allowed in
2681cb0ef41Sopenharmony_ci     * this isolate. This can also be configured via SetAllowAtomicsWait.
2691cb0ef41Sopenharmony_ci     */
2701cb0ef41Sopenharmony_ci    bool allow_atomics_wait = true;
2711cb0ef41Sopenharmony_ci
2721cb0ef41Sopenharmony_ci    /**
2731cb0ef41Sopenharmony_ci     * Termination is postponed when there is no active SafeForTerminationScope.
2741cb0ef41Sopenharmony_ci     */
2751cb0ef41Sopenharmony_ci    bool only_terminate_in_safe_scope = false;
2761cb0ef41Sopenharmony_ci
2771cb0ef41Sopenharmony_ci    /**
2781cb0ef41Sopenharmony_ci     * The following parameters describe the offsets for addressing type info
2791cb0ef41Sopenharmony_ci     * for wrapped API objects and are used by the fast C API
2801cb0ef41Sopenharmony_ci     * (for details see v8-fast-api-calls.h).
2811cb0ef41Sopenharmony_ci     */
2821cb0ef41Sopenharmony_ci    int embedder_wrapper_type_index = -1;
2831cb0ef41Sopenharmony_ci    int embedder_wrapper_object_index = -1;
2841cb0ef41Sopenharmony_ci
2851cb0ef41Sopenharmony_ci    /**
2861cb0ef41Sopenharmony_ci     * Callbacks to invoke in case of fatal or OOM errors.
2871cb0ef41Sopenharmony_ci     */
2881cb0ef41Sopenharmony_ci    FatalErrorCallback fatal_error_callback = nullptr;
2891cb0ef41Sopenharmony_ci    OOMErrorCallback oom_error_callback = nullptr;
2901cb0ef41Sopenharmony_ci
2911cb0ef41Sopenharmony_ci    /**
2921cb0ef41Sopenharmony_ci     * The following parameter is experimental and may change significantly.
2931cb0ef41Sopenharmony_ci     * This is currently for internal testing.
2941cb0ef41Sopenharmony_ci     */
2951cb0ef41Sopenharmony_ci    Isolate* experimental_attach_to_shared_isolate = nullptr;
2961cb0ef41Sopenharmony_ci  };
2971cb0ef41Sopenharmony_ci
2981cb0ef41Sopenharmony_ci  /**
2991cb0ef41Sopenharmony_ci   * Stack-allocated class which sets the isolate for all operations
3001cb0ef41Sopenharmony_ci   * executed within a local scope.
3011cb0ef41Sopenharmony_ci   */
3021cb0ef41Sopenharmony_ci  class V8_EXPORT V8_NODISCARD Scope {
3031cb0ef41Sopenharmony_ci   public:
3041cb0ef41Sopenharmony_ci    explicit Scope(Isolate* isolate) : isolate_(isolate) { isolate->Enter(); }
3051cb0ef41Sopenharmony_ci
3061cb0ef41Sopenharmony_ci    ~Scope() { isolate_->Exit(); }
3071cb0ef41Sopenharmony_ci
3081cb0ef41Sopenharmony_ci    // Prevent copying of Scope objects.
3091cb0ef41Sopenharmony_ci    Scope(const Scope&) = delete;
3101cb0ef41Sopenharmony_ci    Scope& operator=(const Scope&) = delete;
3111cb0ef41Sopenharmony_ci
3121cb0ef41Sopenharmony_ci   private:
3131cb0ef41Sopenharmony_ci    Isolate* const isolate_;
3141cb0ef41Sopenharmony_ci  };
3151cb0ef41Sopenharmony_ci
3161cb0ef41Sopenharmony_ci  /**
3171cb0ef41Sopenharmony_ci   * Assert that no Javascript code is invoked.
3181cb0ef41Sopenharmony_ci   */
3191cb0ef41Sopenharmony_ci  class V8_EXPORT V8_NODISCARD DisallowJavascriptExecutionScope {
3201cb0ef41Sopenharmony_ci   public:
3211cb0ef41Sopenharmony_ci    enum OnFailure { CRASH_ON_FAILURE, THROW_ON_FAILURE, DUMP_ON_FAILURE };
3221cb0ef41Sopenharmony_ci
3231cb0ef41Sopenharmony_ci    DisallowJavascriptExecutionScope(Isolate* isolate, OnFailure on_failure);
3241cb0ef41Sopenharmony_ci    ~DisallowJavascriptExecutionScope();
3251cb0ef41Sopenharmony_ci
3261cb0ef41Sopenharmony_ci    // Prevent copying of Scope objects.
3271cb0ef41Sopenharmony_ci    DisallowJavascriptExecutionScope(const DisallowJavascriptExecutionScope&) =
3281cb0ef41Sopenharmony_ci        delete;
3291cb0ef41Sopenharmony_ci    DisallowJavascriptExecutionScope& operator=(
3301cb0ef41Sopenharmony_ci        const DisallowJavascriptExecutionScope&) = delete;
3311cb0ef41Sopenharmony_ci
3321cb0ef41Sopenharmony_ci   private:
3331cb0ef41Sopenharmony_ci    OnFailure on_failure_;
3341cb0ef41Sopenharmony_ci    Isolate* isolate_;
3351cb0ef41Sopenharmony_ci
3361cb0ef41Sopenharmony_ci    bool was_execution_allowed_assert_;
3371cb0ef41Sopenharmony_ci    bool was_execution_allowed_throws_;
3381cb0ef41Sopenharmony_ci    bool was_execution_allowed_dump_;
3391cb0ef41Sopenharmony_ci  };
3401cb0ef41Sopenharmony_ci
3411cb0ef41Sopenharmony_ci  /**
3421cb0ef41Sopenharmony_ci   * Introduce exception to DisallowJavascriptExecutionScope.
3431cb0ef41Sopenharmony_ci   */
3441cb0ef41Sopenharmony_ci  class V8_EXPORT V8_NODISCARD AllowJavascriptExecutionScope {
3451cb0ef41Sopenharmony_ci   public:
3461cb0ef41Sopenharmony_ci    explicit AllowJavascriptExecutionScope(Isolate* isolate);
3471cb0ef41Sopenharmony_ci    ~AllowJavascriptExecutionScope();
3481cb0ef41Sopenharmony_ci
3491cb0ef41Sopenharmony_ci    // Prevent copying of Scope objects.
3501cb0ef41Sopenharmony_ci    AllowJavascriptExecutionScope(const AllowJavascriptExecutionScope&) =
3511cb0ef41Sopenharmony_ci        delete;
3521cb0ef41Sopenharmony_ci    AllowJavascriptExecutionScope& operator=(
3531cb0ef41Sopenharmony_ci        const AllowJavascriptExecutionScope&) = delete;
3541cb0ef41Sopenharmony_ci
3551cb0ef41Sopenharmony_ci   private:
3561cb0ef41Sopenharmony_ci    Isolate* isolate_;
3571cb0ef41Sopenharmony_ci    bool was_execution_allowed_assert_;
3581cb0ef41Sopenharmony_ci    bool was_execution_allowed_throws_;
3591cb0ef41Sopenharmony_ci    bool was_execution_allowed_dump_;
3601cb0ef41Sopenharmony_ci  };
3611cb0ef41Sopenharmony_ci
3621cb0ef41Sopenharmony_ci  /**
3631cb0ef41Sopenharmony_ci   * Do not run microtasks while this scope is active, even if microtasks are
3641cb0ef41Sopenharmony_ci   * automatically executed otherwise.
3651cb0ef41Sopenharmony_ci   */
3661cb0ef41Sopenharmony_ci  class V8_EXPORT V8_NODISCARD SuppressMicrotaskExecutionScope {
3671cb0ef41Sopenharmony_ci   public:
3681cb0ef41Sopenharmony_ci    explicit SuppressMicrotaskExecutionScope(
3691cb0ef41Sopenharmony_ci        Isolate* isolate, MicrotaskQueue* microtask_queue = nullptr);
3701cb0ef41Sopenharmony_ci    ~SuppressMicrotaskExecutionScope();
3711cb0ef41Sopenharmony_ci
3721cb0ef41Sopenharmony_ci    // Prevent copying of Scope objects.
3731cb0ef41Sopenharmony_ci    SuppressMicrotaskExecutionScope(const SuppressMicrotaskExecutionScope&) =
3741cb0ef41Sopenharmony_ci        delete;
3751cb0ef41Sopenharmony_ci    SuppressMicrotaskExecutionScope& operator=(
3761cb0ef41Sopenharmony_ci        const SuppressMicrotaskExecutionScope&) = delete;
3771cb0ef41Sopenharmony_ci
3781cb0ef41Sopenharmony_ci   private:
3791cb0ef41Sopenharmony_ci    internal::Isolate* const isolate_;
3801cb0ef41Sopenharmony_ci    internal::MicrotaskQueue* const microtask_queue_;
3811cb0ef41Sopenharmony_ci    internal::Address previous_stack_height_;
3821cb0ef41Sopenharmony_ci
3831cb0ef41Sopenharmony_ci    friend class internal::ThreadLocalTop;
3841cb0ef41Sopenharmony_ci  };
3851cb0ef41Sopenharmony_ci
3861cb0ef41Sopenharmony_ci  /**
3871cb0ef41Sopenharmony_ci   * This scope allows terminations inside direct V8 API calls and forbid them
3881cb0ef41Sopenharmony_ci   * inside any recursive API calls without explicit SafeForTerminationScope.
3891cb0ef41Sopenharmony_ci   */
3901cb0ef41Sopenharmony_ci  class V8_EXPORT V8_NODISCARD SafeForTerminationScope {
3911cb0ef41Sopenharmony_ci   public:
3921cb0ef41Sopenharmony_ci    explicit SafeForTerminationScope(v8::Isolate* isolate);
3931cb0ef41Sopenharmony_ci    ~SafeForTerminationScope();
3941cb0ef41Sopenharmony_ci
3951cb0ef41Sopenharmony_ci    // Prevent copying of Scope objects.
3961cb0ef41Sopenharmony_ci    SafeForTerminationScope(const SafeForTerminationScope&) = delete;
3971cb0ef41Sopenharmony_ci    SafeForTerminationScope& operator=(const SafeForTerminationScope&) = delete;
3981cb0ef41Sopenharmony_ci
3991cb0ef41Sopenharmony_ci   private:
4001cb0ef41Sopenharmony_ci    internal::Isolate* isolate_;
4011cb0ef41Sopenharmony_ci    bool prev_value_;
4021cb0ef41Sopenharmony_ci  };
4031cb0ef41Sopenharmony_ci
4041cb0ef41Sopenharmony_ci  /**
4051cb0ef41Sopenharmony_ci   * Types of garbage collections that can be requested via
4061cb0ef41Sopenharmony_ci   * RequestGarbageCollectionForTesting.
4071cb0ef41Sopenharmony_ci   */
4081cb0ef41Sopenharmony_ci  enum GarbageCollectionType {
4091cb0ef41Sopenharmony_ci    kFullGarbageCollection,
4101cb0ef41Sopenharmony_ci    kMinorGarbageCollection
4111cb0ef41Sopenharmony_ci  };
4121cb0ef41Sopenharmony_ci
4131cb0ef41Sopenharmony_ci  /**
4141cb0ef41Sopenharmony_ci   * Features reported via the SetUseCounterCallback callback. Do not change
4151cb0ef41Sopenharmony_ci   * assigned numbers of existing items; add new features to the end of this
4161cb0ef41Sopenharmony_ci   * list.
4171cb0ef41Sopenharmony_ci   */
4181cb0ef41Sopenharmony_ci  enum UseCounterFeature {
4191cb0ef41Sopenharmony_ci    kUseAsm = 0,
4201cb0ef41Sopenharmony_ci    kBreakIterator = 1,
4211cb0ef41Sopenharmony_ci    kLegacyConst = 2,
4221cb0ef41Sopenharmony_ci    kMarkDequeOverflow = 3,
4231cb0ef41Sopenharmony_ci    kStoreBufferOverflow = 4,
4241cb0ef41Sopenharmony_ci    kSlotsBufferOverflow = 5,
4251cb0ef41Sopenharmony_ci    kObjectObserve = 6,
4261cb0ef41Sopenharmony_ci    kForcedGC = 7,
4271cb0ef41Sopenharmony_ci    kSloppyMode = 8,
4281cb0ef41Sopenharmony_ci    kStrictMode = 9,
4291cb0ef41Sopenharmony_ci    kStrongMode = 10,
4301cb0ef41Sopenharmony_ci    kRegExpPrototypeStickyGetter = 11,
4311cb0ef41Sopenharmony_ci    kRegExpPrototypeToString = 12,
4321cb0ef41Sopenharmony_ci    kRegExpPrototypeUnicodeGetter = 13,
4331cb0ef41Sopenharmony_ci    kIntlV8Parse = 14,
4341cb0ef41Sopenharmony_ci    kIntlPattern = 15,
4351cb0ef41Sopenharmony_ci    kIntlResolved = 16,
4361cb0ef41Sopenharmony_ci    kPromiseChain = 17,
4371cb0ef41Sopenharmony_ci    kPromiseAccept = 18,
4381cb0ef41Sopenharmony_ci    kPromiseDefer = 19,
4391cb0ef41Sopenharmony_ci    kHtmlCommentInExternalScript = 20,
4401cb0ef41Sopenharmony_ci    kHtmlComment = 21,
4411cb0ef41Sopenharmony_ci    kSloppyModeBlockScopedFunctionRedefinition = 22,
4421cb0ef41Sopenharmony_ci    kForInInitializer = 23,
4431cb0ef41Sopenharmony_ci    kArrayProtectorDirtied = 24,
4441cb0ef41Sopenharmony_ci    kArraySpeciesModified = 25,
4451cb0ef41Sopenharmony_ci    kArrayPrototypeConstructorModified = 26,
4461cb0ef41Sopenharmony_ci    kArrayInstanceProtoModified = 27,
4471cb0ef41Sopenharmony_ci    kArrayInstanceConstructorModified = 28,
4481cb0ef41Sopenharmony_ci    kLegacyFunctionDeclaration = 29,
4491cb0ef41Sopenharmony_ci    kRegExpPrototypeSourceGetter = 30,   // Unused.
4501cb0ef41Sopenharmony_ci    kRegExpPrototypeOldFlagGetter = 31,  // Unused.
4511cb0ef41Sopenharmony_ci    kDecimalWithLeadingZeroInStrictMode = 32,
4521cb0ef41Sopenharmony_ci    kLegacyDateParser = 33,
4531cb0ef41Sopenharmony_ci    kDefineGetterOrSetterWouldThrow = 34,
4541cb0ef41Sopenharmony_ci    kFunctionConstructorReturnedUndefined = 35,
4551cb0ef41Sopenharmony_ci    kAssigmentExpressionLHSIsCallInSloppy = 36,
4561cb0ef41Sopenharmony_ci    kAssigmentExpressionLHSIsCallInStrict = 37,
4571cb0ef41Sopenharmony_ci    kPromiseConstructorReturnedUndefined = 38,
4581cb0ef41Sopenharmony_ci    kConstructorNonUndefinedPrimitiveReturn = 39,
4591cb0ef41Sopenharmony_ci    kLabeledExpressionStatement = 40,
4601cb0ef41Sopenharmony_ci    kLineOrParagraphSeparatorAsLineTerminator = 41,
4611cb0ef41Sopenharmony_ci    kIndexAccessor = 42,
4621cb0ef41Sopenharmony_ci    kErrorCaptureStackTrace = 43,
4631cb0ef41Sopenharmony_ci    kErrorPrepareStackTrace = 44,
4641cb0ef41Sopenharmony_ci    kErrorStackTraceLimit = 45,
4651cb0ef41Sopenharmony_ci    kWebAssemblyInstantiation = 46,
4661cb0ef41Sopenharmony_ci    kDeoptimizerDisableSpeculation = 47,
4671cb0ef41Sopenharmony_ci    kArrayPrototypeSortJSArrayModifiedPrototype = 48,
4681cb0ef41Sopenharmony_ci    kFunctionTokenOffsetTooLongForToString = 49,
4691cb0ef41Sopenharmony_ci    kWasmSharedMemory = 50,
4701cb0ef41Sopenharmony_ci    kWasmThreadOpcodes = 51,
4711cb0ef41Sopenharmony_ci    kAtomicsNotify = 52,  // Unused.
4721cb0ef41Sopenharmony_ci    kAtomicsWake = 53,    // Unused.
4731cb0ef41Sopenharmony_ci    kCollator = 54,
4741cb0ef41Sopenharmony_ci    kNumberFormat = 55,
4751cb0ef41Sopenharmony_ci    kDateTimeFormat = 56,
4761cb0ef41Sopenharmony_ci    kPluralRules = 57,
4771cb0ef41Sopenharmony_ci    kRelativeTimeFormat = 58,
4781cb0ef41Sopenharmony_ci    kLocale = 59,
4791cb0ef41Sopenharmony_ci    kListFormat = 60,
4801cb0ef41Sopenharmony_ci    kSegmenter = 61,
4811cb0ef41Sopenharmony_ci    kStringLocaleCompare = 62,
4821cb0ef41Sopenharmony_ci    kStringToLocaleUpperCase = 63,
4831cb0ef41Sopenharmony_ci    kStringToLocaleLowerCase = 64,
4841cb0ef41Sopenharmony_ci    kNumberToLocaleString = 65,
4851cb0ef41Sopenharmony_ci    kDateToLocaleString = 66,
4861cb0ef41Sopenharmony_ci    kDateToLocaleDateString = 67,
4871cb0ef41Sopenharmony_ci    kDateToLocaleTimeString = 68,
4881cb0ef41Sopenharmony_ci    kAttemptOverrideReadOnlyOnPrototypeSloppy = 69,
4891cb0ef41Sopenharmony_ci    kAttemptOverrideReadOnlyOnPrototypeStrict = 70,
4901cb0ef41Sopenharmony_ci    kOptimizedFunctionWithOneShotBytecode = 71,  // Unused.
4911cb0ef41Sopenharmony_ci    kRegExpMatchIsTrueishOnNonJSRegExp = 72,
4921cb0ef41Sopenharmony_ci    kRegExpMatchIsFalseishOnJSRegExp = 73,
4931cb0ef41Sopenharmony_ci    kDateGetTimezoneOffset = 74,  // Unused.
4941cb0ef41Sopenharmony_ci    kStringNormalize = 75,
4951cb0ef41Sopenharmony_ci    kCallSiteAPIGetFunctionSloppyCall = 76,
4961cb0ef41Sopenharmony_ci    kCallSiteAPIGetThisSloppyCall = 77,
4971cb0ef41Sopenharmony_ci    kRegExpMatchAllWithNonGlobalRegExp = 78,
4981cb0ef41Sopenharmony_ci    kRegExpExecCalledOnSlowRegExp = 79,
4991cb0ef41Sopenharmony_ci    kRegExpReplaceCalledOnSlowRegExp = 80,
5001cb0ef41Sopenharmony_ci    kDisplayNames = 81,
5011cb0ef41Sopenharmony_ci    kSharedArrayBufferConstructed = 82,
5021cb0ef41Sopenharmony_ci    kArrayPrototypeHasElements = 83,
5031cb0ef41Sopenharmony_ci    kObjectPrototypeHasElements = 84,
5041cb0ef41Sopenharmony_ci    kNumberFormatStyleUnit = 85,
5051cb0ef41Sopenharmony_ci    kDateTimeFormatRange = 86,
5061cb0ef41Sopenharmony_ci    kDateTimeFormatDateTimeStyle = 87,
5071cb0ef41Sopenharmony_ci    kBreakIteratorTypeWord = 88,
5081cb0ef41Sopenharmony_ci    kBreakIteratorTypeLine = 89,
5091cb0ef41Sopenharmony_ci    kInvalidatedArrayBufferDetachingProtector = 90,
5101cb0ef41Sopenharmony_ci    kInvalidatedArrayConstructorProtector = 91,
5111cb0ef41Sopenharmony_ci    kInvalidatedArrayIteratorLookupChainProtector = 92,
5121cb0ef41Sopenharmony_ci    kInvalidatedArraySpeciesLookupChainProtector = 93,
5131cb0ef41Sopenharmony_ci    kInvalidatedIsConcatSpreadableLookupChainProtector = 94,
5141cb0ef41Sopenharmony_ci    kInvalidatedMapIteratorLookupChainProtector = 95,
5151cb0ef41Sopenharmony_ci    kInvalidatedNoElementsProtector = 96,
5161cb0ef41Sopenharmony_ci    kInvalidatedPromiseHookProtector = 97,
5171cb0ef41Sopenharmony_ci    kInvalidatedPromiseResolveLookupChainProtector = 98,
5181cb0ef41Sopenharmony_ci    kInvalidatedPromiseSpeciesLookupChainProtector = 99,
5191cb0ef41Sopenharmony_ci    kInvalidatedPromiseThenLookupChainProtector = 100,
5201cb0ef41Sopenharmony_ci    kInvalidatedRegExpSpeciesLookupChainProtector = 101,
5211cb0ef41Sopenharmony_ci    kInvalidatedSetIteratorLookupChainProtector = 102,
5221cb0ef41Sopenharmony_ci    kInvalidatedStringIteratorLookupChainProtector = 103,
5231cb0ef41Sopenharmony_ci    kInvalidatedStringLengthOverflowLookupChainProtector = 104,
5241cb0ef41Sopenharmony_ci    kInvalidatedTypedArraySpeciesLookupChainProtector = 105,
5251cb0ef41Sopenharmony_ci    kWasmSimdOpcodes = 106,
5261cb0ef41Sopenharmony_ci    kVarRedeclaredCatchBinding = 107,
5271cb0ef41Sopenharmony_ci    kWasmRefTypes = 108,
5281cb0ef41Sopenharmony_ci    kWasmBulkMemory = 109,  // Unused.
5291cb0ef41Sopenharmony_ci    kWasmMultiValue = 110,
5301cb0ef41Sopenharmony_ci    kWasmExceptionHandling = 111,
5311cb0ef41Sopenharmony_ci    kInvalidatedMegaDOMProtector = 112,
5321cb0ef41Sopenharmony_ci    kFunctionPrototypeArguments = 113,
5331cb0ef41Sopenharmony_ci    kFunctionPrototypeCaller = 114,
5341cb0ef41Sopenharmony_ci
5351cb0ef41Sopenharmony_ci    // If you add new values here, you'll also need to update Chromium's:
5361cb0ef41Sopenharmony_ci    // web_feature.mojom, use_counter_callback.cc, and enums.xml. V8 changes to
5371cb0ef41Sopenharmony_ci    // this list need to be landed first, then changes on the Chromium side.
5381cb0ef41Sopenharmony_ci    kUseCounterFeatureCount  // This enum value must be last.
5391cb0ef41Sopenharmony_ci  };
5401cb0ef41Sopenharmony_ci
5411cb0ef41Sopenharmony_ci  enum MessageErrorLevel {
5421cb0ef41Sopenharmony_ci    kMessageLog = (1 << 0),
5431cb0ef41Sopenharmony_ci    kMessageDebug = (1 << 1),
5441cb0ef41Sopenharmony_ci    kMessageInfo = (1 << 2),
5451cb0ef41Sopenharmony_ci    kMessageError = (1 << 3),
5461cb0ef41Sopenharmony_ci    kMessageWarning = (1 << 4),
5471cb0ef41Sopenharmony_ci    kMessageAll = kMessageLog | kMessageDebug | kMessageInfo | kMessageError |
5481cb0ef41Sopenharmony_ci                  kMessageWarning,
5491cb0ef41Sopenharmony_ci  };
5501cb0ef41Sopenharmony_ci
5511cb0ef41Sopenharmony_ci  using UseCounterCallback = void (*)(Isolate* isolate,
5521cb0ef41Sopenharmony_ci                                      UseCounterFeature feature);
5531cb0ef41Sopenharmony_ci
5541cb0ef41Sopenharmony_ci  /**
5551cb0ef41Sopenharmony_ci   * Allocates a new isolate but does not initialize it. Does not change the
5561cb0ef41Sopenharmony_ci   * currently entered isolate.
5571cb0ef41Sopenharmony_ci   *
5581cb0ef41Sopenharmony_ci   * Only Isolate::GetData() and Isolate::SetData(), which access the
5591cb0ef41Sopenharmony_ci   * embedder-controlled parts of the isolate, are allowed to be called on the
5601cb0ef41Sopenharmony_ci   * uninitialized isolate. To initialize the isolate, call
5611cb0ef41Sopenharmony_ci   * Isolate::Initialize().
5621cb0ef41Sopenharmony_ci   *
5631cb0ef41Sopenharmony_ci   * When an isolate is no longer used its resources should be freed
5641cb0ef41Sopenharmony_ci   * by calling Dispose().  Using the delete operator is not allowed.
5651cb0ef41Sopenharmony_ci   *
5661cb0ef41Sopenharmony_ci   * V8::Initialize() must have run prior to this.
5671cb0ef41Sopenharmony_ci   */
5681cb0ef41Sopenharmony_ci  static Isolate* Allocate();
5691cb0ef41Sopenharmony_ci
5701cb0ef41Sopenharmony_ci  /**
5711cb0ef41Sopenharmony_ci   * Initialize an Isolate previously allocated by Isolate::Allocate().
5721cb0ef41Sopenharmony_ci   */
5731cb0ef41Sopenharmony_ci  static void Initialize(Isolate* isolate, const CreateParams& params);
5741cb0ef41Sopenharmony_ci
5751cb0ef41Sopenharmony_ci  /**
5761cb0ef41Sopenharmony_ci   * Creates a new isolate.  Does not change the currently entered
5771cb0ef41Sopenharmony_ci   * isolate.
5781cb0ef41Sopenharmony_ci   *
5791cb0ef41Sopenharmony_ci   * When an isolate is no longer used its resources should be freed
5801cb0ef41Sopenharmony_ci   * by calling Dispose().  Using the delete operator is not allowed.
5811cb0ef41Sopenharmony_ci   *
5821cb0ef41Sopenharmony_ci   * V8::Initialize() must have run prior to this.
5831cb0ef41Sopenharmony_ci   */
5841cb0ef41Sopenharmony_ci  static Isolate* New(const CreateParams& params);
5851cb0ef41Sopenharmony_ci
5861cb0ef41Sopenharmony_ci  /**
5871cb0ef41Sopenharmony_ci   * Returns the entered isolate for the current thread or NULL in
5881cb0ef41Sopenharmony_ci   * case there is no current isolate.
5891cb0ef41Sopenharmony_ci   *
5901cb0ef41Sopenharmony_ci   * This method must not be invoked before V8::Initialize() was invoked.
5911cb0ef41Sopenharmony_ci   */
5921cb0ef41Sopenharmony_ci  static Isolate* GetCurrent();
5931cb0ef41Sopenharmony_ci
5941cb0ef41Sopenharmony_ci  /**
5951cb0ef41Sopenharmony_ci   * Returns the entered isolate for the current thread or NULL in
5961cb0ef41Sopenharmony_ci   * case there is no current isolate.
5971cb0ef41Sopenharmony_ci   *
5981cb0ef41Sopenharmony_ci   * No checks are performed by this method.
5991cb0ef41Sopenharmony_ci   */
6001cb0ef41Sopenharmony_ci  static Isolate* TryGetCurrent();
6011cb0ef41Sopenharmony_ci
6021cb0ef41Sopenharmony_ci  /**
6031cb0ef41Sopenharmony_ci   * Return true if this isolate is currently active.
6041cb0ef41Sopenharmony_ci   **/
6051cb0ef41Sopenharmony_ci  bool IsCurrent() const;
6061cb0ef41Sopenharmony_ci
6071cb0ef41Sopenharmony_ci  /**
6081cb0ef41Sopenharmony_ci   * Clears the set of objects held strongly by the heap. This set of
6091cb0ef41Sopenharmony_ci   * objects are originally built when a WeakRef is created or
6101cb0ef41Sopenharmony_ci   * successfully dereferenced.
6111cb0ef41Sopenharmony_ci   *
6121cb0ef41Sopenharmony_ci   * This is invoked automatically after microtasks are run. See
6131cb0ef41Sopenharmony_ci   * MicrotasksPolicy for when microtasks are run.
6141cb0ef41Sopenharmony_ci   *
6151cb0ef41Sopenharmony_ci   * This needs to be manually invoked only if the embedder is manually running
6161cb0ef41Sopenharmony_ci   * microtasks via a custom MicrotaskQueue class's PerformCheckpoint. In that
6171cb0ef41Sopenharmony_ci   * case, it is the embedder's responsibility to make this call at a time which
6181cb0ef41Sopenharmony_ci   * does not interrupt synchronous ECMAScript code execution.
6191cb0ef41Sopenharmony_ci   */
6201cb0ef41Sopenharmony_ci  void ClearKeptObjects();
6211cb0ef41Sopenharmony_ci
6221cb0ef41Sopenharmony_ci  /**
6231cb0ef41Sopenharmony_ci   * Custom callback used by embedders to help V8 determine if it should abort
6241cb0ef41Sopenharmony_ci   * when it throws and no internal handler is predicted to catch the
6251cb0ef41Sopenharmony_ci   * exception. If --abort-on-uncaught-exception is used on the command line,
6261cb0ef41Sopenharmony_ci   * then V8 will abort if either:
6271cb0ef41Sopenharmony_ci   * - no custom callback is set.
6281cb0ef41Sopenharmony_ci   * - the custom callback set returns true.
6291cb0ef41Sopenharmony_ci   * Otherwise, the custom callback will not be called and V8 will not abort.
6301cb0ef41Sopenharmony_ci   */
6311cb0ef41Sopenharmony_ci  using AbortOnUncaughtExceptionCallback = bool (*)(Isolate*);
6321cb0ef41Sopenharmony_ci  void SetAbortOnUncaughtExceptionCallback(
6331cb0ef41Sopenharmony_ci      AbortOnUncaughtExceptionCallback callback);
6341cb0ef41Sopenharmony_ci
6351cb0ef41Sopenharmony_ci  /**
6361cb0ef41Sopenharmony_ci   * This specifies the callback called by the upcoming dynamic
6371cb0ef41Sopenharmony_ci   * import() language feature to load modules.
6381cb0ef41Sopenharmony_ci   */
6391cb0ef41Sopenharmony_ci  V8_DEPRECATED("Use HostImportModuleDynamicallyCallback")
6401cb0ef41Sopenharmony_ci  void SetHostImportModuleDynamicallyCallback(
6411cb0ef41Sopenharmony_ci      HostImportModuleDynamicallyWithImportAssertionsCallback callback);
6421cb0ef41Sopenharmony_ci  void SetHostImportModuleDynamicallyCallback(
6431cb0ef41Sopenharmony_ci      HostImportModuleDynamicallyCallback callback);
6441cb0ef41Sopenharmony_ci
6451cb0ef41Sopenharmony_ci  /**
6461cb0ef41Sopenharmony_ci   * This specifies the callback called by the upcoming import.meta
6471cb0ef41Sopenharmony_ci   * language feature to retrieve host-defined meta data for a module.
6481cb0ef41Sopenharmony_ci   */
6491cb0ef41Sopenharmony_ci  void SetHostInitializeImportMetaObjectCallback(
6501cb0ef41Sopenharmony_ci      HostInitializeImportMetaObjectCallback callback);
6511cb0ef41Sopenharmony_ci
6521cb0ef41Sopenharmony_ci  /**
6531cb0ef41Sopenharmony_ci   * This specifies the callback called by the upcoming ShadowRealm
6541cb0ef41Sopenharmony_ci   * construction language feature to retrieve host created globals.
6551cb0ef41Sopenharmony_ci   */
6561cb0ef41Sopenharmony_ci  void SetHostCreateShadowRealmContextCallback(
6571cb0ef41Sopenharmony_ci      HostCreateShadowRealmContextCallback callback);
6581cb0ef41Sopenharmony_ci
6591cb0ef41Sopenharmony_ci  /**
6601cb0ef41Sopenharmony_ci   * This specifies the callback called when the stack property of Error
6611cb0ef41Sopenharmony_ci   * is accessed.
6621cb0ef41Sopenharmony_ci   */
6631cb0ef41Sopenharmony_ci  void SetPrepareStackTraceCallback(PrepareStackTraceCallback callback);
6641cb0ef41Sopenharmony_ci
6651cb0ef41Sopenharmony_ci  /**
6661cb0ef41Sopenharmony_ci   * Optional notification that the system is running low on memory.
6671cb0ef41Sopenharmony_ci   * V8 uses these notifications to guide heuristics.
6681cb0ef41Sopenharmony_ci   * It is allowed to call this function from another thread while
6691cb0ef41Sopenharmony_ci   * the isolate is executing long running JavaScript code.
6701cb0ef41Sopenharmony_ci   */
6711cb0ef41Sopenharmony_ci  void MemoryPressureNotification(MemoryPressureLevel level);
6721cb0ef41Sopenharmony_ci
6731cb0ef41Sopenharmony_ci  /**
6741cb0ef41Sopenharmony_ci   * Drop non-essential caches. Should only be called from testing code.
6751cb0ef41Sopenharmony_ci   * The method can potentially block for a long time and does not necessarily
6761cb0ef41Sopenharmony_ci   * trigger GC.
6771cb0ef41Sopenharmony_ci   */
6781cb0ef41Sopenharmony_ci  void ClearCachesForTesting();
6791cb0ef41Sopenharmony_ci
6801cb0ef41Sopenharmony_ci  /**
6811cb0ef41Sopenharmony_ci   * Methods below this point require holding a lock (using Locker) in
6821cb0ef41Sopenharmony_ci   * a multi-threaded environment.
6831cb0ef41Sopenharmony_ci   */
6841cb0ef41Sopenharmony_ci
6851cb0ef41Sopenharmony_ci  /**
6861cb0ef41Sopenharmony_ci   * Sets this isolate as the entered one for the current thread.
6871cb0ef41Sopenharmony_ci   * Saves the previously entered one (if any), so that it can be
6881cb0ef41Sopenharmony_ci   * restored when exiting.  Re-entering an isolate is allowed.
6891cb0ef41Sopenharmony_ci   */
6901cb0ef41Sopenharmony_ci  void Enter();
6911cb0ef41Sopenharmony_ci
6921cb0ef41Sopenharmony_ci  /**
6931cb0ef41Sopenharmony_ci   * Exits this isolate by restoring the previously entered one in the
6941cb0ef41Sopenharmony_ci   * current thread.  The isolate may still stay the same, if it was
6951cb0ef41Sopenharmony_ci   * entered more than once.
6961cb0ef41Sopenharmony_ci   *
6971cb0ef41Sopenharmony_ci   * Requires: this == Isolate::GetCurrent().
6981cb0ef41Sopenharmony_ci   */
6991cb0ef41Sopenharmony_ci  void Exit();
7001cb0ef41Sopenharmony_ci
7011cb0ef41Sopenharmony_ci  /**
7021cb0ef41Sopenharmony_ci   * Disposes the isolate.  The isolate must not be entered by any
7031cb0ef41Sopenharmony_ci   * thread to be disposable.
7041cb0ef41Sopenharmony_ci   */
7051cb0ef41Sopenharmony_ci  void Dispose();
7061cb0ef41Sopenharmony_ci
7071cb0ef41Sopenharmony_ci  /**
7081cb0ef41Sopenharmony_ci   * Dumps activated low-level V8 internal stats. This can be used instead
7091cb0ef41Sopenharmony_ci   * of performing a full isolate disposal.
7101cb0ef41Sopenharmony_ci   */
7111cb0ef41Sopenharmony_ci  void DumpAndResetStats();
7121cb0ef41Sopenharmony_ci
7131cb0ef41Sopenharmony_ci  /**
7141cb0ef41Sopenharmony_ci   * Discards all V8 thread-specific data for the Isolate. Should be used
7151cb0ef41Sopenharmony_ci   * if a thread is terminating and it has used an Isolate that will outlive
7161cb0ef41Sopenharmony_ci   * the thread -- all thread-specific data for an Isolate is discarded when
7171cb0ef41Sopenharmony_ci   * an Isolate is disposed so this call is pointless if an Isolate is about
7181cb0ef41Sopenharmony_ci   * to be Disposed.
7191cb0ef41Sopenharmony_ci   */
7201cb0ef41Sopenharmony_ci  void DiscardThreadSpecificMetadata();
7211cb0ef41Sopenharmony_ci
7221cb0ef41Sopenharmony_ci  /**
7231cb0ef41Sopenharmony_ci   * Associate embedder-specific data with the isolate. |slot| has to be
7241cb0ef41Sopenharmony_ci   * between 0 and GetNumberOfDataSlots() - 1.
7251cb0ef41Sopenharmony_ci   */
7261cb0ef41Sopenharmony_ci  V8_INLINE void SetData(uint32_t slot, void* data);
7271cb0ef41Sopenharmony_ci
7281cb0ef41Sopenharmony_ci  /**
7291cb0ef41Sopenharmony_ci   * Retrieve embedder-specific data from the isolate.
7301cb0ef41Sopenharmony_ci   * Returns NULL if SetData has never been called for the given |slot|.
7311cb0ef41Sopenharmony_ci   */
7321cb0ef41Sopenharmony_ci  V8_INLINE void* GetData(uint32_t slot);
7331cb0ef41Sopenharmony_ci
7341cb0ef41Sopenharmony_ci  /**
7351cb0ef41Sopenharmony_ci   * Returns the maximum number of available embedder data slots. Valid slots
7361cb0ef41Sopenharmony_ci   * are in the range of 0 - GetNumberOfDataSlots() - 1.
7371cb0ef41Sopenharmony_ci   */
7381cb0ef41Sopenharmony_ci  V8_INLINE static uint32_t GetNumberOfDataSlots();
7391cb0ef41Sopenharmony_ci
7401cb0ef41Sopenharmony_ci  /**
7411cb0ef41Sopenharmony_ci   * Return data that was previously attached to the isolate snapshot via
7421cb0ef41Sopenharmony_ci   * SnapshotCreator, and removes the reference to it.
7431cb0ef41Sopenharmony_ci   * Repeated call with the same index returns an empty MaybeLocal.
7441cb0ef41Sopenharmony_ci   */
7451cb0ef41Sopenharmony_ci  template <class T>
7461cb0ef41Sopenharmony_ci  V8_INLINE MaybeLocal<T> GetDataFromSnapshotOnce(size_t index);
7471cb0ef41Sopenharmony_ci
7481cb0ef41Sopenharmony_ci  /**
7491cb0ef41Sopenharmony_ci   * Get statistics about the heap memory usage.
7501cb0ef41Sopenharmony_ci   */
7511cb0ef41Sopenharmony_ci  void GetHeapStatistics(HeapStatistics* heap_statistics);
7521cb0ef41Sopenharmony_ci
7531cb0ef41Sopenharmony_ci  /**
7541cb0ef41Sopenharmony_ci   * Returns the number of spaces in the heap.
7551cb0ef41Sopenharmony_ci   */
7561cb0ef41Sopenharmony_ci  size_t NumberOfHeapSpaces();
7571cb0ef41Sopenharmony_ci
7581cb0ef41Sopenharmony_ci  /**
7591cb0ef41Sopenharmony_ci   * Get the memory usage of a space in the heap.
7601cb0ef41Sopenharmony_ci   *
7611cb0ef41Sopenharmony_ci   * \param space_statistics The HeapSpaceStatistics object to fill in
7621cb0ef41Sopenharmony_ci   *   statistics.
7631cb0ef41Sopenharmony_ci   * \param index The index of the space to get statistics from, which ranges
7641cb0ef41Sopenharmony_ci   *   from 0 to NumberOfHeapSpaces() - 1.
7651cb0ef41Sopenharmony_ci   * \returns true on success.
7661cb0ef41Sopenharmony_ci   */
7671cb0ef41Sopenharmony_ci  bool GetHeapSpaceStatistics(HeapSpaceStatistics* space_statistics,
7681cb0ef41Sopenharmony_ci                              size_t index);
7691cb0ef41Sopenharmony_ci
7701cb0ef41Sopenharmony_ci  /**
7711cb0ef41Sopenharmony_ci   * Returns the number of types of objects tracked in the heap at GC.
7721cb0ef41Sopenharmony_ci   */
7731cb0ef41Sopenharmony_ci  size_t NumberOfTrackedHeapObjectTypes();
7741cb0ef41Sopenharmony_ci
7751cb0ef41Sopenharmony_ci  /**
7761cb0ef41Sopenharmony_ci   * Get statistics about objects in the heap.
7771cb0ef41Sopenharmony_ci   *
7781cb0ef41Sopenharmony_ci   * \param object_statistics The HeapObjectStatistics object to fill in
7791cb0ef41Sopenharmony_ci   *   statistics of objects of given type, which were live in the previous GC.
7801cb0ef41Sopenharmony_ci   * \param type_index The index of the type of object to fill details about,
7811cb0ef41Sopenharmony_ci   *   which ranges from 0 to NumberOfTrackedHeapObjectTypes() - 1.
7821cb0ef41Sopenharmony_ci   * \returns true on success.
7831cb0ef41Sopenharmony_ci   */
7841cb0ef41Sopenharmony_ci  bool GetHeapObjectStatisticsAtLastGC(HeapObjectStatistics* object_statistics,
7851cb0ef41Sopenharmony_ci                                       size_t type_index);
7861cb0ef41Sopenharmony_ci
7871cb0ef41Sopenharmony_ci  /**
7881cb0ef41Sopenharmony_ci   * Get statistics about code and its metadata in the heap.
7891cb0ef41Sopenharmony_ci   *
7901cb0ef41Sopenharmony_ci   * \param object_statistics The HeapCodeStatistics object to fill in
7911cb0ef41Sopenharmony_ci   *   statistics of code, bytecode and their metadata.
7921cb0ef41Sopenharmony_ci   * \returns true on success.
7931cb0ef41Sopenharmony_ci   */
7941cb0ef41Sopenharmony_ci  bool GetHeapCodeAndMetadataStatistics(HeapCodeStatistics* object_statistics);
7951cb0ef41Sopenharmony_ci
7961cb0ef41Sopenharmony_ci  /**
7971cb0ef41Sopenharmony_ci   * This API is experimental and may change significantly.
7981cb0ef41Sopenharmony_ci   *
7991cb0ef41Sopenharmony_ci   * Enqueues a memory measurement request and invokes the delegate with the
8001cb0ef41Sopenharmony_ci   * results.
8011cb0ef41Sopenharmony_ci   *
8021cb0ef41Sopenharmony_ci   * \param delegate the delegate that defines which contexts to measure and
8031cb0ef41Sopenharmony_ci   *   reports the results.
8041cb0ef41Sopenharmony_ci   *
8051cb0ef41Sopenharmony_ci   * \param execution promptness executing the memory measurement.
8061cb0ef41Sopenharmony_ci   *   The kEager value is expected to be used only in tests.
8071cb0ef41Sopenharmony_ci   */
8081cb0ef41Sopenharmony_ci  bool MeasureMemory(
8091cb0ef41Sopenharmony_ci      std::unique_ptr<MeasureMemoryDelegate> delegate,
8101cb0ef41Sopenharmony_ci      MeasureMemoryExecution execution = MeasureMemoryExecution::kDefault);
8111cb0ef41Sopenharmony_ci
8121cb0ef41Sopenharmony_ci  /**
8131cb0ef41Sopenharmony_ci   * Get a call stack sample from the isolate.
8141cb0ef41Sopenharmony_ci   * \param state Execution state.
8151cb0ef41Sopenharmony_ci   * \param frames Caller allocated buffer to store stack frames.
8161cb0ef41Sopenharmony_ci   * \param frames_limit Maximum number of frames to capture. The buffer must
8171cb0ef41Sopenharmony_ci   *                     be large enough to hold the number of frames.
8181cb0ef41Sopenharmony_ci   * \param sample_info The sample info is filled up by the function
8191cb0ef41Sopenharmony_ci   *                    provides number of actual captured stack frames and
8201cb0ef41Sopenharmony_ci   *                    the current VM state.
8211cb0ef41Sopenharmony_ci   * \note GetStackSample should only be called when the JS thread is paused or
8221cb0ef41Sopenharmony_ci   *       interrupted. Otherwise the behavior is undefined.
8231cb0ef41Sopenharmony_ci   */
8241cb0ef41Sopenharmony_ci  void GetStackSample(const RegisterState& state, void** frames,
8251cb0ef41Sopenharmony_ci                      size_t frames_limit, SampleInfo* sample_info);
8261cb0ef41Sopenharmony_ci
8271cb0ef41Sopenharmony_ci  /**
8281cb0ef41Sopenharmony_ci   * Adjusts the amount of registered external memory. Used to give V8 an
8291cb0ef41Sopenharmony_ci   * indication of the amount of externally allocated memory that is kept alive
8301cb0ef41Sopenharmony_ci   * by JavaScript objects. V8 uses this to decide when to perform global
8311cb0ef41Sopenharmony_ci   * garbage collections. Registering externally allocated memory will trigger
8321cb0ef41Sopenharmony_ci   * global garbage collections more often than it would otherwise in an attempt
8331cb0ef41Sopenharmony_ci   * to garbage collect the JavaScript objects that keep the externally
8341cb0ef41Sopenharmony_ci   * allocated memory alive.
8351cb0ef41Sopenharmony_ci   *
8361cb0ef41Sopenharmony_ci   * \param change_in_bytes the change in externally allocated memory that is
8371cb0ef41Sopenharmony_ci   *   kept alive by JavaScript objects.
8381cb0ef41Sopenharmony_ci   * \returns the adjusted value.
8391cb0ef41Sopenharmony_ci   */
8401cb0ef41Sopenharmony_ci  int64_t AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes);
8411cb0ef41Sopenharmony_ci
8421cb0ef41Sopenharmony_ci  /**
8431cb0ef41Sopenharmony_ci   * Returns the number of phantom handles without callbacks that were reset
8441cb0ef41Sopenharmony_ci   * by the garbage collector since the last call to this function.
8451cb0ef41Sopenharmony_ci   */
8461cb0ef41Sopenharmony_ci  size_t NumberOfPhantomHandleResetsSinceLastCall();
8471cb0ef41Sopenharmony_ci
8481cb0ef41Sopenharmony_ci  /**
8491cb0ef41Sopenharmony_ci   * Returns heap profiler for this isolate. Will return NULL until the isolate
8501cb0ef41Sopenharmony_ci   * is initialized.
8511cb0ef41Sopenharmony_ci   */
8521cb0ef41Sopenharmony_ci  HeapProfiler* GetHeapProfiler();
8531cb0ef41Sopenharmony_ci
8541cb0ef41Sopenharmony_ci  /**
8551cb0ef41Sopenharmony_ci   * Tells the VM whether the embedder is idle or not.
8561cb0ef41Sopenharmony_ci   */
8571cb0ef41Sopenharmony_ci  void SetIdle(bool is_idle);
8581cb0ef41Sopenharmony_ci
8591cb0ef41Sopenharmony_ci  /** Returns the ArrayBuffer::Allocator used in this isolate. */
8601cb0ef41Sopenharmony_ci  ArrayBuffer::Allocator* GetArrayBufferAllocator();
8611cb0ef41Sopenharmony_ci
8621cb0ef41Sopenharmony_ci  /** Returns true if this isolate has a current context. */
8631cb0ef41Sopenharmony_ci  bool InContext();
8641cb0ef41Sopenharmony_ci
8651cb0ef41Sopenharmony_ci  /**
8661cb0ef41Sopenharmony_ci   * Returns the context of the currently running JavaScript, or the context
8671cb0ef41Sopenharmony_ci   * on the top of the stack if no JavaScript is running.
8681cb0ef41Sopenharmony_ci   */
8691cb0ef41Sopenharmony_ci  Local<Context> GetCurrentContext();
8701cb0ef41Sopenharmony_ci
8711cb0ef41Sopenharmony_ci  /**
8721cb0ef41Sopenharmony_ci   * Returns either the last context entered through V8's C++ API, or the
8731cb0ef41Sopenharmony_ci   * context of the currently running microtask while processing microtasks.
8741cb0ef41Sopenharmony_ci   * If a context is entered while executing a microtask, that context is
8751cb0ef41Sopenharmony_ci   * returned.
8761cb0ef41Sopenharmony_ci   */
8771cb0ef41Sopenharmony_ci  Local<Context> GetEnteredOrMicrotaskContext();
8781cb0ef41Sopenharmony_ci
8791cb0ef41Sopenharmony_ci  /**
8801cb0ef41Sopenharmony_ci   * Returns the Context that corresponds to the Incumbent realm in HTML spec.
8811cb0ef41Sopenharmony_ci   * https://html.spec.whatwg.org/multipage/webappapis.html#incumbent
8821cb0ef41Sopenharmony_ci   */
8831cb0ef41Sopenharmony_ci  Local<Context> GetIncumbentContext();
8841cb0ef41Sopenharmony_ci
8851cb0ef41Sopenharmony_ci  /**
8861cb0ef41Sopenharmony_ci   * Schedules a v8::Exception::Error with the given message.
8871cb0ef41Sopenharmony_ci   * See ThrowException for more details. Templatized to provide compile-time
8881cb0ef41Sopenharmony_ci   * errors in case of too long strings (see v8::String::NewFromUtf8Literal).
8891cb0ef41Sopenharmony_ci   */
8901cb0ef41Sopenharmony_ci  template <int N>
8911cb0ef41Sopenharmony_ci  Local<Value> ThrowError(const char (&message)[N]) {
8921cb0ef41Sopenharmony_ci    return ThrowError(String::NewFromUtf8Literal(this, message));
8931cb0ef41Sopenharmony_ci  }
8941cb0ef41Sopenharmony_ci  Local<Value> ThrowError(Local<String> message);
8951cb0ef41Sopenharmony_ci
8961cb0ef41Sopenharmony_ci  /**
8971cb0ef41Sopenharmony_ci   * Schedules an exception to be thrown when returning to JavaScript.  When an
8981cb0ef41Sopenharmony_ci   * exception has been scheduled it is illegal to invoke any JavaScript
8991cb0ef41Sopenharmony_ci   * operation; the caller must return immediately and only after the exception
9001cb0ef41Sopenharmony_ci   * has been handled does it become legal to invoke JavaScript operations.
9011cb0ef41Sopenharmony_ci   */
9021cb0ef41Sopenharmony_ci  Local<Value> ThrowException(Local<Value> exception);
9031cb0ef41Sopenharmony_ci
9041cb0ef41Sopenharmony_ci  using GCCallback = void (*)(Isolate* isolate, GCType type,
9051cb0ef41Sopenharmony_ci                              GCCallbackFlags flags);
9061cb0ef41Sopenharmony_ci  using GCCallbackWithData = void (*)(Isolate* isolate, GCType type,
9071cb0ef41Sopenharmony_ci                                      GCCallbackFlags flags, void* data);
9081cb0ef41Sopenharmony_ci
9091cb0ef41Sopenharmony_ci  /**
9101cb0ef41Sopenharmony_ci   * Enables the host application to receive a notification before a
9111cb0ef41Sopenharmony_ci   * garbage collection. Allocations are allowed in the callback function,
9121cb0ef41Sopenharmony_ci   * but the callback is not re-entrant: if the allocation inside it will
9131cb0ef41Sopenharmony_ci   * trigger the garbage collection, the callback won't be called again.
9141cb0ef41Sopenharmony_ci   * It is possible to specify the GCType filter for your callback. But it is
9151cb0ef41Sopenharmony_ci   * not possible to register the same callback function two times with
9161cb0ef41Sopenharmony_ci   * different GCType filters.
9171cb0ef41Sopenharmony_ci   */
9181cb0ef41Sopenharmony_ci  void AddGCPrologueCallback(GCCallbackWithData callback, void* data = nullptr,
9191cb0ef41Sopenharmony_ci                             GCType gc_type_filter = kGCTypeAll);
9201cb0ef41Sopenharmony_ci  void AddGCPrologueCallback(GCCallback callback,
9211cb0ef41Sopenharmony_ci                             GCType gc_type_filter = kGCTypeAll);
9221cb0ef41Sopenharmony_ci
9231cb0ef41Sopenharmony_ci  /**
9241cb0ef41Sopenharmony_ci   * This function removes callback which was installed by
9251cb0ef41Sopenharmony_ci   * AddGCPrologueCallback function.
9261cb0ef41Sopenharmony_ci   */
9271cb0ef41Sopenharmony_ci  void RemoveGCPrologueCallback(GCCallbackWithData, void* data = nullptr);
9281cb0ef41Sopenharmony_ci  void RemoveGCPrologueCallback(GCCallback callback);
9291cb0ef41Sopenharmony_ci
9301cb0ef41Sopenharmony_ci  /**
9311cb0ef41Sopenharmony_ci   * Sets the embedder heap tracer for the isolate.
9321cb0ef41Sopenharmony_ci   * SetEmbedderHeapTracer cannot be used simultaneously with AttachCppHeap.
9331cb0ef41Sopenharmony_ci   */
9341cb0ef41Sopenharmony_ci  void SetEmbedderHeapTracer(EmbedderHeapTracer* tracer);
9351cb0ef41Sopenharmony_ci
9361cb0ef41Sopenharmony_ci  /*
9371cb0ef41Sopenharmony_ci   * Gets the currently active heap tracer for the isolate that was set with
9381cb0ef41Sopenharmony_ci   * SetEmbedderHeapTracer.
9391cb0ef41Sopenharmony_ci   */
9401cb0ef41Sopenharmony_ci  EmbedderHeapTracer* GetEmbedderHeapTracer();
9411cb0ef41Sopenharmony_ci
9421cb0ef41Sopenharmony_ci  /**
9431cb0ef41Sopenharmony_ci   * Sets an embedder roots handle that V8 should consider when performing
9441cb0ef41Sopenharmony_ci   * non-unified heap garbage collections.
9451cb0ef41Sopenharmony_ci   *
9461cb0ef41Sopenharmony_ci   * Using only EmbedderHeapTracer automatically sets up a default handler.
9471cb0ef41Sopenharmony_ci   * The intended use case is for setting a custom handler after invoking
9481cb0ef41Sopenharmony_ci   * `AttachCppHeap()`.
9491cb0ef41Sopenharmony_ci   *
9501cb0ef41Sopenharmony_ci   * V8 does not take ownership of the handler.
9511cb0ef41Sopenharmony_ci   */
9521cb0ef41Sopenharmony_ci  void SetEmbedderRootsHandler(EmbedderRootsHandler* handler);
9531cb0ef41Sopenharmony_ci
9541cb0ef41Sopenharmony_ci  /**
9551cb0ef41Sopenharmony_ci   * Attaches a managed C++ heap as an extension to the JavaScript heap. The
9561cb0ef41Sopenharmony_ci   * embedder maintains ownership of the CppHeap. At most one C++ heap can be
9571cb0ef41Sopenharmony_ci   * attached to V8.
9581cb0ef41Sopenharmony_ci   * AttachCppHeap cannot be used simultaneously with SetEmbedderHeapTracer.
9591cb0ef41Sopenharmony_ci   *
9601cb0ef41Sopenharmony_ci   * This is an experimental feature and may still change significantly.
9611cb0ef41Sopenharmony_ci   */
9621cb0ef41Sopenharmony_ci  void AttachCppHeap(CppHeap*);
9631cb0ef41Sopenharmony_ci
9641cb0ef41Sopenharmony_ci  /**
9651cb0ef41Sopenharmony_ci   * Detaches a managed C++ heap if one was attached using `AttachCppHeap()`.
9661cb0ef41Sopenharmony_ci   *
9671cb0ef41Sopenharmony_ci   * This is an experimental feature and may still change significantly.
9681cb0ef41Sopenharmony_ci   */
9691cb0ef41Sopenharmony_ci  void DetachCppHeap();
9701cb0ef41Sopenharmony_ci
9711cb0ef41Sopenharmony_ci  /**
9721cb0ef41Sopenharmony_ci   * This is an experimental feature and may still change significantly.
9731cb0ef41Sopenharmony_ci
9741cb0ef41Sopenharmony_ci   * \returns the C++ heap managed by V8. Only available if such a heap has been
9751cb0ef41Sopenharmony_ci   *   attached using `AttachCppHeap()`.
9761cb0ef41Sopenharmony_ci   */
9771cb0ef41Sopenharmony_ci  CppHeap* GetCppHeap() const;
9781cb0ef41Sopenharmony_ci
9791cb0ef41Sopenharmony_ci  /**
9801cb0ef41Sopenharmony_ci   * Use for |AtomicsWaitCallback| to indicate the type of event it receives.
9811cb0ef41Sopenharmony_ci   */
9821cb0ef41Sopenharmony_ci  enum class AtomicsWaitEvent {
9831cb0ef41Sopenharmony_ci    /** Indicates that this call is happening before waiting. */
9841cb0ef41Sopenharmony_ci    kStartWait,
9851cb0ef41Sopenharmony_ci    /** `Atomics.wait()` finished because of an `Atomics.wake()` call. */
9861cb0ef41Sopenharmony_ci    kWokenUp,
9871cb0ef41Sopenharmony_ci    /** `Atomics.wait()` finished because it timed out. */
9881cb0ef41Sopenharmony_ci    kTimedOut,
9891cb0ef41Sopenharmony_ci    /** `Atomics.wait()` was interrupted through |TerminateExecution()|. */
9901cb0ef41Sopenharmony_ci    kTerminatedExecution,
9911cb0ef41Sopenharmony_ci    /** `Atomics.wait()` was stopped through |AtomicsWaitWakeHandle|. */
9921cb0ef41Sopenharmony_ci    kAPIStopped,
9931cb0ef41Sopenharmony_ci    /** `Atomics.wait()` did not wait, as the initial condition was not met. */
9941cb0ef41Sopenharmony_ci    kNotEqual
9951cb0ef41Sopenharmony_ci  };
9961cb0ef41Sopenharmony_ci
9971cb0ef41Sopenharmony_ci  /**
9981cb0ef41Sopenharmony_ci   * Passed to |AtomicsWaitCallback| as a means of stopping an ongoing
9991cb0ef41Sopenharmony_ci   * `Atomics.wait` call.
10001cb0ef41Sopenharmony_ci   */
10011cb0ef41Sopenharmony_ci  class V8_EXPORT AtomicsWaitWakeHandle {
10021cb0ef41Sopenharmony_ci   public:
10031cb0ef41Sopenharmony_ci    /**
10041cb0ef41Sopenharmony_ci     * Stop this `Atomics.wait()` call and call the |AtomicsWaitCallback|
10051cb0ef41Sopenharmony_ci     * with |kAPIStopped|.
10061cb0ef41Sopenharmony_ci     *
10071cb0ef41Sopenharmony_ci     * This function may be called from another thread. The caller has to ensure
10081cb0ef41Sopenharmony_ci     * through proper synchronization that it is not called after
10091cb0ef41Sopenharmony_ci     * the finishing |AtomicsWaitCallback|.
10101cb0ef41Sopenharmony_ci     *
10111cb0ef41Sopenharmony_ci     * Note that the ECMAScript specification does not plan for the possibility
10121cb0ef41Sopenharmony_ci     * of wakeups that are neither coming from a timeout or an `Atomics.wake()`
10131cb0ef41Sopenharmony_ci     * call, so this may invalidate assumptions made by existing code.
10141cb0ef41Sopenharmony_ci     * The embedder may accordingly wish to schedule an exception in the
10151cb0ef41Sopenharmony_ci     * finishing |AtomicsWaitCallback|.
10161cb0ef41Sopenharmony_ci     */
10171cb0ef41Sopenharmony_ci    void Wake();
10181cb0ef41Sopenharmony_ci  };
10191cb0ef41Sopenharmony_ci
10201cb0ef41Sopenharmony_ci  /**
10211cb0ef41Sopenharmony_ci   * Embedder callback for `Atomics.wait()` that can be added through
10221cb0ef41Sopenharmony_ci   * |SetAtomicsWaitCallback|.
10231cb0ef41Sopenharmony_ci   *
10241cb0ef41Sopenharmony_ci   * This will be called just before starting to wait with the |event| value
10251cb0ef41Sopenharmony_ci   * |kStartWait| and after finishing waiting with one of the other
10261cb0ef41Sopenharmony_ci   * values of |AtomicsWaitEvent| inside of an `Atomics.wait()` call.
10271cb0ef41Sopenharmony_ci   *
10281cb0ef41Sopenharmony_ci   * |array_buffer| will refer to the underlying SharedArrayBuffer,
10291cb0ef41Sopenharmony_ci   * |offset_in_bytes| to the location of the waited-on memory address inside
10301cb0ef41Sopenharmony_ci   * the SharedArrayBuffer.
10311cb0ef41Sopenharmony_ci   *
10321cb0ef41Sopenharmony_ci   * |value| and |timeout_in_ms| will be the values passed to
10331cb0ef41Sopenharmony_ci   * the `Atomics.wait()` call. If no timeout was used, |timeout_in_ms|
10341cb0ef41Sopenharmony_ci   * will be `INFINITY`.
10351cb0ef41Sopenharmony_ci   *
10361cb0ef41Sopenharmony_ci   * In the |kStartWait| callback, |stop_handle| will be an object that
10371cb0ef41Sopenharmony_ci   * is only valid until the corresponding finishing callback and that
10381cb0ef41Sopenharmony_ci   * can be used to stop the wait process while it is happening.
10391cb0ef41Sopenharmony_ci   *
10401cb0ef41Sopenharmony_ci   * This callback may schedule exceptions, *unless* |event| is equal to
10411cb0ef41Sopenharmony_ci   * |kTerminatedExecution|.
10421cb0ef41Sopenharmony_ci   */
10431cb0ef41Sopenharmony_ci  using AtomicsWaitCallback = void (*)(AtomicsWaitEvent event,
10441cb0ef41Sopenharmony_ci                                       Local<SharedArrayBuffer> array_buffer,
10451cb0ef41Sopenharmony_ci                                       size_t offset_in_bytes, int64_t value,
10461cb0ef41Sopenharmony_ci                                       double timeout_in_ms,
10471cb0ef41Sopenharmony_ci                                       AtomicsWaitWakeHandle* stop_handle,
10481cb0ef41Sopenharmony_ci                                       void* data);
10491cb0ef41Sopenharmony_ci
10501cb0ef41Sopenharmony_ci  /**
10511cb0ef41Sopenharmony_ci   * Set a new |AtomicsWaitCallback|. This overrides an earlier
10521cb0ef41Sopenharmony_ci   * |AtomicsWaitCallback|, if there was any. If |callback| is nullptr,
10531cb0ef41Sopenharmony_ci   * this unsets the callback. |data| will be passed to the callback
10541cb0ef41Sopenharmony_ci   * as its last parameter.
10551cb0ef41Sopenharmony_ci   */
10561cb0ef41Sopenharmony_ci  void SetAtomicsWaitCallback(AtomicsWaitCallback callback, void* data);
10571cb0ef41Sopenharmony_ci
10581cb0ef41Sopenharmony_ci  /**
10591cb0ef41Sopenharmony_ci   * Enables the host application to receive a notification after a
10601cb0ef41Sopenharmony_ci   * garbage collection. Allocations are allowed in the callback function,
10611cb0ef41Sopenharmony_ci   * but the callback is not re-entrant: if the allocation inside it will
10621cb0ef41Sopenharmony_ci   * trigger the garbage collection, the callback won't be called again.
10631cb0ef41Sopenharmony_ci   * It is possible to specify the GCType filter for your callback. But it is
10641cb0ef41Sopenharmony_ci   * not possible to register the same callback function two times with
10651cb0ef41Sopenharmony_ci   * different GCType filters.
10661cb0ef41Sopenharmony_ci   */
10671cb0ef41Sopenharmony_ci  void AddGCEpilogueCallback(GCCallbackWithData callback, void* data = nullptr,
10681cb0ef41Sopenharmony_ci                             GCType gc_type_filter = kGCTypeAll);
10691cb0ef41Sopenharmony_ci  void AddGCEpilogueCallback(GCCallback callback,
10701cb0ef41Sopenharmony_ci                             GCType gc_type_filter = kGCTypeAll);
10711cb0ef41Sopenharmony_ci
10721cb0ef41Sopenharmony_ci  /**
10731cb0ef41Sopenharmony_ci   * This function removes callback which was installed by
10741cb0ef41Sopenharmony_ci   * AddGCEpilogueCallback function.
10751cb0ef41Sopenharmony_ci   */
10761cb0ef41Sopenharmony_ci  void RemoveGCEpilogueCallback(GCCallbackWithData callback,
10771cb0ef41Sopenharmony_ci                                void* data = nullptr);
10781cb0ef41Sopenharmony_ci  void RemoveGCEpilogueCallback(GCCallback callback);
10791cb0ef41Sopenharmony_ci
10801cb0ef41Sopenharmony_ci  using GetExternallyAllocatedMemoryInBytesCallback = size_t (*)();
10811cb0ef41Sopenharmony_ci
10821cb0ef41Sopenharmony_ci  /**
10831cb0ef41Sopenharmony_ci   * Set the callback that tells V8 how much memory is currently allocated
10841cb0ef41Sopenharmony_ci   * externally of the V8 heap. Ideally this memory is somehow connected to V8
10851cb0ef41Sopenharmony_ci   * objects and may get freed-up when the corresponding V8 objects get
10861cb0ef41Sopenharmony_ci   * collected by a V8 garbage collection.
10871cb0ef41Sopenharmony_ci   */
10881cb0ef41Sopenharmony_ci  void SetGetExternallyAllocatedMemoryInBytesCallback(
10891cb0ef41Sopenharmony_ci      GetExternallyAllocatedMemoryInBytesCallback callback);
10901cb0ef41Sopenharmony_ci
10911cb0ef41Sopenharmony_ci  /**
10921cb0ef41Sopenharmony_ci   * Forcefully terminate the current thread of JavaScript execution
10931cb0ef41Sopenharmony_ci   * in the given isolate.
10941cb0ef41Sopenharmony_ci   *
10951cb0ef41Sopenharmony_ci   * This method can be used by any thread even if that thread has not
10961cb0ef41Sopenharmony_ci   * acquired the V8 lock with a Locker object.
10971cb0ef41Sopenharmony_ci   */
10981cb0ef41Sopenharmony_ci  void TerminateExecution();
10991cb0ef41Sopenharmony_ci
11001cb0ef41Sopenharmony_ci  /**
11011cb0ef41Sopenharmony_ci   * Is V8 terminating JavaScript execution.
11021cb0ef41Sopenharmony_ci   *
11031cb0ef41Sopenharmony_ci   * Returns true if JavaScript execution is currently terminating
11041cb0ef41Sopenharmony_ci   * because of a call to TerminateExecution.  In that case there are
11051cb0ef41Sopenharmony_ci   * still JavaScript frames on the stack and the termination
11061cb0ef41Sopenharmony_ci   * exception is still active.
11071cb0ef41Sopenharmony_ci   */
11081cb0ef41Sopenharmony_ci  bool IsExecutionTerminating();
11091cb0ef41Sopenharmony_ci
11101cb0ef41Sopenharmony_ci  /**
11111cb0ef41Sopenharmony_ci   * Resume execution capability in the given isolate, whose execution
11121cb0ef41Sopenharmony_ci   * was previously forcefully terminated using TerminateExecution().
11131cb0ef41Sopenharmony_ci   *
11141cb0ef41Sopenharmony_ci   * When execution is forcefully terminated using TerminateExecution(),
11151cb0ef41Sopenharmony_ci   * the isolate can not resume execution until all JavaScript frames
11161cb0ef41Sopenharmony_ci   * have propagated the uncatchable exception which is generated.  This
11171cb0ef41Sopenharmony_ci   * method allows the program embedding the engine to handle the
11181cb0ef41Sopenharmony_ci   * termination event and resume execution capability, even if
11191cb0ef41Sopenharmony_ci   * JavaScript frames remain on the stack.
11201cb0ef41Sopenharmony_ci   *
11211cb0ef41Sopenharmony_ci   * This method can be used by any thread even if that thread has not
11221cb0ef41Sopenharmony_ci   * acquired the V8 lock with a Locker object.
11231cb0ef41Sopenharmony_ci   */
11241cb0ef41Sopenharmony_ci  void CancelTerminateExecution();
11251cb0ef41Sopenharmony_ci
11261cb0ef41Sopenharmony_ci  /**
11271cb0ef41Sopenharmony_ci   * Request V8 to interrupt long running JavaScript code and invoke
11281cb0ef41Sopenharmony_ci   * the given |callback| passing the given |data| to it. After |callback|
11291cb0ef41Sopenharmony_ci   * returns control will be returned to the JavaScript code.
11301cb0ef41Sopenharmony_ci   * There may be a number of interrupt requests in flight.
11311cb0ef41Sopenharmony_ci   * Can be called from another thread without acquiring a |Locker|.
11321cb0ef41Sopenharmony_ci   * Registered |callback| must not reenter interrupted Isolate.
11331cb0ef41Sopenharmony_ci   */
11341cb0ef41Sopenharmony_ci  void RequestInterrupt(InterruptCallback callback, void* data);
11351cb0ef41Sopenharmony_ci
11361cb0ef41Sopenharmony_ci  /**
11371cb0ef41Sopenharmony_ci   * Returns true if there is ongoing background work within V8 that will
11381cb0ef41Sopenharmony_ci   * eventually post a foreground task, like asynchronous WebAssembly
11391cb0ef41Sopenharmony_ci   * compilation.
11401cb0ef41Sopenharmony_ci   */
11411cb0ef41Sopenharmony_ci  bool HasPendingBackgroundTasks();
11421cb0ef41Sopenharmony_ci
11431cb0ef41Sopenharmony_ci  /**
11441cb0ef41Sopenharmony_ci   * Request garbage collection in this Isolate. It is only valid to call this
11451cb0ef41Sopenharmony_ci   * function if --expose_gc was specified.
11461cb0ef41Sopenharmony_ci   *
11471cb0ef41Sopenharmony_ci   * This should only be used for testing purposes and not to enforce a garbage
11481cb0ef41Sopenharmony_ci   * collection schedule. It has strong negative impact on the garbage
11491cb0ef41Sopenharmony_ci   * collection performance. Use IdleNotificationDeadline() or
11501cb0ef41Sopenharmony_ci   * LowMemoryNotification() instead to influence the garbage collection
11511cb0ef41Sopenharmony_ci   * schedule.
11521cb0ef41Sopenharmony_ci   */
11531cb0ef41Sopenharmony_ci  void RequestGarbageCollectionForTesting(GarbageCollectionType type);
11541cb0ef41Sopenharmony_ci
11551cb0ef41Sopenharmony_ci  /**
11561cb0ef41Sopenharmony_ci   * Request garbage collection with a specific embedderstack state in this
11571cb0ef41Sopenharmony_ci   * Isolate. It is only valid to call this function if --expose_gc was
11581cb0ef41Sopenharmony_ci   * specified.
11591cb0ef41Sopenharmony_ci   *
11601cb0ef41Sopenharmony_ci   * This should only be used for testing purposes and not to enforce a garbage
11611cb0ef41Sopenharmony_ci   * collection schedule. It has strong negative impact on the garbage
11621cb0ef41Sopenharmony_ci   * collection performance. Use IdleNotificationDeadline() or
11631cb0ef41Sopenharmony_ci   * LowMemoryNotification() instead to influence the garbage collection
11641cb0ef41Sopenharmony_ci   * schedule.
11651cb0ef41Sopenharmony_ci   */
11661cb0ef41Sopenharmony_ci  void RequestGarbageCollectionForTesting(
11671cb0ef41Sopenharmony_ci      GarbageCollectionType type,
11681cb0ef41Sopenharmony_ci      EmbedderHeapTracer::EmbedderStackState stack_state);
11691cb0ef41Sopenharmony_ci
11701cb0ef41Sopenharmony_ci  /**
11711cb0ef41Sopenharmony_ci   * Set the callback to invoke for logging event.
11721cb0ef41Sopenharmony_ci   */
11731cb0ef41Sopenharmony_ci  void SetEventLogger(LogEventCallback that);
11741cb0ef41Sopenharmony_ci
11751cb0ef41Sopenharmony_ci  /**
11761cb0ef41Sopenharmony_ci   * Adds a callback to notify the host application right before a script
11771cb0ef41Sopenharmony_ci   * is about to run. If a script re-enters the runtime during executing, the
11781cb0ef41Sopenharmony_ci   * BeforeCallEnteredCallback is invoked for each re-entrance.
11791cb0ef41Sopenharmony_ci   * Executing scripts inside the callback will re-trigger the callback.
11801cb0ef41Sopenharmony_ci   */
11811cb0ef41Sopenharmony_ci  void AddBeforeCallEnteredCallback(BeforeCallEnteredCallback callback);
11821cb0ef41Sopenharmony_ci
11831cb0ef41Sopenharmony_ci  /**
11841cb0ef41Sopenharmony_ci   * Removes callback that was installed by AddBeforeCallEnteredCallback.
11851cb0ef41Sopenharmony_ci   */
11861cb0ef41Sopenharmony_ci  void RemoveBeforeCallEnteredCallback(BeforeCallEnteredCallback callback);
11871cb0ef41Sopenharmony_ci
11881cb0ef41Sopenharmony_ci  /**
11891cb0ef41Sopenharmony_ci   * Adds a callback to notify the host application when a script finished
11901cb0ef41Sopenharmony_ci   * running.  If a script re-enters the runtime during executing, the
11911cb0ef41Sopenharmony_ci   * CallCompletedCallback is only invoked when the outer-most script
11921cb0ef41Sopenharmony_ci   * execution ends.  Executing scripts inside the callback do not trigger
11931cb0ef41Sopenharmony_ci   * further callbacks.
11941cb0ef41Sopenharmony_ci   */
11951cb0ef41Sopenharmony_ci  void AddCallCompletedCallback(CallCompletedCallback callback);
11961cb0ef41Sopenharmony_ci
11971cb0ef41Sopenharmony_ci  /**
11981cb0ef41Sopenharmony_ci   * Removes callback that was installed by AddCallCompletedCallback.
11991cb0ef41Sopenharmony_ci   */
12001cb0ef41Sopenharmony_ci  void RemoveCallCompletedCallback(CallCompletedCallback callback);
12011cb0ef41Sopenharmony_ci
12021cb0ef41Sopenharmony_ci  /**
12031cb0ef41Sopenharmony_ci   * Set the PromiseHook callback for various promise lifecycle
12041cb0ef41Sopenharmony_ci   * events.
12051cb0ef41Sopenharmony_ci   */
12061cb0ef41Sopenharmony_ci  void SetPromiseHook(PromiseHook hook);
12071cb0ef41Sopenharmony_ci
12081cb0ef41Sopenharmony_ci  /**
12091cb0ef41Sopenharmony_ci   * Set callback to notify about promise reject with no handler, or
12101cb0ef41Sopenharmony_ci   * revocation of such a previous notification once the handler is added.
12111cb0ef41Sopenharmony_ci   */
12121cb0ef41Sopenharmony_ci  void SetPromiseRejectCallback(PromiseRejectCallback callback);
12131cb0ef41Sopenharmony_ci
12141cb0ef41Sopenharmony_ci  /**
12151cb0ef41Sopenharmony_ci   * Runs the default MicrotaskQueue until it gets empty and perform other
12161cb0ef41Sopenharmony_ci   * microtask checkpoint steps, such as calling ClearKeptObjects. Asserts that
12171cb0ef41Sopenharmony_ci   * the MicrotasksPolicy is not kScoped. Any exceptions thrown by microtask
12181cb0ef41Sopenharmony_ci   * callbacks are swallowed.
12191cb0ef41Sopenharmony_ci   */
12201cb0ef41Sopenharmony_ci  void PerformMicrotaskCheckpoint();
12211cb0ef41Sopenharmony_ci
12221cb0ef41Sopenharmony_ci  /**
12231cb0ef41Sopenharmony_ci   * Enqueues the callback to the default MicrotaskQueue
12241cb0ef41Sopenharmony_ci   */
12251cb0ef41Sopenharmony_ci  void EnqueueMicrotask(Local<Function> microtask);
12261cb0ef41Sopenharmony_ci
12271cb0ef41Sopenharmony_ci  /**
12281cb0ef41Sopenharmony_ci   * Enqueues the callback to the default MicrotaskQueue
12291cb0ef41Sopenharmony_ci   */
12301cb0ef41Sopenharmony_ci  void EnqueueMicrotask(MicrotaskCallback callback, void* data = nullptr);
12311cb0ef41Sopenharmony_ci
12321cb0ef41Sopenharmony_ci  /**
12331cb0ef41Sopenharmony_ci   * Controls how Microtasks are invoked. See MicrotasksPolicy for details.
12341cb0ef41Sopenharmony_ci   */
12351cb0ef41Sopenharmony_ci  void SetMicrotasksPolicy(MicrotasksPolicy policy);
12361cb0ef41Sopenharmony_ci
12371cb0ef41Sopenharmony_ci  /**
12381cb0ef41Sopenharmony_ci   * Returns the policy controlling how Microtasks are invoked.
12391cb0ef41Sopenharmony_ci   */
12401cb0ef41Sopenharmony_ci  MicrotasksPolicy GetMicrotasksPolicy() const;
12411cb0ef41Sopenharmony_ci
12421cb0ef41Sopenharmony_ci  /**
12431cb0ef41Sopenharmony_ci   * Adds a callback to notify the host application after
12441cb0ef41Sopenharmony_ci   * microtasks were run on the default MicrotaskQueue. The callback is
12451cb0ef41Sopenharmony_ci   * triggered by explicit RunMicrotasks call or automatic microtasks execution
12461cb0ef41Sopenharmony_ci   * (see SetMicrotaskPolicy).
12471cb0ef41Sopenharmony_ci   *
12481cb0ef41Sopenharmony_ci   * Callback will trigger even if microtasks were attempted to run,
12491cb0ef41Sopenharmony_ci   * but the microtasks queue was empty and no single microtask was actually
12501cb0ef41Sopenharmony_ci   * executed.
12511cb0ef41Sopenharmony_ci   *
12521cb0ef41Sopenharmony_ci   * Executing scripts inside the callback will not re-trigger microtasks and
12531cb0ef41Sopenharmony_ci   * the callback.
12541cb0ef41Sopenharmony_ci   */
12551cb0ef41Sopenharmony_ci  void AddMicrotasksCompletedCallback(
12561cb0ef41Sopenharmony_ci      MicrotasksCompletedCallbackWithData callback, void* data = nullptr);
12571cb0ef41Sopenharmony_ci
12581cb0ef41Sopenharmony_ci  /**
12591cb0ef41Sopenharmony_ci   * Removes callback that was installed by AddMicrotasksCompletedCallback.
12601cb0ef41Sopenharmony_ci   */
12611cb0ef41Sopenharmony_ci  void RemoveMicrotasksCompletedCallback(
12621cb0ef41Sopenharmony_ci      MicrotasksCompletedCallbackWithData callback, void* data = nullptr);
12631cb0ef41Sopenharmony_ci
12641cb0ef41Sopenharmony_ci  /**
12651cb0ef41Sopenharmony_ci   * Sets a callback for counting the number of times a feature of V8 is used.
12661cb0ef41Sopenharmony_ci   */
12671cb0ef41Sopenharmony_ci  void SetUseCounterCallback(UseCounterCallback callback);
12681cb0ef41Sopenharmony_ci
12691cb0ef41Sopenharmony_ci  /**
12701cb0ef41Sopenharmony_ci   * Enables the host application to provide a mechanism for recording
12711cb0ef41Sopenharmony_ci   * statistics counters.
12721cb0ef41Sopenharmony_ci   */
12731cb0ef41Sopenharmony_ci  void SetCounterFunction(CounterLookupCallback);
12741cb0ef41Sopenharmony_ci
12751cb0ef41Sopenharmony_ci  /**
12761cb0ef41Sopenharmony_ci   * Enables the host application to provide a mechanism for recording
12771cb0ef41Sopenharmony_ci   * histograms. The CreateHistogram function returns a
12781cb0ef41Sopenharmony_ci   * histogram which will later be passed to the AddHistogramSample
12791cb0ef41Sopenharmony_ci   * function.
12801cb0ef41Sopenharmony_ci   */
12811cb0ef41Sopenharmony_ci  void SetCreateHistogramFunction(CreateHistogramCallback);
12821cb0ef41Sopenharmony_ci  void SetAddHistogramSampleFunction(AddHistogramSampleCallback);
12831cb0ef41Sopenharmony_ci
12841cb0ef41Sopenharmony_ci  /**
12851cb0ef41Sopenharmony_ci   * Enables the host application to provide a mechanism for recording
12861cb0ef41Sopenharmony_ci   * event based metrics. In order to use this interface
12871cb0ef41Sopenharmony_ci   *   include/v8-metrics.h
12881cb0ef41Sopenharmony_ci   * needs to be included and the recorder needs to be derived from the
12891cb0ef41Sopenharmony_ci   * Recorder base class defined there.
12901cb0ef41Sopenharmony_ci   * This method can only be called once per isolate and must happen during
12911cb0ef41Sopenharmony_ci   * isolate initialization before background threads are spawned.
12921cb0ef41Sopenharmony_ci   */
12931cb0ef41Sopenharmony_ci  void SetMetricsRecorder(
12941cb0ef41Sopenharmony_ci      const std::shared_ptr<metrics::Recorder>& metrics_recorder);
12951cb0ef41Sopenharmony_ci
12961cb0ef41Sopenharmony_ci  /**
12971cb0ef41Sopenharmony_ci   * Enables the host application to provide a mechanism for recording a
12981cb0ef41Sopenharmony_ci   * predefined set of data as crash keys to be used in postmortem debugging in
12991cb0ef41Sopenharmony_ci   * case of a crash.
13001cb0ef41Sopenharmony_ci   */
13011cb0ef41Sopenharmony_ci  void SetAddCrashKeyCallback(AddCrashKeyCallback);
13021cb0ef41Sopenharmony_ci
13031cb0ef41Sopenharmony_ci  /**
13041cb0ef41Sopenharmony_ci   * Optional notification that the embedder is idle.
13051cb0ef41Sopenharmony_ci   * V8 uses the notification to perform garbage collection.
13061cb0ef41Sopenharmony_ci   * This call can be used repeatedly if the embedder remains idle.
13071cb0ef41Sopenharmony_ci   * Returns true if the embedder should stop calling IdleNotificationDeadline
13081cb0ef41Sopenharmony_ci   * until real work has been done.  This indicates that V8 has done
13091cb0ef41Sopenharmony_ci   * as much cleanup as it will be able to do.
13101cb0ef41Sopenharmony_ci   *
13111cb0ef41Sopenharmony_ci   * The deadline_in_seconds argument specifies the deadline V8 has to finish
13121cb0ef41Sopenharmony_ci   * garbage collection work. deadline_in_seconds is compared with
13131cb0ef41Sopenharmony_ci   * MonotonicallyIncreasingTime() and should be based on the same timebase as
13141cb0ef41Sopenharmony_ci   * that function. There is no guarantee that the actual work will be done
13151cb0ef41Sopenharmony_ci   * within the time limit.
13161cb0ef41Sopenharmony_ci   */
13171cb0ef41Sopenharmony_ci  bool IdleNotificationDeadline(double deadline_in_seconds);
13181cb0ef41Sopenharmony_ci
13191cb0ef41Sopenharmony_ci  /**
13201cb0ef41Sopenharmony_ci   * Optional notification that the system is running low on memory.
13211cb0ef41Sopenharmony_ci   * V8 uses these notifications to attempt to free memory.
13221cb0ef41Sopenharmony_ci   */
13231cb0ef41Sopenharmony_ci  void LowMemoryNotification();
13241cb0ef41Sopenharmony_ci
13251cb0ef41Sopenharmony_ci  /**
13261cb0ef41Sopenharmony_ci   * Optional notification that a context has been disposed. V8 uses these
13271cb0ef41Sopenharmony_ci   * notifications to guide the GC heuristic and cancel FinalizationRegistry
13281cb0ef41Sopenharmony_ci   * cleanup tasks. Returns the number of context disposals - including this one
13291cb0ef41Sopenharmony_ci   * - since the last time V8 had a chance to clean up.
13301cb0ef41Sopenharmony_ci   *
13311cb0ef41Sopenharmony_ci   * The optional parameter |dependant_context| specifies whether the disposed
13321cb0ef41Sopenharmony_ci   * context was depending on state from other contexts or not.
13331cb0ef41Sopenharmony_ci   */
13341cb0ef41Sopenharmony_ci  int ContextDisposedNotification(bool dependant_context = true);
13351cb0ef41Sopenharmony_ci
13361cb0ef41Sopenharmony_ci  /**
13371cb0ef41Sopenharmony_ci   * Optional notification that the isolate switched to the foreground.
13381cb0ef41Sopenharmony_ci   * V8 uses these notifications to guide heuristics.
13391cb0ef41Sopenharmony_ci   */
13401cb0ef41Sopenharmony_ci  void IsolateInForegroundNotification();
13411cb0ef41Sopenharmony_ci
13421cb0ef41Sopenharmony_ci  /**
13431cb0ef41Sopenharmony_ci   * Optional notification that the isolate switched to the background.
13441cb0ef41Sopenharmony_ci   * V8 uses these notifications to guide heuristics.
13451cb0ef41Sopenharmony_ci   */
13461cb0ef41Sopenharmony_ci  void IsolateInBackgroundNotification();
13471cb0ef41Sopenharmony_ci
13481cb0ef41Sopenharmony_ci  /**
13491cb0ef41Sopenharmony_ci   * Optional notification which will enable the memory savings mode.
13501cb0ef41Sopenharmony_ci   * V8 uses this notification to guide heuristics which may result in a
13511cb0ef41Sopenharmony_ci   * smaller memory footprint at the cost of reduced runtime performance.
13521cb0ef41Sopenharmony_ci   */
13531cb0ef41Sopenharmony_ci  void EnableMemorySavingsMode();
13541cb0ef41Sopenharmony_ci
13551cb0ef41Sopenharmony_ci  /**
13561cb0ef41Sopenharmony_ci   * Optional notification which will disable the memory savings mode.
13571cb0ef41Sopenharmony_ci   */
13581cb0ef41Sopenharmony_ci  void DisableMemorySavingsMode();
13591cb0ef41Sopenharmony_ci
13601cb0ef41Sopenharmony_ci  /**
13611cb0ef41Sopenharmony_ci   * Optional notification to tell V8 the current performance requirements
13621cb0ef41Sopenharmony_ci   * of the embedder based on RAIL.
13631cb0ef41Sopenharmony_ci   * V8 uses these notifications to guide heuristics.
13641cb0ef41Sopenharmony_ci   * This is an unfinished experimental feature. Semantics and implementation
13651cb0ef41Sopenharmony_ci   * may change frequently.
13661cb0ef41Sopenharmony_ci   */
13671cb0ef41Sopenharmony_ci  void SetRAILMode(RAILMode rail_mode);
13681cb0ef41Sopenharmony_ci
13691cb0ef41Sopenharmony_ci  /**
13701cb0ef41Sopenharmony_ci   * Update load start time of the RAIL mode
13711cb0ef41Sopenharmony_ci   */
13721cb0ef41Sopenharmony_ci  void UpdateLoadStartTime();
13731cb0ef41Sopenharmony_ci
13741cb0ef41Sopenharmony_ci  /**
13751cb0ef41Sopenharmony_ci   * Optional notification to tell V8 the current isolate is used for debugging
13761cb0ef41Sopenharmony_ci   * and requires higher heap limit.
13771cb0ef41Sopenharmony_ci   */
13781cb0ef41Sopenharmony_ci  void IncreaseHeapLimitForDebugging();
13791cb0ef41Sopenharmony_ci
13801cb0ef41Sopenharmony_ci  /**
13811cb0ef41Sopenharmony_ci   * Restores the original heap limit after IncreaseHeapLimitForDebugging().
13821cb0ef41Sopenharmony_ci   */
13831cb0ef41Sopenharmony_ci  void RestoreOriginalHeapLimit();
13841cb0ef41Sopenharmony_ci
13851cb0ef41Sopenharmony_ci  /**
13861cb0ef41Sopenharmony_ci   * Returns true if the heap limit was increased for debugging and the
13871cb0ef41Sopenharmony_ci   * original heap limit was not restored yet.
13881cb0ef41Sopenharmony_ci   */
13891cb0ef41Sopenharmony_ci  bool IsHeapLimitIncreasedForDebugging();
13901cb0ef41Sopenharmony_ci
13911cb0ef41Sopenharmony_ci  /**
13921cb0ef41Sopenharmony_ci   * Allows the host application to provide the address of a function that is
13931cb0ef41Sopenharmony_ci   * notified each time code is added, moved or removed.
13941cb0ef41Sopenharmony_ci   *
13951cb0ef41Sopenharmony_ci   * \param options options for the JIT code event handler.
13961cb0ef41Sopenharmony_ci   * \param event_handler the JIT code event handler, which will be invoked
13971cb0ef41Sopenharmony_ci   *     each time code is added, moved or removed.
13981cb0ef41Sopenharmony_ci   * \note \p event_handler won't get notified of existent code.
13991cb0ef41Sopenharmony_ci   * \note since code removal notifications are not currently issued, the
14001cb0ef41Sopenharmony_ci   *     \p event_handler may get notifications of code that overlaps earlier
14011cb0ef41Sopenharmony_ci   *     code notifications. This happens when code areas are reused, and the
14021cb0ef41Sopenharmony_ci   *     earlier overlapping code areas should therefore be discarded.
14031cb0ef41Sopenharmony_ci   * \note the events passed to \p event_handler and the strings they point to
14041cb0ef41Sopenharmony_ci   *     are not guaranteed to live past each call. The \p event_handler must
14051cb0ef41Sopenharmony_ci   *     copy strings and other parameters it needs to keep around.
14061cb0ef41Sopenharmony_ci   * \note the set of events declared in JitCodeEvent::EventType is expected to
14071cb0ef41Sopenharmony_ci   *     grow over time, and the JitCodeEvent structure is expected to accrue
14081cb0ef41Sopenharmony_ci   *     new members. The \p event_handler function must ignore event codes
14091cb0ef41Sopenharmony_ci   *     it does not recognize to maintain future compatibility.
14101cb0ef41Sopenharmony_ci   * \note Use Isolate::CreateParams to get events for code executed during
14111cb0ef41Sopenharmony_ci   *     Isolate setup.
14121cb0ef41Sopenharmony_ci   */
14131cb0ef41Sopenharmony_ci  void SetJitCodeEventHandler(JitCodeEventOptions options,
14141cb0ef41Sopenharmony_ci                              JitCodeEventHandler event_handler);
14151cb0ef41Sopenharmony_ci
14161cb0ef41Sopenharmony_ci  /**
14171cb0ef41Sopenharmony_ci   * Modifies the stack limit for this Isolate.
14181cb0ef41Sopenharmony_ci   *
14191cb0ef41Sopenharmony_ci   * \param stack_limit An address beyond which the Vm's stack may not grow.
14201cb0ef41Sopenharmony_ci   *
14211cb0ef41Sopenharmony_ci   * \note  If you are using threads then you should hold the V8::Locker lock
14221cb0ef41Sopenharmony_ci   *     while setting the stack limit and you must set a non-default stack
14231cb0ef41Sopenharmony_ci   *     limit separately for each thread.
14241cb0ef41Sopenharmony_ci   */
14251cb0ef41Sopenharmony_ci  void SetStackLimit(uintptr_t stack_limit);
14261cb0ef41Sopenharmony_ci
14271cb0ef41Sopenharmony_ci  /**
14281cb0ef41Sopenharmony_ci   * Returns a memory range that can potentially contain jitted code. Code for
14291cb0ef41Sopenharmony_ci   * V8's 'builtins' will not be in this range if embedded builtins is enabled.
14301cb0ef41Sopenharmony_ci   *
14311cb0ef41Sopenharmony_ci   * On Win64, embedders are advised to install function table callbacks for
14321cb0ef41Sopenharmony_ci   * these ranges, as default SEH won't be able to unwind through jitted code.
14331cb0ef41Sopenharmony_ci   * The first page of the code range is reserved for the embedder and is
14341cb0ef41Sopenharmony_ci   * committed, writable, and executable, to be used to store unwind data, as
14351cb0ef41Sopenharmony_ci   * documented in
14361cb0ef41Sopenharmony_ci   * https://docs.microsoft.com/en-us/cpp/build/exception-handling-x64.
14371cb0ef41Sopenharmony_ci   *
14381cb0ef41Sopenharmony_ci   * Might be empty on other platforms.
14391cb0ef41Sopenharmony_ci   *
14401cb0ef41Sopenharmony_ci   * https://code.google.com/p/v8/issues/detail?id=3598
14411cb0ef41Sopenharmony_ci   */
14421cb0ef41Sopenharmony_ci  void GetCodeRange(void** start, size_t* length_in_bytes);
14431cb0ef41Sopenharmony_ci
14441cb0ef41Sopenharmony_ci  /**
14451cb0ef41Sopenharmony_ci   * As GetCodeRange, but for embedded builtins (these live in a distinct
14461cb0ef41Sopenharmony_ci   * memory region from other V8 Code objects).
14471cb0ef41Sopenharmony_ci   */
14481cb0ef41Sopenharmony_ci  void GetEmbeddedCodeRange(const void** start, size_t* length_in_bytes);
14491cb0ef41Sopenharmony_ci
14501cb0ef41Sopenharmony_ci  /**
14511cb0ef41Sopenharmony_ci   * Returns the JSEntryStubs necessary for use with the Unwinder API.
14521cb0ef41Sopenharmony_ci   */
14531cb0ef41Sopenharmony_ci  JSEntryStubs GetJSEntryStubs();
14541cb0ef41Sopenharmony_ci
14551cb0ef41Sopenharmony_ci  static constexpr size_t kMinCodePagesBufferSize = 32;
14561cb0ef41Sopenharmony_ci
14571cb0ef41Sopenharmony_ci  /**
14581cb0ef41Sopenharmony_ci   * Copies the code heap pages currently in use by V8 into |code_pages_out|.
14591cb0ef41Sopenharmony_ci   * |code_pages_out| must have at least kMinCodePagesBufferSize capacity and
14601cb0ef41Sopenharmony_ci   * must be empty.
14611cb0ef41Sopenharmony_ci   *
14621cb0ef41Sopenharmony_ci   * Signal-safe, does not allocate, does not access the V8 heap.
14631cb0ef41Sopenharmony_ci   * No code on the stack can rely on pages that might be missing.
14641cb0ef41Sopenharmony_ci   *
14651cb0ef41Sopenharmony_ci   * Returns the number of pages available to be copied, which might be greater
14661cb0ef41Sopenharmony_ci   * than |capacity|. In this case, only |capacity| pages will be copied into
14671cb0ef41Sopenharmony_ci   * |code_pages_out|. The caller should provide a bigger buffer on the next
14681cb0ef41Sopenharmony_ci   * call in order to get all available code pages, but this is not required.
14691cb0ef41Sopenharmony_ci   */
14701cb0ef41Sopenharmony_ci  size_t CopyCodePages(size_t capacity, MemoryRange* code_pages_out);
14711cb0ef41Sopenharmony_ci
14721cb0ef41Sopenharmony_ci  /** Set the callback to invoke in case of fatal errors. */
14731cb0ef41Sopenharmony_ci  void SetFatalErrorHandler(FatalErrorCallback that);
14741cb0ef41Sopenharmony_ci
14751cb0ef41Sopenharmony_ci  /** Set the callback to invoke in case of OOM errors. */
14761cb0ef41Sopenharmony_ci  void SetOOMErrorHandler(OOMErrorCallback that);
14771cb0ef41Sopenharmony_ci
14781cb0ef41Sopenharmony_ci  /**
14791cb0ef41Sopenharmony_ci   * Add a callback to invoke in case the heap size is close to the heap limit.
14801cb0ef41Sopenharmony_ci   * If multiple callbacks are added, only the most recently added callback is
14811cb0ef41Sopenharmony_ci   * invoked.
14821cb0ef41Sopenharmony_ci   */
14831cb0ef41Sopenharmony_ci  void AddNearHeapLimitCallback(NearHeapLimitCallback callback, void* data);
14841cb0ef41Sopenharmony_ci
14851cb0ef41Sopenharmony_ci  /**
14861cb0ef41Sopenharmony_ci   * Remove the given callback and restore the heap limit to the
14871cb0ef41Sopenharmony_ci   * given limit. If the given limit is zero, then it is ignored.
14881cb0ef41Sopenharmony_ci   * If the current heap size is greater than the given limit,
14891cb0ef41Sopenharmony_ci   * then the heap limit is restored to the minimal limit that
14901cb0ef41Sopenharmony_ci   * is possible for the current heap size.
14911cb0ef41Sopenharmony_ci   */
14921cb0ef41Sopenharmony_ci  void RemoveNearHeapLimitCallback(NearHeapLimitCallback callback,
14931cb0ef41Sopenharmony_ci                                   size_t heap_limit);
14941cb0ef41Sopenharmony_ci
14951cb0ef41Sopenharmony_ci  /**
14961cb0ef41Sopenharmony_ci   * If the heap limit was changed by the NearHeapLimitCallback, then the
14971cb0ef41Sopenharmony_ci   * initial heap limit will be restored once the heap size falls below the
14981cb0ef41Sopenharmony_ci   * given threshold percentage of the initial heap limit.
14991cb0ef41Sopenharmony_ci   * The threshold percentage is a number in (0.0, 1.0) range.
15001cb0ef41Sopenharmony_ci   */
15011cb0ef41Sopenharmony_ci  void AutomaticallyRestoreInitialHeapLimit(double threshold_percent = 0.5);
15021cb0ef41Sopenharmony_ci
15031cb0ef41Sopenharmony_ci  /**
15041cb0ef41Sopenharmony_ci   * Set the callback to invoke to check if code generation from
15051cb0ef41Sopenharmony_ci   * strings should be allowed.
15061cb0ef41Sopenharmony_ci   */
15071cb0ef41Sopenharmony_ci  void SetModifyCodeGenerationFromStringsCallback(
15081cb0ef41Sopenharmony_ci      ModifyCodeGenerationFromStringsCallback2 callback);
15091cb0ef41Sopenharmony_ci
15101cb0ef41Sopenharmony_ci  /**
15111cb0ef41Sopenharmony_ci   * Set the callback to invoke to check if wasm code generation should
15121cb0ef41Sopenharmony_ci   * be allowed.
15131cb0ef41Sopenharmony_ci   */
15141cb0ef41Sopenharmony_ci  void SetAllowWasmCodeGenerationCallback(
15151cb0ef41Sopenharmony_ci      AllowWasmCodeGenerationCallback callback);
15161cb0ef41Sopenharmony_ci
15171cb0ef41Sopenharmony_ci  /**
15181cb0ef41Sopenharmony_ci   * Embedder over{ride|load} injection points for wasm APIs. The expectation
15191cb0ef41Sopenharmony_ci   * is that the embedder sets them at most once.
15201cb0ef41Sopenharmony_ci   */
15211cb0ef41Sopenharmony_ci  void SetWasmModuleCallback(ExtensionCallback callback);
15221cb0ef41Sopenharmony_ci  void SetWasmInstanceCallback(ExtensionCallback callback);
15231cb0ef41Sopenharmony_ci
15241cb0ef41Sopenharmony_ci  void SetWasmStreamingCallback(WasmStreamingCallback callback);
15251cb0ef41Sopenharmony_ci
15261cb0ef41Sopenharmony_ci  void SetWasmLoadSourceMapCallback(WasmLoadSourceMapCallback callback);
15271cb0ef41Sopenharmony_ci
15281cb0ef41Sopenharmony_ci  void SetWasmSimdEnabledCallback(WasmSimdEnabledCallback callback);
15291cb0ef41Sopenharmony_ci
15301cb0ef41Sopenharmony_ci  void SetWasmExceptionsEnabledCallback(WasmExceptionsEnabledCallback callback);
15311cb0ef41Sopenharmony_ci
15321cb0ef41Sopenharmony_ci  void SetWasmDynamicTieringEnabledCallback(
15331cb0ef41Sopenharmony_ci      WasmDynamicTieringEnabledCallback callback);
15341cb0ef41Sopenharmony_ci
15351cb0ef41Sopenharmony_ci  void SetSharedArrayBufferConstructorEnabledCallback(
15361cb0ef41Sopenharmony_ci      SharedArrayBufferConstructorEnabledCallback callback);
15371cb0ef41Sopenharmony_ci
15381cb0ef41Sopenharmony_ci  /**
15391cb0ef41Sopenharmony_ci   * This function can be called by the embedder to signal V8 that the dynamic
15401cb0ef41Sopenharmony_ci   * enabling of features has finished. V8 can now set up dynamically added
15411cb0ef41Sopenharmony_ci   * features.
15421cb0ef41Sopenharmony_ci   */
15431cb0ef41Sopenharmony_ci  void InstallConditionalFeatures(Local<Context> context);
15441cb0ef41Sopenharmony_ci
15451cb0ef41Sopenharmony_ci  /**
15461cb0ef41Sopenharmony_ci   * Check if V8 is dead and therefore unusable.  This is the case after
15471cb0ef41Sopenharmony_ci   * fatal errors such as out-of-memory situations.
15481cb0ef41Sopenharmony_ci   */
15491cb0ef41Sopenharmony_ci  bool IsDead();
15501cb0ef41Sopenharmony_ci
15511cb0ef41Sopenharmony_ci  /**
15521cb0ef41Sopenharmony_ci   * Adds a message listener (errors only).
15531cb0ef41Sopenharmony_ci   *
15541cb0ef41Sopenharmony_ci   * The same message listener can be added more than once and in that
15551cb0ef41Sopenharmony_ci   * case it will be called more than once for each message.
15561cb0ef41Sopenharmony_ci   *
15571cb0ef41Sopenharmony_ci   * If data is specified, it will be passed to the callback when it is called.
15581cb0ef41Sopenharmony_ci   * Otherwise, the exception object will be passed to the callback instead.
15591cb0ef41Sopenharmony_ci   */
15601cb0ef41Sopenharmony_ci  bool AddMessageListener(MessageCallback that,
15611cb0ef41Sopenharmony_ci                          Local<Value> data = Local<Value>());
15621cb0ef41Sopenharmony_ci
15631cb0ef41Sopenharmony_ci  /**
15641cb0ef41Sopenharmony_ci   * Adds a message listener.
15651cb0ef41Sopenharmony_ci   *
15661cb0ef41Sopenharmony_ci   * The same message listener can be added more than once and in that
15671cb0ef41Sopenharmony_ci   * case it will be called more than once for each message.
15681cb0ef41Sopenharmony_ci   *
15691cb0ef41Sopenharmony_ci   * If data is specified, it will be passed to the callback when it is called.
15701cb0ef41Sopenharmony_ci   * Otherwise, the exception object will be passed to the callback instead.
15711cb0ef41Sopenharmony_ci   *
15721cb0ef41Sopenharmony_ci   * A listener can listen for particular error levels by providing a mask.
15731cb0ef41Sopenharmony_ci   */
15741cb0ef41Sopenharmony_ci  bool AddMessageListenerWithErrorLevel(MessageCallback that,
15751cb0ef41Sopenharmony_ci                                        int message_levels,
15761cb0ef41Sopenharmony_ci                                        Local<Value> data = Local<Value>());
15771cb0ef41Sopenharmony_ci
15781cb0ef41Sopenharmony_ci  /**
15791cb0ef41Sopenharmony_ci   * Remove all message listeners from the specified callback function.
15801cb0ef41Sopenharmony_ci   */
15811cb0ef41Sopenharmony_ci  void RemoveMessageListeners(MessageCallback that);
15821cb0ef41Sopenharmony_ci
15831cb0ef41Sopenharmony_ci  /** Callback function for reporting failed access checks.*/
15841cb0ef41Sopenharmony_ci  void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback);
15851cb0ef41Sopenharmony_ci
15861cb0ef41Sopenharmony_ci  /**
15871cb0ef41Sopenharmony_ci   * Tells V8 to capture current stack trace when uncaught exception occurs
15881cb0ef41Sopenharmony_ci   * and report it to the message listeners. The option is off by default.
15891cb0ef41Sopenharmony_ci   */
15901cb0ef41Sopenharmony_ci  void SetCaptureStackTraceForUncaughtExceptions(
15911cb0ef41Sopenharmony_ci      bool capture, int frame_limit = 10,
15921cb0ef41Sopenharmony_ci      StackTrace::StackTraceOptions options = StackTrace::kOverview);
15931cb0ef41Sopenharmony_ci
15941cb0ef41Sopenharmony_ci  /**
15951cb0ef41Sopenharmony_ci   * Iterates through all external resources referenced from current isolate
15961cb0ef41Sopenharmony_ci   * heap.  GC is not invoked prior to iterating, therefore there is no
15971cb0ef41Sopenharmony_ci   * guarantee that visited objects are still alive.
15981cb0ef41Sopenharmony_ci   */
15991cb0ef41Sopenharmony_ci  void VisitExternalResources(ExternalResourceVisitor* visitor);
16001cb0ef41Sopenharmony_ci
16011cb0ef41Sopenharmony_ci  /**
16021cb0ef41Sopenharmony_ci   * Iterates through all the persistent handles in the current isolate's heap
16031cb0ef41Sopenharmony_ci   * that have class_ids.
16041cb0ef41Sopenharmony_ci   */
16051cb0ef41Sopenharmony_ci  void VisitHandlesWithClassIds(PersistentHandleVisitor* visitor);
16061cb0ef41Sopenharmony_ci
16071cb0ef41Sopenharmony_ci  /**
16081cb0ef41Sopenharmony_ci   * Iterates through all the persistent handles in the current isolate's heap
16091cb0ef41Sopenharmony_ci   * that have class_ids and are weak to be marked as inactive if there is no
16101cb0ef41Sopenharmony_ci   * pending activity for the handle.
16111cb0ef41Sopenharmony_ci   */
16121cb0ef41Sopenharmony_ci  void VisitWeakHandles(PersistentHandleVisitor* visitor);
16131cb0ef41Sopenharmony_ci
16141cb0ef41Sopenharmony_ci  /**
16151cb0ef41Sopenharmony_ci   * Check if this isolate is in use.
16161cb0ef41Sopenharmony_ci   * True if at least one thread Enter'ed this isolate.
16171cb0ef41Sopenharmony_ci   */
16181cb0ef41Sopenharmony_ci  bool IsInUse();
16191cb0ef41Sopenharmony_ci
16201cb0ef41Sopenharmony_ci  /**
16211cb0ef41Sopenharmony_ci   * Set whether calling Atomics.wait (a function that may block) is allowed in
16221cb0ef41Sopenharmony_ci   * this isolate. This can also be configured via
16231cb0ef41Sopenharmony_ci   * CreateParams::allow_atomics_wait.
16241cb0ef41Sopenharmony_ci   */
16251cb0ef41Sopenharmony_ci  void SetAllowAtomicsWait(bool allow);
16261cb0ef41Sopenharmony_ci
16271cb0ef41Sopenharmony_ci  /**
16281cb0ef41Sopenharmony_ci   * Time zone redetection indicator for
16291cb0ef41Sopenharmony_ci   * DateTimeConfigurationChangeNotification.
16301cb0ef41Sopenharmony_ci   *
16311cb0ef41Sopenharmony_ci   * kSkip indicates V8 that the notification should not trigger redetecting
16321cb0ef41Sopenharmony_ci   * host time zone. kRedetect indicates V8 that host time zone should be
16331cb0ef41Sopenharmony_ci   * redetected, and used to set the default time zone.
16341cb0ef41Sopenharmony_ci   *
16351cb0ef41Sopenharmony_ci   * The host time zone detection may require file system access or similar
16361cb0ef41Sopenharmony_ci   * operations unlikely to be available inside a sandbox. If v8 is run inside a
16371cb0ef41Sopenharmony_ci   * sandbox, the host time zone has to be detected outside the sandbox before
16381cb0ef41Sopenharmony_ci   * calling DateTimeConfigurationChangeNotification function.
16391cb0ef41Sopenharmony_ci   */
16401cb0ef41Sopenharmony_ci  enum class TimeZoneDetection { kSkip, kRedetect };
16411cb0ef41Sopenharmony_ci
16421cb0ef41Sopenharmony_ci  /**
16431cb0ef41Sopenharmony_ci   * Notification that the embedder has changed the time zone, daylight savings
16441cb0ef41Sopenharmony_ci   * time or other date / time configuration parameters. V8 keeps a cache of
16451cb0ef41Sopenharmony_ci   * various values used for date / time computation. This notification will
16461cb0ef41Sopenharmony_ci   * reset those cached values for the current context so that date / time
16471cb0ef41Sopenharmony_ci   * configuration changes would be reflected.
16481cb0ef41Sopenharmony_ci   *
16491cb0ef41Sopenharmony_ci   * This API should not be called more than needed as it will negatively impact
16501cb0ef41Sopenharmony_ci   * the performance of date operations.
16511cb0ef41Sopenharmony_ci   */
16521cb0ef41Sopenharmony_ci  void DateTimeConfigurationChangeNotification(
16531cb0ef41Sopenharmony_ci      TimeZoneDetection time_zone_detection = TimeZoneDetection::kSkip);
16541cb0ef41Sopenharmony_ci
16551cb0ef41Sopenharmony_ci  /**
16561cb0ef41Sopenharmony_ci   * Notification that the embedder has changed the locale. V8 keeps a cache of
16571cb0ef41Sopenharmony_ci   * various values used for locale computation. This notification will reset
16581cb0ef41Sopenharmony_ci   * those cached values for the current context so that locale configuration
16591cb0ef41Sopenharmony_ci   * changes would be reflected.
16601cb0ef41Sopenharmony_ci   *
16611cb0ef41Sopenharmony_ci   * This API should not be called more than needed as it will negatively impact
16621cb0ef41Sopenharmony_ci   * the performance of locale operations.
16631cb0ef41Sopenharmony_ci   */
16641cb0ef41Sopenharmony_ci  void LocaleConfigurationChangeNotification();
16651cb0ef41Sopenharmony_ci
16661cb0ef41Sopenharmony_ci  Isolate() = delete;
16671cb0ef41Sopenharmony_ci  ~Isolate() = delete;
16681cb0ef41Sopenharmony_ci  Isolate(const Isolate&) = delete;
16691cb0ef41Sopenharmony_ci  Isolate& operator=(const Isolate&) = delete;
16701cb0ef41Sopenharmony_ci  // Deleting operator new and delete here is allowed as ctor and dtor is also
16711cb0ef41Sopenharmony_ci  // deleted.
16721cb0ef41Sopenharmony_ci  void* operator new(size_t size) = delete;
16731cb0ef41Sopenharmony_ci  void* operator new[](size_t size) = delete;
16741cb0ef41Sopenharmony_ci  void operator delete(void*, size_t) = delete;
16751cb0ef41Sopenharmony_ci  void operator delete[](void*, size_t) = delete;
16761cb0ef41Sopenharmony_ci
16771cb0ef41Sopenharmony_ci private:
16781cb0ef41Sopenharmony_ci  template <class K, class V, class Traits>
16791cb0ef41Sopenharmony_ci  friend class PersistentValueMapBase;
16801cb0ef41Sopenharmony_ci
16811cb0ef41Sopenharmony_ci  internal::Address* GetDataFromSnapshotOnce(size_t index);
16821cb0ef41Sopenharmony_ci  void ReportExternalAllocationLimitReached();
16831cb0ef41Sopenharmony_ci};
16841cb0ef41Sopenharmony_ci
16851cb0ef41Sopenharmony_civoid Isolate::SetData(uint32_t slot, void* data) {
16861cb0ef41Sopenharmony_ci  using I = internal::Internals;
16871cb0ef41Sopenharmony_ci  I::SetEmbedderData(this, slot, data);
16881cb0ef41Sopenharmony_ci}
16891cb0ef41Sopenharmony_ci
16901cb0ef41Sopenharmony_civoid* Isolate::GetData(uint32_t slot) {
16911cb0ef41Sopenharmony_ci  using I = internal::Internals;
16921cb0ef41Sopenharmony_ci  return I::GetEmbedderData(this, slot);
16931cb0ef41Sopenharmony_ci}
16941cb0ef41Sopenharmony_ci
16951cb0ef41Sopenharmony_ciuint32_t Isolate::GetNumberOfDataSlots() {
16961cb0ef41Sopenharmony_ci  using I = internal::Internals;
16971cb0ef41Sopenharmony_ci  return I::kNumIsolateDataSlots;
16981cb0ef41Sopenharmony_ci}
16991cb0ef41Sopenharmony_ci
17001cb0ef41Sopenharmony_citemplate <class T>
17011cb0ef41Sopenharmony_ciMaybeLocal<T> Isolate::GetDataFromSnapshotOnce(size_t index) {
17021cb0ef41Sopenharmony_ci  T* data = reinterpret_cast<T*>(GetDataFromSnapshotOnce(index));
17031cb0ef41Sopenharmony_ci  if (data) internal::PerformCastCheck(data);
17041cb0ef41Sopenharmony_ci  return Local<T>(data);
17051cb0ef41Sopenharmony_ci}
17061cb0ef41Sopenharmony_ci
17071cb0ef41Sopenharmony_ci}  // namespace v8
17081cb0ef41Sopenharmony_ci
17091cb0ef41Sopenharmony_ci#endif  // INCLUDE_V8_ISOLATE_H_
1710