Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-05 09:21:31

0001 // Copyright 2021 the V8 project authors. All rights reserved.
0002 // Use of this source code is governed by a BSD-style license that can be
0003 // found in the LICENSE file.
0004 
0005 #ifndef INCLUDE_V8_ISOLATE_H_
0006 #define INCLUDE_V8_ISOLATE_H_
0007 
0008 #include <stddef.h>
0009 #include <stdint.h>
0010 
0011 #include <functional>
0012 #include <memory>
0013 #include <string>
0014 #include <utility>
0015 
0016 #include "cppgc/common.h"
0017 #include "v8-array-buffer.h"       // NOLINT(build/include_directory)
0018 #include "v8-callbacks.h"          // NOLINT(build/include_directory)
0019 #include "v8-data.h"               // NOLINT(build/include_directory)
0020 #include "v8-debug.h"              // NOLINT(build/include_directory)
0021 #include "v8-embedder-heap.h"      // NOLINT(build/include_directory)
0022 #include "v8-exception.h"          // NOLINT(build/include_directory)
0023 #include "v8-function-callback.h"  // NOLINT(build/include_directory)
0024 #include "v8-internal.h"           // NOLINT(build/include_directory)
0025 #include "v8-local-handle.h"       // NOLINT(build/include_directory)
0026 #include "v8-microtask.h"          // NOLINT(build/include_directory)
0027 #include "v8-persistent-handle.h"  // NOLINT(build/include_directory)
0028 #include "v8-primitive.h"          // NOLINT(build/include_directory)
0029 #include "v8-statistics.h"         // NOLINT(build/include_directory)
0030 #include "v8-unwinder.h"           // NOLINT(build/include_directory)
0031 #include "v8config.h"              // NOLINT(build/include_directory)
0032 
0033 namespace v8 {
0034 
0035 class CppHeap;
0036 class HeapProfiler;
0037 class MicrotaskQueue;
0038 class StartupData;
0039 class ScriptOrModule;
0040 class SharedArrayBuffer;
0041 
0042 namespace internal {
0043 class MicrotaskQueue;
0044 class ThreadLocalTop;
0045 }  // namespace internal
0046 
0047 namespace metrics {
0048 class Recorder;
0049 }  // namespace metrics
0050 
0051 /**
0052  * A set of constraints that specifies the limits of the runtime's memory use.
0053  * You must set the heap size before initializing the VM - the size cannot be
0054  * adjusted after the VM is initialized.
0055  *
0056  * If you are using threads then you should hold the V8::Locker lock while
0057  * setting the stack limit and you must set a non-default stack limit separately
0058  * for each thread.
0059  *
0060  * The arguments for set_max_semi_space_size, set_max_old_space_size,
0061  * set_max_executable_size, set_code_range_size specify limits in MB.
0062  *
0063  * The argument for set_max_semi_space_size_in_kb is in KB.
0064  */
0065 class V8_EXPORT ResourceConstraints {
0066  public:
0067   /**
0068    * Configures the constraints with reasonable default values based on the
0069    * provided heap size limit. The heap size includes both the young and
0070    * the old generation.
0071    *
0072    * \param initial_heap_size_in_bytes The initial heap size or zero.
0073    *    By default V8 starts with a small heap and dynamically grows it to
0074    *    match the set of live objects. This may lead to ineffective
0075    *    garbage collections at startup if the live set is large.
0076    *    Setting the initial heap size avoids such garbage collections.
0077    *    Note that this does not affect young generation garbage collections.
0078    *
0079    * \param maximum_heap_size_in_bytes The hard limit for the heap size.
0080    *    When the heap size approaches this limit, V8 will perform series of
0081    *    garbage collections and invoke the NearHeapLimitCallback. If the garbage
0082    *    collections do not help and the callback does not increase the limit,
0083    *    then V8 will crash with V8::FatalProcessOutOfMemory.
0084    */
0085   void ConfigureDefaultsFromHeapSize(size_t initial_heap_size_in_bytes,
0086                                      size_t maximum_heap_size_in_bytes);
0087 
0088   /**
0089    * Configures the constraints with reasonable default values based on the
0090    * capabilities of the current device the VM is running on.
0091    *
0092    * \param physical_memory The total amount of physical memory on the current
0093    *   device, in bytes.
0094    * \param virtual_memory_limit The amount of virtual memory on the current
0095    *   device, in bytes, or zero, if there is no limit.
0096    */
0097   void ConfigureDefaults(uint64_t physical_memory,
0098                          uint64_t virtual_memory_limit);
0099 
0100   /**
0101    * The address beyond which the VM's stack may not grow.
0102    */
0103   uint32_t* stack_limit() const { return stack_limit_; }
0104   void set_stack_limit(uint32_t* value) { stack_limit_ = value; }
0105 
0106   /**
0107    * The amount of virtual memory reserved for generated code. This is relevant
0108    * for 64-bit architectures that rely on code range for calls in code.
0109    *
0110    * When V8_COMPRESS_POINTERS_IN_SHARED_CAGE is defined, there is a shared
0111    * process-wide code range that is lazily initialized. This value is used to
0112    * configure that shared code range when the first Isolate is
0113    * created. Subsequent Isolates ignore this value.
0114    */
0115   size_t code_range_size_in_bytes() const { return code_range_size_; }
0116   void set_code_range_size_in_bytes(size_t limit) { code_range_size_ = limit; }
0117 
0118   /**
0119    * The maximum size of the old generation.
0120    * When the old generation approaches this limit, V8 will perform series of
0121    * garbage collections and invoke the NearHeapLimitCallback.
0122    * If the garbage collections do not help and the callback does not
0123    * increase the limit, then V8 will crash with V8::FatalProcessOutOfMemory.
0124    */
0125   size_t max_old_generation_size_in_bytes() const {
0126     return max_old_generation_size_;
0127   }
0128   void set_max_old_generation_size_in_bytes(size_t limit) {
0129     max_old_generation_size_ = limit;
0130   }
0131 
0132   /**
0133    * The maximum size of the young generation, which consists of two semi-spaces
0134    * and a large object space. This affects frequency of Scavenge garbage
0135    * collections and should be typically much smaller that the old generation.
0136    */
0137   size_t max_young_generation_size_in_bytes() const {
0138     return max_young_generation_size_;
0139   }
0140   void set_max_young_generation_size_in_bytes(size_t limit) {
0141     max_young_generation_size_ = limit;
0142   }
0143 
0144   size_t initial_old_generation_size_in_bytes() const {
0145     return initial_old_generation_size_;
0146   }
0147   void set_initial_old_generation_size_in_bytes(size_t initial_size) {
0148     initial_old_generation_size_ = initial_size;
0149   }
0150 
0151   size_t initial_young_generation_size_in_bytes() const {
0152     return initial_young_generation_size_;
0153   }
0154   void set_initial_young_generation_size_in_bytes(size_t initial_size) {
0155     initial_young_generation_size_ = initial_size;
0156   }
0157 
0158   uint64_t physical_memory_size_in_bytes() const {
0159     return physical_memory_size_;
0160   }
0161 
0162  private:
0163   static constexpr size_t kMB = 1048576u;
0164   size_t code_range_size_ = 0;
0165   size_t max_old_generation_size_ = 0;
0166   size_t max_young_generation_size_ = 0;
0167   size_t initial_old_generation_size_ = 0;
0168   size_t initial_young_generation_size_ = 0;
0169   uint64_t physical_memory_size_ = 0;
0170   uint32_t* stack_limit_ = nullptr;
0171 };
0172 
0173 /**
0174  * Memory pressure level for the MemoryPressureNotification.
0175  * kNone hints V8 that there is no memory pressure.
0176  * kModerate hints V8 to speed up incremental garbage collection at the cost of
0177  * of higher latency due to garbage collection pauses.
0178  * kCritical hints V8 to free memory as soon as possible. Garbage collection
0179  * pauses at this level will be large.
0180  */
0181 enum class MemoryPressureLevel { kNone, kModerate, kCritical };
0182 
0183 /**
0184  * Signal for dependants of contexts. Useful for
0185  * `ContextDisposedNotification()` to implement different strategies.
0186  */
0187 enum class ContextDependants {
0188   /** Context has no dependants. These are usually top-level contexts. */
0189   kNoDependants,
0190   /** Context has some dependants, i.e., it may depend on other contexts. This
0191      is usually the case for inner contexts.  */
0192   kSomeDependants
0193 };
0194 
0195 /**
0196  * Indicator for the stack state.
0197  */
0198 using StackState = cppgc::EmbedderStackState;
0199 
0200 /**
0201  * The set of V8 isolates in a process is partitioned into groups. Each group
0202  * has its own sandbox (if V8 was configured with support for the sandbox) and
0203  * pointer-compression cage (if configured with pointer compression).
0204  *
0205  * By default, all isolates are placed in the same group. This is the most
0206  * efficient configuration in terms of speed and memory use. However, with
0207  * pointer compression enabled, total heap usage of isolates in a group
0208  * cannot exceed 4 GB, not counting array buffers and other off-heap storage.
0209  * Using multiple isolate groups can allow embedders to allocate more than 4GB
0210  * of objects with pointer compression enabled, if the embedder's use case can
0211  * span multiple isolates.
0212  *
0213  * Creating an isolate group reserves a range of virtual memory addresses. A
0214  * group's memory mapping will be released when the last isolate in the group is
0215  * disposed, and there are no more live IsolateGroup objects that refer to it.
0216  *
0217  * Note that Isolate groups are reference counted, and
0218  * the IsolateGroup type is a reference to one.
0219  *
0220  * Note that it's not going to be possible to pass shared JS objects
0221  * across IsolateGroup boundary.
0222  *
0223  */
0224 class V8_EXPORT IsolateGroup {
0225  public:
0226   /**
0227    * Get the default isolate group. If this V8's build configuration only
0228    * supports a single group, this is a reference to that single group.
0229    * Otherwise this is a group like any other, distinguished only
0230    * in that it is the first group.
0231    */
0232   static IsolateGroup GetDefault();
0233 
0234   /**
0235    * Return true if new isolate groups can be created at run-time, or false if
0236    * all isolates must be in the same group.
0237    */
0238   static bool CanCreateNewGroups();
0239 
0240   /**
0241    * Create a new isolate group. If this V8's build configuration only supports
0242    * a single group, abort.
0243    */
0244   static IsolateGroup Create();
0245 
0246   IsolateGroup(IsolateGroup&& other);
0247   IsolateGroup& operator=(IsolateGroup&& other);
0248 
0249   IsolateGroup(const IsolateGroup&);
0250   IsolateGroup& operator=(const IsolateGroup&);
0251 
0252   ~IsolateGroup();
0253 
0254   bool operator==(const IsolateGroup& other) const {
0255     return isolate_group_ == other.isolate_group_;
0256   }
0257 
0258   bool operator!=(const IsolateGroup& other) const {
0259     return !operator==(other);
0260   }
0261 
0262 #ifdef V8_ENABLE_SANDBOX
0263   /**
0264    * Whether the sandbox of the isolate group contains a given pointer.
0265    * Will always return true if the sandbox is not enabled.
0266    */
0267   bool SandboxContains(void* pointer) const;
0268   VirtualAddressSpace* GetSandboxAddressSpace();
0269 #else
0270   V8_INLINE bool SandboxContains(void* pointer) const { return true; }
0271 #endif
0272 
0273  private:
0274   friend class Isolate;
0275   friend class ArrayBuffer::Allocator;
0276 
0277   // The isolate_group pointer should be already acquired.
0278   explicit IsolateGroup(internal::IsolateGroup*&& isolate_group);
0279 
0280   internal::IsolateGroup* isolate_group_;
0281 };
0282 
0283 /**
0284  * Isolate represents an isolated instance of the V8 engine.  V8 isolates have
0285  * completely separate states.  Objects from one isolate must not be used in
0286  * other isolates.  The embedder can create multiple isolates and use them in
0287  * parallel in multiple threads.  An isolate can be entered by at most one
0288  * thread at any given time.  The Locker/Unlocker API must be used to
0289  * synchronize.
0290  */
0291 class V8_EXPORT Isolate {
0292  public:
0293   /**
0294    * Initial configuration parameters for a new Isolate.
0295    */
0296   struct V8_EXPORT CreateParams {
0297     CreateParams();
0298     ~CreateParams();
0299 
0300     ALLOW_COPY_AND_MOVE_WITH_DEPRECATED_FIELDS(CreateParams)
0301 
0302     /**
0303      * Allows the host application to provide the address of a function that is
0304      * notified each time code is added, moved or removed.
0305      */
0306     JitCodeEventHandler code_event_handler = nullptr;
0307 
0308     /**
0309      * ResourceConstraints to use for the new Isolate.
0310      */
0311     ResourceConstraints constraints;
0312 
0313     /**
0314      * Explicitly specify a startup snapshot blob. The embedder owns the blob.
0315      * The embedder *must* ensure that the snapshot is from a trusted source.
0316      */
0317     const StartupData* snapshot_blob = nullptr;
0318 
0319     /**
0320      * Enables the host application to provide a mechanism for recording
0321      * statistics counters.
0322      */
0323     CounterLookupCallback counter_lookup_callback = nullptr;
0324 
0325     /**
0326      * Enables the host application to provide a mechanism for recording
0327      * histograms. The CreateHistogram function returns a
0328      * histogram which will later be passed to the AddHistogramSample
0329      * function.
0330      */
0331     CreateHistogramCallback create_histogram_callback = nullptr;
0332     AddHistogramSampleCallback add_histogram_sample_callback = nullptr;
0333 
0334     /**
0335      * The ArrayBuffer::Allocator to use for allocating and freeing the backing
0336      * store of ArrayBuffers.
0337      *
0338      * If the shared_ptr version is used, the Isolate instance and every
0339      * |BackingStore| allocated using this allocator hold a std::shared_ptr
0340      * to the allocator, in order to facilitate lifetime
0341      * management for the allocator instance.
0342      */
0343     ArrayBuffer::Allocator* array_buffer_allocator = nullptr;
0344     std::shared_ptr<ArrayBuffer::Allocator> array_buffer_allocator_shared;
0345 
0346     /**
0347      * Specifies an optional nullptr-terminated array of raw addresses in the
0348      * embedder that V8 can match against during serialization and use for
0349      * deserialization. This array and its content must stay valid for the
0350      * entire lifetime of the isolate.
0351      */
0352     const intptr_t* external_references = nullptr;
0353 
0354     /**
0355      * Whether calling Atomics.wait (a function that may block) is allowed in
0356      * this isolate. This can also be configured via SetAllowAtomicsWait.
0357      */
0358     bool allow_atomics_wait = true;
0359 
0360     /**
0361      * Callbacks to invoke in case of fatal or OOM errors.
0362      */
0363     FatalErrorCallback fatal_error_callback = nullptr;
0364     OOMErrorCallback oom_error_callback = nullptr;
0365 
0366     /**
0367      * A CppHeap used to construct the Isolate. V8 takes ownership of the
0368      * CppHeap passed this way.
0369      */
0370     CppHeap* cpp_heap = nullptr;
0371   };
0372 
0373   /**
0374    * Stack-allocated class which sets the isolate for all operations
0375    * executed within a local scope.
0376    */
0377   class V8_EXPORT V8_NODISCARD Scope {
0378    public:
0379     explicit Scope(Isolate* isolate) : v8_isolate_(isolate) {
0380       v8_isolate_->Enter();
0381     }
0382 
0383     ~Scope() { v8_isolate_->Exit(); }
0384 
0385     // Prevent copying of Scope objects.
0386     Scope(const Scope&) = delete;
0387     Scope& operator=(const Scope&) = delete;
0388 
0389    private:
0390     Isolate* const v8_isolate_;
0391   };
0392 
0393   /**
0394    * Assert that no Javascript code is invoked.
0395    */
0396   class V8_EXPORT V8_NODISCARD DisallowJavascriptExecutionScope {
0397    public:
0398     enum OnFailure { CRASH_ON_FAILURE, THROW_ON_FAILURE, DUMP_ON_FAILURE };
0399 
0400     DisallowJavascriptExecutionScope(Isolate* isolate, OnFailure on_failure);
0401     ~DisallowJavascriptExecutionScope();
0402 
0403     // Prevent copying of Scope objects.
0404     DisallowJavascriptExecutionScope(const DisallowJavascriptExecutionScope&) =
0405         delete;
0406     DisallowJavascriptExecutionScope& operator=(
0407         const DisallowJavascriptExecutionScope&) = delete;
0408 
0409    private:
0410     v8::Isolate* const v8_isolate_;
0411     const OnFailure on_failure_;
0412     bool was_execution_allowed_;
0413   };
0414 
0415   /**
0416    * Introduce exception to DisallowJavascriptExecutionScope.
0417    */
0418   class V8_EXPORT V8_NODISCARD AllowJavascriptExecutionScope {
0419    public:
0420     explicit AllowJavascriptExecutionScope(Isolate* isolate);
0421     ~AllowJavascriptExecutionScope();
0422 
0423     // Prevent copying of Scope objects.
0424     AllowJavascriptExecutionScope(const AllowJavascriptExecutionScope&) =
0425         delete;
0426     AllowJavascriptExecutionScope& operator=(
0427         const AllowJavascriptExecutionScope&) = delete;
0428 
0429    private:
0430     Isolate* const v8_isolate_;
0431     bool was_execution_allowed_assert_;
0432     bool was_execution_allowed_throws_;
0433     bool was_execution_allowed_dump_;
0434   };
0435 
0436   /**
0437    * Do not run microtasks while this scope is active, even if microtasks are
0438    * automatically executed otherwise.
0439    */
0440   class V8_EXPORT V8_NODISCARD SuppressMicrotaskExecutionScope {
0441    public:
0442     explicit SuppressMicrotaskExecutionScope(
0443         Isolate* isolate, MicrotaskQueue* microtask_queue = nullptr);
0444     ~SuppressMicrotaskExecutionScope();
0445 
0446     // Prevent copying of Scope objects.
0447     SuppressMicrotaskExecutionScope(const SuppressMicrotaskExecutionScope&) =
0448         delete;
0449     SuppressMicrotaskExecutionScope& operator=(
0450         const SuppressMicrotaskExecutionScope&) = delete;
0451 
0452    private:
0453     internal::Isolate* const i_isolate_;
0454     internal::MicrotaskQueue* const microtask_queue_;
0455     internal::Address previous_stack_height_;
0456 
0457     friend class internal::ThreadLocalTop;
0458   };
0459 
0460   /**
0461    * Types of garbage collections that can be requested via
0462    * RequestGarbageCollectionForTesting.
0463    */
0464   enum GarbageCollectionType {
0465     kFullGarbageCollection,
0466     kMinorGarbageCollection
0467   };
0468 
0469   /**
0470    * Features reported via the SetUseCounterCallback callback. Do not change
0471    * assigned numbers of existing items; add new features to the end of this
0472    * list.
0473    * Dead features can be marked `V8_DEPRECATE_SOON`, then `V8_DEPRECATED`, and
0474    * then finally be renamed to `kOBSOLETE_...` to stop embedders from using
0475    * them.
0476    */
0477   enum UseCounterFeature {
0478     kUseAsm = 0,
0479     kBreakIterator = 1,
0480     kOBSOLETE_LegacyConst = 2,
0481     kOBSOLETE_MarkDequeOverflow = 3,
0482     kOBSOLETE_StoreBufferOverflow = 4,
0483     kOBSOLETE_SlotsBufferOverflow = 5,
0484     kOBSOLETE_ObjectObserve = 6,
0485     kForcedGC = 7,
0486     kSloppyMode = 8,
0487     kStrictMode = 9,
0488     kOBSOLETE_StrongMode = 10,
0489     kRegExpPrototypeStickyGetter = 11,
0490     kRegExpPrototypeToString = 12,
0491     kRegExpPrototypeUnicodeGetter = 13,
0492     kOBSOLETE_IntlV8Parse = 14,
0493     kOBSOLETE_IntlPattern = 15,
0494     kOBSOLETE_IntlResolved = 16,
0495     kOBSOLETE_PromiseChain = 17,
0496     kOBSOLETE_PromiseAccept = 18,
0497     kOBSOLETE_PromiseDefer = 19,
0498     kHtmlCommentInExternalScript = 20,
0499     kHtmlComment = 21,
0500     kSloppyModeBlockScopedFunctionRedefinition = 22,
0501     kForInInitializer = 23,
0502     kOBSOLETE_ArrayProtectorDirtied = 24,
0503     kArraySpeciesModified = 25,
0504     kArrayPrototypeConstructorModified = 26,
0505     kOBSOLETE_ArrayInstanceProtoModified = 27,
0506     kArrayInstanceConstructorModified = 28,
0507     kOBSOLETE_LegacyFunctionDeclaration = 29,
0508     kOBSOLETE_RegExpPrototypeSourceGetter = 30,
0509     kOBSOLETE_RegExpPrototypeOldFlagGetter = 31,
0510     kDecimalWithLeadingZeroInStrictMode = 32,
0511     kLegacyDateParser = 33,
0512     kDefineGetterOrSetterWouldThrow = 34,
0513     kFunctionConstructorReturnedUndefined = 35,
0514     kAssigmentExpressionLHSIsCallInSloppy = 36,
0515     kAssigmentExpressionLHSIsCallInStrict = 37,
0516     kPromiseConstructorReturnedUndefined = 38,
0517     kOBSOLETE_ConstructorNonUndefinedPrimitiveReturn = 39,
0518     kOBSOLETE_LabeledExpressionStatement = 40,
0519     kOBSOLETE_LineOrParagraphSeparatorAsLineTerminator = 41,
0520     kIndexAccessor = 42,
0521     kErrorCaptureStackTrace = 43,
0522     kErrorPrepareStackTrace = 44,
0523     kErrorStackTraceLimit = 45,
0524     kWebAssemblyInstantiation = 46,
0525     kDeoptimizerDisableSpeculation = 47,
0526     kOBSOLETE_ArrayPrototypeSortJSArrayModifiedPrototype = 48,
0527     kFunctionTokenOffsetTooLongForToString = 49,
0528     kWasmSharedMemory = 50,
0529     kWasmThreadOpcodes = 51,
0530     kOBSOLETE_AtomicsNotify = 52,
0531     kOBSOLETE_AtomicsWake = 53,
0532     kCollator = 54,
0533     kNumberFormat = 55,
0534     kDateTimeFormat = 56,
0535     kPluralRules = 57,
0536     kRelativeTimeFormat = 58,
0537     kLocale = 59,
0538     kListFormat = 60,
0539     kSegmenter = 61,
0540     kStringLocaleCompare = 62,
0541     kOBSOLETE_StringToLocaleUpperCase = 63,
0542     kStringToLocaleLowerCase = 64,
0543     kNumberToLocaleString = 65,
0544     kDateToLocaleString = 66,
0545     kDateToLocaleDateString = 67,
0546     kDateToLocaleTimeString = 68,
0547     kAttemptOverrideReadOnlyOnPrototypeSloppy = 69,
0548     kAttemptOverrideReadOnlyOnPrototypeStrict = 70,
0549     kOBSOLETE_OptimizedFunctionWithOneShotBytecode = 71,
0550     kRegExpMatchIsTrueishOnNonJSRegExp = 72,
0551     kRegExpMatchIsFalseishOnJSRegExp = 73,
0552     kOBSOLETE_DateGetTimezoneOffset = 74,
0553     kStringNormalize = 75,
0554     kCallSiteAPIGetFunctionSloppyCall = 76,
0555     kCallSiteAPIGetThisSloppyCall = 77,
0556     kOBSOLETE_RegExpMatchAllWithNonGlobalRegExp = 78,
0557     kRegExpExecCalledOnSlowRegExp = 79,
0558     kRegExpReplaceCalledOnSlowRegExp = 80,
0559     kDisplayNames = 81,
0560     kSharedArrayBufferConstructed = 82,
0561     kArrayPrototypeHasElements = 83,
0562     kObjectPrototypeHasElements = 84,
0563     kNumberFormatStyleUnit = 85,
0564     kDateTimeFormatRange = 86,
0565     kDateTimeFormatDateTimeStyle = 87,
0566     kBreakIteratorTypeWord = 88,
0567     kBreakIteratorTypeLine = 89,
0568     kInvalidatedArrayBufferDetachingProtector = 90,
0569     kInvalidatedArrayConstructorProtector V8_DEPRECATE_SOON(
0570         "The ArrayConstructorProtector has been removed") = 91,
0571     kInvalidatedArrayIteratorLookupChainProtector = 92,
0572     kInvalidatedArraySpeciesLookupChainProtector = 93,
0573     kInvalidatedIsConcatSpreadableLookupChainProtector = 94,
0574     kInvalidatedMapIteratorLookupChainProtector = 95,
0575     kInvalidatedNoElementsProtector = 96,
0576     kInvalidatedPromiseHookProtector = 97,
0577     kInvalidatedPromiseResolveLookupChainProtector = 98,
0578     kInvalidatedPromiseSpeciesLookupChainProtector = 99,
0579     kInvalidatedPromiseThenLookupChainProtector = 100,
0580     kInvalidatedRegExpSpeciesLookupChainProtector = 101,
0581     kInvalidatedSetIteratorLookupChainProtector = 102,
0582     kInvalidatedStringIteratorLookupChainProtector = 103,
0583     kInvalidatedStringLengthOverflowLookupChainProtector = 104,
0584     kInvalidatedTypedArraySpeciesLookupChainProtector = 105,
0585     kWasmSimdOpcodes = 106,
0586     kVarRedeclaredCatchBinding = 107,
0587     kWasmRefTypes = 108,
0588     kWasmBulkMemory = 109,
0589     kWasmMultiValue = 110,
0590     kWasmExceptionHandling = 111,
0591     kInvalidatedMegaDOMProtector = 112,
0592     kFunctionPrototypeArguments = 113,
0593     kFunctionPrototypeCaller = 114,
0594     kTurboFanOsrCompileStarted = 115,
0595     kAsyncStackTaggingCreateTaskCall = 116,
0596     kDurationFormat = 117,
0597     kInvalidatedNumberStringNotRegexpLikeProtector = 118,
0598     kOBSOLETE_RegExpUnicodeSetIncompatibilitiesWithUnicodeMode = 119,
0599     kOBSOLETE_ImportAssertionDeprecatedSyntax = 120,
0600     kLocaleInfoObsoletedGetters = 121,
0601     kLocaleInfoFunctions = 122,
0602     kCompileHintsMagicAll = 123,
0603     kInvalidatedNoProfilingProtector = 124,
0604     kWasmMemory64 = 125,
0605     kWasmMultiMemory = 126,
0606     kWasmGC = 127,
0607     kWasmImportedStrings = 128,
0608     kSourceMappingUrlMagicCommentAtSign = 129,
0609     kTemporalObject = 130,
0610     kWasmModuleCompilation = 131,
0611     kInvalidatedNoUndetectableObjectsProtector = 132,
0612     kWasmJavaScriptPromiseIntegration = 133,
0613     kWasmReturnCall = 134,
0614     kWasmExtendedConst = 135,
0615     kWasmRelaxedSimd = 136,
0616     kWasmTypeReflection = 137,
0617     kWasmExnRef = 138,
0618     kWasmTypedFuncRef = 139,
0619     kInvalidatedStringWrapperToPrimitiveProtector = 140,
0620     kDocumentAllLegacyCall = 141,
0621     kDocumentAllLegacyConstruct = 142,
0622     kConsoleContext = 143,
0623     kWasmImportedStringsUtf8 = 144,
0624     kResizableArrayBuffer = 145,
0625     kGrowableSharedArrayBuffer = 146,
0626     kArrayByCopy = 147,
0627     kArrayFromAsync = 148,
0628     kIteratorMethods = 149,
0629     kPromiseAny = 150,
0630     kSetMethods = 151,
0631     kArrayFindLast = 152,
0632     kArrayGroup = 153,
0633     kArrayBufferTransfer = 154,
0634     kPromiseWithResolvers = 155,
0635     kAtomicsWaitAsync = 156,
0636     kExtendingNonExtensibleWithPrivate = 157,
0637     kPromiseTry = 158,
0638     kStringReplaceAll = 159,
0639     kStringWellFormed = 160,
0640     kWeakReferences = 161,
0641     kErrorIsError = 162,
0642     kInvalidatedTypedArrayLengthLookupChainProtector = 163,
0643     kRegExpEscape = 164,
0644     kFloat16Array = 165,
0645     kExplicitResourceManagement = 166,
0646     kWasmBranchHinting = 167,
0647     kWasmMutableGlobals = 168,
0648     kUint8ArrayToFromBase64AndHex = 169,
0649     kAtomicsPause = 170,
0650     kTopLevelAwait = 171,
0651     kLogicalAssignment = 172,
0652     kNullishCoalescing = 173,
0653     kInvalidatedNoDateTimeConfigurationChangeProtector = 174,
0654     kWasmNonTrappingFloatToInt = 175,
0655     kWasmSignExtensionOps = 176,
0656     kRegExpCompile = 177,
0657     kRegExpStaticProperties = 178,
0658     kRegExpStaticPropertiesWithLastMatch = 179,
0659     kWithStatement = 180,
0660     kHtmlWrapperMethods = 181,
0661     kWasmCustomDescriptors = 182,
0662     kWasmResizableBuffers = 183,
0663 
0664     // If you add new values here, you'll also need to update Chromium's:
0665     // web_feature.mojom, use_counter_callback.cc, and enums.xml. V8 changes to
0666     // this list need to be landed first, then changes on the Chromium side.
0667     kUseCounterFeatureCount  // This enum value must be last.
0668   };
0669 
0670   enum MessageErrorLevel {
0671     kMessageLog = (1 << 0),
0672     kMessageDebug = (1 << 1),
0673     kMessageInfo = (1 << 2),
0674     kMessageError = (1 << 3),
0675     kMessageWarning = (1 << 4),
0676     kMessageAll = kMessageLog | kMessageDebug | kMessageInfo | kMessageError |
0677                   kMessageWarning,
0678   };
0679 
0680   // The different priorities that an isolate can have.
0681   enum class Priority {
0682     // The isolate does not relate to content that is currently important
0683     // to the user. Lowest priority.
0684     kBestEffort,
0685 
0686     // The isolate contributes to content that is visible to the user, like a
0687     // visible iframe that's not interacted directly with. High priority.
0688     kUserVisible,
0689 
0690     // The isolate contributes to content that is of the utmost importance to
0691     // the user, like visible content in the focused window. Highest priority.
0692     kUserBlocking,
0693   };
0694 
0695   using UseCounterCallback = void (*)(Isolate* isolate,
0696                                       UseCounterFeature feature);
0697 
0698   /**
0699    * Allocates a new isolate but does not initialize it. Does not change the
0700    * currently entered isolate.
0701    *
0702    * Only Isolate::GetData() and Isolate::SetData(), which access the
0703    * embedder-controlled parts of the isolate, as well as Isolate::GetGroup(),
0704    * are allowed to be called on the uninitialized isolate. To initialize the
0705    * isolate, call `Isolate::Initialize()` or initialize a `SnapshotCreator`.
0706    *
0707    * When an isolate is no longer used its resources should be freed
0708    * by calling Dispose().  Using the delete operator is not allowed.
0709    *
0710    * V8::Initialize() must have run prior to this.
0711    */
0712   static Isolate* Allocate();
0713   static Isolate* Allocate(const IsolateGroup& group);
0714 
0715   /**
0716    * Return the group for this isolate.
0717    */
0718   IsolateGroup GetGroup() const;
0719 
0720   /**
0721    * Initialize an Isolate previously allocated by Isolate::Allocate().
0722    */
0723   static void Initialize(Isolate* isolate, const CreateParams& params);
0724 
0725   /**
0726    * Creates a new isolate.  Does not change the currently entered
0727    * isolate.
0728    *
0729    * When an isolate is no longer used its resources should be freed
0730    * by calling Dispose().  Using the delete operator is not allowed.
0731    *
0732    * V8::Initialize() must have run prior to this.
0733    */
0734   static Isolate* New(const CreateParams& params);
0735   static Isolate* New(const IsolateGroup& group, const CreateParams& params);
0736 
0737   /**
0738    * Returns the entered isolate for the current thread or NULL in
0739    * case there is no current isolate.
0740    *
0741    * This method must not be invoked before V8::Initialize() was invoked.
0742    */
0743   static Isolate* GetCurrent();
0744 
0745   /**
0746    * Returns the entered isolate for the current thread or NULL in
0747    * case there is no current isolate.
0748    *
0749    * No checks are performed by this method.
0750    */
0751   static Isolate* TryGetCurrent();
0752 
0753   /**
0754    * Return true if this isolate is currently active.
0755    **/
0756   bool IsCurrent() const;
0757 
0758   /**
0759    * Clears the set of objects held strongly by the heap. This set of
0760    * objects are originally built when a WeakRef is created or
0761    * successfully dereferenced.
0762    *
0763    * This is invoked automatically after microtasks are run. See
0764    * MicrotasksPolicy for when microtasks are run.
0765    *
0766    * This needs to be manually invoked only if the embedder is manually running
0767    * microtasks via a custom MicrotaskQueue class's PerformCheckpoint. In that
0768    * case, it is the embedder's responsibility to make this call at a time which
0769    * does not interrupt synchronous ECMAScript code execution.
0770    */
0771   void ClearKeptObjects();
0772 
0773   /**
0774    * Custom callback used by embedders to help V8 determine if it should abort
0775    * when it throws and no internal handler is predicted to catch the
0776    * exception. If --abort-on-uncaught-exception is used on the command line,
0777    * then V8 will abort if either:
0778    * - no custom callback is set.
0779    * - the custom callback set returns true.
0780    * Otherwise, the custom callback will not be called and V8 will not abort.
0781    */
0782   using AbortOnUncaughtExceptionCallback = bool (*)(Isolate*);
0783   void SetAbortOnUncaughtExceptionCallback(
0784       AbortOnUncaughtExceptionCallback callback);
0785 
0786   /**
0787    * This specifies the callback called by the upcoming dynamic
0788    * import() language feature to load modules.
0789    */
0790   void SetHostImportModuleDynamicallyCallback(
0791       HostImportModuleDynamicallyCallback callback);
0792 
0793   /**
0794    * This specifies the callback called by the upcoming dynamic
0795    * import() and import.source() language feature to load modules.
0796    *
0797    * This API is experimental and is expected to be changed or removed in the
0798    * future. The callback is currently only called when for source-phase
0799    * imports. Evaluation-phase imports use the existing
0800    * HostImportModuleDynamicallyCallback callback.
0801    */
0802   void SetHostImportModuleWithPhaseDynamicallyCallback(
0803       HostImportModuleWithPhaseDynamicallyCallback callback);
0804 
0805   /**
0806    * This specifies the callback called by the upcoming import.meta
0807    * language feature to retrieve host-defined meta data for a module.
0808    */
0809   void SetHostInitializeImportMetaObjectCallback(
0810       HostInitializeImportMetaObjectCallback callback);
0811 
0812   /**
0813    * This specifies the callback called by the upcoming ShadowRealm
0814    * construction language feature to retrieve host created globals.
0815    */
0816   void SetHostCreateShadowRealmContextCallback(
0817       HostCreateShadowRealmContextCallback callback);
0818 
0819   /**
0820    * Set the callback that checks whether a Error.isError should return true for
0821    * a JSApiWrapper object, i.e. whether it represents a native JS error. For
0822    * example, in an HTML embedder, DOMExceptions are considered native errors.
0823    */
0824   void SetIsJSApiWrapperNativeErrorCallback(
0825       IsJSApiWrapperNativeErrorCallback callback);
0826 
0827   /**
0828    * This specifies the callback called when the stack property of Error
0829    * is accessed.
0830    */
0831   void SetPrepareStackTraceCallback(PrepareStackTraceCallback callback);
0832 
0833   /**
0834    * Get the stackTraceLimit property of Error.
0835    */
0836   int GetStackTraceLimit();
0837 
0838 #if defined(V8_OS_WIN)
0839   /**
0840    * This specifies the callback called when an ETW tracing session starts.
0841    */
0842   V8_DEPRECATE_SOON("Use SetFilterETWSessionByURL2Callback instead")
0843   void SetFilterETWSessionByURLCallback(FilterETWSessionByURLCallback callback);
0844   void SetFilterETWSessionByURL2Callback(
0845       FilterETWSessionByURL2Callback callback);
0846 #endif  // V8_OS_WIN
0847 
0848   /**
0849    * Optional notification that the system is running low on memory.
0850    * V8 uses these notifications to guide heuristics.
0851    * It is allowed to call this function from another thread while
0852    * the isolate is executing long running JavaScript code.
0853    */
0854   void MemoryPressureNotification(MemoryPressureLevel level);
0855 
0856   /**
0857    * This triggers garbage collections until either `allocate` succeeds, or
0858    * until v8 gives up and triggers an OOM error.
0859    */
0860   bool RetryCustomAllocate(std::function<bool()> allocate);
0861 
0862   /**
0863    * Optional request from the embedder to tune v8 towards energy efficiency
0864    * rather than speed if `battery_saver_mode_enabled` is true, because the
0865    * embedder is in battery saver mode. If false, the correct tuning is left
0866    * to v8 to decide.
0867    */
0868   void SetBatterySaverMode(bool battery_saver_mode_enabled);
0869 
0870   /**
0871    * Optional request from the embedder to tune v8 towards memory efficiency
0872    * rather than speed if `memory_saver_mode_enabled` is true, because the
0873    * embedder is in memory saver mode. If false, the correct tuning is left
0874    * to v8 to decide.
0875    */
0876   void SetMemorySaverMode(bool memory_saver_mode_enabled);
0877 
0878   /**
0879    * Drop non-essential caches. Should only be called from testing code.
0880    * The method can potentially block for a long time and does not necessarily
0881    * trigger GC.
0882    */
0883   void ClearCachesForTesting();
0884 
0885   /**
0886    * Methods below this point require holding a lock (using Locker) in
0887    * a multi-threaded environment.
0888    */
0889 
0890   /**
0891    * Sets this isolate as the entered one for the current thread.
0892    * Saves the previously entered one (if any), so that it can be
0893    * restored when exiting.  Re-entering an isolate is allowed.
0894    */
0895   void Enter();
0896 
0897   /**
0898    * Exits this isolate by restoring the previously entered one in the
0899    * current thread.  The isolate may still stay the same, if it was
0900    * entered more than once.
0901    *
0902    * Requires: this == Isolate::GetCurrent().
0903    */
0904   void Exit();
0905 
0906   /**
0907    * Deinitializes and frees the isolate. The isolate must not be entered by any
0908    * thread to be disposable.
0909    */
0910   void Dispose();
0911 
0912   /**
0913    * Deinitializes the isolate, but does not free the address. The isolate must
0914    * not be entered by any thread to be deinitializable. Embedders must call
0915    * Isolate::Free() to free the isolate afterwards.
0916    */
0917   void Deinitialize();
0918 
0919   /**
0920    * Frees the memory allocated for the isolate. Can only be called after the
0921    * Isolate has already been deinitialized with Isolate::Deinitialize(). After
0922    * the isolate is freed, the next call to Isolate::New() or
0923    * Isolate::Allocate() might return the same address that just get freed.
0924    */
0925   static void Free(Isolate* isolate);
0926 
0927   /**
0928    * Dumps activated low-level V8 internal stats. This can be used instead
0929    * of performing a full isolate disposal.
0930    */
0931   void DumpAndResetStats();
0932 
0933   /**
0934    * Discards all V8 thread-specific data for the Isolate. Should be used
0935    * if a thread is terminating and it has used an Isolate that will outlive
0936    * the thread -- all thread-specific data for an Isolate is discarded when
0937    * an Isolate is disposed so this call is pointless if an Isolate is about
0938    * to be Disposed.
0939    */
0940   void DiscardThreadSpecificMetadata();
0941 
0942   /**
0943    * Associate embedder-specific data with the isolate. |slot| has to be
0944    * between 0 and GetNumberOfDataSlots() - 1.
0945    */
0946   V8_INLINE void SetData(uint32_t slot, void* data);
0947 
0948   /**
0949    * Retrieve embedder-specific data from the isolate.
0950    * Returns NULL if SetData has never been called for the given |slot|.
0951    */
0952   V8_INLINE void* GetData(uint32_t slot);
0953 
0954   /**
0955    * Returns the maximum number of available embedder data slots. Valid slots
0956    * are in the range of 0 - GetNumberOfDataSlots() - 1.
0957    */
0958   V8_INLINE static uint32_t GetNumberOfDataSlots();
0959 
0960   /**
0961    * Return data that was previously attached to the isolate snapshot via
0962    * SnapshotCreator, and removes the reference to it.
0963    * Repeated call with the same index returns an empty MaybeLocal.
0964    */
0965   template <class T>
0966   V8_INLINE MaybeLocal<T> GetDataFromSnapshotOnce(size_t index);
0967 
0968   /**
0969    * Returns the value that was set or restored by
0970    * SetContinuationPreservedEmbedderData(), if any.
0971    */
0972   V8_DEPRECATED("Use GetContinuationPreservedEmbedderDataV2 instead")
0973   Local<Value> GetContinuationPreservedEmbedderData();
0974 
0975   /**
0976    * Sets a value that will be stored on continuations and reset while the
0977    * continuation runs.
0978    */
0979   V8_DEPRECATED("Use SetContinuationPreservedEmbedderDataV2 instead")
0980   void SetContinuationPreservedEmbedderData(Local<Value> data);
0981 
0982   /**
0983    * Returns the value set by `SetContinuationPreservedEmbedderDataV2()` or
0984    * restored during microtask execution for the currently running continuation,
0985    * if any. Returns undefiend if no continuation preserved embedder data was
0986    * set.
0987    */
0988   Local<Data> GetContinuationPreservedEmbedderDataV2();
0989 
0990   /**
0991    * Sets a value that will be stored on continuations and restored while the
0992    * continuation runs. If `data` is empty, the continuation preserved embedder
0993    * data is set to undefined.
0994    */
0995   void SetContinuationPreservedEmbedderDataV2(Local<Data> data);
0996 
0997   /**
0998    * Get statistics about the heap memory usage.
0999    */
1000   void GetHeapStatistics(HeapStatistics* heap_statistics);
1001 
1002   /**
1003    * Returns the number of spaces in the heap.
1004    */
1005   size_t NumberOfHeapSpaces();
1006 
1007   /**
1008    * Get the memory usage of a space in the heap.
1009    *
1010    * \param space_statistics The HeapSpaceStatistics object to fill in
1011    *   statistics.
1012    * \param index The index of the space to get statistics from, which ranges
1013    *   from 0 to NumberOfHeapSpaces() - 1.
1014    * \returns true on success.
1015    */
1016   bool GetHeapSpaceStatistics(HeapSpaceStatistics* space_statistics,
1017                               size_t index);
1018 
1019   /**
1020    * Returns the number of types of objects tracked in the heap at GC.
1021    */
1022   size_t NumberOfTrackedHeapObjectTypes();
1023 
1024   /**
1025    * Get statistics about objects in the heap.
1026    *
1027    * \param object_statistics The HeapObjectStatistics object to fill in
1028    *   statistics of objects of given type, which were live in the previous GC.
1029    * \param type_index The index of the type of object to fill details about,
1030    *   which ranges from 0 to NumberOfTrackedHeapObjectTypes() - 1.
1031    * \returns true on success.
1032    */
1033   bool GetHeapObjectStatisticsAtLastGC(HeapObjectStatistics* object_statistics,
1034                                        size_t type_index);
1035 
1036   /**
1037    * Get statistics about code and its metadata in the heap.
1038    *
1039    * \param object_statistics The HeapCodeStatistics object to fill in
1040    *   statistics of code, bytecode and their metadata.
1041    * \returns true on success.
1042    */
1043   bool GetHeapCodeAndMetadataStatistics(HeapCodeStatistics* object_statistics);
1044 
1045   /**
1046    * This API is experimental and may change significantly.
1047    *
1048    * Enqueues a memory measurement request and invokes the delegate with the
1049    * results.
1050    *
1051    * \param delegate the delegate that defines which contexts to measure and
1052    *   reports the results.
1053    *
1054    * \param execution promptness executing the memory measurement.
1055    *   The kEager value is expected to be used only in tests.
1056    */
1057   bool MeasureMemory(
1058       std::unique_ptr<MeasureMemoryDelegate> delegate,
1059       MeasureMemoryExecution execution = MeasureMemoryExecution::kDefault);
1060 
1061   /**
1062    * Get a call stack sample from the isolate.
1063    * \param state Execution state.
1064    * \param frames Caller allocated buffer to store stack frames.
1065    * \param frames_limit Maximum number of frames to capture. The buffer must
1066    *                     be large enough to hold the number of frames.
1067    * \param sample_info The sample info is filled up by the function
1068    *                    provides number of actual captured stack frames and
1069    *                    the current VM state.
1070    * \note GetStackSample should only be called when the JS thread is paused or
1071    *       interrupted. Otherwise the behavior is undefined.
1072    */
1073   void GetStackSample(const RegisterState& state, void** frames,
1074                       size_t frames_limit, SampleInfo* sample_info);
1075 
1076   /**
1077    * Adjusts the amount of registered external memory.
1078    *
1079    * \param change_in_bytes the change in externally allocated memory that is
1080    *   kept alive by JavaScript objects.
1081    * \returns the adjusted value.
1082    */
1083   V8_DEPRECATE_SOON("Use ExternalMemoryAccounter instead.")
1084   int64_t AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes);
1085 
1086   /**
1087    * Returns heap profiler for this isolate. Will return NULL until the isolate
1088    * is initialized.
1089    */
1090   HeapProfiler* GetHeapProfiler();
1091 
1092   /**
1093    * Tells the VM whether the embedder is idle or not.
1094    */
1095   void SetIdle(bool is_idle);
1096 
1097   /** Returns the ArrayBuffer::Allocator used in this isolate. */
1098   ArrayBuffer::Allocator* GetArrayBufferAllocator();
1099 
1100   /** Returns true if this isolate has a current context. */
1101   bool InContext();
1102 
1103   /**
1104    * Returns the context of the currently running JavaScript, or the context
1105    * on the top of the stack if no JavaScript is running.
1106    */
1107   Local<Context> GetCurrentContext();
1108 
1109   /**
1110    * Returns either the last context entered through V8's C++ API, or the
1111    * context of the currently running microtask while processing microtasks.
1112    * If a context is entered while executing a microtask, that context is
1113    * returned.
1114    */
1115   Local<Context> GetEnteredOrMicrotaskContext();
1116 
1117   /**
1118    * Returns the Context that corresponds to the Incumbent realm in HTML spec.
1119    * https://html.spec.whatwg.org/multipage/webappapis.html#incumbent
1120    */
1121   Local<Context> GetIncumbentContext();
1122 
1123   /**
1124    * Returns the host defined options set for currently running script or
1125    * module, if available.
1126    */
1127   MaybeLocal<Data> GetCurrentHostDefinedOptions();
1128 
1129   /**
1130    * Schedules a v8::Exception::Error with the given message.
1131    * See ThrowException for more details. Templatized to provide compile-time
1132    * errors in case of too long strings (see v8::String::NewFromUtf8Literal).
1133    */
1134   template <int N>
1135   Local<Value> ThrowError(const char (&message)[N]) {
1136     return ThrowError(String::NewFromUtf8Literal(this, message));
1137   }
1138   Local<Value> ThrowError(Local<String> message);
1139 
1140   /**
1141    * Schedules an exception to be thrown when returning to JavaScript.  When an
1142    * exception has been scheduled it is illegal to invoke any JavaScript
1143    * operation; the caller must return immediately and only after the exception
1144    * has been handled does it become legal to invoke JavaScript operations.
1145    */
1146   Local<Value> ThrowException(Local<Value> exception);
1147 
1148   /**
1149    * Returns true if an exception was thrown but not processed yet by an
1150    * exception handler on JavaScript side or by v8::TryCatch handler.
1151    *
1152    * This is an experimental feature and may still change significantly.
1153    */
1154   bool HasPendingException();
1155 
1156   using GCCallback = void (*)(Isolate* isolate, GCType type,
1157                               GCCallbackFlags flags);
1158   using GCCallbackWithData = void (*)(Isolate* isolate, GCType type,
1159                                       GCCallbackFlags flags, void* data);
1160 
1161   /**
1162    * Enables the host application to receive a notification before a
1163    * garbage collection.
1164    *
1165    * \param callback The callback to be invoked. The callback is allowed to
1166    *     allocate but invocation is not re-entrant: a callback triggering
1167    *     garbage collection will not be called again. JS execution is prohibited
1168    *     from these callbacks. A single callback may only be registered once.
1169    * \param gc_type_filter A filter in case it should be applied.
1170    */
1171   void AddGCPrologueCallback(GCCallback callback,
1172                              GCType gc_type_filter = kGCTypeAll);
1173 
1174   /**
1175    * \copydoc AddGCPrologueCallback(GCCallback, GCType)
1176    *
1177    * \param data Additional data that should be passed to the callback.
1178    */
1179   void AddGCPrologueCallback(GCCallbackWithData callback, void* data = nullptr,
1180                              GCType gc_type_filter = kGCTypeAll);
1181 
1182   /**
1183    * This function removes a callback which was added by
1184    * `AddGCPrologueCallback`.
1185    *
1186    * \param callback the callback to remove.
1187    */
1188   void RemoveGCPrologueCallback(GCCallback callback);
1189 
1190   /**
1191    * \copydoc AddGCPrologueCallback(GCCallback)
1192    *
1193    * \param data Additional data that was used to install the callback.
1194    */
1195   void RemoveGCPrologueCallback(GCCallbackWithData, void* data = nullptr);
1196 
1197   /**
1198    * Enables the host application to receive a notification after a
1199    * garbage collection.
1200    *
1201    * \copydetails AddGCPrologueCallback(GCCallback, GCType)
1202    */
1203   void AddGCEpilogueCallback(GCCallback callback,
1204                              GCType gc_type_filter = kGCTypeAll);
1205 
1206   /**
1207    * \copydoc AddGCEpilogueCallback(GCCallback, GCType)
1208    *
1209    * \param data Additional data that should be passed to the callback.
1210    */
1211   void AddGCEpilogueCallback(GCCallbackWithData callback, void* data = nullptr,
1212                              GCType gc_type_filter = kGCTypeAll);
1213 
1214   /**
1215    * This function removes a callback which was added by
1216    * `AddGCEpilogueCallback`.
1217    *
1218    * \param callback the callback to remove.
1219    */
1220   void RemoveGCEpilogueCallback(GCCallback callback);
1221 
1222   /**
1223    * \copydoc RemoveGCEpilogueCallback(GCCallback)
1224    *
1225    * \param data Additional data that was used to install the callback.
1226    */
1227   void RemoveGCEpilogueCallback(GCCallbackWithData callback,
1228                                 void* data = nullptr);
1229 
1230   /**
1231    * Sets an embedder roots handle that V8 should consider when performing
1232    * non-unified heap garbage collections. The intended use case is for setting
1233    * a custom handler after invoking `AttachCppHeap()`.
1234    *
1235    * V8 does not take ownership of the handler.
1236    */
1237   void SetEmbedderRootsHandler(EmbedderRootsHandler* handler);
1238 
1239   using ReleaseCppHeapCallback = void (*)(std::unique_ptr<CppHeap>);
1240 
1241   /**
1242    * Sets a callback on the isolate that gets called when the CppHeap gets
1243    * detached. The callback can then either take ownership of the CppHeap, or
1244    * the CppHeap gets deallocated.
1245    */
1246   void SetReleaseCppHeapCallbackForTesting(ReleaseCppHeapCallback callback);
1247 
1248   /**
1249    * \returns the C++ heap managed by V8. Only available if such a heap has been
1250    *   attached using `AttachCppHeap()`.
1251    */
1252   CppHeap* GetCppHeap() const;
1253 
1254   using GetExternallyAllocatedMemoryInBytesCallback = size_t (*)();
1255 
1256   /**
1257    * Set the callback that tells V8 how much memory is currently allocated
1258    * externally of the V8 heap. Ideally this memory is somehow connected to V8
1259    * objects and may get freed-up when the corresponding V8 objects get
1260    * collected by a V8 garbage collection.
1261    */
1262   void SetGetExternallyAllocatedMemoryInBytesCallback(
1263       GetExternallyAllocatedMemoryInBytesCallback callback);
1264 
1265   /**
1266    * Forcefully terminate the current thread of JavaScript execution
1267    * in the given isolate.
1268    *
1269    * This method can be used by any thread even if that thread has not
1270    * acquired the V8 lock with a Locker object.
1271    */
1272   void TerminateExecution();
1273 
1274   /**
1275    * Is V8 terminating JavaScript execution.
1276    *
1277    * Returns true if JavaScript execution is currently terminating
1278    * because of a call to TerminateExecution.  In that case there are
1279    * still JavaScript frames on the stack and the termination
1280    * exception is still active.
1281    */
1282   bool IsExecutionTerminating();
1283 
1284   /**
1285    * Resume execution capability in the given isolate, whose execution
1286    * was previously forcefully terminated using TerminateExecution().
1287    *
1288    * When execution is forcefully terminated using TerminateExecution(),
1289    * the isolate can not resume execution until all JavaScript frames
1290    * have propagated the uncatchable exception which is generated.  This
1291    * method allows the program embedding the engine to handle the
1292    * termination event and resume execution capability, even if
1293    * JavaScript frames remain on the stack.
1294    *
1295    * This method can be used by any thread even if that thread has not
1296    * acquired the V8 lock with a Locker object.
1297    */
1298   void CancelTerminateExecution();
1299 
1300   /**
1301    * Request V8 to interrupt long running JavaScript code and invoke
1302    * the given |callback| passing the given |data| to it. After |callback|
1303    * returns control will be returned to the JavaScript code.
1304    * There may be a number of interrupt requests in flight.
1305    * Can be called from another thread without acquiring a |Locker|.
1306    * Registered |callback| must not reenter interrupted Isolate.
1307    */
1308   void RequestInterrupt(InterruptCallback callback, void* data);
1309 
1310   /**
1311    * Returns true if there is ongoing background work within V8 that will
1312    * eventually post a foreground task, like asynchronous WebAssembly
1313    * compilation.
1314    */
1315   bool HasPendingBackgroundTasks();
1316 
1317   /**
1318    * Request garbage collection in this Isolate. It is only valid to call this
1319    * function if --expose_gc was specified.
1320    *
1321    * This should only be used for testing purposes and not to enforce a garbage
1322    * collection schedule. It has strong negative impact on the garbage
1323    * collection performance. Use MemoryPressureNotification() instead to
1324    * influence the garbage collection schedule.
1325    */
1326   void RequestGarbageCollectionForTesting(GarbageCollectionType type);
1327 
1328   /**
1329    * Request garbage collection with a specific embedderstack state in this
1330    * Isolate. It is only valid to call this function if --expose_gc was
1331    * specified.
1332    *
1333    * This should only be used for testing purposes and not to enforce a garbage
1334    * collection schedule. It has strong negative impact on the garbage
1335    * collection performance. Use MemoryPressureNotification() instead to
1336    * influence the garbage collection schedule.
1337    */
1338   void RequestGarbageCollectionForTesting(GarbageCollectionType type,
1339                                           StackState stack_state);
1340 
1341   /**
1342    * Set the callback to invoke for logging event.
1343    */
1344   void SetEventLogger(LogEventCallback that);
1345 
1346   /**
1347    * Adds a callback to notify the host application right before a script
1348    * is about to run. If a script re-enters the runtime during executing, the
1349    * BeforeCallEnteredCallback is invoked for each re-entrance.
1350    * Executing scripts inside the callback will re-trigger the callback.
1351    */
1352   void AddBeforeCallEnteredCallback(BeforeCallEnteredCallback callback);
1353 
1354   /**
1355    * Removes callback that was installed by AddBeforeCallEnteredCallback.
1356    */
1357   void RemoveBeforeCallEnteredCallback(BeforeCallEnteredCallback callback);
1358 
1359   /**
1360    * Adds a callback to notify the host application when a script finished
1361    * running.  If a script re-enters the runtime during executing, the
1362    * CallCompletedCallback is only invoked when the outer-most script
1363    * execution ends.  Executing scripts inside the callback do not trigger
1364    * further callbacks.
1365    */
1366   void AddCallCompletedCallback(CallCompletedCallback callback);
1367 
1368   /**
1369    * Removes callback that was installed by AddCallCompletedCallback.
1370    */
1371   void RemoveCallCompletedCallback(CallCompletedCallback callback);
1372 
1373   /**
1374    * Set the PromiseHook callback for various promise lifecycle
1375    * events.
1376    */
1377   void SetPromiseHook(PromiseHook hook);
1378 
1379   /**
1380    * Set callback to notify about promise reject with no handler, or
1381    * revocation of such a previous notification once the handler is added.
1382    */
1383   void SetPromiseRejectCallback(PromiseRejectCallback callback);
1384 
1385   /**
1386    * This is a part of experimental Api and might be changed without further
1387    * notice.
1388    * Do not use it.
1389    *
1390    * Set callback to notify about a new exception being thrown.
1391    */
1392   void SetExceptionPropagationCallback(ExceptionPropagationCallback callback);
1393 
1394   /**
1395    * Runs the default MicrotaskQueue until it gets empty and perform other
1396    * microtask checkpoint steps, such as calling ClearKeptObjects. Asserts that
1397    * the MicrotasksPolicy is not kScoped. Any exceptions thrown by microtask
1398    * callbacks are swallowed.
1399    */
1400   void PerformMicrotaskCheckpoint();
1401 
1402   /**
1403    * Enqueues the callback to the default MicrotaskQueue
1404    */
1405   void EnqueueMicrotask(Local<Function> microtask);
1406 
1407   /**
1408    * Enqueues the callback to the default MicrotaskQueue
1409    */
1410   void EnqueueMicrotask(MicrotaskCallback callback, void* data = nullptr);
1411 
1412   /**
1413    * Controls how Microtasks are invoked. See MicrotasksPolicy for details.
1414    */
1415   void SetMicrotasksPolicy(MicrotasksPolicy policy);
1416 
1417   /**
1418    * Returns the policy controlling how Microtasks are invoked.
1419    */
1420   MicrotasksPolicy GetMicrotasksPolicy() const;
1421 
1422   /**
1423    * Adds a callback to notify the host application after
1424    * microtasks were run on the default MicrotaskQueue. The callback is
1425    * triggered by explicit RunMicrotasks call or automatic microtasks execution
1426    * (see SetMicrotaskPolicy).
1427    *
1428    * Callback will trigger even if microtasks were attempted to run,
1429    * but the microtasks queue was empty and no single microtask was actually
1430    * executed.
1431    *
1432    * Executing scripts inside the callback will not re-trigger microtasks and
1433    * the callback.
1434    */
1435   void AddMicrotasksCompletedCallback(
1436       MicrotasksCompletedCallbackWithData callback, void* data = nullptr);
1437 
1438   /**
1439    * Removes callback that was installed by AddMicrotasksCompletedCallback.
1440    */
1441   void RemoveMicrotasksCompletedCallback(
1442       MicrotasksCompletedCallbackWithData callback, void* data = nullptr);
1443 
1444   /**
1445    * Sets a callback for counting the number of times a feature of V8 is used.
1446    */
1447   void SetUseCounterCallback(UseCounterCallback callback);
1448 
1449   /**
1450    * Enables the host application to provide a mechanism for recording
1451    * statistics counters.
1452    */
1453   void SetCounterFunction(CounterLookupCallback);
1454 
1455   /**
1456    * Enables the host application to provide a mechanism for recording
1457    * histograms. The CreateHistogram function returns a
1458    * histogram which will later be passed to the AddHistogramSample
1459    * function.
1460    */
1461   void SetCreateHistogramFunction(CreateHistogramCallback);
1462   void SetAddHistogramSampleFunction(AddHistogramSampleCallback);
1463 
1464   /**
1465    * Enables the host application to provide a mechanism for recording
1466    * event based metrics. In order to use this interface
1467    *   include/v8-metrics.h
1468    * needs to be included and the recorder needs to be derived from the
1469    * Recorder base class defined there.
1470    * This method can only be called once per isolate and must happen during
1471    * isolate initialization before background threads are spawned.
1472    */
1473   void SetMetricsRecorder(
1474       const std::shared_ptr<metrics::Recorder>& metrics_recorder);
1475 
1476   /**
1477    * Enables the host application to provide a mechanism for recording a
1478    * predefined set of data as crash keys to be used in postmortem debugging in
1479    * case of a crash.
1480    */
1481   void SetAddCrashKeyCallback(AddCrashKeyCallback);
1482 
1483   /**
1484    * Enables the host application to provide a mechanism for allocating a new
1485    * crash key and setting/updating values for them.
1486    */
1487   void SetCrashKeyStringCallbacks(AllocateCrashKeyStringCallback,
1488                                   SetCrashKeyStringCallback);
1489 
1490   /**
1491    * Optional notification that the system is running low on memory.
1492    * V8 uses these notifications to attempt to free memory.
1493    */
1494   void LowMemoryNotification();
1495 
1496   /**
1497    * Optional notification that a context has been disposed. V8 uses these
1498    * notifications to guide the GC heuristic and cancel FinalizationRegistry
1499    * cleanup tasks. Returns the number of context disposals - including this one
1500    * - since the last time V8 had a chance to clean up.
1501    *
1502    * The optional parameter |dependant_context| specifies whether the disposed
1503    * context was depending on state from other contexts or not.
1504    */
1505   V8_DEPRECATE_SOON("Use version that passes ContextDependants.")
1506   int ContextDisposedNotification(bool dependant_context = true);
1507 
1508   /**
1509    * Optional notification that a context has been disposed. V8 uses these
1510    * notifications to guide heuristics on e.g. GC or compilers.
1511    *
1512    * \param dependants A signal on whether this context possibly had any
1513    *     dependants.
1514    */
1515   void ContextDisposedNotification(ContextDependants dependants);
1516 
1517   /**
1518    * Optional notification that the isolate switched to the foreground.
1519    * V8 uses these notifications to guide heuristics.
1520    */
1521   V8_DEPRECATE_SOON("Use SetPriority(Priority::kUserBlocking) instead")
1522   void IsolateInForegroundNotification();
1523 
1524   /**
1525    * Optional notification that the isolate switched to the background.
1526    * V8 uses these notifications to guide heuristics.
1527    */
1528   V8_DEPRECATE_SOON("Use SetPriority(Priority::kBestEffort) instead")
1529   void IsolateInBackgroundNotification();
1530 
1531   /**
1532    * Optional notification that the isolate changed `priority`.
1533    * V8 uses the priority value to guide heuristics.
1534    */
1535   void SetPriority(Priority priority);
1536 
1537   /**
1538    * Optional notification to tell V8 whether the embedder is currently loading
1539    * resources. If the embedder uses this notification, it should call
1540    * SetIsLoading(true) when loading starts and SetIsLoading(false) when it
1541    * ends.
1542    * It's valid to call SetIsLoading(true) again while loading, which will
1543    * update the timestamp when V8 considers the load started. Calling
1544    * SetIsLoading(false) while not loading does nothing.
1545    * V8 uses these notifications to guide heuristics.
1546    * This is an unfinished experimental feature. Semantics and implementation
1547    * may change frequently.
1548    */
1549   void SetIsLoading(bool is_loading);
1550 
1551   /**
1552    * Optional notification to tell V8 whether the embedder is currently
1553    * handling user input. If the embedder uses this notification, it should
1554    * call SetIsInputHandling(true) when input handling starts, and
1555    * SetIsInputHandling(false) when it ends.
1556    * Calling SetIsInputHandling(true) while handling input, or calling
1557    * SetIsInputHandling(false) while not handling input, both have no effect.
1558    * V8 uses these notifications to guide heuristics.
1559    * This is an unfinished experimental feature. Semantics and implementation
1560    * may change frequently.
1561    */
1562   void SetIsInputHandling(bool is_input_handling);
1563 
1564   /**
1565    * Optional notification to tell V8 whether the embedder is currently frozen.
1566    * V8 uses these notifications to guide heuristics.
1567    * This is an unfinished experimental feature. Semantics and implementation
1568    * may change frequently.
1569    */
1570   void Freeze(bool is_frozen);
1571 
1572   /**
1573    * Optional notification to tell V8 the current isolate is used for debugging
1574    * and requires higher heap limit.
1575    */
1576   void IncreaseHeapLimitForDebugging();
1577 
1578   /**
1579    * Restores the original heap limit after IncreaseHeapLimitForDebugging().
1580    */
1581   void RestoreOriginalHeapLimit();
1582 
1583   /**
1584    * Returns true if the heap limit was increased for debugging and the
1585    * original heap limit was not restored yet.
1586    */
1587   bool IsHeapLimitIncreasedForDebugging();
1588 
1589   /**
1590    * Allows the host application to provide the address of a function that is
1591    * notified each time code is added, moved or removed.
1592    *
1593    * \param options options for the JIT code event handler.
1594    * \param event_handler the JIT code event handler, which will be invoked
1595    *     each time code is added, moved or removed.
1596    * \note \p event_handler won't get notified of existent code.
1597    * \note since code removal notifications are not currently issued, the
1598    *     \p event_handler may get notifications of code that overlaps earlier
1599    *     code notifications. This happens when code areas are reused, and the
1600    *     earlier overlapping code areas should therefore be discarded.
1601    * \note the events passed to \p event_handler and the strings they point to
1602    *     are not guaranteed to live past each call. The \p event_handler must
1603    *     copy strings and other parameters it needs to keep around.
1604    * \note the set of events declared in JitCodeEvent::EventType is expected to
1605    *     grow over time, and the JitCodeEvent structure is expected to accrue
1606    *     new members. The \p event_handler function must ignore event codes
1607    *     it does not recognize to maintain future compatibility.
1608    * \note Use Isolate::CreateParams to get events for code executed during
1609    *     Isolate setup.
1610    */
1611   void SetJitCodeEventHandler(JitCodeEventOptions options,
1612                               JitCodeEventHandler event_handler);
1613 
1614   /**
1615    * Modifies the stack limit for this Isolate.
1616    *
1617    * \param stack_limit An address beyond which the Vm's stack may not grow.
1618    *
1619    * \note  If you are using threads then you should hold the V8::Locker lock
1620    *     while setting the stack limit and you must set a non-default stack
1621    *     limit separately for each thread.
1622    */
1623   void SetStackLimit(uintptr_t stack_limit);
1624 
1625   /**
1626    * Returns a memory range that can potentially contain jitted code. Code for
1627    * V8's 'builtins' will not be in this range if embedded builtins is enabled.
1628    *
1629    * On Win64, embedders are advised to install function table callbacks for
1630    * these ranges, as default SEH won't be able to unwind through jitted code.
1631    * The first page of the code range is reserved for the embedder and is
1632    * committed, writable, and executable, to be used to store unwind data, as
1633    * documented in
1634    * https://docs.microsoft.com/en-us/cpp/build/exception-handling-x64.
1635    *
1636    * Might be empty on other platforms.
1637    *
1638    * https://code.google.com/p/v8/issues/detail?id=3598
1639    */
1640   void GetCodeRange(void** start, size_t* length_in_bytes);
1641 
1642   /**
1643    * As GetCodeRange, but for embedded builtins (these live in a distinct
1644    * memory region from other V8 Code objects).
1645    */
1646   void GetEmbeddedCodeRange(const void** start, size_t* length_in_bytes);
1647 
1648   /**
1649    * Returns the JSEntryStubs necessary for use with the Unwinder API.
1650    */
1651   JSEntryStubs GetJSEntryStubs();
1652 
1653   static constexpr size_t kMinCodePagesBufferSize = 32;
1654 
1655   /**
1656    * Copies the code heap pages currently in use by V8 into |code_pages_out|.
1657    * |code_pages_out| must have at least kMinCodePagesBufferSize capacity and
1658    * must be empty.
1659    *
1660    * Signal-safe, does not allocate, does not access the V8 heap.
1661    * No code on the stack can rely on pages that might be missing.
1662    *
1663    * Returns the number of pages available to be copied, which might be greater
1664    * than |capacity|. In this case, only |capacity| pages will be copied into
1665    * |code_pages_out|. The caller should provide a bigger buffer on the next
1666    * call in order to get all available code pages, but this is not required.
1667    */
1668   size_t CopyCodePages(size_t capacity, MemoryRange* code_pages_out);
1669 
1670   /** Set the callback to invoke in case of fatal errors. */
1671   void SetFatalErrorHandler(FatalErrorCallback that);
1672 
1673   /** Set the callback to invoke in case of OOM errors. */
1674   void SetOOMErrorHandler(OOMErrorCallback that);
1675 
1676   /**
1677    * \copydoc SetOOMErrorHandler(OOMErrorCallback)
1678    *
1679    * \param data Additional data that should be passed to the callback.
1680    */
1681   void SetOOMErrorHandler(OOMErrorCallbackWithData that, void* data);
1682 
1683   /**
1684    * Add a callback to invoke in case the heap size is close to the heap limit.
1685    * If multiple callbacks are added, only the most recently added callback is
1686    * invoked.
1687    */
1688   void AddNearHeapLimitCallback(NearHeapLimitCallback callback, void* data);
1689 
1690   /**
1691    * Remove the given callback and restore the heap limit to the
1692    * given limit. If the given limit is zero, then it is ignored.
1693    * If the current heap size is greater than the given limit,
1694    * then the heap limit is restored to the minimal limit that
1695    * is possible for the current heap size.
1696    */
1697   void RemoveNearHeapLimitCallback(NearHeapLimitCallback callback,
1698                                    size_t heap_limit);
1699 
1700   /**
1701    * If the heap limit was changed by the NearHeapLimitCallback, then the
1702    * initial heap limit will be restored once the heap size falls below the
1703    * given threshold percentage of the initial heap limit.
1704    * The threshold percentage is a number in (0.0, 1.0) range.
1705    */
1706   void AutomaticallyRestoreInitialHeapLimit(double threshold_percent = 0.5);
1707 
1708   /**
1709    * Set the callback to invoke to check if code generation from
1710    * strings should be allowed.
1711    */
1712   void SetModifyCodeGenerationFromStringsCallback(
1713       ModifyCodeGenerationFromStringsCallback2 callback);
1714 
1715   /**
1716    * Set the callback to invoke to check if wasm code generation should
1717    * be allowed.
1718    */
1719   void SetAllowWasmCodeGenerationCallback(
1720       AllowWasmCodeGenerationCallback callback);
1721 
1722   /**
1723    * Embedder over{ride|load} injection points for wasm APIs. The expectation
1724    * is that the embedder sets them at most once.
1725    */
1726   void SetWasmModuleCallback(ExtensionCallback callback);
1727   void SetWasmInstanceCallback(ExtensionCallback callback);
1728 
1729   void SetWasmStreamingCallback(WasmStreamingCallback callback);
1730 
1731   void SetWasmAsyncResolvePromiseCallback(
1732       WasmAsyncResolvePromiseCallback callback);
1733 
1734   void SetWasmLoadSourceMapCallback(WasmLoadSourceMapCallback callback);
1735 
1736   void SetWasmCustomDescriptorsEnabledCallback(
1737       WasmCustomDescriptorsEnabledCallback callback);
1738 
1739   void SetSharedArrayBufferConstructorEnabledCallback(
1740       SharedArrayBufferConstructorEnabledCallback callback);
1741 
1742   /**
1743    * This function can be called by the embedder to signal V8 that the dynamic
1744    * enabling of features has finished. V8 can now set up dynamically added
1745    * features.
1746    */
1747   void InstallConditionalFeatures(Local<Context> context);
1748 
1749   /**
1750    * Check if V8 is dead and therefore unusable.  This is the case after
1751    * fatal errors such as out-of-memory situations.
1752    */
1753   bool IsDead();
1754 
1755   /**
1756    * Adds a message listener (errors only).
1757    *
1758    * The same message listener can be added more than once and in that
1759    * case it will be called more than once for each message.
1760    *
1761    * If data is specified, it will be passed to the callback when it is called.
1762    * Otherwise, the exception object will be passed to the callback instead.
1763    */
1764   bool AddMessageListener(MessageCallback callback,
1765                           Local<Value> data = Local<Value>());
1766 
1767   /**
1768    * Adds a message listener.
1769    *
1770    * The same message listener can be added more than once and in that
1771    * case it will be called more than once for each message.
1772    *
1773    * If data is specified, it will be passed to the callback when it is called.
1774    * Otherwise, the exception object will be passed to the callback instead.
1775    *
1776    * A listener can listen for particular error levels by providing a mask.
1777    */
1778   bool AddMessageListenerWithErrorLevel(MessageCallback callback,
1779                                         int message_levels,
1780                                         Local<Value> data = Local<Value>());
1781 
1782   /**
1783    * Remove all message listeners from the specified callback function.
1784    */
1785   void RemoveMessageListeners(MessageCallback callback);
1786 
1787   /** Callback function for reporting failed access checks.*/
1788   void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback);
1789 
1790   /**
1791    * Tells V8 to capture current stack trace when uncaught exception occurs
1792    * and report it to the message listeners. The option is off by default.
1793    */
1794   void SetCaptureStackTraceForUncaughtExceptions(
1795       bool capture, int frame_limit = 10,
1796       StackTrace::StackTraceOptions options = StackTrace::kOverview);
1797 
1798   /**
1799    * Check if this isolate is in use.
1800    * True if at least one thread Enter'ed this isolate.
1801    */
1802   bool IsInUse();
1803 
1804   /**
1805    * Set whether calling Atomics.wait (a function that may block) is allowed in
1806    * this isolate. This can also be configured via
1807    * CreateParams::allow_atomics_wait.
1808    */
1809   void SetAllowAtomicsWait(bool allow);
1810 
1811   /**
1812    * Time zone redetection indicator for
1813    * DateTimeConfigurationChangeNotification.
1814    *
1815    * kSkip indicates V8 that the notification should not trigger redetecting
1816    * host time zone. kRedetect indicates V8 that host time zone should be
1817    * redetected, and used to set the default time zone.
1818    *
1819    * The host time zone detection may require file system access or similar
1820    * operations unlikely to be available inside a sandbox. If v8 is run inside a
1821    * sandbox, the host time zone has to be detected outside the sandbox before
1822    * calling DateTimeConfigurationChangeNotification function.
1823    */
1824   enum class TimeZoneDetection { kSkip, kRedetect };
1825 
1826   /**
1827    * Notification that the embedder has changed the time zone, daylight savings
1828    * time or other date / time configuration parameters. V8 keeps a cache of
1829    * various values used for date / time computation. This notification will
1830    * reset those cached values for the current context so that date / time
1831    * configuration changes would be reflected.
1832    *
1833    * This API should not be called more than needed as it will negatively impact
1834    * the performance of date operations.
1835    */
1836   void DateTimeConfigurationChangeNotification(
1837       TimeZoneDetection time_zone_detection = TimeZoneDetection::kSkip);
1838 
1839   /**
1840    * Notification that the embedder has changed the locale. V8 keeps a cache of
1841    * various values used for locale computation. This notification will reset
1842    * those cached values for the current context so that locale configuration
1843    * changes would be reflected.
1844    *
1845    * This API should not be called more than needed as it will negatively impact
1846    * the performance of locale operations.
1847    */
1848   void LocaleConfigurationChangeNotification();
1849 
1850   /**
1851    * Returns the default locale in a string if Intl support is enabled.
1852    * Otherwise returns an empty string.
1853    */
1854   std::string GetDefaultLocale();
1855 
1856   /**
1857    * Returns a canonical and case-regularized form of locale if Intl support is
1858    * enabled. If the locale is not syntactically well-formed, throws a
1859    * RangeError.
1860    *
1861    * If Intl support is not enabled, returns Nothing<std::string>().
1862    *
1863    * Corresponds to the combination of the abstract operations
1864    * IsStructurallyValidLanguageTag and CanonicalizeUnicodeLocaleId. See:
1865    * https://tc39.es/ecma402/#sec-isstructurallyvalidlanguagetag
1866    * https://tc39.es/ecma402/#sec-canonicalizeunicodelocaleid
1867    */
1868   V8_WARN_UNUSED_RESULT Maybe<std::string>
1869   ValidateAndCanonicalizeUnicodeLocaleId(std::string_view locale);
1870 
1871   /**
1872    * Returns the hash seed for that isolate, for testing purposes.
1873    */
1874   uint64_t GetHashSeed();
1875 
1876   Isolate() = delete;
1877   ~Isolate() = delete;
1878   Isolate(const Isolate&) = delete;
1879   Isolate& operator=(const Isolate&) = delete;
1880   // Deleting operator new and delete here is allowed as ctor and dtor is also
1881   // deleted.
1882   void* operator new(size_t size) = delete;
1883   void* operator new[](size_t size) = delete;
1884   void operator delete(void*, size_t) = delete;
1885   void operator delete[](void*, size_t) = delete;
1886 
1887  private:
1888   template <class K, class V, class Traits>
1889   friend class PersistentValueMapBase;
1890   friend class ExternalMemoryAccounter;
1891 
1892   internal::ValueHelper::InternalRepresentationType GetDataFromSnapshotOnce(
1893       size_t index);
1894   int64_t AdjustAmountOfExternalAllocatedMemoryImpl(int64_t change_in_bytes);
1895   void HandleExternalMemoryInterrupt();
1896 };
1897 
1898 void Isolate::SetData(uint32_t slot, void* data) {
1899   using I = internal::Internals;
1900   I::SetEmbedderData(this, slot, data);
1901 }
1902 
1903 void* Isolate::GetData(uint32_t slot) {
1904   using I = internal::Internals;
1905   return I::GetEmbedderData(this, slot);
1906 }
1907 
1908 uint32_t Isolate::GetNumberOfDataSlots() {
1909   using I = internal::Internals;
1910   return I::kNumIsolateDataSlots;
1911 }
1912 
1913 template <class T>
1914 MaybeLocal<T> Isolate::GetDataFromSnapshotOnce(size_t index) {
1915   if (auto repr = GetDataFromSnapshotOnce(index);
1916       repr != internal::ValueHelper::kEmpty) {
1917     internal::PerformCastCheck(internal::ValueHelper::ReprAsValue<T>(repr));
1918     return Local<T>::FromRepr(repr);
1919   }
1920   return {};
1921 }
1922 
1923 }  // namespace v8
1924 
1925 #endif  // INCLUDE_V8_ISOLATE_H_