LCOV - code coverage report
Current view: top level - include - v8.h (source / functions) Hit Total Coverage
Test: app.info Lines: 192 209 91.9 %
Date: 2017-04-26 Functions: 6 36 16.7 %

          Line data    Source code
       1             : // Copyright 2012 the V8 project authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : /** \mainpage V8 API Reference Guide
       6             :  *
       7             :  * V8 is Google's open source JavaScript engine.
       8             :  *
       9             :  * This set of documents provides reference material generated from the
      10             :  * V8 header file, include/v8.h.
      11             :  *
      12             :  * For other documentation see http://code.google.com/apis/v8/
      13             :  */
      14             : 
      15             : #ifndef INCLUDE_V8_H_
      16             : #define INCLUDE_V8_H_
      17             : 
      18             : #include <stddef.h>
      19             : #include <stdint.h>
      20             : #include <stdio.h>
      21             : #include <memory>
      22             : #include <utility>
      23             : #include <vector>
      24             : 
      25             : #include "v8-version.h"  // NOLINT(build/include)
      26             : #include "v8config.h"    // NOLINT(build/include)
      27             : 
      28             : // We reserve the V8_* prefix for macros defined in V8 public API and
      29             : // assume there are no name conflicts with the embedder's code.
      30             : 
      31             : #ifdef V8_OS_WIN
      32             : 
      33             : // Setup for Windows DLL export/import. When building the V8 DLL the
      34             : // BUILDING_V8_SHARED needs to be defined. When building a program which uses
      35             : // the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8
      36             : // static library or building a program which uses the V8 static library neither
      37             : // BUILDING_V8_SHARED nor USING_V8_SHARED should be defined.
      38             : #ifdef BUILDING_V8_SHARED
      39             : # define V8_EXPORT __declspec(dllexport)
      40             : #elif USING_V8_SHARED
      41             : # define V8_EXPORT __declspec(dllimport)
      42             : #else
      43             : # define V8_EXPORT
      44             : #endif  // BUILDING_V8_SHARED
      45             : 
      46             : #else  // V8_OS_WIN
      47             : 
      48             : // Setup for Linux shared library export.
      49             : #if V8_HAS_ATTRIBUTE_VISIBILITY
      50             : # ifdef BUILDING_V8_SHARED
      51             : #  define V8_EXPORT __attribute__ ((visibility("default")))
      52             : # else
      53             : #  define V8_EXPORT
      54             : # endif
      55             : #else
      56             : # define V8_EXPORT
      57             : #endif
      58             : 
      59             : #endif  // V8_OS_WIN
      60             : 
      61             : /**
      62             :  * The v8 JavaScript engine.
      63             :  */
      64             : namespace v8 {
      65             : 
      66             : class AccessorSignature;
      67             : class Array;
      68             : class ArrayBuffer;
      69             : class Boolean;
      70             : class BooleanObject;
      71             : class Context;
      72             : class CpuProfiler;
      73             : class Data;
      74             : class Date;
      75             : class External;
      76             : class Function;
      77             : class FunctionTemplate;
      78             : class HeapProfiler;
      79             : class ImplementationUtilities;
      80             : class Int32;
      81             : class Integer;
      82             : class Isolate;
      83             : template <class T>
      84             : class Maybe;
      85             : class Name;
      86             : class Number;
      87             : class NumberObject;
      88             : class Object;
      89             : class ObjectOperationDescriptor;
      90             : class ObjectTemplate;
      91             : class Platform;
      92             : class Primitive;
      93             : class Promise;
      94             : class PropertyDescriptor;
      95             : class Proxy;
      96             : class RawOperationDescriptor;
      97             : class Script;
      98             : class SharedArrayBuffer;
      99             : class Signature;
     100             : class StartupData;
     101             : class StackFrame;
     102             : class StackTrace;
     103             : class String;
     104             : class StringObject;
     105             : class Symbol;
     106             : class SymbolObject;
     107             : class Private;
     108             : class Uint32;
     109             : class Utils;
     110             : class Value;
     111             : class WasmCompiledModule;
     112             : template <class T> class Local;
     113             : template <class T>
     114             : class MaybeLocal;
     115             : template <class T> class Eternal;
     116             : template<class T> class NonCopyablePersistentTraits;
     117             : template<class T> class PersistentBase;
     118             : template <class T, class M = NonCopyablePersistentTraits<T> >
     119             : class Persistent;
     120             : template <class T>
     121             : class Global;
     122             : template<class K, class V, class T> class PersistentValueMap;
     123             : template <class K, class V, class T>
     124             : class PersistentValueMapBase;
     125             : template <class K, class V, class T>
     126             : class GlobalValueMap;
     127             : template<class V, class T> class PersistentValueVector;
     128             : template<class T, class P> class WeakCallbackObject;
     129             : class FunctionTemplate;
     130             : class ObjectTemplate;
     131             : template<typename T> class FunctionCallbackInfo;
     132             : template<typename T> class PropertyCallbackInfo;
     133             : class StackTrace;
     134             : class StackFrame;
     135             : class Isolate;
     136             : class CallHandlerHelper;
     137             : class EscapableHandleScope;
     138             : template<typename T> class ReturnValue;
     139             : 
     140             : namespace internal {
     141             : class Arguments;
     142             : class Heap;
     143             : class HeapObject;
     144             : class Isolate;
     145             : class Object;
     146             : struct StreamedSource;
     147             : template<typename T> class CustomArguments;
     148             : class PropertyCallbackArguments;
     149             : class FunctionCallbackArguments;
     150             : class GlobalHandles;
     151             : }  // namespace internal
     152             : 
     153             : namespace debug {
     154             : class ConsoleCallArguments;
     155             : }  // namespace debug
     156             : 
     157             : // --- Handles ---
     158             : 
     159             : #define TYPE_CHECK(T, S)                                       \
     160             :   while (false) {                                              \
     161             :     *(static_cast<T* volatile*>(0)) = static_cast<S*>(0);      \
     162             :   }
     163             : 
     164             : /**
     165             :  * An object reference managed by the v8 garbage collector.
     166             :  *
     167             :  * All objects returned from v8 have to be tracked by the garbage
     168             :  * collector so that it knows that the objects are still alive.  Also,
     169             :  * because the garbage collector may move objects, it is unsafe to
     170             :  * point directly to an object.  Instead, all objects are stored in
     171             :  * handles which are known by the garbage collector and updated
     172             :  * whenever an object moves.  Handles should always be passed by value
     173             :  * (except in cases like out-parameters) and they should never be
     174             :  * allocated on the heap.
     175             :  *
     176             :  * There are two types of handles: local and persistent handles.
     177             :  *
     178             :  * Local handles are light-weight and transient and typically used in
     179             :  * local operations.  They are managed by HandleScopes. That means that a
     180             :  * HandleScope must exist on the stack when they are created and that they are
     181             :  * only valid inside of the HandleScope active during their creation.
     182             :  * For passing a local handle to an outer HandleScope, an EscapableHandleScope
     183             :  * and its Escape() method must be used.
     184             :  *
     185             :  * Persistent handles can be used when storing objects across several
     186             :  * independent operations and have to be explicitly deallocated when they're no
     187             :  * longer used.
     188             :  *
     189             :  * It is safe to extract the object stored in the handle by
     190             :  * dereferencing the handle (for instance, to extract the Object* from
     191             :  * a Local<Object>); the value will still be governed by a handle
     192             :  * behind the scenes and the same rules apply to these values as to
     193             :  * their handles.
     194             :  */
     195             : template <class T>
     196             : class Local {
     197             :  public:
     198    11686153 :   V8_INLINE Local() : val_(0) {}
     199             :   template <class S>
     200             :   V8_INLINE Local(Local<S> that)
     201    92212197 :       : val_(reinterpret_cast<T*>(*that)) {
     202             :     /**
     203             :      * This check fails when trying to convert between incompatible
     204             :      * handles. For example, converting from a Local<String> to a
     205             :      * Local<Number>.
     206             :      */
     207             :     TYPE_CHECK(T, S);
     208             :   }
     209             : 
     210             :   /**
     211             :    * Returns true if the handle is empty.
     212             :    */
     213   257466082 :   V8_INLINE bool IsEmpty() const { return val_ == 0; }
     214             : 
     215             :   /**
     216             :    * Sets the handle to be empty. IsEmpty() will then return true.
     217             :    */
     218      287981 :   V8_INLINE void Clear() { val_ = 0; }
     219             : 
     220    32004059 :   V8_INLINE T* operator->() const { return val_; }
     221             : 
     222   202422685 :   V8_INLINE T* operator*() const { return val_; }
     223             : 
     224             :   /**
     225             :    * Checks whether two handles are the same.
     226             :    * Returns true if both are empty, or if the objects
     227             :    * to which they refer are identical.
     228             :    * The handles' references are not checked.
     229             :    */
     230             :   template <class S>
     231             :   V8_INLINE bool operator==(const Local<S>& that) const {
     232         264 :     internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
     233       77324 :     internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
     234       77324 :     if (a == 0) return b == 0;
     235       77324 :     if (b == 0) return false;
     236       77324 :     return *a == *b;
     237             :   }
     238             : 
     239             :   template <class S> V8_INLINE bool operator==(
     240             :       const PersistentBase<S>& that) const {
     241             :     internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
     242             :     internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
     243             :     if (a == 0) return b == 0;
     244             :     if (b == 0) return false;
     245             :     return *a == *b;
     246             :   }
     247             : 
     248             :   /**
     249             :    * Checks whether two handles are different.
     250             :    * Returns true if only one of the handles is empty, or if
     251             :    * the objects to which they refer are different.
     252             :    * The handles' references are not checked.
     253             :    */
     254             :   template <class S>
     255             :   V8_INLINE bool operator!=(const Local<S>& that) const {
     256             :     return !operator==(that);
     257             :   }
     258             : 
     259             :   template <class S> V8_INLINE bool operator!=(
     260             :       const Persistent<S>& that) const {
     261             :     return !operator==(that);
     262             :   }
     263             : 
     264             :   /**
     265             :    * Cast a handle to a subclass, e.g. Local<Value> to Local<Object>.
     266             :    * This is only valid if the handle actually refers to a value of the
     267             :    * target type.
     268             :    */
     269             :   template <class S> V8_INLINE static Local<T> Cast(Local<S> that) {
     270             : #ifdef V8_ENABLE_CHECKS
     271             :     // If we're going to perform the type check then we have to check
     272             :     // that the handle isn't empty before doing the checked cast.
     273             :     if (that.IsEmpty()) return Local<T>();
     274             : #endif
     275          56 :     return Local<T>(T::Cast(*that));
     276             :   }
     277             : 
     278             :   /**
     279             :    * Calling this is equivalent to Local<S>::Cast().
     280             :    * In particular, this is only valid if the handle actually refers to a value
     281             :    * of the target type.
     282             :    */
     283             :   template <class S>
     284             :   V8_INLINE Local<S> As() const {
     285             :     return Local<S>::Cast(*this);
     286             :   }
     287             : 
     288             :   /**
     289             :    * Create a local handle for the content of another handle.
     290             :    * The referee is kept alive by the local handle even when
     291             :    * the original handle is destroyed/disposed.
     292             :    */
     293             :   V8_INLINE static Local<T> New(Isolate* isolate, Local<T> that);
     294             :   V8_INLINE static Local<T> New(Isolate* isolate,
     295             :                                 const PersistentBase<T>& that);
     296             : 
     297             :  private:
     298             :   friend class Utils;
     299             :   template<class F> friend class Eternal;
     300             :   template<class F> friend class PersistentBase;
     301             :   template<class F, class M> friend class Persistent;
     302             :   template<class F> friend class Local;
     303             :   template <class F>
     304             :   friend class MaybeLocal;
     305             :   template<class F> friend class FunctionCallbackInfo;
     306             :   template<class F> friend class PropertyCallbackInfo;
     307             :   friend class String;
     308             :   friend class Object;
     309             :   friend class Context;
     310             :   friend class Private;
     311             :   template<class F> friend class internal::CustomArguments;
     312             :   friend Local<Primitive> Undefined(Isolate* isolate);
     313             :   friend Local<Primitive> Null(Isolate* isolate);
     314             :   friend Local<Boolean> True(Isolate* isolate);
     315             :   friend Local<Boolean> False(Isolate* isolate);
     316             :   friend class HandleScope;
     317             :   friend class EscapableHandleScope;
     318             :   template <class F1, class F2, class F3>
     319             :   friend class PersistentValueMapBase;
     320             :   template<class F1, class F2> friend class PersistentValueVector;
     321             :   template <class F>
     322             :   friend class ReturnValue;
     323             : 
     324    13970127 :   explicit V8_INLINE Local(T* that) : val_(that) {}
     325             :   V8_INLINE static Local<T> New(Isolate* isolate, T* that);
     326             :   T* val_;
     327             : };
     328             : 
     329             : 
     330             : #if !defined(V8_IMMINENT_DEPRECATION_WARNINGS)
     331             : // Handle is an alias for Local for historical reasons.
     332             : template <class T>
     333             : using Handle = Local<T>;
     334             : #endif
     335             : 
     336             : 
     337             : /**
     338             :  * A MaybeLocal<> is a wrapper around Local<> that enforces a check whether
     339             :  * the Local<> is empty before it can be used.
     340             :  *
     341             :  * If an API method returns a MaybeLocal<>, the API method can potentially fail
     342             :  * either because an exception is thrown, or because an exception is pending,
     343             :  * e.g. because a previous API call threw an exception that hasn't been caught
     344             :  * yet, or because a TerminateExecution exception was thrown. In that case, an
     345             :  * empty MaybeLocal is returned.
     346             :  */
     347             : template <class T>
     348             : class MaybeLocal {
     349             :  public:
     350       67612 :   V8_INLINE MaybeLocal() : val_(nullptr) {}
     351             :   template <class S>
     352             :   V8_INLINE MaybeLocal(Local<S> that)
     353       69532 :       : val_(reinterpret_cast<T*>(*that)) {
     354             :     TYPE_CHECK(T, S);
     355             :   }
     356             : 
     357   184246710 :   V8_INLINE bool IsEmpty() const { return val_ == nullptr; }
     358             : 
     359             :   /**
     360             :    * Converts this MaybeLocal<> to a Local<>. If this MaybeLocal<> is empty,
     361             :    * |false| is returned and |out| is left untouched.
     362             :    */
     363             :   template <class S>
     364             :   V8_WARN_UNUSED_RESULT V8_INLINE bool ToLocal(Local<S>* out) const {
     365   184382725 :     out->val_ = IsEmpty() ? nullptr : this->val_;
     366             :     return !IsEmpty();
     367             :   }
     368             : 
     369             :   /**
     370             :    * Converts this MaybeLocal<> to a Local<>. If this MaybeLocal<> is empty,
     371             :    * V8 will crash the process.
     372             :    */
     373             :   V8_INLINE Local<T> ToLocalChecked();
     374             : 
     375             :   /**
     376             :    * Converts this MaybeLocal<> to a Local<>, using a default value if this
     377             :    * MaybeLocal<> is empty.
     378             :    */
     379             :   template <class S>
     380             :   V8_INLINE Local<S> FromMaybe(Local<S> default_value) const {
     381        7346 :     return IsEmpty() ? default_value : Local<S>(val_);
     382             :   }
     383             : 
     384             :  private:
     385             :   T* val_;
     386             : };
     387             : 
     388             : /**
     389             :  * Eternal handles are set-once handles that live for the lifetime of the
     390             :  * isolate.
     391             :  */
     392             : template <class T> class Eternal {
     393             :  public:
     394             :   V8_INLINE Eternal() : val_(nullptr) {}
     395             :   template <class S>
     396             :   V8_INLINE Eternal(Isolate* isolate, Local<S> handle) : val_(nullptr) {
     397             :     Set(isolate, handle);
     398             :   }
     399             :   // Can only be safely called if already set.
     400             :   V8_INLINE Local<T> Get(Isolate* isolate) const;
     401             :   V8_INLINE bool IsEmpty() const { return val_ == nullptr; }
     402             :   template<class S> V8_INLINE void Set(Isolate* isolate, Local<S> handle);
     403             : 
     404             :  private:
     405             :   T* val_;
     406             : };
     407             : 
     408             : 
     409             : static const int kInternalFieldsInWeakCallback = 2;
     410             : static const int kEmbedderFieldsInWeakCallback = 2;
     411             : 
     412             : template <typename T>
     413             : class WeakCallbackInfo {
     414             :  public:
     415             :   typedef void (*Callback)(const WeakCallbackInfo<T>& data);
     416             : 
     417             :   WeakCallbackInfo(Isolate* isolate, T* parameter,
     418             :                    void* embedder_fields[kEmbedderFieldsInWeakCallback],
     419             :                    Callback* callback)
     420       39178 :       : isolate_(isolate), parameter_(parameter), callback_(callback) {
     421       78356 :     for (int i = 0; i < kEmbedderFieldsInWeakCallback; ++i) {
     422       78356 :       embedder_fields_[i] = embedder_fields[i];
     423             :     }
     424             :   }
     425             : 
     426             :   V8_INLINE Isolate* GetIsolate() const { return isolate_; }
     427             :   V8_INLINE T* GetParameter() const { return parameter_; }
     428             :   V8_INLINE void* GetInternalField(int index) const;
     429             : 
     430             :   V8_INLINE V8_DEPRECATED("use indexed version",
     431             :                           void* GetInternalField1() const) {
     432             :     return embedder_fields_[0];
     433             :   }
     434             :   V8_INLINE V8_DEPRECATED("use indexed version",
     435             :                           void* GetInternalField2() const) {
     436             :     return embedder_fields_[1];
     437             :   }
     438             : 
     439             :   V8_DEPRECATED("Not realiable once SetSecondPassCallback() was used.",
     440             :                 bool IsFirstPass() const) {
     441             :     return callback_ != nullptr;
     442             :   }
     443             : 
     444             :   // When first called, the embedder MUST Reset() the Global which triggered the
     445             :   // callback. The Global itself is unusable for anything else. No v8 other api
     446             :   // calls may be called in the first callback. Should additional work be
     447             :   // required, the embedder must set a second pass callback, which will be
     448             :   // called after all the initial callbacks are processed.
     449             :   // Calling SetSecondPassCallback on the second pass will immediately crash.
     450          96 :   void SetSecondPassCallback(Callback callback) const { *callback_ = callback; }
     451             : 
     452             :  private:
     453             :   Isolate* isolate_;
     454             :   T* parameter_;
     455             :   Callback* callback_;
     456             :   void* embedder_fields_[kEmbedderFieldsInWeakCallback];
     457             : };
     458             : 
     459             : 
     460             : // kParameter will pass a void* parameter back to the callback, kInternalFields
     461             : // will pass the first two internal fields back to the callback, kFinalizer
     462             : // will pass a void* parameter back, but is invoked before the object is
     463             : // actually collected, so it can be resurrected. In the last case, it is not
     464             : // possible to request a second pass callback.
     465             : enum class WeakCallbackType { kParameter, kInternalFields, kFinalizer };
     466             : 
     467             : /**
     468             :  * An object reference that is independent of any handle scope.  Where
     469             :  * a Local handle only lives as long as the HandleScope in which it was
     470             :  * allocated, a PersistentBase handle remains valid until it is explicitly
     471             :  * disposed using Reset().
     472             :  *
     473             :  * A persistent handle contains a reference to a storage cell within
     474             :  * the V8 engine which holds an object value and which is updated by
     475             :  * the garbage collector whenever the object is moved.  A new storage
     476             :  * cell can be created using the constructor or PersistentBase::Reset and
     477             :  * existing handles can be disposed using PersistentBase::Reset.
     478             :  *
     479             :  */
     480             : template <class T> class PersistentBase {
     481             :  public:
     482             :   /**
     483             :    * If non-empty, destroy the underlying storage cell
     484             :    * IsEmpty() will return true after this call.
     485             :    */
     486             :   V8_INLINE void Reset();
     487             :   /**
     488             :    * If non-empty, destroy the underlying storage cell
     489             :    * and create a new one with the contents of other if other is non empty
     490             :    */
     491             :   template <class S>
     492             :   V8_INLINE void Reset(Isolate* isolate, const Local<S>& other);
     493             : 
     494             :   /**
     495             :    * If non-empty, destroy the underlying storage cell
     496             :    * and create a new one with the contents of other if other is non empty
     497             :    */
     498             :   template <class S>
     499             :   V8_INLINE void Reset(Isolate* isolate, const PersistentBase<S>& other);
     500             : 
     501     8935437 :   V8_INLINE bool IsEmpty() const { return val_ == NULL; }
     502             :   V8_INLINE void Empty() { val_ = 0; }
     503             : 
     504             :   V8_INLINE Local<T> Get(Isolate* isolate) const {
     505             :     return Local<T>::New(isolate, *this);
     506             :   }
     507             : 
     508             :   template <class S>
     509             :   V8_INLINE bool operator==(const PersistentBase<S>& that) const {
     510        1072 :     internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
     511        1072 :     internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
     512        1072 :     if (a == NULL) return b == NULL;
     513        1072 :     if (b == NULL) return false;
     514        1072 :     return *a == *b;
     515             :   }
     516             : 
     517             :   template <class S>
     518             :   V8_INLINE bool operator==(const Local<S>& that) const {
     519        3629 :     internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
     520        3629 :     internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
     521        3629 :     if (a == NULL) return b == NULL;
     522         779 :     if (b == NULL) return false;
     523         779 :     return *a == *b;
     524             :   }
     525             : 
     526             :   template <class S>
     527             :   V8_INLINE bool operator!=(const PersistentBase<S>& that) const {
     528             :     return !operator==(that);
     529             :   }
     530             : 
     531             :   template <class S>
     532             :   V8_INLINE bool operator!=(const Local<S>& that) const {
     533             :     return !operator==(that);
     534             :   }
     535             : 
     536             :   /**
     537             :    *  Install a finalization callback on this object.
     538             :    *  NOTE: There is no guarantee as to *when* or even *if* the callback is
     539             :    *  invoked. The invocation is performed solely on a best effort basis.
     540             :    *  As always, GC-based finalization should *not* be relied upon for any
     541             :    *  critical form of resource management!
     542             :    */
     543             :   template <typename P>
     544             :   V8_INLINE void SetWeak(P* parameter,
     545             :                          typename WeakCallbackInfo<P>::Callback callback,
     546             :                          WeakCallbackType type);
     547             : 
     548             :   /**
     549             :    * Turns this handle into a weak phantom handle without finalization callback.
     550             :    * The handle will be reset automatically when the garbage collector detects
     551             :    * that the object is no longer reachable.
     552             :    * A related function Isolate::NumberOfPhantomHandleResetsSinceLastCall
     553             :    * returns how many phantom handles were reset by the garbage collector.
     554             :    */
     555             :   V8_INLINE void SetWeak();
     556             : 
     557             :   template<typename P>
     558             :   V8_INLINE P* ClearWeak();
     559             : 
     560             :   // TODO(dcarney): remove this.
     561             :   V8_INLINE void ClearWeak() { ClearWeak<void>(); }
     562             : 
     563             :   /**
     564             :    * Allows the embedder to tell the v8 garbage collector that a certain object
     565             :    * is alive. Only allowed when the embedder is asked to trace its heap by
     566             :    * EmbedderHeapTracer.
     567             :    */
     568             :   V8_INLINE void RegisterExternalReference(Isolate* isolate) const;
     569             : 
     570             :   /**
     571             :    * Marks the reference to this object independent. Garbage collector is free
     572             :    * to ignore any object groups containing this object. Weak callback for an
     573             :    * independent handle should not assume that it will be preceded by a global
     574             :    * GC prologue callback or followed by a global GC epilogue callback.
     575             :    */
     576             :   V8_INLINE void MarkIndependent();
     577             : 
     578             :   /**
     579             :    * Marks the reference to this object as active. The scavenge garbage
     580             :    * collection should not reclaim the objects marked as active.
     581             :    * This bit is cleared after the each garbage collection pass.
     582             :    */
     583             :   V8_INLINE void MarkActive();
     584             : 
     585             :   V8_INLINE bool IsIndependent() const;
     586             : 
     587             :   /** Checks if the handle holds the only reference to an object. */
     588             :   V8_INLINE bool IsNearDeath() const;
     589             : 
     590             :   /** Returns true if the handle's reference is weak.  */
     591             :   V8_INLINE bool IsWeak() const;
     592             : 
     593             :   /**
     594             :    * Assigns a wrapper class ID to the handle. See RetainedObjectInfo interface
     595             :    * description in v8-profiler.h for details.
     596             :    */
     597             :   V8_INLINE void SetWrapperClassId(uint16_t class_id);
     598             : 
     599             :   /**
     600             :    * Returns the class ID previously assigned to this handle or 0 if no class ID
     601             :    * was previously assigned.
     602             :    */
     603             :   V8_INLINE uint16_t WrapperClassId() const;
     604             : 
     605             :   PersistentBase(const PersistentBase& other) = delete;  // NOLINT
     606             :   void operator=(const PersistentBase&) = delete;
     607             : 
     608             :  private:
     609             :   friend class Isolate;
     610             :   friend class Utils;
     611             :   template<class F> friend class Local;
     612             :   template<class F1, class F2> friend class Persistent;
     613             :   template <class F>
     614             :   friend class Global;
     615             :   template<class F> friend class PersistentBase;
     616             :   template<class F> friend class ReturnValue;
     617             :   template <class F1, class F2, class F3>
     618             :   friend class PersistentValueMapBase;
     619             :   template<class F1, class F2> friend class PersistentValueVector;
     620             :   friend class Object;
     621             : 
     622     8278914 :   explicit V8_INLINE PersistentBase(T* val) : val_(val) {}
     623             :   V8_INLINE static T* New(Isolate* isolate, T* that);
     624             : 
     625             :   T* val_;
     626             : };
     627             : 
     628             : 
     629             : /**
     630             :  * Default traits for Persistent. This class does not allow
     631             :  * use of the copy constructor or assignment operator.
     632             :  * At present kResetInDestructor is not set, but that will change in a future
     633             :  * version.
     634             :  */
     635             : template<class T>
     636             : class NonCopyablePersistentTraits {
     637             :  public:
     638             :   typedef Persistent<T, NonCopyablePersistentTraits<T> > NonCopyablePersistent;
     639             :   static const bool kResetInDestructor = false;
     640             :   template<class S, class M>
     641             :   V8_INLINE static void Copy(const Persistent<S, M>& source,
     642             :                              NonCopyablePersistent* dest) {
     643             :     Uncompilable<Object>();
     644             :   }
     645             :   // TODO(dcarney): come up with a good compile error here.
     646             :   template<class O> V8_INLINE static void Uncompilable() {
     647             :     TYPE_CHECK(O, Primitive);
     648             :   }
     649             : };
     650             : 
     651             : 
     652             : /**
     653             :  * Helper class traits to allow copying and assignment of Persistent.
     654             :  * This will clone the contents of storage cell, but not any of the flags, etc.
     655             :  */
     656             : template<class T>
     657             : struct CopyablePersistentTraits {
     658             :   typedef Persistent<T, CopyablePersistentTraits<T> > CopyablePersistent;
     659             :   static const bool kResetInDestructor = true;
     660             :   template<class S, class M>
     661             :   static V8_INLINE void Copy(const Persistent<S, M>& source,
     662             :                              CopyablePersistent* dest) {
     663             :     // do nothing, just allow copy
     664             :   }
     665             : };
     666             : 
     667             : 
     668             : /**
     669             :  * A PersistentBase which allows copy and assignment.
     670             :  *
     671             :  * Copy, assignment and destructor behavior is controlled by the traits
     672             :  * class M.
     673             :  *
     674             :  * Note: Persistent class hierarchy is subject to future changes.
     675             :  */
     676             : template <class T, class M> class Persistent : public PersistentBase<T> {
     677             :  public:
     678             :   /**
     679             :    * A Persistent with no storage cell.
     680             :    */
     681             :   V8_INLINE Persistent() : PersistentBase<T>(0) { }
     682             :   /**
     683             :    * Construct a Persistent from a Local.
     684             :    * When the Local is non-empty, a new storage cell is created
     685             :    * pointing to the same object, and no flags are set.
     686             :    */
     687             :   template <class S>
     688             :   V8_INLINE Persistent(Isolate* isolate, Local<S> that)
     689             :       : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
     690             :     TYPE_CHECK(T, S);
     691             :   }
     692             :   /**
     693             :    * Construct a Persistent from a Persistent.
     694             :    * When the Persistent is non-empty, a new storage cell is created
     695             :    * pointing to the same object, and no flags are set.
     696             :    */
     697             :   template <class S, class M2>
     698             :   V8_INLINE Persistent(Isolate* isolate, const Persistent<S, M2>& that)
     699             :     : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
     700             :     TYPE_CHECK(T, S);
     701             :   }
     702             :   /**
     703             :    * The copy constructors and assignment operator create a Persistent
     704             :    * exactly as the Persistent constructor, but the Copy function from the
     705             :    * traits class is called, allowing the setting of flags based on the
     706             :    * copied Persistent.
     707             :    */
     708             :   V8_INLINE Persistent(const Persistent& that) : PersistentBase<T>(0) {
     709             :     Copy(that);
     710             :   }
     711             :   template <class S, class M2>
     712             :   V8_INLINE Persistent(const Persistent<S, M2>& that) : PersistentBase<T>(0) {
     713             :     Copy(that);
     714             :   }
     715             :   V8_INLINE Persistent& operator=(const Persistent& that) { // NOLINT
     716             :     Copy(that);
     717             :     return *this;
     718             :   }
     719             :   template <class S, class M2>
     720             :   V8_INLINE Persistent& operator=(const Persistent<S, M2>& that) { // NOLINT
     721             :     Copy(that);
     722             :     return *this;
     723             :   }
     724             :   /**
     725             :    * The destructor will dispose the Persistent based on the
     726             :    * kResetInDestructor flags in the traits class.  Since not calling dispose
     727             :    * can result in a memory leak, it is recommended to always set this flag.
     728             :    */
     729             :   V8_INLINE ~Persistent() {
     730             :     if (M::kResetInDestructor) this->Reset();
     731             :   }
     732             : 
     733             :   // TODO(dcarney): this is pretty useless, fix or remove
     734             :   template <class S>
     735             :   V8_INLINE static Persistent<T>& Cast(const Persistent<S>& that) {  // NOLINT
     736             : #ifdef V8_ENABLE_CHECKS
     737             :     // If we're going to perform the type check then we have to check
     738             :     // that the handle isn't empty before doing the checked cast.
     739             :     if (!that.IsEmpty()) T::Cast(*that);
     740             : #endif
     741             :     return reinterpret_cast<Persistent<T>&>(const_cast<Persistent<S>&>(that));
     742             :   }
     743             : 
     744             :   // TODO(dcarney): this is pretty useless, fix or remove
     745             :   template <class S>
     746             :   V8_INLINE Persistent<S>& As() const {  // NOLINT
     747             :     return Persistent<S>::Cast(*this);
     748             :   }
     749             : 
     750             :  private:
     751             :   friend class Isolate;
     752             :   friend class Utils;
     753             :   template<class F> friend class Local;
     754             :   template<class F1, class F2> friend class Persistent;
     755             :   template<class F> friend class ReturnValue;
     756             : 
     757             :   explicit V8_INLINE Persistent(T* that) : PersistentBase<T>(that) {}
     758             :   V8_INLINE T* operator*() const { return this->val_; }
     759             :   template<class S, class M2>
     760             :   V8_INLINE void Copy(const Persistent<S, M2>& that);
     761             : };
     762             : 
     763             : 
     764             : /**
     765             :  * A PersistentBase which has move semantics.
     766             :  *
     767             :  * Note: Persistent class hierarchy is subject to future changes.
     768             :  */
     769             : template <class T>
     770             : class Global : public PersistentBase<T> {
     771             :  public:
     772             :   /**
     773             :    * A Global with no storage cell.
     774             :    */
     775             :   V8_INLINE Global() : PersistentBase<T>(nullptr) {}
     776             :   /**
     777             :    * Construct a Global from a Local.
     778             :    * When the Local is non-empty, a new storage cell is created
     779             :    * pointing to the same object, and no flags are set.
     780             :    */
     781             :   template <class S>
     782             :   V8_INLINE Global(Isolate* isolate, Local<S> that)
     783             :       : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
     784             :     TYPE_CHECK(T, S);
     785             :   }
     786             :   /**
     787             :    * Construct a Global from a PersistentBase.
     788             :    * When the Persistent is non-empty, a new storage cell is created
     789             :    * pointing to the same object, and no flags are set.
     790             :    */
     791             :   template <class S>
     792             :   V8_INLINE Global(Isolate* isolate, const PersistentBase<S>& that)
     793             :       : PersistentBase<T>(PersistentBase<T>::New(isolate, that.val_)) {
     794             :     TYPE_CHECK(T, S);
     795             :   }
     796             :   /**
     797             :    * Move constructor.
     798             :    */
     799     3783709 :   V8_INLINE Global(Global&& other) : PersistentBase<T>(other.val_) {  // NOLINT
     800     3783709 :     other.val_ = nullptr;
     801             :   }
     802           0 :   V8_INLINE ~Global() { this->Reset(); }
     803             :   /**
     804             :    * Move via assignment.
     805             :    */
     806             :   template <class S>
     807             :   V8_INLINE Global& operator=(Global<S>&& rhs) {  // NOLINT
     808             :     TYPE_CHECK(T, S);
     809             :     if (this != &rhs) {
     810             :       this->Reset();
     811             :       this->val_ = rhs.val_;
     812             :       rhs.val_ = nullptr;
     813             :     }
     814             :     return *this;
     815             :   }
     816             :   /**
     817             :    * Pass allows returning uniques from functions, etc.
     818             :    */
     819             :   Global Pass() { return static_cast<Global&&>(*this); }  // NOLINT
     820             : 
     821             :   /*
     822             :    * For compatibility with Chromium's base::Bind (base::Passed).
     823             :    */
     824             :   typedef void MoveOnlyTypeForCPP03;
     825             : 
     826             :   Global(const Global&) = delete;
     827             :   void operator=(const Global&) = delete;
     828             : 
     829             :  private:
     830             :   template <class F>
     831             :   friend class ReturnValue;
     832             :   V8_INLINE T* operator*() const { return this->val_; }
     833             : };
     834             : 
     835             : 
     836             : // UniquePersistent is an alias for Global for historical reason.
     837             : template <class T>
     838             : using UniquePersistent = Global<T>;
     839             : 
     840             : 
     841             :  /**
     842             :  * A stack-allocated class that governs a number of local handles.
     843             :  * After a handle scope has been created, all local handles will be
     844             :  * allocated within that handle scope until either the handle scope is
     845             :  * deleted or another handle scope is created.  If there is already a
     846             :  * handle scope and a new one is created, all allocations will take
     847             :  * place in the new handle scope until it is deleted.  After that,
     848             :  * new handles will again be allocated in the original handle scope.
     849             :  *
     850             :  * After the handle scope of a local handle has been deleted the
     851             :  * garbage collector will no longer track the object stored in the
     852             :  * handle and may deallocate it.  The behavior of accessing a handle
     853             :  * for which the handle scope has been deleted is undefined.
     854             :  */
     855             : class V8_EXPORT HandleScope {
     856             :  public:
     857             :   explicit HandleScope(Isolate* isolate);
     858             : 
     859             :   ~HandleScope();
     860             : 
     861             :   /**
     862             :    * Counts the number of allocated handles.
     863             :    */
     864             :   static int NumberOfHandles(Isolate* isolate);
     865             : 
     866             :   V8_INLINE Isolate* GetIsolate() const {
     867             :     return reinterpret_cast<Isolate*>(isolate_);
     868             :   }
     869             : 
     870             :   HandleScope(const HandleScope&) = delete;
     871             :   void operator=(const HandleScope&) = delete;
     872             :   void* operator new(size_t size);
     873             :   void operator delete(void*, size_t);
     874             : 
     875             :  protected:
     876             :   V8_INLINE HandleScope() {}
     877             : 
     878             :   void Initialize(Isolate* isolate);
     879             : 
     880             :   static internal::Object** CreateHandle(internal::Isolate* isolate,
     881             :                                          internal::Object* value);
     882             : 
     883             :  private:
     884             :   // Uses heap_object to obtain the current Isolate.
     885             :   static internal::Object** CreateHandle(internal::HeapObject* heap_object,
     886             :                                          internal::Object* value);
     887             : 
     888             :   internal::Isolate* isolate_;
     889             :   internal::Object** prev_next_;
     890             :   internal::Object** prev_limit_;
     891             : 
     892             :   // Local::New uses CreateHandle with an Isolate* parameter.
     893             :   template<class F> friend class Local;
     894             : 
     895             :   // Object::GetInternalField and Context::GetEmbedderData use CreateHandle with
     896             :   // a HeapObject* in their shortcuts.
     897             :   friend class Object;
     898             :   friend class Context;
     899             : };
     900             : 
     901             : 
     902             : /**
     903             :  * A HandleScope which first allocates a handle in the current scope
     904             :  * which will be later filled with the escape value.
     905             :  */
     906             : class V8_EXPORT EscapableHandleScope : public HandleScope {
     907             :  public:
     908             :   explicit EscapableHandleScope(Isolate* isolate);
     909   160590147 :   V8_INLINE ~EscapableHandleScope() {}
     910             : 
     911             :   /**
     912             :    * Pushes the value into the previous scope and returns a handle to it.
     913             :    * Cannot be called twice.
     914             :    */
     915             :   template <class T>
     916             :   V8_INLINE Local<T> Escape(Local<T> value) {
     917             :     internal::Object** slot =
     918   160529813 :         Escape(reinterpret_cast<internal::Object**>(*value));
     919             :     return Local<T>(reinterpret_cast<T*>(slot));
     920             :   }
     921             : 
     922             :   EscapableHandleScope(const EscapableHandleScope&) = delete;
     923             :   void operator=(const EscapableHandleScope&) = delete;
     924             :   void* operator new(size_t size);
     925             :   void operator delete(void*, size_t);
     926             : 
     927             :  private:
     928             :   internal::Object** Escape(internal::Object** escape_value);
     929             :   internal::Object** escape_slot_;
     930             : };
     931             : 
     932             : /**
     933             :  * A SealHandleScope acts like a handle scope in which no handle allocations
     934             :  * are allowed. It can be useful for debugging handle leaks.
     935             :  * Handles can be allocated within inner normal HandleScopes.
     936             :  */
     937             : class V8_EXPORT SealHandleScope {
     938             :  public:
     939             :   SealHandleScope(Isolate* isolate);
     940             :   ~SealHandleScope();
     941             : 
     942             :   SealHandleScope(const SealHandleScope&) = delete;
     943             :   void operator=(const SealHandleScope&) = delete;
     944             :   void* operator new(size_t size);
     945             :   void operator delete(void*, size_t);
     946             : 
     947             :  private:
     948             :   internal::Isolate* const isolate_;
     949             :   internal::Object** prev_limit_;
     950             :   int prev_sealed_level_;
     951             : };
     952             : 
     953             : 
     954             : // --- Special objects ---
     955             : 
     956             : 
     957             : /**
     958             :  * The superclass of values and API object templates.
     959             :  */
     960             : class V8_EXPORT Data {
     961             :  private:
     962             :   Data();
     963             : };
     964             : 
     965             : 
     966             : /**
     967             :  * The optional attributes of ScriptOrigin.
     968             :  */
     969             : class ScriptOriginOptions {
     970             :  public:
     971             :   V8_INLINE ScriptOriginOptions(bool is_shared_cross_origin = false,
     972             :                                 bool is_opaque = false, bool is_wasm = false,
     973             :                                 bool is_module = false)
     974       30831 :       : flags_((is_shared_cross_origin ? kIsSharedCrossOrigin : 0) |
     975       32412 :                (is_wasm ? kIsWasm : 0) | (is_opaque ? kIsOpaque : 0) |
     976     5767826 :                (is_module ? kIsModule : 0)) {}
     977             :   V8_INLINE ScriptOriginOptions(int flags)
     978      144835 :       : flags_(flags &
     979             :                (kIsSharedCrossOrigin | kIsOpaque | kIsWasm | kIsModule)) {}
     980             : 
     981             :   bool IsSharedCrossOrigin() const {
     982       25619 :     return (flags_ & kIsSharedCrossOrigin) != 0;
     983             :   }
     984       25576 :   bool IsOpaque() const { return (flags_ & kIsOpaque) != 0; }
     985       11504 :   bool IsWasm() const { return (flags_ & kIsWasm) != 0; }
     986      587139 :   bool IsModule() const { return (flags_ & kIsModule) != 0; }
     987             : 
     988       82640 :   int Flags() const { return flags_; }
     989             : 
     990             :  private:
     991             :   enum {
     992             :     kIsSharedCrossOrigin = 1,
     993             :     kIsOpaque = 1 << 1,
     994             :     kIsWasm = 1 << 2,
     995             :     kIsModule = 1 << 3
     996             :   };
     997             :   const int flags_;
     998             : };
     999             : 
    1000             : /**
    1001             :  * The origin, within a file, of a script.
    1002             :  */
    1003             : class ScriptOrigin {
    1004             :  public:
    1005             :   V8_INLINE ScriptOrigin(
    1006             :       Local<Value> resource_name,
    1007             :       Local<Integer> resource_line_offset = Local<Integer>(),
    1008             :       Local<Integer> resource_column_offset = Local<Integer>(),
    1009             :       Local<Boolean> resource_is_shared_cross_origin = Local<Boolean>(),
    1010             :       Local<Integer> script_id = Local<Integer>(),
    1011             :       Local<Value> source_map_url = Local<Value>(),
    1012             :       Local<Boolean> resource_is_opaque = Local<Boolean>(),
    1013             :       Local<Boolean> is_wasm = Local<Boolean>(),
    1014             :       Local<Boolean> is_module = Local<Boolean>());
    1015             : 
    1016             :   V8_INLINE Local<Value> ResourceName() const;
    1017             :   V8_INLINE Local<Integer> ResourceLineOffset() const;
    1018             :   V8_INLINE Local<Integer> ResourceColumnOffset() const;
    1019             :   /**
    1020             :     * Returns true for embedder's debugger scripts
    1021             :     */
    1022             :   V8_INLINE Local<Integer> ScriptID() const;
    1023             :   V8_INLINE Local<Value> SourceMapUrl() const;
    1024             :   V8_INLINE ScriptOriginOptions Options() const { return options_; }
    1025             : 
    1026             :  private:
    1027             :   Local<Value> resource_name_;
    1028             :   Local<Integer> resource_line_offset_;
    1029             :   Local<Integer> resource_column_offset_;
    1030             :   ScriptOriginOptions options_;
    1031             :   Local<Integer> script_id_;
    1032             :   Local<Value> source_map_url_;
    1033             : };
    1034             : 
    1035             : 
    1036             : /**
    1037             :  * A compiled JavaScript script, not yet tied to a Context.
    1038             :  */
    1039             : class V8_EXPORT UnboundScript {
    1040             :  public:
    1041             :   /**
    1042             :    * Binds the script to the currently entered context.
    1043             :    */
    1044             :   Local<Script> BindToCurrentContext();
    1045             : 
    1046             :   int GetId();
    1047             :   Local<Value> GetScriptName();
    1048             : 
    1049             :   /**
    1050             :    * Data read from magic sourceURL comments.
    1051             :    */
    1052             :   Local<Value> GetSourceURL();
    1053             :   /**
    1054             :    * Data read from magic sourceMappingURL comments.
    1055             :    */
    1056             :   Local<Value> GetSourceMappingURL();
    1057             : 
    1058             :   /**
    1059             :    * Returns zero based line number of the code_pos location in the script.
    1060             :    * -1 will be returned if no information available.
    1061             :    */
    1062             :   int GetLineNumber(int code_pos);
    1063             : 
    1064             :   static const int kNoScriptId = 0;
    1065             : };
    1066             : 
    1067             : /**
    1068             :  * This is an unfinished experimental feature, and is only exposed
    1069             :  * here for internal testing purposes. DO NOT USE.
    1070             :  *
    1071             :  * A compiled JavaScript module.
    1072             :  */
    1073             : class V8_EXPORT Module {
    1074             :  public:
    1075             :   /**
    1076             :    * Returns the number of modules requested by this module.
    1077             :    */
    1078             :   int GetModuleRequestsLength() const;
    1079             : 
    1080             :   /**
    1081             :    * Returns the ith module specifier in this module.
    1082             :    * i must be < GetModuleRequestsLength() and >= 0.
    1083             :    */
    1084             :   Local<String> GetModuleRequest(int i) const;
    1085             : 
    1086             :   /**
    1087             :    * Returns the identity hash for this object.
    1088             :    */
    1089             :   int GetIdentityHash() const;
    1090             : 
    1091             :   typedef MaybeLocal<Module> (*ResolveCallback)(Local<Context> context,
    1092             :                                                 Local<String> specifier,
    1093             :                                                 Local<Module> referrer);
    1094             : 
    1095             :   /**
    1096             :    * ModuleDeclarationInstantiation
    1097             :    *
    1098             :    * Returns false if an exception occurred during instantiation. (In the case
    1099             :    * where the callback throws an exception, that exception is propagated.)
    1100             :    */
    1101             :   V8_WARN_UNUSED_RESULT bool Instantiate(Local<Context> context,
    1102             :                                          ResolveCallback callback);
    1103             : 
    1104             :   /**
    1105             :    * ModuleEvaluation
    1106             :    *
    1107             :    * Returns the completion value.
    1108             :    */
    1109             :   V8_WARN_UNUSED_RESULT MaybeLocal<Value> Evaluate(Local<Context> context);
    1110             : };
    1111             : 
    1112             : /**
    1113             :  * This is an unfinished experimental feature, and is only exposed
    1114             :  * here for internal testing purposes. DO NOT USE.
    1115             :  *
    1116             :  * A compiled JavaScript module.
    1117             :  */
    1118             : class V8_EXPORT DynamicImportResult {
    1119             :  public:
    1120             :   /**
    1121             :    * Resolves the promise with the namespace object of the given
    1122             :    * module.
    1123             :    */
    1124             :   V8_WARN_UNUSED_RESULT bool FinishDynamicImportSuccess(Local<Context> context,
    1125             :                                                         Local<Module> module);
    1126             : 
    1127             :   /**
    1128             :    * Rejects the promise with the given exception.
    1129             :    */
    1130             :   V8_WARN_UNUSED_RESULT bool FinishDynamicImportFailure(Local<Context> context,
    1131             :                                                         Local<Value> exception);
    1132             : };
    1133             : 
    1134             : /**
    1135             :  * A compiled JavaScript script, tied to a Context which was active when the
    1136             :  * script was compiled.
    1137             :  */
    1138             : class V8_EXPORT Script {
    1139             :  public:
    1140             :   /**
    1141             :    * A shorthand for ScriptCompiler::Compile().
    1142             :    */
    1143             :   static V8_DEPRECATE_SOON(
    1144             :       "Use maybe version",
    1145             :       Local<Script> Compile(Local<String> source,
    1146             :                             ScriptOrigin* origin = nullptr));
    1147             :   static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile(
    1148             :       Local<Context> context, Local<String> source,
    1149             :       ScriptOrigin* origin = nullptr);
    1150             : 
    1151             :   static Local<Script> V8_DEPRECATE_SOON("Use maybe version",
    1152             :                                          Compile(Local<String> source,
    1153             :                                                  Local<String> file_name));
    1154             : 
    1155             :   /**
    1156             :    * Runs the script returning the resulting value. It will be run in the
    1157             :    * context in which it was created (ScriptCompiler::CompileBound or
    1158             :    * UnboundScript::BindToCurrentContext()).
    1159             :    */
    1160             :   V8_DEPRECATE_SOON("Use maybe version", Local<Value> Run());
    1161             :   V8_WARN_UNUSED_RESULT MaybeLocal<Value> Run(Local<Context> context);
    1162             : 
    1163             :   /**
    1164             :    * Returns the corresponding context-unbound script.
    1165             :    */
    1166             :   Local<UnboundScript> GetUnboundScript();
    1167             : };
    1168             : 
    1169             : 
    1170             : /**
    1171             :  * For compiling scripts.
    1172             :  */
    1173             : class V8_EXPORT ScriptCompiler {
    1174             :  public:
    1175             :   /**
    1176             :    * Compilation data that the embedder can cache and pass back to speed up
    1177             :    * future compilations. The data is produced if the CompilerOptions passed to
    1178             :    * the compilation functions in ScriptCompiler contains produce_data_to_cache
    1179             :    * = true. The data to cache can then can be retrieved from
    1180             :    * UnboundScript.
    1181             :    */
    1182             :   struct V8_EXPORT CachedData {
    1183             :     enum BufferPolicy {
    1184             :       BufferNotOwned,
    1185             :       BufferOwned
    1186             :     };
    1187             : 
    1188             :     CachedData()
    1189             :         : data(NULL),
    1190             :           length(0),
    1191             :           rejected(false),
    1192             :           buffer_policy(BufferNotOwned) {}
    1193             : 
    1194             :     // If buffer_policy is BufferNotOwned, the caller keeps the ownership of
    1195             :     // data and guarantees that it stays alive until the CachedData object is
    1196             :     // destroyed. If the policy is BufferOwned, the given data will be deleted
    1197             :     // (with delete[]) when the CachedData object is destroyed.
    1198             :     CachedData(const uint8_t* data, int length,
    1199             :                BufferPolicy buffer_policy = BufferNotOwned);
    1200             :     ~CachedData();
    1201             :     // TODO(marja): Async compilation; add constructors which take a callback
    1202             :     // which will be called when V8 no longer needs the data.
    1203             :     const uint8_t* data;
    1204             :     int length;
    1205             :     bool rejected;
    1206             :     BufferPolicy buffer_policy;
    1207             : 
    1208             :     // Prevent copying.
    1209             :     CachedData(const CachedData&) = delete;
    1210             :     CachedData& operator=(const CachedData&) = delete;
    1211             :   };
    1212             : 
    1213             :   /**
    1214             :    * Source code which can be then compiled to a UnboundScript or Script.
    1215             :    */
    1216             :   class Source {
    1217             :    public:
    1218             :     // Source takes ownership of CachedData.
    1219             :     V8_INLINE Source(Local<String> source_string, const ScriptOrigin& origin,
    1220             :            CachedData* cached_data = NULL);
    1221             :     V8_INLINE Source(Local<String> source_string,
    1222             :                      CachedData* cached_data = NULL);
    1223             :     V8_INLINE ~Source();
    1224             : 
    1225             :     // Ownership of the CachedData or its buffers is *not* transferred to the
    1226             :     // caller. The CachedData object is alive as long as the Source object is
    1227             :     // alive.
    1228             :     V8_INLINE const CachedData* GetCachedData() const;
    1229             : 
    1230             :     V8_INLINE const ScriptOriginOptions& GetResourceOptions() const;
    1231             : 
    1232             :     // Prevent copying.
    1233             :     Source(const Source&) = delete;
    1234             :     Source& operator=(const Source&) = delete;
    1235             : 
    1236             :    private:
    1237             :     friend class ScriptCompiler;
    1238             : 
    1239             :     Local<String> source_string;
    1240             : 
    1241             :     // Origin information
    1242             :     Local<Value> resource_name;
    1243             :     Local<Integer> resource_line_offset;
    1244             :     Local<Integer> resource_column_offset;
    1245             :     ScriptOriginOptions resource_options;
    1246             :     Local<Value> source_map_url;
    1247             : 
    1248             :     // Cached data from previous compilation (if a kConsume*Cache flag is
    1249             :     // set), or hold newly generated cache data (kProduce*Cache flags) are
    1250             :     // set when calling a compile method.
    1251             :     CachedData* cached_data;
    1252             :   };
    1253             : 
    1254             :   /**
    1255             :    * For streaming incomplete script data to V8. The embedder should implement a
    1256             :    * subclass of this class.
    1257             :    */
    1258             :   class V8_EXPORT ExternalSourceStream {
    1259             :    public:
    1260           0 :     virtual ~ExternalSourceStream() {}
    1261             : 
    1262             :     /**
    1263             :      * V8 calls this to request the next chunk of data from the embedder. This
    1264             :      * function will be called on a background thread, so it's OK to block and
    1265             :      * wait for the data, if the embedder doesn't have data yet. Returns the
    1266             :      * length of the data returned. When the data ends, GetMoreData should
    1267             :      * return 0. Caller takes ownership of the data.
    1268             :      *
    1269             :      * When streaming UTF-8 data, V8 handles multi-byte characters split between
    1270             :      * two data chunks, but doesn't handle multi-byte characters split between
    1271             :      * more than two data chunks. The embedder can avoid this problem by always
    1272             :      * returning at least 2 bytes of data.
    1273             :      *
    1274             :      * If the embedder wants to cancel the streaming, they should make the next
    1275             :      * GetMoreData call return 0. V8 will interpret it as end of data (and most
    1276             :      * probably, parsing will fail). The streaming task will return as soon as
    1277             :      * V8 has parsed the data it received so far.
    1278             :      */
    1279             :     virtual size_t GetMoreData(const uint8_t** src) = 0;
    1280             : 
    1281             :     /**
    1282             :      * V8 calls this method to set a 'bookmark' at the current position in
    1283             :      * the source stream, for the purpose of (maybe) later calling
    1284             :      * ResetToBookmark. If ResetToBookmark is called later, then subsequent
    1285             :      * calls to GetMoreData should return the same data as they did when
    1286             :      * SetBookmark was called earlier.
    1287             :      *
    1288             :      * The embedder may return 'false' to indicate it cannot provide this
    1289             :      * functionality.
    1290             :      */
    1291             :     virtual bool SetBookmark();
    1292             : 
    1293             :     /**
    1294             :      * V8 calls this to return to a previously set bookmark.
    1295             :      */
    1296             :     virtual void ResetToBookmark();
    1297             :   };
    1298             : 
    1299             : 
    1300             :   /**
    1301             :    * Source code which can be streamed into V8 in pieces. It will be parsed
    1302             :    * while streaming. It can be compiled after the streaming is complete.
    1303             :    * StreamedSource must be kept alive while the streaming task is ran (see
    1304             :    * ScriptStreamingTask below).
    1305             :    */
    1306             :   class V8_EXPORT StreamedSource {
    1307             :    public:
    1308             :     enum Encoding { ONE_BYTE, TWO_BYTE, UTF8 };
    1309             : 
    1310             :     StreamedSource(ExternalSourceStream* source_stream, Encoding encoding);
    1311             :     ~StreamedSource();
    1312             : 
    1313             :     // Ownership of the CachedData or its buffers is *not* transferred to the
    1314             :     // caller. The CachedData object is alive as long as the StreamedSource
    1315             :     // object is alive.
    1316             :     const CachedData* GetCachedData() const;
    1317             : 
    1318         258 :     internal::StreamedSource* impl() const { return impl_; }
    1319             : 
    1320             :     // Prevent copying.
    1321             :     StreamedSource(const StreamedSource&) = delete;
    1322             :     StreamedSource& operator=(const StreamedSource&) = delete;
    1323             : 
    1324             :    private:
    1325             :     internal::StreamedSource* impl_;
    1326             :   };
    1327             : 
    1328             :   /**
    1329             :    * A streaming task which the embedder must run on a background thread to
    1330             :    * stream scripts into V8. Returned by ScriptCompiler::StartStreamingScript.
    1331             :    */
    1332         132 :   class ScriptStreamingTask {
    1333             :    public:
    1334         132 :     virtual ~ScriptStreamingTask() {}
    1335             :     virtual void Run() = 0;
    1336             :   };
    1337             : 
    1338             :   enum CompileOptions {
    1339             :     kNoCompileOptions = 0,
    1340             :     kProduceParserCache,
    1341             :     kConsumeParserCache,
    1342             :     kProduceCodeCache,
    1343             :     kConsumeCodeCache
    1344             :   };
    1345             : 
    1346             :   /**
    1347             :    * Compiles the specified script (context-independent).
    1348             :    * Cached data as part of the source object can be optionally produced to be
    1349             :    * consumed later to speed up compilation of identical source scripts.
    1350             :    *
    1351             :    * Note that when producing cached data, the source must point to NULL for
    1352             :    * cached data. When consuming cached data, the cached data must have been
    1353             :    * produced by the same version of V8.
    1354             :    *
    1355             :    * \param source Script source code.
    1356             :    * \return Compiled script object (context independent; for running it must be
    1357             :    *   bound to a context).
    1358             :    */
    1359             :   static V8_DEPRECATED("Use maybe version",
    1360             :                        Local<UnboundScript> CompileUnbound(
    1361             :                            Isolate* isolate, Source* source,
    1362             :                            CompileOptions options = kNoCompileOptions));
    1363             :   static V8_WARN_UNUSED_RESULT MaybeLocal<UnboundScript> CompileUnboundScript(
    1364             :       Isolate* isolate, Source* source,
    1365             :       CompileOptions options = kNoCompileOptions);
    1366             : 
    1367             :   /**
    1368             :    * Compiles the specified script (bound to current context).
    1369             :    *
    1370             :    * \param source Script source code.
    1371             :    * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile()
    1372             :    *   using pre_data speeds compilation if it's done multiple times.
    1373             :    *   Owned by caller, no references are kept when this function returns.
    1374             :    * \return Compiled script object, bound to the context that was active
    1375             :    *   when this function was called. When run it will always use this
    1376             :    *   context.
    1377             :    */
    1378             :   static V8_DEPRECATED(
    1379             :       "Use maybe version",
    1380             :       Local<Script> Compile(Isolate* isolate, Source* source,
    1381             :                             CompileOptions options = kNoCompileOptions));
    1382             :   static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile(
    1383             :       Local<Context> context, Source* source,
    1384             :       CompileOptions options = kNoCompileOptions);
    1385             : 
    1386             :   /**
    1387             :    * Returns a task which streams script data into V8, or NULL if the script
    1388             :    * cannot be streamed. The user is responsible for running the task on a
    1389             :    * background thread and deleting it. When ran, the task starts parsing the
    1390             :    * script, and it will request data from the StreamedSource as needed. When
    1391             :    * ScriptStreamingTask::Run exits, all data has been streamed and the script
    1392             :    * can be compiled (see Compile below).
    1393             :    *
    1394             :    * This API allows to start the streaming with as little data as possible, and
    1395             :    * the remaining data (for example, the ScriptOrigin) is passed to Compile.
    1396             :    */
    1397             :   static ScriptStreamingTask* StartStreamingScript(
    1398             :       Isolate* isolate, StreamedSource* source,
    1399             :       CompileOptions options = kNoCompileOptions);
    1400             : 
    1401             :   /**
    1402             :    * Compiles a streamed script (bound to current context).
    1403             :    *
    1404             :    * This can only be called after the streaming has finished
    1405             :    * (ScriptStreamingTask has been run). V8 doesn't construct the source string
    1406             :    * during streaming, so the embedder needs to pass the full source here.
    1407             :    */
    1408             :   static V8_DEPRECATED("Use maybe version",
    1409             :                        Local<Script> Compile(Isolate* isolate,
    1410             :                                              StreamedSource* source,
    1411             :                                              Local<String> full_source_string,
    1412             :                                              const ScriptOrigin& origin));
    1413             :   static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile(
    1414             :       Local<Context> context, StreamedSource* source,
    1415             :       Local<String> full_source_string, const ScriptOrigin& origin);
    1416             : 
    1417             :   /**
    1418             :    * Return a version tag for CachedData for the current V8 version & flags.
    1419             :    *
    1420             :    * This value is meant only for determining whether a previously generated
    1421             :    * CachedData instance is still valid; the tag has no other meaing.
    1422             :    *
    1423             :    * Background: The data carried by CachedData may depend on the exact
    1424             :    *   V8 version number or current compiler flags. This means that when
    1425             :    *   persisting CachedData, the embedder must take care to not pass in
    1426             :    *   data from another V8 version, or the same version with different
    1427             :    *   features enabled.
    1428             :    *
    1429             :    *   The easiest way to do so is to clear the embedder's cache on any
    1430             :    *   such change.
    1431             :    *
    1432             :    *   Alternatively, this tag can be stored alongside the cached data and
    1433             :    *   compared when it is being used.
    1434             :    */
    1435             :   static uint32_t CachedDataVersionTag();
    1436             : 
    1437             :   /**
    1438             :    * This is an unfinished experimental feature, and is only exposed
    1439             :    * here for internal testing purposes. DO NOT USE.
    1440             :    *
    1441             :    * Compile an ES module, returning a Module that encapsulates
    1442             :    * the compiled code.
    1443             :    *
    1444             :    * Corresponds to the ParseModule abstract operation in the
    1445             :    * ECMAScript specification.
    1446             :    */
    1447             :   static V8_WARN_UNUSED_RESULT MaybeLocal<Module> CompileModule(
    1448             :       Isolate* isolate, Source* source);
    1449             : 
    1450             :   /**
    1451             :    * Compile a function for a given context. This is equivalent to running
    1452             :    *
    1453             :    * with (obj) {
    1454             :    *   return function(args) { ... }
    1455             :    * }
    1456             :    *
    1457             :    * It is possible to specify multiple context extensions (obj in the above
    1458             :    * example).
    1459             :    */
    1460             :   static V8_DEPRECATE_SOON("Use maybe version",
    1461             :                            Local<Function> CompileFunctionInContext(
    1462             :                                Isolate* isolate, Source* source,
    1463             :                                Local<Context> context, size_t arguments_count,
    1464             :                                Local<String> arguments[],
    1465             :                                size_t context_extension_count,
    1466             :                                Local<Object> context_extensions[]));
    1467             :   static V8_WARN_UNUSED_RESULT MaybeLocal<Function> CompileFunctionInContext(
    1468             :       Local<Context> context, Source* source, size_t arguments_count,
    1469             :       Local<String> arguments[], size_t context_extension_count,
    1470             :       Local<Object> context_extensions[]);
    1471             : 
    1472             :  private:
    1473             :   static V8_WARN_UNUSED_RESULT MaybeLocal<UnboundScript> CompileUnboundInternal(
    1474             :       Isolate* isolate, Source* source, CompileOptions options);
    1475             : };
    1476             : 
    1477             : 
    1478             : /**
    1479             :  * An error message.
    1480             :  */
    1481             : class V8_EXPORT Message {
    1482             :  public:
    1483             :   Local<String> Get() const;
    1484             : 
    1485             :   V8_DEPRECATE_SOON("Use maybe version", Local<String> GetSourceLine() const);
    1486             :   V8_WARN_UNUSED_RESULT MaybeLocal<String> GetSourceLine(
    1487             :       Local<Context> context) const;
    1488             : 
    1489             :   /**
    1490             :    * Returns the origin for the script from where the function causing the
    1491             :    * error originates.
    1492             :    */
    1493             :   ScriptOrigin GetScriptOrigin() const;
    1494             : 
    1495             :   /**
    1496             :    * Returns the resource name for the script from where the function causing
    1497             :    * the error originates.
    1498             :    */
    1499             :   Local<Value> GetScriptResourceName() const;
    1500             : 
    1501             :   /**
    1502             :    * Exception stack trace. By default stack traces are not captured for
    1503             :    * uncaught exceptions. SetCaptureStackTraceForUncaughtExceptions allows
    1504             :    * to change this option.
    1505             :    */
    1506             :   Local<StackTrace> GetStackTrace() const;
    1507             : 
    1508             :   /**
    1509             :    * Returns the number, 1-based, of the line where the error occurred.
    1510             :    */
    1511             :   V8_DEPRECATE_SOON("Use maybe version", int GetLineNumber() const);
    1512             :   V8_WARN_UNUSED_RESULT Maybe<int> GetLineNumber(Local<Context> context) const;
    1513             : 
    1514             :   /**
    1515             :    * Returns the index within the script of the first character where
    1516             :    * the error occurred.
    1517             :    */
    1518             :   int GetStartPosition() const;
    1519             : 
    1520             :   /**
    1521             :    * Returns the index within the script of the last character where
    1522             :    * the error occurred.
    1523             :    */
    1524             :   int GetEndPosition() const;
    1525             : 
    1526             :   /**
    1527             :    * Returns the error level of the message.
    1528             :    */
    1529             :   int ErrorLevel() const;
    1530             : 
    1531             :   /**
    1532             :    * Returns the index within the line of the first character where
    1533             :    * the error occurred.
    1534             :    */
    1535             :   V8_DEPRECATE_SOON("Use maybe version", int GetStartColumn() const);
    1536             :   V8_WARN_UNUSED_RESULT Maybe<int> GetStartColumn(Local<Context> context) const;
    1537             : 
    1538             :   /**
    1539             :    * Returns the index within the line of the last character where
    1540             :    * the error occurred.
    1541             :    */
    1542             :   V8_DEPRECATED("Use maybe version", int GetEndColumn() const);
    1543             :   V8_WARN_UNUSED_RESULT Maybe<int> GetEndColumn(Local<Context> context) const;
    1544             : 
    1545             :   /**
    1546             :    * Passes on the value set by the embedder when it fed the script from which
    1547             :    * this Message was generated to V8.
    1548             :    */
    1549             :   bool IsSharedCrossOrigin() const;
    1550             :   bool IsOpaque() const;
    1551             : 
    1552             :   // TODO(1245381): Print to a string instead of on a FILE.
    1553             :   static void PrintCurrentStackTrace(Isolate* isolate, FILE* out);
    1554             : 
    1555             :   static const int kNoLineNumberInfo = 0;
    1556             :   static const int kNoColumnInfo = 0;
    1557             :   static const int kNoScriptIdInfo = 0;
    1558             : };
    1559             : 
    1560             : 
    1561             : /**
    1562             :  * Representation of a JavaScript stack trace. The information collected is a
    1563             :  * snapshot of the execution stack and the information remains valid after
    1564             :  * execution continues.
    1565             :  */
    1566             : class V8_EXPORT StackTrace {
    1567             :  public:
    1568             :   /**
    1569             :    * Flags that determine what information is placed captured for each
    1570             :    * StackFrame when grabbing the current stack trace.
    1571             :    * Note: these options are deprecated and we always collect all available
    1572             :    * information (kDetailed).
    1573             :    */
    1574             :   enum StackTraceOptions {
    1575             :     kLineNumber = 1,
    1576             :     kColumnOffset = 1 << 1 | kLineNumber,
    1577             :     kScriptName = 1 << 2,
    1578             :     kFunctionName = 1 << 3,
    1579             :     kIsEval = 1 << 4,
    1580             :     kIsConstructor = 1 << 5,
    1581             :     kScriptNameOrSourceURL = 1 << 6,
    1582             :     kScriptId = 1 << 7,
    1583             :     kExposeFramesAcrossSecurityOrigins = 1 << 8,
    1584             :     kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName,
    1585             :     kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL
    1586             :   };
    1587             : 
    1588             :   /**
    1589             :    * Returns a StackFrame at a particular index.
    1590             :    */
    1591             :   Local<StackFrame> GetFrame(uint32_t index) const;
    1592             : 
    1593             :   /**
    1594             :    * Returns the number of StackFrames.
    1595             :    */
    1596             :   int GetFrameCount() const;
    1597             : 
    1598             :   /**
    1599             :    * Returns StackTrace as a v8::Array that contains StackFrame objects.
    1600             :    */
    1601             :   V8_DEPRECATED("Use native API instead", Local<Array> AsArray());
    1602             : 
    1603             :   /**
    1604             :    * Grab a snapshot of the current JavaScript execution stack.
    1605             :    *
    1606             :    * \param frame_limit The maximum number of stack frames we want to capture.
    1607             :    * \param options Enumerates the set of things we will capture for each
    1608             :    *   StackFrame.
    1609             :    */
    1610             :   static Local<StackTrace> CurrentStackTrace(
    1611             :       Isolate* isolate, int frame_limit, StackTraceOptions options = kDetailed);
    1612             : };
    1613             : 
    1614             : 
    1615             : /**
    1616             :  * A single JavaScript stack frame.
    1617             :  */
    1618             : class V8_EXPORT StackFrame {
    1619             :  public:
    1620             :   /**
    1621             :    * Returns the number, 1-based, of the line for the associate function call.
    1622             :    * This method will return Message::kNoLineNumberInfo if it is unable to
    1623             :    * retrieve the line number, or if kLineNumber was not passed as an option
    1624             :    * when capturing the StackTrace.
    1625             :    */
    1626             :   int GetLineNumber() const;
    1627             : 
    1628             :   /**
    1629             :    * Returns the 1-based column offset on the line for the associated function
    1630             :    * call.
    1631             :    * This method will return Message::kNoColumnInfo if it is unable to retrieve
    1632             :    * the column number, or if kColumnOffset was not passed as an option when
    1633             :    * capturing the StackTrace.
    1634             :    */
    1635             :   int GetColumn() const;
    1636             : 
    1637             :   /**
    1638             :    * Returns the id of the script for the function for this StackFrame.
    1639             :    * This method will return Message::kNoScriptIdInfo if it is unable to
    1640             :    * retrieve the script id, or if kScriptId was not passed as an option when
    1641             :    * capturing the StackTrace.
    1642             :    */
    1643             :   int GetScriptId() const;
    1644             : 
    1645             :   /**
    1646             :    * Returns the name of the resource that contains the script for the
    1647             :    * function for this StackFrame.
    1648             :    */
    1649             :   Local<String> GetScriptName() const;
    1650             : 
    1651             :   /**
    1652             :    * Returns the name of the resource that contains the script for the
    1653             :    * function for this StackFrame or sourceURL value if the script name
    1654             :    * is undefined and its source ends with //# sourceURL=... string or
    1655             :    * deprecated //@ sourceURL=... string.
    1656             :    */
    1657             :   Local<String> GetScriptNameOrSourceURL() const;
    1658             : 
    1659             :   /**
    1660             :    * Returns the name of the function associated with this stack frame.
    1661             :    */
    1662             :   Local<String> GetFunctionName() const;
    1663             : 
    1664             :   /**
    1665             :    * Returns whether or not the associated function is compiled via a call to
    1666             :    * eval().
    1667             :    */
    1668             :   bool IsEval() const;
    1669             : 
    1670             :   /**
    1671             :    * Returns whether or not the associated function is called as a
    1672             :    * constructor via "new".
    1673             :    */
    1674             :   bool IsConstructor() const;
    1675             : 
    1676             :   /**
    1677             :    * Returns whether or not the associated functions is defined in wasm.
    1678             :    */
    1679             :   bool IsWasm() const;
    1680             : };
    1681             : 
    1682             : 
    1683             : // A StateTag represents a possible state of the VM.
    1684             : enum StateTag { JS, GC, COMPILER, OTHER, EXTERNAL, IDLE };
    1685             : 
    1686             : // A RegisterState represents the current state of registers used
    1687             : // by the sampling profiler API.
    1688             : struct RegisterState {
    1689      239555 :   RegisterState() : pc(nullptr), sp(nullptr), fp(nullptr) {}
    1690             :   void* pc;  // Instruction pointer.
    1691             :   void* sp;  // Stack pointer.
    1692             :   void* fp;  // Frame pointer.
    1693             : };
    1694             : 
    1695             : // The output structure filled up by GetStackSample API function.
    1696             : struct SampleInfo {
    1697             :   size_t frames_count;            // Number of frames collected.
    1698             :   StateTag vm_state;              // Current VM state.
    1699             :   void* external_callback_entry;  // External callback address if VM is
    1700             :                                   // executing an external callback.
    1701             : };
    1702             : 
    1703             : /**
    1704             :  * A JSON Parser and Stringifier.
    1705             :  */
    1706             : class V8_EXPORT JSON {
    1707             :  public:
    1708             :   /**
    1709             :    * Tries to parse the string |json_string| and returns it as value if
    1710             :    * successful.
    1711             :    *
    1712             :    * \param json_string The string to parse.
    1713             :    * \return The corresponding value if successfully parsed.
    1714             :    */
    1715             :   static V8_DEPRECATED("Use the maybe version taking context",
    1716             :                        Local<Value> Parse(Local<String> json_string));
    1717             :   static V8_DEPRECATE_SOON("Use the maybe version taking context",
    1718             :                            MaybeLocal<Value> Parse(Isolate* isolate,
    1719             :                                                    Local<String> json_string));
    1720             :   static V8_WARN_UNUSED_RESULT MaybeLocal<Value> Parse(
    1721             :       Local<Context> context, Local<String> json_string);
    1722             : 
    1723             :   /**
    1724             :    * Tries to stringify the JSON-serializable object |json_object| and returns
    1725             :    * it as string if successful.
    1726             :    *
    1727             :    * \param json_object The JSON-serializable object to stringify.
    1728             :    * \return The corresponding string if successfully stringified.
    1729             :    */
    1730             :   static V8_WARN_UNUSED_RESULT MaybeLocal<String> Stringify(
    1731             :       Local<Context> context, Local<Object> json_object,
    1732             :       Local<String> gap = Local<String>());
    1733             : };
    1734             : 
    1735             : /**
    1736             :  * Value serialization compatible with the HTML structured clone algorithm.
    1737             :  * The format is backward-compatible (i.e. safe to store to disk).
    1738             :  *
    1739             :  * WARNING: This API is under development, and changes (including incompatible
    1740             :  * changes to the API or wire format) may occur without notice until this
    1741             :  * warning is removed.
    1742             :  */
    1743             : class V8_EXPORT ValueSerializer {
    1744             :  public:
    1745        1116 :   class V8_EXPORT Delegate {
    1746             :    public:
    1747        1116 :     virtual ~Delegate() {}
    1748             : 
    1749             :     /**
    1750             :      * Handles the case where a DataCloneError would be thrown in the structured
    1751             :      * clone spec. Other V8 embedders may throw some other appropriate exception
    1752             :      * type.
    1753             :      */
    1754             :     virtual void ThrowDataCloneError(Local<String> message) = 0;
    1755             : 
    1756             :     /**
    1757             :      * The embedder overrides this method to write some kind of host object, if
    1758             :      * possible. If not, a suitable exception should be thrown and
    1759             :      * Nothing<bool>() returned.
    1760             :      */
    1761             :     virtual Maybe<bool> WriteHostObject(Isolate* isolate, Local<Object> object);
    1762             : 
    1763             :     /**
    1764             :      * Called when the ValueSerializer is going to serialize a
    1765             :      * SharedArrayBuffer object. The embedder must return an ID for the
    1766             :      * object, using the same ID if this SharedArrayBuffer has already been
    1767             :      * serialized in this buffer. When deserializing, this ID will be passed to
    1768             :      * ValueDeserializer::TransferSharedArrayBuffer as |transfer_id|.
    1769             :      *
    1770             :      * If the object cannot be serialized, an
    1771             :      * exception should be thrown and Nothing<uint32_t>() returned.
    1772             :      */
    1773             :     virtual Maybe<uint32_t> GetSharedArrayBufferId(
    1774             :         Isolate* isolate, Local<SharedArrayBuffer> shared_array_buffer);
    1775             : 
    1776             :     virtual Maybe<uint32_t> GetWasmModuleTransferId(
    1777             :         Isolate* isolate, Local<WasmCompiledModule> module);
    1778             :     /**
    1779             :      * Allocates memory for the buffer of at least the size provided. The actual
    1780             :      * size (which may be greater or equal) is written to |actual_size|. If no
    1781             :      * buffer has been allocated yet, nullptr will be provided.
    1782             :      *
    1783             :      * If the memory cannot be allocated, nullptr should be returned.
    1784             :      * |actual_size| will be ignored. It is assumed that |old_buffer| is still
    1785             :      * valid in this case and has not been modified.
    1786             :      */
    1787             :     virtual void* ReallocateBufferMemory(void* old_buffer, size_t size,
    1788             :                                          size_t* actual_size);
    1789             : 
    1790             :     /**
    1791             :      * Frees a buffer allocated with |ReallocateBufferMemory|.
    1792             :      */
    1793             :     virtual void FreeBufferMemory(void* buffer);
    1794             :   };
    1795             : 
    1796             :   static uint32_t GetCurrentDataFormatVersion();
    1797             : 
    1798             :   explicit ValueSerializer(Isolate* isolate);
    1799             :   ValueSerializer(Isolate* isolate, Delegate* delegate);
    1800             :   ~ValueSerializer();
    1801             : 
    1802             :   /**
    1803             :    * Writes out a header, which includes the format version.
    1804             :    */
    1805             :   void WriteHeader();
    1806             : 
    1807             :   /**
    1808             :    * Serializes a JavaScript value into the buffer.
    1809             :    */
    1810             :   V8_WARN_UNUSED_RESULT Maybe<bool> WriteValue(Local<Context> context,
    1811             :                                                Local<Value> value);
    1812             : 
    1813             :   /**
    1814             :    * Returns the stored data. This serializer should not be used once the buffer
    1815             :    * is released. The contents are undefined if a previous write has failed.
    1816             :    */
    1817             :   V8_DEPRECATE_SOON("Use Release()", std::vector<uint8_t> ReleaseBuffer());
    1818             : 
    1819             :   /**
    1820             :    * Returns the stored data (allocated using the delegate's
    1821             :    * AllocateBufferMemory) and its size. This serializer should not be used once
    1822             :    * the buffer is released. The contents are undefined if a previous write has
    1823             :    * failed.
    1824             :    */
    1825             :   V8_WARN_UNUSED_RESULT std::pair<uint8_t*, size_t> Release();
    1826             : 
    1827             :   /**
    1828             :    * Marks an ArrayBuffer as havings its contents transferred out of band.
    1829             :    * Pass the corresponding ArrayBuffer in the deserializing context to
    1830             :    * ValueDeserializer::TransferArrayBuffer.
    1831             :    */
    1832             :   void TransferArrayBuffer(uint32_t transfer_id,
    1833             :                            Local<ArrayBuffer> array_buffer);
    1834             : 
    1835             :   /**
    1836             :    * Similar to TransferArrayBuffer, but for SharedArrayBuffer.
    1837             :    */
    1838             :   V8_DEPRECATE_SOON("Use Delegate::GetSharedArrayBufferId",
    1839             :                     void TransferSharedArrayBuffer(
    1840             :                         uint32_t transfer_id,
    1841             :                         Local<SharedArrayBuffer> shared_array_buffer));
    1842             : 
    1843             :   /**
    1844             :    * Indicate whether to treat ArrayBufferView objects as host objects,
    1845             :    * i.e. pass them to Delegate::WriteHostObject. This should not be
    1846             :    * called when no Delegate was passed.
    1847             :    *
    1848             :    * The default is not to treat ArrayBufferViews as host objects.
    1849             :    */
    1850             :   void SetTreatArrayBufferViewsAsHostObjects(bool mode);
    1851             : 
    1852             :   /**
    1853             :    * Write raw data in various common formats to the buffer.
    1854             :    * Note that integer types are written in base-128 varint format, not with a
    1855             :    * binary copy. For use during an override of Delegate::WriteHostObject.
    1856             :    */
    1857             :   void WriteUint32(uint32_t value);
    1858             :   void WriteUint64(uint64_t value);
    1859             :   void WriteDouble(double value);
    1860             :   void WriteRawBytes(const void* source, size_t length);
    1861             : 
    1862             :  private:
    1863             :   ValueSerializer(const ValueSerializer&) = delete;
    1864             :   void operator=(const ValueSerializer&) = delete;
    1865             : 
    1866             :   struct PrivateData;
    1867             :   PrivateData* private_;
    1868             : };
    1869             : 
    1870             : /**
    1871             :  * Deserializes values from data written with ValueSerializer, or a compatible
    1872             :  * implementation.
    1873             :  *
    1874             :  * WARNING: This API is under development, and changes (including incompatible
    1875             :  * changes to the API or wire format) may occur without notice until this
    1876             :  * warning is removed.
    1877             :  */
    1878             : class V8_EXPORT ValueDeserializer {
    1879             :  public:
    1880         784 :   class V8_EXPORT Delegate {
    1881             :    public:
    1882         784 :     virtual ~Delegate() {}
    1883             : 
    1884             :     /**
    1885             :      * The embedder overrides this method to read some kind of host object, if
    1886             :      * possible. If not, a suitable exception should be thrown and
    1887             :      * MaybeLocal<Object>() returned.
    1888             :      */
    1889             :     virtual MaybeLocal<Object> ReadHostObject(Isolate* isolate);
    1890             : 
    1891             :     /**
    1892             :      * Get a WasmCompiledModule given a transfer_id previously provided
    1893             :      * by ValueSerializer::GetWasmModuleTransferId
    1894             :      */
    1895             :     virtual MaybeLocal<WasmCompiledModule> GetWasmModuleFromId(
    1896             :         Isolate* isolate, uint32_t transfer_id);
    1897             :   };
    1898             : 
    1899             :   ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size);
    1900             :   ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size,
    1901             :                     Delegate* delegate);
    1902             :   ~ValueDeserializer();
    1903             : 
    1904             :   /**
    1905             :    * Reads and validates a header (including the format version).
    1906             :    * May, for example, reject an invalid or unsupported wire format.
    1907             :    */
    1908             :   V8_WARN_UNUSED_RESULT Maybe<bool> ReadHeader(Local<Context> context);
    1909             : 
    1910             :   /**
    1911             :    * Deserializes a JavaScript value from the buffer.
    1912             :    */
    1913             :   V8_WARN_UNUSED_RESULT MaybeLocal<Value> ReadValue(Local<Context> context);
    1914             : 
    1915             :   /**
    1916             :    * Accepts the array buffer corresponding to the one passed previously to
    1917             :    * ValueSerializer::TransferArrayBuffer.
    1918             :    */
    1919             :   void TransferArrayBuffer(uint32_t transfer_id,
    1920             :                            Local<ArrayBuffer> array_buffer);
    1921             : 
    1922             :   /**
    1923             :    * Similar to TransferArrayBuffer, but for SharedArrayBuffer.
    1924             :    * The id is not necessarily in the same namespace as unshared ArrayBuffer
    1925             :    * objects.
    1926             :    */
    1927             :   void TransferSharedArrayBuffer(uint32_t id,
    1928             :                                  Local<SharedArrayBuffer> shared_array_buffer);
    1929             : 
    1930             :   /**
    1931             :    * Must be called before ReadHeader to enable support for reading the legacy
    1932             :    * wire format (i.e., which predates this being shipped).
    1933             :    *
    1934             :    * Don't use this unless you need to read data written by previous versions of
    1935             :    * blink::ScriptValueSerializer.
    1936             :    */
    1937             :   void SetSupportsLegacyWireFormat(bool supports_legacy_wire_format);
    1938             : 
    1939             :   /**
    1940             :    * Expect inline wasm in the data stream (rather than in-memory transfer)
    1941             :    */
    1942             :   void SetExpectInlineWasm(bool allow_inline_wasm);
    1943             : 
    1944             :   /**
    1945             :    * Reads the underlying wire format version. Likely mostly to be useful to
    1946             :    * legacy code reading old wire format versions. Must be called after
    1947             :    * ReadHeader.
    1948             :    */
    1949             :   uint32_t GetWireFormatVersion() const;
    1950             : 
    1951             :   /**
    1952             :    * Reads raw data in various common formats to the buffer.
    1953             :    * Note that integer types are read in base-128 varint format, not with a
    1954             :    * binary copy. For use during an override of Delegate::ReadHostObject.
    1955             :    */
    1956             :   V8_WARN_UNUSED_RESULT bool ReadUint32(uint32_t* value);
    1957             :   V8_WARN_UNUSED_RESULT bool ReadUint64(uint64_t* value);
    1958             :   V8_WARN_UNUSED_RESULT bool ReadDouble(double* value);
    1959             :   V8_WARN_UNUSED_RESULT bool ReadRawBytes(size_t length, const void** data);
    1960             : 
    1961             :  private:
    1962             :   ValueDeserializer(const ValueDeserializer&) = delete;
    1963             :   void operator=(const ValueDeserializer&) = delete;
    1964             : 
    1965             :   struct PrivateData;
    1966             :   PrivateData* private_;
    1967             : };
    1968             : 
    1969             : /**
    1970             :  * A map whose keys are referenced weakly. It is similar to JavaScript WeakMap
    1971             :  * but can be created without entering a v8::Context and hence shouldn't
    1972             :  * escape to JavaScript.
    1973             :  */
    1974             : class V8_EXPORT NativeWeakMap : public Data {
    1975             :  public:
    1976             :   static Local<NativeWeakMap> New(Isolate* isolate);
    1977             :   void Set(Local<Value> key, Local<Value> value);
    1978             :   Local<Value> Get(Local<Value> key) const;
    1979             :   bool Has(Local<Value> key);
    1980             :   bool Delete(Local<Value> key);
    1981             : };
    1982             : 
    1983             : 
    1984             : // --- Value ---
    1985             : 
    1986             : 
    1987             : /**
    1988             :  * The superclass of all JavaScript values and objects.
    1989             :  */
    1990             : class V8_EXPORT Value : public Data {
    1991             :  public:
    1992             :   /**
    1993             :    * Returns true if this value is the undefined value.  See ECMA-262
    1994             :    * 4.3.10.
    1995             :    */
    1996             :   V8_INLINE bool IsUndefined() const;
    1997             : 
    1998             :   /**
    1999             :    * Returns true if this value is the null value.  See ECMA-262
    2000             :    * 4.3.11.
    2001             :    */
    2002             :   V8_INLINE bool IsNull() const;
    2003             : 
    2004             :   /**
    2005             :    * Returns true if this value is either the null or the undefined value.
    2006             :    * See ECMA-262
    2007             :    * 4.3.11. and 4.3.12
    2008             :    */
    2009             :   V8_INLINE bool IsNullOrUndefined() const;
    2010             : 
    2011             :   /**
    2012             :   * Returns true if this value is true.
    2013             :   */
    2014             :   bool IsTrue() const;
    2015             : 
    2016             :   /**
    2017             :    * Returns true if this value is false.
    2018             :    */
    2019             :   bool IsFalse() const;
    2020             : 
    2021             :   /**
    2022             :    * Returns true if this value is a symbol or a string.
    2023             :    */
    2024             :   bool IsName() const;
    2025             : 
    2026             :   /**
    2027             :    * Returns true if this value is an instance of the String type.
    2028             :    * See ECMA-262 8.4.
    2029             :    */
    2030             :   V8_INLINE bool IsString() const;
    2031             : 
    2032             :   /**
    2033             :    * Returns true if this value is a symbol.
    2034             :    */
    2035             :   bool IsSymbol() const;
    2036             : 
    2037             :   /**
    2038             :    * Returns true if this value is a function.
    2039             :    */
    2040             :   bool IsFunction() const;
    2041             : 
    2042             :   /**
    2043             :    * Returns true if this value is an array. Note that it will return false for
    2044             :    * an Proxy for an array.
    2045             :    */
    2046             :   bool IsArray() const;
    2047             : 
    2048             :   /**
    2049             :    * Returns true if this value is an object.
    2050             :    */
    2051             :   bool IsObject() const;
    2052             : 
    2053             :   /**
    2054             :    * Returns true if this value is boolean.
    2055             :    */
    2056             :   bool IsBoolean() const;
    2057             : 
    2058             :   /**
    2059             :    * Returns true if this value is a number.
    2060             :    */
    2061             :   bool IsNumber() const;
    2062             : 
    2063             :   /**
    2064             :    * Returns true if this value is external.
    2065             :    */
    2066             :   bool IsExternal() const;
    2067             : 
    2068             :   /**
    2069             :    * Returns true if this value is a 32-bit signed integer.
    2070             :    */
    2071             :   bool IsInt32() const;
    2072             : 
    2073             :   /**
    2074             :    * Returns true if this value is a 32-bit unsigned integer.
    2075             :    */
    2076             :   bool IsUint32() const;
    2077             : 
    2078             :   /**
    2079             :    * Returns true if this value is a Date.
    2080             :    */
    2081             :   bool IsDate() const;
    2082             : 
    2083             :   /**
    2084             :    * Returns true if this value is an Arguments object.
    2085             :    */
    2086             :   bool IsArgumentsObject() const;
    2087             : 
    2088             :   /**
    2089             :    * Returns true if this value is a Boolean object.
    2090             :    */
    2091             :   bool IsBooleanObject() const;
    2092             : 
    2093             :   /**
    2094             :    * Returns true if this value is a Number object.
    2095             :    */
    2096             :   bool IsNumberObject() const;
    2097             : 
    2098             :   /**
    2099             :    * Returns true if this value is a String object.
    2100             :    */
    2101             :   bool IsStringObject() const;
    2102             : 
    2103             :   /**
    2104             :    * Returns true if this value is a Symbol object.
    2105             :    */
    2106             :   bool IsSymbolObject() const;
    2107             : 
    2108             :   /**
    2109             :    * Returns true if this value is a NativeError.
    2110             :    */
    2111             :   bool IsNativeError() const;
    2112             : 
    2113             :   /**
    2114             :    * Returns true if this value is a RegExp.
    2115             :    */
    2116             :   bool IsRegExp() const;
    2117             : 
    2118             :   /**
    2119             :    * Returns true if this value is an async function.
    2120             :    */
    2121             :   bool IsAsyncFunction() const;
    2122             : 
    2123             :   /**
    2124             :    * Returns true if this value is a Generator function.
    2125             :    */
    2126             :   bool IsGeneratorFunction() const;
    2127             : 
    2128             :   /**
    2129             :    * Returns true if this value is a Generator object (iterator).
    2130             :    */
    2131             :   bool IsGeneratorObject() const;
    2132             : 
    2133             :   /**
    2134             :    * Returns true if this value is a Promise.
    2135             :    */
    2136             :   bool IsPromise() const;
    2137             : 
    2138             :   /**
    2139             :    * Returns true if this value is a Map.
    2140             :    */
    2141             :   bool IsMap() const;
    2142             : 
    2143             :   /**
    2144             :    * Returns true if this value is a Set.
    2145             :    */
    2146             :   bool IsSet() const;
    2147             : 
    2148             :   /**
    2149             :    * Returns true if this value is a Map Iterator.
    2150             :    */
    2151             :   bool IsMapIterator() const;
    2152             : 
    2153             :   /**
    2154             :    * Returns true if this value is a Set Iterator.
    2155             :    */
    2156             :   bool IsSetIterator() const;
    2157             : 
    2158             :   /**
    2159             :    * Returns true if this value is a WeakMap.
    2160             :    */
    2161             :   bool IsWeakMap() const;
    2162             : 
    2163             :   /**
    2164             :    * Returns true if this value is a WeakSet.
    2165             :    */
    2166             :   bool IsWeakSet() const;
    2167             : 
    2168             :   /**
    2169             :    * Returns true if this value is an ArrayBuffer.
    2170             :    */
    2171             :   bool IsArrayBuffer() const;
    2172             : 
    2173             :   /**
    2174             :    * Returns true if this value is an ArrayBufferView.
    2175             :    */
    2176             :   bool IsArrayBufferView() const;
    2177             : 
    2178             :   /**
    2179             :    * Returns true if this value is one of TypedArrays.
    2180             :    */
    2181             :   bool IsTypedArray() const;
    2182             : 
    2183             :   /**
    2184             :    * Returns true if this value is an Uint8Array.
    2185             :    */
    2186             :   bool IsUint8Array() const;
    2187             : 
    2188             :   /**
    2189             :    * Returns true if this value is an Uint8ClampedArray.
    2190             :    */
    2191             :   bool IsUint8ClampedArray() const;
    2192             : 
    2193             :   /**
    2194             :    * Returns true if this value is an Int8Array.
    2195             :    */
    2196             :   bool IsInt8Array() const;
    2197             : 
    2198             :   /**
    2199             :    * Returns true if this value is an Uint16Array.
    2200             :    */
    2201             :   bool IsUint16Array() const;
    2202             : 
    2203             :   /**
    2204             :    * Returns true if this value is an Int16Array.
    2205             :    */
    2206             :   bool IsInt16Array() const;
    2207             : 
    2208             :   /**
    2209             :    * Returns true if this value is an Uint32Array.
    2210             :    */
    2211             :   bool IsUint32Array() const;
    2212             : 
    2213             :   /**
    2214             :    * Returns true if this value is an Int32Array.
    2215             :    */
    2216             :   bool IsInt32Array() const;
    2217             : 
    2218             :   /**
    2219             :    * Returns true if this value is a Float32Array.
    2220             :    */
    2221             :   bool IsFloat32Array() const;
    2222             : 
    2223             :   /**
    2224             :    * Returns true if this value is a Float64Array.
    2225             :    */
    2226             :   bool IsFloat64Array() const;
    2227             : 
    2228             :   /**
    2229             :    * Returns true if this value is a DataView.
    2230             :    */
    2231             :   bool IsDataView() const;
    2232             : 
    2233             :   /**
    2234             :    * Returns true if this value is a SharedArrayBuffer.
    2235             :    * This is an experimental feature.
    2236             :    */
    2237             :   bool IsSharedArrayBuffer() const;
    2238             : 
    2239             :   /**
    2240             :    * Returns true if this value is a JavaScript Proxy.
    2241             :    */
    2242             :   bool IsProxy() const;
    2243             : 
    2244             :   bool IsWebAssemblyCompiledModule() const;
    2245             : 
    2246             :   V8_WARN_UNUSED_RESULT MaybeLocal<Boolean> ToBoolean(
    2247             :       Local<Context> context) const;
    2248             :   V8_WARN_UNUSED_RESULT MaybeLocal<Number> ToNumber(
    2249             :       Local<Context> context) const;
    2250             :   V8_WARN_UNUSED_RESULT MaybeLocal<String> ToString(
    2251             :       Local<Context> context) const;
    2252             :   V8_WARN_UNUSED_RESULT MaybeLocal<String> ToDetailString(
    2253             :       Local<Context> context) const;
    2254             :   V8_WARN_UNUSED_RESULT MaybeLocal<Object> ToObject(
    2255             :       Local<Context> context) const;
    2256             :   V8_WARN_UNUSED_RESULT MaybeLocal<Integer> ToInteger(
    2257             :       Local<Context> context) const;
    2258             :   V8_WARN_UNUSED_RESULT MaybeLocal<Uint32> ToUint32(
    2259             :       Local<Context> context) const;
    2260             :   V8_WARN_UNUSED_RESULT MaybeLocal<Int32> ToInt32(Local<Context> context) const;
    2261             : 
    2262             :   V8_DEPRECATE_SOON("Use maybe version",
    2263             :                     Local<Boolean> ToBoolean(Isolate* isolate) const);
    2264             :   V8_DEPRECATE_SOON("Use maybe version",
    2265             :                     Local<Number> ToNumber(Isolate* isolate) const);
    2266             :   V8_DEPRECATE_SOON("Use maybe version",
    2267             :                     Local<String> ToString(Isolate* isolate) const);
    2268             :   V8_DEPRECATED("Use maybe version",
    2269             :                 Local<String> ToDetailString(Isolate* isolate) const);
    2270             :   V8_DEPRECATE_SOON("Use maybe version",
    2271             :                     Local<Object> ToObject(Isolate* isolate) const);
    2272             :   V8_DEPRECATE_SOON("Use maybe version",
    2273             :                     Local<Integer> ToInteger(Isolate* isolate) const);
    2274             :   V8_DEPRECATED("Use maybe version",
    2275             :                 Local<Uint32> ToUint32(Isolate* isolate) const);
    2276             :   V8_DEPRECATE_SOON("Use maybe version",
    2277             :                     Local<Int32> ToInt32(Isolate* isolate) const);
    2278             : 
    2279             :   inline V8_DEPRECATE_SOON("Use maybe version",
    2280             :                            Local<Boolean> ToBoolean() const);
    2281             :   inline V8_DEPRECATED("Use maybe version", Local<Number> ToNumber() const);
    2282             :   inline V8_DEPRECATE_SOON("Use maybe version", Local<String> ToString() const);
    2283             :   inline V8_DEPRECATED("Use maybe version",
    2284             :                        Local<String> ToDetailString() const);
    2285             :   inline V8_DEPRECATE_SOON("Use maybe version", Local<Object> ToObject() const);
    2286             :   inline V8_DEPRECATE_SOON("Use maybe version",
    2287             :                            Local<Integer> ToInteger() const);
    2288             :   inline V8_DEPRECATED("Use maybe version", Local<Uint32> ToUint32() const);
    2289             :   inline V8_DEPRECATED("Use maybe version", Local<Int32> ToInt32() const);
    2290             : 
    2291             :   /**
    2292             :    * Attempts to convert a string to an array index.
    2293             :    * Returns an empty handle if the conversion fails.
    2294             :    */
    2295             :   V8_DEPRECATED("Use maybe version", Local<Uint32> ToArrayIndex() const);
    2296             :   V8_WARN_UNUSED_RESULT MaybeLocal<Uint32> ToArrayIndex(
    2297             :       Local<Context> context) const;
    2298             : 
    2299             :   V8_WARN_UNUSED_RESULT Maybe<bool> BooleanValue(Local<Context> context) const;
    2300             :   V8_WARN_UNUSED_RESULT Maybe<double> NumberValue(Local<Context> context) const;
    2301             :   V8_WARN_UNUSED_RESULT Maybe<int64_t> IntegerValue(
    2302             :       Local<Context> context) const;
    2303             :   V8_WARN_UNUSED_RESULT Maybe<uint32_t> Uint32Value(
    2304             :       Local<Context> context) const;
    2305             :   V8_WARN_UNUSED_RESULT Maybe<int32_t> Int32Value(Local<Context> context) const;
    2306             : 
    2307             :   V8_DEPRECATE_SOON("Use maybe version", bool BooleanValue() const);
    2308             :   V8_DEPRECATE_SOON("Use maybe version", double NumberValue() const);
    2309             :   V8_DEPRECATE_SOON("Use maybe version", int64_t IntegerValue() const);
    2310             :   V8_DEPRECATE_SOON("Use maybe version", uint32_t Uint32Value() const);
    2311             :   V8_DEPRECATE_SOON("Use maybe version", int32_t Int32Value() const);
    2312             : 
    2313             :   /** JS == */
    2314             :   V8_DEPRECATE_SOON("Use maybe version", bool Equals(Local<Value> that) const);
    2315             :   V8_WARN_UNUSED_RESULT Maybe<bool> Equals(Local<Context> context,
    2316             :                                            Local<Value> that) const;
    2317             :   bool StrictEquals(Local<Value> that) const;
    2318             :   bool SameValue(Local<Value> that) const;
    2319             : 
    2320             :   template <class T> V8_INLINE static Value* Cast(T* value);
    2321             : 
    2322             :   Local<String> TypeOf(Isolate*);
    2323             : 
    2324             :   Maybe<bool> InstanceOf(Local<Context> context, Local<Object> object);
    2325             : 
    2326             :  private:
    2327             :   V8_INLINE bool QuickIsUndefined() const;
    2328             :   V8_INLINE bool QuickIsNull() const;
    2329             :   V8_INLINE bool QuickIsNullOrUndefined() const;
    2330             :   V8_INLINE bool QuickIsString() const;
    2331             :   bool FullIsUndefined() const;
    2332             :   bool FullIsNull() const;
    2333             :   bool FullIsString() const;
    2334             : };
    2335             : 
    2336             : 
    2337             : /**
    2338             :  * The superclass of primitive values.  See ECMA-262 4.3.2.
    2339             :  */
    2340             : class V8_EXPORT Primitive : public Value { };
    2341             : 
    2342             : 
    2343             : /**
    2344             :  * A primitive boolean value (ECMA-262, 4.3.14).  Either the true
    2345             :  * or false value.
    2346             :  */
    2347             : class V8_EXPORT Boolean : public Primitive {
    2348             :  public:
    2349             :   bool Value() const;
    2350             :   V8_INLINE static Boolean* Cast(v8::Value* obj);
    2351             :   V8_INLINE static Local<Boolean> New(Isolate* isolate, bool value);
    2352             : 
    2353             :  private:
    2354             :   static void CheckCast(v8::Value* obj);
    2355             : };
    2356             : 
    2357             : 
    2358             : /**
    2359             :  * A superclass for symbols and strings.
    2360             :  */
    2361             : class V8_EXPORT Name : public Primitive {
    2362             :  public:
    2363             :   /**
    2364             :    * Returns the identity hash for this object. The current implementation
    2365             :    * uses an inline property on the object to store the identity hash.
    2366             :    *
    2367             :    * The return value will never be 0. Also, it is not guaranteed to be
    2368             :    * unique.
    2369             :    */
    2370             :   int GetIdentityHash();
    2371             : 
    2372             :   V8_INLINE static Name* Cast(Value* obj);
    2373             : 
    2374             :  private:
    2375             :   static void CheckCast(Value* obj);
    2376             : };
    2377             : 
    2378             : /**
    2379             :  * A flag describing different modes of string creation.
    2380             :  *
    2381             :  * Aside from performance implications there are no differences between the two
    2382             :  * creation modes.
    2383             :  */
    2384             : enum class NewStringType {
    2385             :   /**
    2386             :    * Create a new string, always allocating new storage memory.
    2387             :    */
    2388             :   kNormal,
    2389             : 
    2390             :   /**
    2391             :    * Acts as a hint that the string should be created in the
    2392             :    * old generation heap space and be deduplicated if an identical string
    2393             :    * already exists.
    2394             :    */
    2395             :   kInternalized
    2396             : };
    2397             : 
    2398             : /**
    2399             :  * A JavaScript string value (ECMA-262, 4.3.17).
    2400             :  */
    2401             : class V8_EXPORT String : public Name {
    2402             :  public:
    2403             :   static const int kMaxLength = (1 << 28) - 16;
    2404             : 
    2405             :   enum Encoding {
    2406             :     UNKNOWN_ENCODING = 0x1,
    2407             :     TWO_BYTE_ENCODING = 0x0,
    2408             :     ONE_BYTE_ENCODING = 0x8
    2409             :   };
    2410             :   /**
    2411             :    * Returns the number of characters (UTF-16 code units) in this string.
    2412             :    */
    2413             :   int Length() const;
    2414             : 
    2415             :   /**
    2416             :    * Returns the number of bytes in the UTF-8 encoded
    2417             :    * representation of this string.
    2418             :    */
    2419             :   int Utf8Length() const;
    2420             : 
    2421             :   /**
    2422             :    * Returns whether this string is known to contain only one byte data,
    2423             :    * i.e. ISO-8859-1 code points.
    2424             :    * Does not read the string.
    2425             :    * False negatives are possible.
    2426             :    */
    2427             :   bool IsOneByte() const;
    2428             : 
    2429             :   /**
    2430             :    * Returns whether this string contain only one byte data,
    2431             :    * i.e. ISO-8859-1 code points.
    2432             :    * Will read the entire string in some cases.
    2433             :    */
    2434             :   bool ContainsOnlyOneByte() const;
    2435             : 
    2436             :   /**
    2437             :    * Write the contents of the string to an external buffer.
    2438             :    * If no arguments are given, expects the buffer to be large
    2439             :    * enough to hold the entire string and NULL terminator. Copies
    2440             :    * the contents of the string and the NULL terminator into the
    2441             :    * buffer.
    2442             :    *
    2443             :    * WriteUtf8 will not write partial UTF-8 sequences, preferring to stop
    2444             :    * before the end of the buffer.
    2445             :    *
    2446             :    * Copies up to length characters into the output buffer.
    2447             :    * Only null-terminates if there is enough space in the buffer.
    2448             :    *
    2449             :    * \param buffer The buffer into which the string will be copied.
    2450             :    * \param start The starting position within the string at which
    2451             :    * copying begins.
    2452             :    * \param length The number of characters to copy from the string.  For
    2453             :    *    WriteUtf8 the number of bytes in the buffer.
    2454             :    * \param nchars_ref The number of characters written, can be NULL.
    2455             :    * \param options Various options that might affect performance of this or
    2456             :    *    subsequent operations.
    2457             :    * \return The number of characters copied to the buffer excluding the null
    2458             :    *    terminator.  For WriteUtf8: The number of bytes copied to the buffer
    2459             :    *    including the null terminator (if written).
    2460             :    */
    2461             :   enum WriteOptions {
    2462             :     NO_OPTIONS = 0,
    2463             :     HINT_MANY_WRITES_EXPECTED = 1,
    2464             :     NO_NULL_TERMINATION = 2,
    2465             :     PRESERVE_ONE_BYTE_NULL = 4,
    2466             :     // Used by WriteUtf8 to replace orphan surrogate code units with the
    2467             :     // unicode replacement character. Needs to be set to guarantee valid UTF-8
    2468             :     // output.
    2469             :     REPLACE_INVALID_UTF8 = 8
    2470             :   };
    2471             : 
    2472             :   // 16-bit character codes.
    2473             :   int Write(uint16_t* buffer,
    2474             :             int start = 0,
    2475             :             int length = -1,
    2476             :             int options = NO_OPTIONS) const;
    2477             :   // One byte characters.
    2478             :   int WriteOneByte(uint8_t* buffer,
    2479             :                    int start = 0,
    2480             :                    int length = -1,
    2481             :                    int options = NO_OPTIONS) const;
    2482             :   // UTF-8 encoded characters.
    2483             :   int WriteUtf8(char* buffer,
    2484             :                 int length = -1,
    2485             :                 int* nchars_ref = NULL,
    2486             :                 int options = NO_OPTIONS) const;
    2487             : 
    2488             :   /**
    2489             :    * A zero length string.
    2490             :    */
    2491             :   V8_INLINE static Local<String> Empty(Isolate* isolate);
    2492             : 
    2493             :   /**
    2494             :    * Returns true if the string is external
    2495             :    */
    2496             :   bool IsExternal() const;
    2497             : 
    2498             :   /**
    2499             :    * Returns true if the string is both external and one-byte.
    2500             :    */
    2501             :   bool IsExternalOneByte() const;
    2502             : 
    2503             :   class V8_EXPORT ExternalStringResourceBase {  // NOLINT
    2504             :    public:
    2505     1160638 :     virtual ~ExternalStringResourceBase() {}
    2506             : 
    2507        3832 :     virtual bool IsCompressible() const { return false; }
    2508             : 
    2509             :    protected:
    2510     1426902 :     ExternalStringResourceBase() {}
    2511             : 
    2512             :     /**
    2513             :      * Internally V8 will call this Dispose method when the external string
    2514             :      * resource is no longer needed. The default implementation will use the
    2515             :      * delete operator. This method can be overridden in subclasses to
    2516             :      * control how allocated external string resources are disposed.
    2517             :      */
    2518      505613 :     virtual void Dispose() { delete this; }
    2519             : 
    2520             :     // Disallow copying and assigning.
    2521             :     ExternalStringResourceBase(const ExternalStringResourceBase&) = delete;
    2522             :     void operator=(const ExternalStringResourceBase&) = delete;
    2523             : 
    2524             :    private:
    2525             :     friend class internal::Heap;
    2526             :     friend class v8::String;
    2527             :   };
    2528             : 
    2529             :   /**
    2530             :    * An ExternalStringResource is a wrapper around a two-byte string
    2531             :    * buffer that resides outside V8's heap. Implement an
    2532             :    * ExternalStringResource to manage the life cycle of the underlying
    2533             :    * buffer.  Note that the string data must be immutable.
    2534             :    */
    2535             :   class V8_EXPORT ExternalStringResource
    2536             :       : public ExternalStringResourceBase {
    2537             :    public:
    2538             :     /**
    2539             :      * Override the destructor to manage the life cycle of the underlying
    2540             :      * buffer.
    2541             :      */
    2542         424 :     virtual ~ExternalStringResource() {}
    2543             : 
    2544             :     /**
    2545             :      * The string data from the underlying buffer.
    2546             :      */
    2547             :     virtual const uint16_t* data() const = 0;
    2548             : 
    2549             :     /**
    2550             :      * The length of the string. That is, the number of two-byte characters.
    2551             :      */
    2552             :     virtual size_t length() const = 0;
    2553             : 
    2554             :    protected:
    2555         424 :     ExternalStringResource() {}
    2556             :   };
    2557             : 
    2558             :   /**
    2559             :    * An ExternalOneByteStringResource is a wrapper around an one-byte
    2560             :    * string buffer that resides outside V8's heap. Implement an
    2561             :    * ExternalOneByteStringResource to manage the life cycle of the
    2562             :    * underlying buffer.  Note that the string data must be immutable
    2563             :    * and that the data must be Latin-1 and not UTF-8, which would require
    2564             :    * special treatment internally in the engine and do not allow efficient
    2565             :    * indexing.  Use String::New or convert to 16 bit data for non-Latin1.
    2566             :    */
    2567             : 
    2568             :   class V8_EXPORT ExternalOneByteStringResource
    2569             :       : public ExternalStringResourceBase {
    2570             :    public:
    2571             :     /**
    2572             :      * Override the destructor to manage the life cycle of the underlying
    2573             :      * buffer.
    2574             :      */
    2575     1160214 :     virtual ~ExternalOneByteStringResource() {}
    2576             :     /** The string data from the underlying buffer.*/
    2577             :     virtual const char* data() const = 0;
    2578             :     /** The number of Latin-1 characters in the string.*/
    2579             :     virtual size_t length() const = 0;
    2580             :    protected:
    2581     1426478 :     ExternalOneByteStringResource() {}
    2582             :   };
    2583             : 
    2584             :   /**
    2585             :    * If the string is an external string, return the ExternalStringResourceBase
    2586             :    * regardless of the encoding, otherwise return NULL.  The encoding of the
    2587             :    * string is returned in encoding_out.
    2588             :    */
    2589             :   V8_INLINE ExternalStringResourceBase* GetExternalStringResourceBase(
    2590             :       Encoding* encoding_out) const;
    2591             : 
    2592             :   /**
    2593             :    * Get the ExternalStringResource for an external string.  Returns
    2594             :    * NULL if IsExternal() doesn't return true.
    2595             :    */
    2596             :   V8_INLINE ExternalStringResource* GetExternalStringResource() const;
    2597             : 
    2598             :   /**
    2599             :    * Get the ExternalOneByteStringResource for an external one-byte string.
    2600             :    * Returns NULL if IsExternalOneByte() doesn't return true.
    2601             :    */
    2602             :   const ExternalOneByteStringResource* GetExternalOneByteStringResource() const;
    2603             : 
    2604             :   V8_INLINE static String* Cast(v8::Value* obj);
    2605             : 
    2606             :   // TODO(dcarney): remove with deprecation of New functions.
    2607             :   enum NewStringType {
    2608             :     kNormalString = static_cast<int>(v8::NewStringType::kNormal),
    2609             :     kInternalizedString = static_cast<int>(v8::NewStringType::kInternalized)
    2610             :   };
    2611             : 
    2612             :   /** Allocates a new string from UTF-8 data.*/
    2613             :   static V8_DEPRECATE_SOON(
    2614             :       "Use maybe version",
    2615             :       Local<String> NewFromUtf8(Isolate* isolate, const char* data,
    2616             :                                 NewStringType type = kNormalString,
    2617             :                                 int length = -1));
    2618             : 
    2619             :   /** Allocates a new string from UTF-8 data. Only returns an empty value when
    2620             :    * length > kMaxLength. **/
    2621             :   static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromUtf8(
    2622             :       Isolate* isolate, const char* data, v8::NewStringType type,
    2623             :       int length = -1);
    2624             : 
    2625             :   /** Allocates a new string from Latin-1 data.*/
    2626             :   static V8_DEPRECATED(
    2627             :       "Use maybe version",
    2628             :       Local<String> NewFromOneByte(Isolate* isolate, const uint8_t* data,
    2629             :                                    NewStringType type = kNormalString,
    2630             :                                    int length = -1));
    2631             : 
    2632             :   /** Allocates a new string from Latin-1 data.  Only returns an empty value
    2633             :    * when length > kMaxLength. **/
    2634             :   static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromOneByte(
    2635             :       Isolate* isolate, const uint8_t* data, v8::NewStringType type,
    2636             :       int length = -1);
    2637             : 
    2638             :   /** Allocates a new string from UTF-16 data.*/
    2639             :   static V8_DEPRECATE_SOON(
    2640             :       "Use maybe version",
    2641             :       Local<String> NewFromTwoByte(Isolate* isolate, const uint16_t* data,
    2642             :                                    NewStringType type = kNormalString,
    2643             :                                    int length = -1));
    2644             : 
    2645             :   /** Allocates a new string from UTF-16 data. Only returns an empty value when
    2646             :    * length > kMaxLength. **/
    2647             :   static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromTwoByte(
    2648             :       Isolate* isolate, const uint16_t* data, v8::NewStringType type,
    2649             :       int length = -1);
    2650             : 
    2651             :   /**
    2652             :    * Creates a new string by concatenating the left and the right strings
    2653             :    * passed in as parameters.
    2654             :    */
    2655             :   static Local<String> Concat(Local<String> left, Local<String> right);
    2656             : 
    2657             :   /**
    2658             :    * Creates a new external string using the data defined in the given
    2659             :    * resource. When the external string is no longer live on V8's heap the
    2660             :    * resource will be disposed by calling its Dispose method. The caller of
    2661             :    * this function should not otherwise delete or modify the resource. Neither
    2662             :    * should the underlying buffer be deallocated or modified except through the
    2663             :    * destructor of the external string resource.
    2664             :    */
    2665             :   static V8_DEPRECATED("Use maybe version",
    2666             :                        Local<String> NewExternal(
    2667             :                            Isolate* isolate, ExternalStringResource* resource));
    2668             :   static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewExternalTwoByte(
    2669             :       Isolate* isolate, ExternalStringResource* resource);
    2670             : 
    2671             :   /**
    2672             :    * Associate an external string resource with this string by transforming it
    2673             :    * in place so that existing references to this string in the JavaScript heap
    2674             :    * will use the external string resource. The external string resource's
    2675             :    * character contents need to be equivalent to this string.
    2676             :    * Returns true if the string has been changed to be an external string.
    2677             :    * The string is not modified if the operation fails. See NewExternal for
    2678             :    * information on the lifetime of the resource.
    2679             :    */
    2680             :   bool MakeExternal(ExternalStringResource* resource);
    2681             : 
    2682             :   /**
    2683             :    * Creates a new external string using the one-byte data defined in the given
    2684             :    * resource. When the external string is no longer live on V8's heap the
    2685             :    * resource will be disposed by calling its Dispose method. The caller of
    2686             :    * this function should not otherwise delete or modify the resource. Neither
    2687             :    * should the underlying buffer be deallocated or modified except through the
    2688             :    * destructor of the external string resource.
    2689             :    */
    2690             :   static V8_DEPRECATE_SOON(
    2691             :       "Use maybe version",
    2692             :       Local<String> NewExternal(Isolate* isolate,
    2693             :                                 ExternalOneByteStringResource* resource));
    2694             :   static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewExternalOneByte(
    2695             :       Isolate* isolate, ExternalOneByteStringResource* resource);
    2696             : 
    2697             :   /**
    2698             :    * Associate an external string resource with this string by transforming it
    2699             :    * in place so that existing references to this string in the JavaScript heap
    2700             :    * will use the external string resource. The external string resource's
    2701             :    * character contents need to be equivalent to this string.
    2702             :    * Returns true if the string has been changed to be an external string.
    2703             :    * The string is not modified if the operation fails. See NewExternal for
    2704             :    * information on the lifetime of the resource.
    2705             :    */
    2706             :   bool MakeExternal(ExternalOneByteStringResource* resource);
    2707             : 
    2708             :   /**
    2709             :    * Returns true if this string can be made external.
    2710             :    */
    2711             :   bool CanMakeExternal();
    2712             : 
    2713             :   /**
    2714             :    * Converts an object to a UTF-8-encoded character array.  Useful if
    2715             :    * you want to print the object.  If conversion to a string fails
    2716             :    * (e.g. due to an exception in the toString() method of the object)
    2717             :    * then the length() method returns 0 and the * operator returns
    2718             :    * NULL.
    2719             :    */
    2720             :   class V8_EXPORT Utf8Value {
    2721             :    public:
    2722             :     explicit Utf8Value(Local<v8::Value> obj);
    2723             :     ~Utf8Value();
    2724        1089 :     char* operator*() { return str_; }
    2725             :     const char* operator*() const { return str_; }
    2726             :     int length() const { return length_; }
    2727             : 
    2728             :     // Disallow copying and assigning.
    2729             :     Utf8Value(const Utf8Value&) = delete;
    2730             :     void operator=(const Utf8Value&) = delete;
    2731             : 
    2732             :    private:
    2733             :     char* str_;
    2734             :     int length_;
    2735             :   };
    2736             : 
    2737             :   /**
    2738             :    * Converts an object to a two-byte (UTF-16-encoded) string.
    2739             :    * If conversion to a string fails (eg. due to an exception in the toString()
    2740             :    * method of the object) then the length() method returns 0 and the * operator
    2741             :    * returns NULL.
    2742             :    */
    2743             :   class V8_EXPORT Value {
    2744             :    public:
    2745             :     explicit Value(Local<v8::Value> obj);
    2746             :     ~Value();
    2747             :     uint16_t* operator*() { return str_; }
    2748             :     const uint16_t* operator*() const { return str_; }
    2749             :     int length() const { return length_; }
    2750             : 
    2751             :     // Disallow copying and assigning.
    2752             :     Value(const Value&) = delete;
    2753             :     void operator=(const Value&) = delete;
    2754             : 
    2755             :    private:
    2756             :     uint16_t* str_;
    2757             :     int length_;
    2758             :   };
    2759             : 
    2760             :  private:
    2761             :   void VerifyExternalStringResourceBase(ExternalStringResourceBase* v,
    2762             :                                         Encoding encoding) const;
    2763             :   void VerifyExternalStringResource(ExternalStringResource* val) const;
    2764             :   static void CheckCast(v8::Value* obj);
    2765             : };
    2766             : 
    2767             : 
    2768             : /**
    2769             :  * A JavaScript symbol (ECMA-262 edition 6)
    2770             :  */
    2771             : class V8_EXPORT Symbol : public Name {
    2772             :  public:
    2773             :   /**
    2774             :    * Returns the print name string of the symbol, or undefined if none.
    2775             :    */
    2776             :   Local<Value> Name() const;
    2777             : 
    2778             :   /**
    2779             :    * Create a symbol. If name is not empty, it will be used as the description.
    2780             :    */
    2781             :   static Local<Symbol> New(Isolate* isolate,
    2782             :                            Local<String> name = Local<String>());
    2783             : 
    2784             :   /**
    2785             :    * Access global symbol registry.
    2786             :    * Note that symbols created this way are never collected, so
    2787             :    * they should only be used for statically fixed properties.
    2788             :    * Also, there is only one global name space for the names used as keys.
    2789             :    * To minimize the potential for clashes, use qualified names as keys.
    2790             :    */
    2791             :   static Local<Symbol> For(Isolate *isolate, Local<String> name);
    2792             : 
    2793             :   /**
    2794             :    * Retrieve a global symbol. Similar to |For|, but using a separate
    2795             :    * registry that is not accessible by (and cannot clash with) JavaScript code.
    2796             :    */
    2797             :   static Local<Symbol> ForApi(Isolate *isolate, Local<String> name);
    2798             : 
    2799             :   // Well-known symbols
    2800             :   static Local<Symbol> GetHasInstance(Isolate* isolate);
    2801             :   static Local<Symbol> GetIsConcatSpreadable(Isolate* isolate);
    2802             :   static Local<Symbol> GetIterator(Isolate* isolate);
    2803             :   static Local<Symbol> GetMatch(Isolate* isolate);
    2804             :   static Local<Symbol> GetReplace(Isolate* isolate);
    2805             :   static Local<Symbol> GetSearch(Isolate* isolate);
    2806             :   static Local<Symbol> GetSplit(Isolate* isolate);
    2807             :   static Local<Symbol> GetToPrimitive(Isolate* isolate);
    2808             :   static Local<Symbol> GetToStringTag(Isolate* isolate);
    2809             :   static Local<Symbol> GetUnscopables(Isolate* isolate);
    2810             : 
    2811             :   V8_INLINE static Symbol* Cast(Value* obj);
    2812             : 
    2813             :  private:
    2814             :   Symbol();
    2815             :   static void CheckCast(Value* obj);
    2816             : };
    2817             : 
    2818             : 
    2819             : /**
    2820             :  * A private symbol
    2821             :  *
    2822             :  * This is an experimental feature. Use at your own risk.
    2823             :  */
    2824             : class V8_EXPORT Private : public Data {
    2825             :  public:
    2826             :   /**
    2827             :    * Returns the print name string of the private symbol, or undefined if none.
    2828             :    */
    2829             :   Local<Value> Name() const;
    2830             : 
    2831             :   /**
    2832             :    * Create a private symbol. If name is not empty, it will be the description.
    2833             :    */
    2834             :   static Local<Private> New(Isolate* isolate,
    2835             :                             Local<String> name = Local<String>());
    2836             : 
    2837             :   /**
    2838             :    * Retrieve a global private symbol. If a symbol with this name has not
    2839             :    * been retrieved in the same isolate before, it is created.
    2840             :    * Note that private symbols created this way are never collected, so
    2841             :    * they should only be used for statically fixed properties.
    2842             :    * Also, there is only one global name space for the names used as keys.
    2843             :    * To minimize the potential for clashes, use qualified names as keys,
    2844             :    * e.g., "Class#property".
    2845             :    */
    2846             :   static Local<Private> ForApi(Isolate* isolate, Local<String> name);
    2847             : 
    2848             :  private:
    2849             :   Private();
    2850             : };
    2851             : 
    2852             : 
    2853             : /**
    2854             :  * A JavaScript number value (ECMA-262, 4.3.20)
    2855             :  */
    2856             : class V8_EXPORT Number : public Primitive {
    2857             :  public:
    2858             :   double Value() const;
    2859             :   static Local<Number> New(Isolate* isolate, double value);
    2860             :   V8_INLINE static Number* Cast(v8::Value* obj);
    2861             :  private:
    2862             :   Number();
    2863             :   static void CheckCast(v8::Value* obj);
    2864             : };
    2865             : 
    2866             : 
    2867             : /**
    2868             :  * A JavaScript value representing a signed integer.
    2869             :  */
    2870             : class V8_EXPORT Integer : public Number {
    2871             :  public:
    2872             :   static Local<Integer> New(Isolate* isolate, int32_t value);
    2873             :   static Local<Integer> NewFromUnsigned(Isolate* isolate, uint32_t value);
    2874             :   int64_t Value() const;
    2875             :   V8_INLINE static Integer* Cast(v8::Value* obj);
    2876             :  private:
    2877             :   Integer();
    2878             :   static void CheckCast(v8::Value* obj);
    2879             : };
    2880             : 
    2881             : 
    2882             : /**
    2883             :  * A JavaScript value representing a 32-bit signed integer.
    2884             :  */
    2885             : class V8_EXPORT Int32 : public Integer {
    2886             :  public:
    2887             :   int32_t Value() const;
    2888             :   V8_INLINE static Int32* Cast(v8::Value* obj);
    2889             : 
    2890             :  private:
    2891             :   Int32();
    2892             :   static void CheckCast(v8::Value* obj);
    2893             : };
    2894             : 
    2895             : 
    2896             : /**
    2897             :  * A JavaScript value representing a 32-bit unsigned integer.
    2898             :  */
    2899             : class V8_EXPORT Uint32 : public Integer {
    2900             :  public:
    2901             :   uint32_t Value() const;
    2902             :   V8_INLINE static Uint32* Cast(v8::Value* obj);
    2903             : 
    2904             :  private:
    2905             :   Uint32();
    2906             :   static void CheckCast(v8::Value* obj);
    2907             : };
    2908             : 
    2909             : /**
    2910             :  * PropertyAttribute.
    2911             :  */
    2912             : enum PropertyAttribute {
    2913             :   /** None. **/
    2914             :   None = 0,
    2915             :   /** ReadOnly, i.e., not writable. **/
    2916             :   ReadOnly = 1 << 0,
    2917             :   /** DontEnum, i.e., not enumerable. **/
    2918             :   DontEnum = 1 << 1,
    2919             :   /** DontDelete, i.e., not configurable. **/
    2920             :   DontDelete = 1 << 2
    2921             : };
    2922             : 
    2923             : /**
    2924             :  * Accessor[Getter|Setter] are used as callback functions when
    2925             :  * setting|getting a particular property. See Object and ObjectTemplate's
    2926             :  * method SetAccessor.
    2927             :  */
    2928             : typedef void (*AccessorGetterCallback)(
    2929             :     Local<String> property,
    2930             :     const PropertyCallbackInfo<Value>& info);
    2931             : typedef void (*AccessorNameGetterCallback)(
    2932             :     Local<Name> property,
    2933             :     const PropertyCallbackInfo<Value>& info);
    2934             : 
    2935             : 
    2936             : typedef void (*AccessorSetterCallback)(
    2937             :     Local<String> property,
    2938             :     Local<Value> value,
    2939             :     const PropertyCallbackInfo<void>& info);
    2940             : typedef void (*AccessorNameSetterCallback)(
    2941             :     Local<Name> property,
    2942             :     Local<Value> value,
    2943             :     const PropertyCallbackInfo<void>& info);
    2944             : 
    2945             : 
    2946             : /**
    2947             :  * Access control specifications.
    2948             :  *
    2949             :  * Some accessors should be accessible across contexts.  These
    2950             :  * accessors have an explicit access control parameter which specifies
    2951             :  * the kind of cross-context access that should be allowed.
    2952             :  *
    2953             :  * TODO(dcarney): Remove PROHIBITS_OVERWRITING as it is now unused.
    2954             :  */
    2955             : enum AccessControl {
    2956             :   DEFAULT               = 0,
    2957             :   ALL_CAN_READ          = 1,
    2958             :   ALL_CAN_WRITE         = 1 << 1,
    2959             :   PROHIBITS_OVERWRITING = 1 << 2
    2960             : };
    2961             : 
    2962             : /**
    2963             :  * Property filter bits. They can be or'ed to build a composite filter.
    2964             :  */
    2965             : enum PropertyFilter {
    2966             :   ALL_PROPERTIES = 0,
    2967             :   ONLY_WRITABLE = 1,
    2968             :   ONLY_ENUMERABLE = 2,
    2969             :   ONLY_CONFIGURABLE = 4,
    2970             :   SKIP_STRINGS = 8,
    2971             :   SKIP_SYMBOLS = 16
    2972             : };
    2973             : 
    2974             : /**
    2975             :  * Keys/Properties filter enums:
    2976             :  *
    2977             :  * KeyCollectionMode limits the range of collected properties. kOwnOnly limits
    2978             :  * the collected properties to the given Object only. kIncludesPrototypes will
    2979             :  * include all keys of the objects's prototype chain as well.
    2980             :  */
    2981             : enum class KeyCollectionMode { kOwnOnly, kIncludePrototypes };
    2982             : 
    2983             : /**
    2984             :  * kIncludesIndices allows for integer indices to be collected, while
    2985             :  * kSkipIndices will exclude integer indicies from being collected.
    2986             :  */
    2987             : enum class IndexFilter { kIncludeIndices, kSkipIndices };
    2988             : 
    2989             : /**
    2990             :  * Integrity level for objects.
    2991             :  */
    2992             : enum class IntegrityLevel { kFrozen, kSealed };
    2993             : 
    2994             : /**
    2995             :  * A JavaScript object (ECMA-262, 4.3.3)
    2996             :  */
    2997             : class V8_EXPORT Object : public Value {
    2998             :  public:
    2999             :   V8_DEPRECATE_SOON("Use maybe version",
    3000             :                     bool Set(Local<Value> key, Local<Value> value));
    3001             :   V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
    3002             :                                         Local<Value> key, Local<Value> value);
    3003             : 
    3004             :   V8_DEPRECATE_SOON("Use maybe version",
    3005             :                     bool Set(uint32_t index, Local<Value> value));
    3006             :   V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
    3007             :                                         Local<Value> value);
    3008             : 
    3009             :   // Implements CreateDataProperty (ECMA-262, 7.3.4).
    3010             :   //
    3011             :   // Defines a configurable, writable, enumerable property with the given value
    3012             :   // on the object unless the property already exists and is not configurable
    3013             :   // or the object is not extensible.
    3014             :   //
    3015             :   // Returns true on success.
    3016             :   V8_WARN_UNUSED_RESULT Maybe<bool> CreateDataProperty(Local<Context> context,
    3017             :                                                        Local<Name> key,
    3018             :                                                        Local<Value> value);
    3019             :   V8_WARN_UNUSED_RESULT Maybe<bool> CreateDataProperty(Local<Context> context,
    3020             :                                                        uint32_t index,
    3021             :                                                        Local<Value> value);
    3022             : 
    3023             :   // Implements DefineOwnProperty.
    3024             :   //
    3025             :   // In general, CreateDataProperty will be faster, however, does not allow
    3026             :   // for specifying attributes.
    3027             :   //
    3028             :   // Returns true on success.
    3029             :   V8_WARN_UNUSED_RESULT Maybe<bool> DefineOwnProperty(
    3030             :       Local<Context> context, Local<Name> key, Local<Value> value,
    3031             :       PropertyAttribute attributes = None);
    3032             : 
    3033             :   // Implements Object.DefineProperty(O, P, Attributes), see Ecma-262 19.1.2.4.
    3034             :   //
    3035             :   // The defineProperty function is used to add an own property or
    3036             :   // update the attributes of an existing own property of an object.
    3037             :   //
    3038             :   // Both data and accessor descriptors can be used.
    3039             :   //
    3040             :   // In general, CreateDataProperty is faster, however, does not allow
    3041             :   // for specifying attributes or an accessor descriptor.
    3042             :   //
    3043             :   // The PropertyDescriptor can change when redefining a property.
    3044             :   //
    3045             :   // Returns true on success.
    3046             :   V8_WARN_UNUSED_RESULT Maybe<bool> DefineProperty(
    3047             :       Local<Context> context, Local<Name> key, PropertyDescriptor& descriptor);
    3048             : 
    3049             :   // Sets an own property on this object bypassing interceptors and
    3050             :   // overriding accessors or read-only properties.
    3051             :   //
    3052             :   // Note that if the object has an interceptor the property will be set
    3053             :   // locally, but since the interceptor takes precedence the local property
    3054             :   // will only be returned if the interceptor doesn't return a value.
    3055             :   //
    3056             :   // Note also that this only works for named properties.
    3057             :   V8_DEPRECATED("Use CreateDataProperty / DefineOwnProperty",
    3058             :                 bool ForceSet(Local<Value> key, Local<Value> value,
    3059             :                               PropertyAttribute attribs = None));
    3060             :   V8_DEPRECATE_SOON("Use CreateDataProperty / DefineOwnProperty",
    3061             :                     Maybe<bool> ForceSet(Local<Context> context,
    3062             :                                          Local<Value> key, Local<Value> value,
    3063             :                                          PropertyAttribute attribs = None));
    3064             : 
    3065             :   V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(Local<Value> key));
    3066             :   V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
    3067             :                                               Local<Value> key);
    3068             : 
    3069             :   V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(uint32_t index));
    3070             :   V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
    3071             :                                               uint32_t index);
    3072             : 
    3073             :   /**
    3074             :    * Gets the property attributes of a property which can be None or
    3075             :    * any combination of ReadOnly, DontEnum and DontDelete. Returns
    3076             :    * None when the property doesn't exist.
    3077             :    */
    3078             :   V8_DEPRECATED("Use maybe version",
    3079             :                 PropertyAttribute GetPropertyAttributes(Local<Value> key));
    3080             :   V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute> GetPropertyAttributes(
    3081             :       Local<Context> context, Local<Value> key);
    3082             : 
    3083             :   /**
    3084             :    * Returns Object.getOwnPropertyDescriptor as per ES5 section 15.2.3.3.
    3085             :    */
    3086             :   V8_DEPRECATED("Use maybe version",
    3087             :                 Local<Value> GetOwnPropertyDescriptor(Local<String> key));
    3088             :   V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetOwnPropertyDescriptor(
    3089             :       Local<Context> context, Local<String> key);
    3090             : 
    3091             :   V8_DEPRECATE_SOON("Use maybe version", bool Has(Local<Value> key));
    3092             :   /**
    3093             :    * Object::Has() calls the abstract operation HasProperty(O, P) described
    3094             :    * in ECMA-262, 7.3.10. Has() returns
    3095             :    * true, if the object has the property, either own or on the prototype chain.
    3096             :    * Interceptors, i.e., PropertyQueryCallbacks, are called if present.
    3097             :    *
    3098             :    * Has() has the same side effects as JavaScript's `variable in object`.
    3099             :    * For example, calling Has() on a revoked proxy will throw an exception.
    3100             :    *
    3101             :    * \note Has() converts the key to a name, which possibly calls back into
    3102             :    * JavaScript.
    3103             :    *
    3104             :    * See also v8::Object::HasOwnProperty() and
    3105             :    * v8::Object::HasRealNamedProperty().
    3106             :    */
    3107             :   V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context,
    3108             :                                         Local<Value> key);
    3109             : 
    3110             :   V8_DEPRECATE_SOON("Use maybe version", bool Delete(Local<Value> key));
    3111             :   V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context,
    3112             :                                            Local<Value> key);
    3113             : 
    3114             :   V8_DEPRECATED("Use maybe version", bool Has(uint32_t index));
    3115             :   V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context,
    3116             :                                         uint32_t index);
    3117             : 
    3118             :   V8_DEPRECATED("Use maybe version", bool Delete(uint32_t index));
    3119             :   V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context,
    3120             :                                            uint32_t index);
    3121             : 
    3122             :   V8_DEPRECATED("Use maybe version",
    3123             :                 bool SetAccessor(Local<String> name,
    3124             :                                  AccessorGetterCallback getter,
    3125             :                                  AccessorSetterCallback setter = 0,
    3126             :                                  Local<Value> data = Local<Value>(),
    3127             :                                  AccessControl settings = DEFAULT,
    3128             :                                  PropertyAttribute attribute = None));
    3129             :   V8_DEPRECATED("Use maybe version",
    3130             :                 bool SetAccessor(Local<Name> name,
    3131             :                                  AccessorNameGetterCallback getter,
    3132             :                                  AccessorNameSetterCallback setter = 0,
    3133             :                                  Local<Value> data = Local<Value>(),
    3134             :                                  AccessControl settings = DEFAULT,
    3135             :                                  PropertyAttribute attribute = None));
    3136             :   V8_WARN_UNUSED_RESULT Maybe<bool> SetAccessor(Local<Context> context,
    3137             :                           Local<Name> name,
    3138             :                           AccessorNameGetterCallback getter,
    3139             :                           AccessorNameSetterCallback setter = 0,
    3140             :                           MaybeLocal<Value> data = MaybeLocal<Value>(),
    3141             :                           AccessControl settings = DEFAULT,
    3142             :                           PropertyAttribute attribute = None);
    3143             : 
    3144             :   void SetAccessorProperty(Local<Name> name, Local<Function> getter,
    3145             :                            Local<Function> setter = Local<Function>(),
    3146             :                            PropertyAttribute attribute = None,
    3147             :                            AccessControl settings = DEFAULT);
    3148             : 
    3149             :   /**
    3150             :    * Sets a native data property like Template::SetNativeDataProperty, but
    3151             :    * this method sets on this object directly.
    3152             :    */
    3153             :   V8_WARN_UNUSED_RESULT Maybe<bool> SetNativeDataProperty(
    3154             :       Local<Context> context, Local<Name> name,
    3155             :       AccessorNameGetterCallback getter,
    3156             :       AccessorNameSetterCallback setter = nullptr,
    3157             :       Local<Value> data = Local<Value>(), PropertyAttribute attributes = None);
    3158             : 
    3159             :   /**
    3160             :    * Functionality for private properties.
    3161             :    * This is an experimental feature, use at your own risk.
    3162             :    * Note: Private properties are not inherited. Do not rely on this, since it
    3163             :    * may change.
    3164             :    */
    3165             :   Maybe<bool> HasPrivate(Local<Context> context, Local<Private> key);
    3166             :   Maybe<bool> SetPrivate(Local<Context> context, Local<Private> key,
    3167             :                          Local<Value> value);
    3168             :   Maybe<bool> DeletePrivate(Local<Context> context, Local<Private> key);
    3169             :   MaybeLocal<Value> GetPrivate(Local<Context> context, Local<Private> key);
    3170             : 
    3171             :   /**
    3172             :    * Returns an array containing the names of the enumerable properties
    3173             :    * of this object, including properties from prototype objects.  The
    3174             :    * array returned by this method contains the same values as would
    3175             :    * be enumerated by a for-in statement over this object.
    3176             :    */
    3177             :   V8_DEPRECATE_SOON("Use maybe version", Local<Array> GetPropertyNames());
    3178             :   V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetPropertyNames(
    3179             :       Local<Context> context);
    3180             :   V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetPropertyNames(
    3181             :       Local<Context> context, KeyCollectionMode mode,
    3182             :       PropertyFilter property_filter, IndexFilter index_filter);
    3183             : 
    3184             :   /**
    3185             :    * This function has the same functionality as GetPropertyNames but
    3186             :    * the returned array doesn't contain the names of properties from
    3187             :    * prototype objects.
    3188             :    */
    3189             :   V8_DEPRECATE_SOON("Use maybe version", Local<Array> GetOwnPropertyNames());
    3190             :   V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetOwnPropertyNames(
    3191             :       Local<Context> context);
    3192             : 
    3193             :   /**
    3194             :    * Returns an array containing the names of the filtered properties
    3195             :    * of this object, including properties from prototype objects.  The
    3196             :    * array returned by this method contains the same values as would
    3197             :    * be enumerated by a for-in statement over this object.
    3198             :    */
    3199             :   V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetOwnPropertyNames(
    3200             :       Local<Context> context, PropertyFilter filter);
    3201             : 
    3202             :   /**
    3203             :    * Get the prototype object.  This does not skip objects marked to
    3204             :    * be skipped by __proto__ and it does not consult the security
    3205             :    * handler.
    3206             :    */
    3207             :   Local<Value> GetPrototype();
    3208             : 
    3209             :   /**
    3210             :    * Set the prototype object.  This does not skip objects marked to
    3211             :    * be skipped by __proto__ and it does not consult the security
    3212             :    * handler.
    3213             :    */
    3214             :   V8_DEPRECATED("Use maybe version", bool SetPrototype(Local<Value> prototype));
    3215             :   V8_WARN_UNUSED_RESULT Maybe<bool> SetPrototype(Local<Context> context,
    3216             :                                                  Local<Value> prototype);
    3217             : 
    3218             :   /**
    3219             :    * Finds an instance of the given function template in the prototype
    3220             :    * chain.
    3221             :    */
    3222             :   Local<Object> FindInstanceInPrototypeChain(Local<FunctionTemplate> tmpl);
    3223             : 
    3224             :   /**
    3225             :    * Call builtin Object.prototype.toString on this object.
    3226             :    * This is different from Value::ToString() that may call
    3227             :    * user-defined toString function. This one does not.
    3228             :    */
    3229             :   V8_DEPRECATED("Use maybe version", Local<String> ObjectProtoToString());
    3230             :   V8_WARN_UNUSED_RESULT MaybeLocal<String> ObjectProtoToString(
    3231             :       Local<Context> context);
    3232             : 
    3233             :   /**
    3234             :    * Returns the name of the function invoked as a constructor for this object.
    3235             :    */
    3236             :   Local<String> GetConstructorName();
    3237             : 
    3238             :   /**
    3239             :    * Sets the integrity level of the object.
    3240             :    */
    3241             :   Maybe<bool> SetIntegrityLevel(Local<Context> context, IntegrityLevel level);
    3242             : 
    3243             :   /** Gets the number of internal fields for this Object. */
    3244             :   int InternalFieldCount();
    3245             : 
    3246             :   /** Same as above, but works for Persistents */
    3247             :   V8_INLINE static int InternalFieldCount(
    3248             :       const PersistentBase<Object>& object) {
    3249             :     return object.val_->InternalFieldCount();
    3250             :   }
    3251             : 
    3252             :   /** Gets the value from an internal field. */
    3253             :   V8_INLINE Local<Value> GetInternalField(int index);
    3254             : 
    3255             :   /** Sets the value in an internal field. */
    3256             :   void SetInternalField(int index, Local<Value> value);
    3257             : 
    3258             :   /**
    3259             :    * Gets a 2-byte-aligned native pointer from an internal field. This field
    3260             :    * must have been set by SetAlignedPointerInInternalField, everything else
    3261             :    * leads to undefined behavior.
    3262             :    */
    3263             :   V8_INLINE void* GetAlignedPointerFromInternalField(int index);
    3264             : 
    3265             :   /** Same as above, but works for Persistents */
    3266             :   V8_INLINE static void* GetAlignedPointerFromInternalField(
    3267             :       const PersistentBase<Object>& object, int index) {
    3268             :     return object.val_->GetAlignedPointerFromInternalField(index);
    3269             :   }
    3270             : 
    3271             :   /**
    3272             :    * Sets a 2-byte-aligned native pointer in an internal field. To retrieve such
    3273             :    * a field, GetAlignedPointerFromInternalField must be used, everything else
    3274             :    * leads to undefined behavior.
    3275             :    */
    3276             :   void SetAlignedPointerInInternalField(int index, void* value);
    3277             :   void SetAlignedPointerInInternalFields(int argc, int indices[],
    3278             :                                          void* values[]);
    3279             : 
    3280             :   // Testers for local properties.
    3281             :   V8_DEPRECATED("Use maybe version", bool HasOwnProperty(Local<String> key));
    3282             : 
    3283             :   /**
    3284             :    * HasOwnProperty() is like JavaScript's Object.prototype.hasOwnProperty().
    3285             :    *
    3286             :    * See also v8::Object::Has() and v8::Object::HasRealNamedProperty().
    3287             :    */
    3288             :   V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context,
    3289             :                                                    Local<Name> key);
    3290             :   V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context,
    3291             :                                                    uint32_t index);
    3292             :   V8_DEPRECATE_SOON("Use maybe version",
    3293             :                     bool HasRealNamedProperty(Local<String> key));
    3294             :   /**
    3295             :    * Use HasRealNamedProperty() if you want to check if an object has an own
    3296             :    * property without causing side effects, i.e., without calling interceptors.
    3297             :    *
    3298             :    * This function is similar to v8::Object::HasOwnProperty(), but it does not
    3299             :    * call interceptors.
    3300             :    *
    3301             :    * \note Consider using non-masking interceptors, i.e., the interceptors are
    3302             :    * not called if the receiver has the real named property. See
    3303             :    * `v8::PropertyHandlerFlags::kNonMasking`.
    3304             :    *
    3305             :    * See also v8::Object::Has().
    3306             :    */
    3307             :   V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedProperty(Local<Context> context,
    3308             :                                                          Local<Name> key);
    3309             :   V8_DEPRECATE_SOON("Use maybe version",
    3310             :                     bool HasRealIndexedProperty(uint32_t index));
    3311             :   V8_WARN_UNUSED_RESULT Maybe<bool> HasRealIndexedProperty(
    3312             :       Local<Context> context, uint32_t index);
    3313             :   V8_DEPRECATE_SOON("Use maybe version",
    3314             :                     bool HasRealNamedCallbackProperty(Local<String> key));
    3315             :   V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedCallbackProperty(
    3316             :       Local<Context> context, Local<Name> key);
    3317             : 
    3318             :   /**
    3319             :    * If result.IsEmpty() no real property was located in the prototype chain.
    3320             :    * This means interceptors in the prototype chain are not called.
    3321             :    */
    3322             :   V8_DEPRECATED(
    3323             :       "Use maybe version",
    3324             :       Local<Value> GetRealNamedPropertyInPrototypeChain(Local<String> key));
    3325             :   V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetRealNamedPropertyInPrototypeChain(
    3326             :       Local<Context> context, Local<Name> key);
    3327             : 
    3328             :   /**
    3329             :    * Gets the property attributes of a real property in the prototype chain,
    3330             :    * which can be None or any combination of ReadOnly, DontEnum and DontDelete.
    3331             :    * Interceptors in the prototype chain are not called.
    3332             :    */
    3333             :   V8_DEPRECATED(
    3334             :       "Use maybe version",
    3335             :       Maybe<PropertyAttribute> GetRealNamedPropertyAttributesInPrototypeChain(
    3336             :           Local<String> key));
    3337             :   V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute>
    3338             :   GetRealNamedPropertyAttributesInPrototypeChain(Local<Context> context,
    3339             :                                                  Local<Name> key);
    3340             : 
    3341             :   /**
    3342             :    * If result.IsEmpty() no real property was located on the object or
    3343             :    * in the prototype chain.
    3344             :    * This means interceptors in the prototype chain are not called.
    3345             :    */
    3346             :   V8_DEPRECATED("Use maybe version",
    3347             :                 Local<Value> GetRealNamedProperty(Local<String> key));
    3348             :   V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetRealNamedProperty(
    3349             :       Local<Context> context, Local<Name> key);
    3350             : 
    3351             :   /**
    3352             :    * Gets the property attributes of a real property which can be
    3353             :    * None or any combination of ReadOnly, DontEnum and DontDelete.
    3354             :    * Interceptors in the prototype chain are not called.
    3355             :    */
    3356             :   V8_DEPRECATED("Use maybe version",
    3357             :                 Maybe<PropertyAttribute> GetRealNamedPropertyAttributes(
    3358             :                     Local<String> key));
    3359             :   V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute> GetRealNamedPropertyAttributes(
    3360             :       Local<Context> context, Local<Name> key);
    3361             : 
    3362             :   /** Tests for a named lookup interceptor.*/
    3363             :   bool HasNamedLookupInterceptor();
    3364             : 
    3365             :   /** Tests for an index lookup interceptor.*/
    3366             :   bool HasIndexedLookupInterceptor();
    3367             : 
    3368             :   /**
    3369             :    * Returns the identity hash for this object. The current implementation
    3370             :    * uses a hidden property on the object to store the identity hash.
    3371             :    *
    3372             :    * The return value will never be 0. Also, it is not guaranteed to be
    3373             :    * unique.
    3374             :    */
    3375             :   int GetIdentityHash();
    3376             : 
    3377             :   /**
    3378             :    * Clone this object with a fast but shallow copy.  Values will point
    3379             :    * to the same values as the original object.
    3380             :    */
    3381             :   // TODO(dcarney): take an isolate and optionally bail out?
    3382             :   Local<Object> Clone();
    3383             : 
    3384             :   /**
    3385             :    * Returns the context in which the object was created.
    3386             :    */
    3387             :   Local<Context> CreationContext();
    3388             : 
    3389             :   /** Same as above, but works for Persistents */
    3390             :   V8_INLINE static Local<Context> CreationContext(
    3391             :       const PersistentBase<Object>& object) {
    3392             :     return object.val_->CreationContext();
    3393             :   }
    3394             : 
    3395             :   /**
    3396             :    * Checks whether a callback is set by the
    3397             :    * ObjectTemplate::SetCallAsFunctionHandler method.
    3398             :    * When an Object is callable this method returns true.
    3399             :    */
    3400             :   bool IsCallable();
    3401             : 
    3402             :   /**
    3403             :    * True if this object is a constructor.
    3404             :    */
    3405             :   bool IsConstructor();
    3406             : 
    3407             :   /**
    3408             :    * Call an Object as a function if a callback is set by the
    3409             :    * ObjectTemplate::SetCallAsFunctionHandler method.
    3410             :    */
    3411             :   V8_DEPRECATED("Use maybe version",
    3412             :                 Local<Value> CallAsFunction(Local<Value> recv, int argc,
    3413             :                                             Local<Value> argv[]));
    3414             :   V8_WARN_UNUSED_RESULT MaybeLocal<Value> CallAsFunction(Local<Context> context,
    3415             :                                                          Local<Value> recv,
    3416             :                                                          int argc,
    3417             :                                                          Local<Value> argv[]);
    3418             : 
    3419             :   /**
    3420             :    * Call an Object as a constructor if a callback is set by the
    3421             :    * ObjectTemplate::SetCallAsFunctionHandler method.
    3422             :    * Note: This method behaves like the Function::NewInstance method.
    3423             :    */
    3424             :   V8_DEPRECATED("Use maybe version",
    3425             :                 Local<Value> CallAsConstructor(int argc, Local<Value> argv[]));
    3426             :   V8_WARN_UNUSED_RESULT MaybeLocal<Value> CallAsConstructor(
    3427             :       Local<Context> context, int argc, Local<Value> argv[]);
    3428             : 
    3429             :   /**
    3430             :    * Return the isolate to which the Object belongs to.
    3431             :    */
    3432             :   V8_DEPRECATE_SOON("Keep track of isolate correctly", Isolate* GetIsolate());
    3433             : 
    3434             :   static Local<Object> New(Isolate* isolate);
    3435             : 
    3436             :   V8_INLINE static Object* Cast(Value* obj);
    3437             : 
    3438             :  private:
    3439             :   Object();
    3440             :   static void CheckCast(Value* obj);
    3441             :   Local<Value> SlowGetInternalField(int index);
    3442             :   void* SlowGetAlignedPointerFromInternalField(int index);
    3443             : };
    3444             : 
    3445             : 
    3446             : /**
    3447             :  * An instance of the built-in array constructor (ECMA-262, 15.4.2).
    3448             :  */
    3449             : class V8_EXPORT Array : public Object {
    3450             :  public:
    3451             :   uint32_t Length() const;
    3452             : 
    3453             :   /**
    3454             :    * Clones an element at index |index|.  Returns an empty
    3455             :    * handle if cloning fails (for any reason).
    3456             :    */
    3457             :   V8_DEPRECATED("Cloning is not supported.",
    3458             :                 Local<Object> CloneElementAt(uint32_t index));
    3459             :   V8_DEPRECATED("Cloning is not supported.",
    3460             :                 MaybeLocal<Object> CloneElementAt(Local<Context> context,
    3461             :                                                   uint32_t index));
    3462             : 
    3463             :   /**
    3464             :    * Creates a JavaScript array with the given length. If the length
    3465             :    * is negative the returned array will have length 0.
    3466             :    */
    3467             :   static Local<Array> New(Isolate* isolate, int length = 0);
    3468             : 
    3469             :   V8_INLINE static Array* Cast(Value* obj);
    3470             :  private:
    3471             :   Array();
    3472             :   static void CheckCast(Value* obj);
    3473             : };
    3474             : 
    3475             : 
    3476             : /**
    3477             :  * An instance of the built-in Map constructor (ECMA-262, 6th Edition, 23.1.1).
    3478             :  */
    3479             : class V8_EXPORT Map : public Object {
    3480             :  public:
    3481             :   size_t Size() const;
    3482             :   void Clear();
    3483             :   V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
    3484             :                                               Local<Value> key);
    3485             :   V8_WARN_UNUSED_RESULT MaybeLocal<Map> Set(Local<Context> context,
    3486             :                                             Local<Value> key,
    3487             :                                             Local<Value> value);
    3488             :   V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context,
    3489             :                                         Local<Value> key);
    3490             :   V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context,
    3491             :                                            Local<Value> key);
    3492             : 
    3493             :   /**
    3494             :    * Returns an array of length Size() * 2, where index N is the Nth key and
    3495             :    * index N + 1 is the Nth value.
    3496             :    */
    3497             :   Local<Array> AsArray() const;
    3498             : 
    3499             :   /**
    3500             :    * Creates a new empty Map.
    3501             :    */
    3502             :   static Local<Map> New(Isolate* isolate);
    3503             : 
    3504             :   V8_INLINE static Map* Cast(Value* obj);
    3505             : 
    3506             :  private:
    3507             :   Map();
    3508             :   static void CheckCast(Value* obj);
    3509             : };
    3510             : 
    3511             : 
    3512             : /**
    3513             :  * An instance of the built-in Set constructor (ECMA-262, 6th Edition, 23.2.1).
    3514             :  */
    3515             : class V8_EXPORT Set : public Object {
    3516             :  public:
    3517             :   size_t Size() const;
    3518             :   void Clear();
    3519             :   V8_WARN_UNUSED_RESULT MaybeLocal<Set> Add(Local<Context> context,
    3520             :                                             Local<Value> key);
    3521             :   V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context,
    3522             :                                         Local<Value> key);
    3523             :   V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context,
    3524             :                                            Local<Value> key);
    3525             : 
    3526             :   /**
    3527             :    * Returns an array of the keys in this Set.
    3528             :    */
    3529             :   Local<Array> AsArray() const;
    3530             : 
    3531             :   /**
    3532             :    * Creates a new empty Set.
    3533             :    */
    3534             :   static Local<Set> New(Isolate* isolate);
    3535             : 
    3536             :   V8_INLINE static Set* Cast(Value* obj);
    3537             : 
    3538             :  private:
    3539             :   Set();
    3540             :   static void CheckCast(Value* obj);
    3541             : };
    3542             : 
    3543             : 
    3544             : template<typename T>
    3545             : class ReturnValue {
    3546             :  public:
    3547             :   template <class S> V8_INLINE ReturnValue(const ReturnValue<S>& that)
    3548             :       : value_(that.value_) {
    3549             :     TYPE_CHECK(T, S);
    3550             :   }
    3551             :   // Local setters
    3552             :   template <typename S>
    3553             :   V8_INLINE V8_DEPRECATE_SOON("Use Global<> instead",
    3554             :                               void Set(const Persistent<S>& handle));
    3555             :   template <typename S>
    3556             :   V8_INLINE void Set(const Global<S>& handle);
    3557             :   template <typename S>
    3558             :   V8_INLINE void Set(const Local<S> handle);
    3559             :   // Fast primitive setters
    3560             :   V8_INLINE void Set(bool value);
    3561             :   V8_INLINE void Set(double i);
    3562             :   V8_INLINE void Set(int32_t i);
    3563             :   V8_INLINE void Set(uint32_t i);
    3564             :   // Fast JS primitive setters
    3565             :   V8_INLINE void SetNull();
    3566             :   V8_INLINE void SetUndefined();
    3567             :   V8_INLINE void SetEmptyString();
    3568             :   // Convenience getter for Isolate
    3569             :   V8_INLINE Isolate* GetIsolate() const;
    3570             : 
    3571             :   // Pointer setter: Uncompilable to prevent inadvertent misuse.
    3572             :   template <typename S>
    3573             :   V8_INLINE void Set(S* whatever);
    3574             : 
    3575             :   // Getter. Creates a new Local<> so it comes with a certain performance
    3576             :   // hit. If the ReturnValue was not yet set, this will return the undefined
    3577             :   // value.
    3578             :   V8_INLINE Local<Value> Get() const;
    3579             : 
    3580             :  private:
    3581             :   template<class F> friend class ReturnValue;
    3582             :   template<class F> friend class FunctionCallbackInfo;
    3583             :   template<class F> friend class PropertyCallbackInfo;
    3584             :   template <class F, class G, class H>
    3585             :   friend class PersistentValueMapBase;
    3586             :   V8_INLINE void SetInternal(internal::Object* value) { *value_ = value; }
    3587             :   V8_INLINE internal::Object* GetDefaultValue();
    3588             :   V8_INLINE explicit ReturnValue(internal::Object** slot);
    3589             :   internal::Object** value_;
    3590             : };
    3591             : 
    3592             : 
    3593             : /**
    3594             :  * The argument information given to function call callbacks.  This
    3595             :  * class provides access to information about the context of the call,
    3596             :  * including the receiver, the number and values of arguments, and
    3597             :  * the holder of the function.
    3598             :  */
    3599             : template<typename T>
    3600             : class FunctionCallbackInfo {
    3601             :  public:
    3602             :   V8_INLINE int Length() const;
    3603             :   V8_INLINE Local<Value> operator[](int i) const;
    3604             :   V8_INLINE V8_DEPRECATED("Use Data() to explicitly pass Callee instead",
    3605             :                           Local<Function> Callee() const);
    3606             :   V8_INLINE Local<Object> This() const;
    3607             :   V8_INLINE Local<Object> Holder() const;
    3608             :   V8_INLINE Local<Value> NewTarget() const;
    3609             :   V8_INLINE bool IsConstructCall() const;
    3610             :   V8_INLINE Local<Value> Data() const;
    3611             :   V8_INLINE Isolate* GetIsolate() const;
    3612             :   V8_INLINE ReturnValue<T> GetReturnValue() const;
    3613             :   // This shouldn't be public, but the arm compiler needs it.
    3614             :   static const int kArgsLength = 8;
    3615             : 
    3616             :  protected:
    3617             :   friend class internal::FunctionCallbackArguments;
    3618             :   friend class internal::CustomArguments<FunctionCallbackInfo>;
    3619             :   friend class debug::ConsoleCallArguments;
    3620             :   static const int kHolderIndex = 0;
    3621             :   static const int kIsolateIndex = 1;
    3622             :   static const int kReturnValueDefaultValueIndex = 2;
    3623             :   static const int kReturnValueIndex = 3;
    3624             :   static const int kDataIndex = 4;
    3625             :   static const int kCalleeIndex = 5;
    3626             :   static const int kContextSaveIndex = 6;
    3627             :   static const int kNewTargetIndex = 7;
    3628             : 
    3629             :   V8_INLINE FunctionCallbackInfo(internal::Object** implicit_args,
    3630             :                                  internal::Object** values, int length);
    3631             :   internal::Object** implicit_args_;
    3632             :   internal::Object** values_;
    3633             :   int length_;
    3634             : };
    3635             : 
    3636             : 
    3637             : /**
    3638             :  * The information passed to a property callback about the context
    3639             :  * of the property access.
    3640             :  */
    3641             : template<typename T>
    3642             : class PropertyCallbackInfo {
    3643             :  public:
    3644             :   /**
    3645             :    * \return The isolate of the property access.
    3646             :    */
    3647             :   V8_INLINE Isolate* GetIsolate() const;
    3648             : 
    3649             :   /**
    3650             :    * \return The data set in the configuration, i.e., in
    3651             :    * `NamedPropertyHandlerConfiguration` or
    3652             :    * `IndexedPropertyHandlerConfiguration.`
    3653             :    */
    3654             :   V8_INLINE Local<Value> Data() const;
    3655             : 
    3656             :   /**
    3657             :    * \return The receiver. In many cases, this is the object on which the
    3658             :    * property access was intercepted. When using
    3659             :    * `Reflect.get`, `Function.prototype.call`, or similar functions, it is the
    3660             :    * object passed in as receiver or thisArg.
    3661             :    *
    3662             :    * \code
    3663             :    *  void GetterCallback(Local<Name> name,
    3664             :    *                      const v8::PropertyCallbackInfo<v8::Value>& info) {
    3665             :    *     auto context = info.GetIsolate()->GetCurrentContext();
    3666             :    *
    3667             :    *     v8::Local<v8::Value> a_this =
    3668             :    *         info.This()
    3669             :    *             ->GetRealNamedProperty(context, v8_str("a"))
    3670             :    *             .ToLocalChecked();
    3671             :    *     v8::Local<v8::Value> a_holder =
    3672             :    *         info.Holder()
    3673             :    *             ->GetRealNamedProperty(context, v8_str("a"))
    3674             :    *             .ToLocalChecked();
    3675             :    *
    3676             :    *    CHECK(v8_str("r")->Equals(context, a_this).FromJust());
    3677             :    *    CHECK(v8_str("obj")->Equals(context, a_holder).FromJust());
    3678             :    *
    3679             :    *    info.GetReturnValue().Set(name);
    3680             :    *  }
    3681             :    *
    3682             :    *  v8::Local<v8::FunctionTemplate> templ =
    3683             :    *  v8::FunctionTemplate::New(isolate);
    3684             :    *  templ->InstanceTemplate()->SetHandler(
    3685             :    *      v8::NamedPropertyHandlerConfiguration(GetterCallback));
    3686             :    *  LocalContext env;
    3687             :    *  env->Global()
    3688             :    *      ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local())
    3689             :    *                                           .ToLocalChecked()
    3690             :    *                                           ->NewInstance(env.local())
    3691             :    *                                           .ToLocalChecked())
    3692             :    *      .FromJust();
    3693             :    *
    3694             :    *  CompileRun("obj.a = 'obj'; var r = {a: 'r'}; Reflect.get(obj, 'x', r)");
    3695             :    * \endcode
    3696             :    */
    3697             :   V8_INLINE Local<Object> This() const;
    3698             : 
    3699             :   /**
    3700             :    * \return The object in the prototype chain of the receiver that has the
    3701             :    * interceptor. Suppose you have `x` and its prototype is `y`, and `y`
    3702             :    * has an interceptor. Then `info.This()` is `x` and `info.Holder()` is `y`.
    3703             :    * The Holder() could be a hidden object (the global object, rather
    3704             :    * than the global proxy).
    3705             :    *
    3706             :    * \note For security reasons, do not pass the object back into the runtime.
    3707             :    */
    3708             :   V8_INLINE Local<Object> Holder() const;
    3709             : 
    3710             :   /**
    3711             :    * \return The return value of the callback.
    3712             :    * Can be changed by calling Set().
    3713             :    * \code
    3714             :    * info.GetReturnValue().Set(...)
    3715             :    * \endcode
    3716             :    *
    3717             :    */
    3718             :   V8_INLINE ReturnValue<T> GetReturnValue() const;
    3719             : 
    3720             :   /**
    3721             :    * \return True if the intercepted function should throw if an error occurs.
    3722             :    * Usually, `true` corresponds to `'use strict'`.
    3723             :    *
    3724             :    * \note Always `false` when intercepting `Reflect.set()`
    3725             :    * independent of the language mode.
    3726             :    */
    3727             :   V8_INLINE bool ShouldThrowOnError() const;
    3728             : 
    3729             :   // This shouldn't be public, but the arm compiler needs it.
    3730             :   static const int kArgsLength = 7;
    3731             : 
    3732             :  protected:
    3733             :   friend class MacroAssembler;
    3734             :   friend class internal::PropertyCallbackArguments;
    3735             :   friend class internal::CustomArguments<PropertyCallbackInfo>;
    3736             :   static const int kShouldThrowOnErrorIndex = 0;
    3737             :   static const int kHolderIndex = 1;
    3738             :   static const int kIsolateIndex = 2;
    3739             :   static const int kReturnValueDefaultValueIndex = 3;
    3740             :   static const int kReturnValueIndex = 4;
    3741             :   static const int kDataIndex = 5;
    3742             :   static const int kThisIndex = 6;
    3743             : 
    3744    42662119 :   V8_INLINE PropertyCallbackInfo(internal::Object** args) : args_(args) {}
    3745             :   internal::Object** args_;
    3746             : };
    3747             : 
    3748             : 
    3749             : typedef void (*FunctionCallback)(const FunctionCallbackInfo<Value>& info);
    3750             : 
    3751             : enum class ConstructorBehavior { kThrow, kAllow };
    3752             : 
    3753             : /**
    3754             :  * A JavaScript function object (ECMA-262, 15.3).
    3755             :  */
    3756             : class V8_EXPORT Function : public Object {
    3757             :  public:
    3758             :   /**
    3759             :    * Create a function in the current execution context
    3760             :    * for a given FunctionCallback.
    3761             :    */
    3762             :   static MaybeLocal<Function> New(
    3763             :       Local<Context> context, FunctionCallback callback,
    3764             :       Local<Value> data = Local<Value>(), int length = 0,
    3765             :       ConstructorBehavior behavior = ConstructorBehavior::kAllow);
    3766             :   static V8_DEPRECATE_SOON(
    3767             :       "Use maybe version",
    3768             :       Local<Function> New(Isolate* isolate, FunctionCallback callback,
    3769             :                           Local<Value> data = Local<Value>(), int length = 0));
    3770             : 
    3771             :   V8_DEPRECATED("Use maybe version",
    3772             :                 Local<Object> NewInstance(int argc, Local<Value> argv[]) const);
    3773             :   V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance(
    3774             :       Local<Context> context, int argc, Local<Value> argv[]) const;
    3775             : 
    3776             :   V8_DEPRECATED("Use maybe version", Local<Object> NewInstance() const);
    3777          15 :   V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance(
    3778             :       Local<Context> context) const {
    3779          15 :     return NewInstance(context, 0, nullptr);
    3780             :   }
    3781             : 
    3782             :   V8_DEPRECATE_SOON("Use maybe version",
    3783             :                     Local<Value> Call(Local<Value> recv, int argc,
    3784             :                                       Local<Value> argv[]));
    3785             :   V8_WARN_UNUSED_RESULT MaybeLocal<Value> Call(Local<Context> context,
    3786             :                                                Local<Value> recv, int argc,
    3787             :                                                Local<Value> argv[]);
    3788             : 
    3789             :   void SetName(Local<String> name);
    3790             :   Local<Value> GetName() const;
    3791             : 
    3792             :   /**
    3793             :    * Name inferred from variable or property assignment of this function.
    3794             :    * Used to facilitate debugging and profiling of JavaScript code written
    3795             :    * in an OO style, where many functions are anonymous but are assigned
    3796             :    * to object properties.
    3797             :    */
    3798             :   Local<Value> GetInferredName() const;
    3799             : 
    3800             :   /**
    3801             :    * displayName if it is set, otherwise name if it is configured, otherwise
    3802             :    * function name, otherwise inferred name.
    3803             :    */
    3804             :   Local<Value> GetDebugName() const;
    3805             : 
    3806             :   /**
    3807             :    * User-defined name assigned to the "displayName" property of this function.
    3808             :    * Used to facilitate debugging and profiling of JavaScript code.
    3809             :    */
    3810             :   Local<Value> GetDisplayName() const;
    3811             : 
    3812             :   /**
    3813             :    * Returns zero based line number of function body and
    3814             :    * kLineOffsetNotFound if no information available.
    3815             :    */
    3816             :   int GetScriptLineNumber() const;
    3817             :   /**
    3818             :    * Returns zero based column number of function body and
    3819             :    * kLineOffsetNotFound if no information available.
    3820             :    */
    3821             :   int GetScriptColumnNumber() const;
    3822             : 
    3823             :   /**
    3824             :    * Tells whether this function is builtin.
    3825             :    */
    3826             :   V8_DEPRECATED("this should no longer be used.", bool IsBuiltin() const);
    3827             : 
    3828             :   /**
    3829             :    * Returns scriptId.
    3830             :    */
    3831             :   int ScriptId() const;
    3832             : 
    3833             :   /**
    3834             :    * Returns the original function if this function is bound, else returns
    3835             :    * v8::Undefined.
    3836             :    */
    3837             :   Local<Value> GetBoundFunction() const;
    3838             : 
    3839             :   ScriptOrigin GetScriptOrigin() const;
    3840             :   V8_INLINE static Function* Cast(Value* obj);
    3841             :   static const int kLineOffsetNotFound;
    3842             : 
    3843             :  private:
    3844             :   Function();
    3845             :   static void CheckCast(Value* obj);
    3846             : };
    3847             : 
    3848             : 
    3849             : /**
    3850             :  * An instance of the built-in Promise constructor (ES6 draft).
    3851             :  */
    3852             : class V8_EXPORT Promise : public Object {
    3853             :  public:
    3854             :   /**
    3855             :    * State of the promise. Each value corresponds to one of the possible values
    3856             :    * of the [[PromiseState]] field.
    3857             :    */
    3858             :   enum PromiseState { kPending, kFulfilled, kRejected };
    3859             : 
    3860             :   class V8_EXPORT Resolver : public Object {
    3861             :    public:
    3862             :     /**
    3863             :      * Create a new resolver, along with an associated promise in pending state.
    3864             :      */
    3865             :     static V8_DEPRECATE_SOON("Use maybe version",
    3866             :                              Local<Resolver> New(Isolate* isolate));
    3867             :     static V8_WARN_UNUSED_RESULT MaybeLocal<Resolver> New(
    3868             :         Local<Context> context);
    3869             : 
    3870             :     /**
    3871             :      * Extract the associated promise.
    3872             :      */
    3873             :     Local<Promise> GetPromise();
    3874             : 
    3875             :     /**
    3876             :      * Resolve/reject the associated promise with a given value.
    3877             :      * Ignored if the promise is no longer pending.
    3878             :      */
    3879             :     V8_DEPRECATE_SOON("Use maybe version", void Resolve(Local<Value> value));
    3880             :     V8_WARN_UNUSED_RESULT Maybe<bool> Resolve(Local<Context> context,
    3881             :                                               Local<Value> value);
    3882             : 
    3883             :     V8_DEPRECATE_SOON("Use maybe version", void Reject(Local<Value> value));
    3884             :     V8_WARN_UNUSED_RESULT Maybe<bool> Reject(Local<Context> context,
    3885             :                                              Local<Value> value);
    3886             : 
    3887             :     V8_INLINE static Resolver* Cast(Value* obj);
    3888             : 
    3889             :    private:
    3890             :     Resolver();
    3891             :     static void CheckCast(Value* obj);
    3892             :   };
    3893             : 
    3894             :   /**
    3895             :    * Register a resolution/rejection handler with a promise.
    3896             :    * The handler is given the respective resolution/rejection value as
    3897             :    * an argument. If the promise is already resolved/rejected, the handler is
    3898             :    * invoked at the end of turn.
    3899             :    */
    3900             :   V8_DEPRECATED("Use maybe version",
    3901             :                 Local<Promise> Catch(Local<Function> handler));
    3902             :   V8_WARN_UNUSED_RESULT MaybeLocal<Promise> Catch(Local<Context> context,
    3903             :                                                   Local<Function> handler);
    3904             : 
    3905             :   V8_DEPRECATED("Use maybe version",
    3906             :                 Local<Promise> Then(Local<Function> handler));
    3907             :   V8_WARN_UNUSED_RESULT MaybeLocal<Promise> Then(Local<Context> context,
    3908             :                                                  Local<Function> handler);
    3909             : 
    3910             :   /**
    3911             :    * Returns true if the promise has at least one derived promise, and
    3912             :    * therefore resolve/reject handlers (including default handler).
    3913             :    */
    3914             :   bool HasHandler();
    3915             : 
    3916             :   /**
    3917             :    * Returns the content of the [[PromiseResult]] field. The Promise must not
    3918             :    * be pending.
    3919             :    */
    3920             :   Local<Value> Result();
    3921             : 
    3922             :   /**
    3923             :    * Returns the value of the [[PromiseState]] field.
    3924             :    */
    3925             :   PromiseState State();
    3926             : 
    3927             :   V8_INLINE static Promise* Cast(Value* obj);
    3928             : 
    3929             :  private:
    3930             :   Promise();
    3931             :   static void CheckCast(Value* obj);
    3932             : };
    3933             : 
    3934             : /**
    3935             :  * An instance of a Property Descriptor, see Ecma-262 6.2.4.
    3936             :  *
    3937             :  * Properties in a descriptor are present or absent. If you do not set
    3938             :  * `enumerable`, `configurable`, and `writable`, they are absent. If `value`,
    3939             :  * `get`, or `set` are absent, but you must specify them in the constructor, use
    3940             :  * empty handles.
    3941             :  *
    3942             :  * Accessors `get` and `set` must be callable or undefined if they are present.
    3943             :  *
    3944             :  * \note Only query properties if they are present, i.e., call `x()` only if
    3945             :  * `has_x()` returns true.
    3946             :  *
    3947             :  * \code
    3948             :  * // var desc = {writable: false}
    3949             :  * v8::PropertyDescriptor d(Local<Value>()), false);
    3950             :  * d.value(); // error, value not set
    3951             :  * if (d.has_writable()) {
    3952             :  *   d.writable(); // false
    3953             :  * }
    3954             :  *
    3955             :  * // var desc = {value: undefined}
    3956             :  * v8::PropertyDescriptor d(v8::Undefined(isolate));
    3957             :  *
    3958             :  * // var desc = {get: undefined}
    3959             :  * v8::PropertyDescriptor d(v8::Undefined(isolate), Local<Value>()));
    3960             :  * \endcode
    3961             :  */
    3962             : class V8_EXPORT PropertyDescriptor {
    3963             :  public:
    3964             :   // GenericDescriptor
    3965             :   PropertyDescriptor();
    3966             : 
    3967             :   // DataDescriptor
    3968             :   PropertyDescriptor(Local<Value> value);
    3969             : 
    3970             :   // DataDescriptor with writable property
    3971             :   PropertyDescriptor(Local<Value> value, bool writable);
    3972             : 
    3973             :   // AccessorDescriptor
    3974             :   PropertyDescriptor(Local<Value> get, Local<Value> set);
    3975             : 
    3976             :   ~PropertyDescriptor();
    3977             : 
    3978             :   Local<Value> value() const;
    3979             :   bool has_value() const;
    3980             : 
    3981             :   Local<Value> get() const;
    3982             :   bool has_get() const;
    3983             :   Local<Value> set() const;
    3984             :   bool has_set() const;
    3985             : 
    3986             :   void set_enumerable(bool enumerable);
    3987             :   bool enumerable() const;
    3988             :   bool has_enumerable() const;
    3989             : 
    3990             :   void set_configurable(bool configurable);
    3991             :   bool configurable() const;
    3992             :   bool has_configurable() const;
    3993             : 
    3994             :   bool writable() const;
    3995             :   bool has_writable() const;
    3996             : 
    3997             :   struct PrivateData;
    3998         151 :   PrivateData* get_private() const { return private_; }
    3999             : 
    4000             :   PropertyDescriptor(const PropertyDescriptor&) = delete;
    4001             :   void operator=(const PropertyDescriptor&) = delete;
    4002             : 
    4003             :  private:
    4004             :   PrivateData* private_;
    4005             : };
    4006             : 
    4007             : /**
    4008             :  * An instance of the built-in Proxy constructor (ECMA-262, 6th Edition,
    4009             :  * 26.2.1).
    4010             :  */
    4011             : class V8_EXPORT Proxy : public Object {
    4012             :  public:
    4013             :   Local<Object> GetTarget();
    4014             :   Local<Value> GetHandler();
    4015             :   bool IsRevoked();
    4016             :   void Revoke();
    4017             : 
    4018             :   /**
    4019             :    * Creates a new Proxy for the target object.
    4020             :    */
    4021             :   static MaybeLocal<Proxy> New(Local<Context> context,
    4022             :                                Local<Object> local_target,
    4023             :                                Local<Object> local_handler);
    4024             : 
    4025             :   V8_INLINE static Proxy* Cast(Value* obj);
    4026             : 
    4027             :  private:
    4028             :   Proxy();
    4029             :   static void CheckCast(Value* obj);
    4030             : };
    4031             : 
    4032             : // TODO(mtrofin): rename WasmCompiledModule to WasmModuleObject, for
    4033             : // consistency with internal APIs.
    4034             : class V8_EXPORT WasmCompiledModule : public Object {
    4035             :  public:
    4036             :   typedef std::pair<std::unique_ptr<const uint8_t[]>, size_t> SerializedModule;
    4037             :   // A buffer that is owned by the caller.
    4038             :   typedef std::pair<const uint8_t*, size_t> CallerOwnedBuffer;
    4039             : 
    4040             :   // An opaque, native heap object for transferring wasm modules. It
    4041             :   // supports move semantics, and does not support copy semantics.
    4042             :   class TransferrableModule final {
    4043             :    public:
    4044             :     TransferrableModule(TransferrableModule&& src) = default;
    4045             :     TransferrableModule(const TransferrableModule& src) = delete;
    4046             : 
    4047             :     TransferrableModule& operator=(TransferrableModule&& src) = default;
    4048             :     TransferrableModule& operator=(const TransferrableModule& src) = delete;
    4049             : 
    4050             :    private:
    4051             :     typedef std::pair<std::unique_ptr<const uint8_t[]>, size_t> OwnedBuffer;
    4052             :     friend class WasmCompiledModule;
    4053             :     TransferrableModule(OwnedBuffer&& code, OwnedBuffer&& bytes)
    4054             :         : compiled_code(std::move(code)), wire_bytes(std::move(bytes)) {}
    4055             : 
    4056             :     OwnedBuffer compiled_code = {nullptr, 0};
    4057             :     OwnedBuffer wire_bytes = {nullptr, 0};
    4058             :   };
    4059             : 
    4060             :   // Get an in-memory, non-persistable, and context-independent (meaning,
    4061             :   // suitable for transfer to another Isolate and Context) representation
    4062             :   // of this wasm compiled module.
    4063             :   TransferrableModule GetTransferrableModule();
    4064             : 
    4065             :   // Efficiently re-create a WasmCompiledModule, without recompiling, from
    4066             :   // a TransferrableModule.
    4067             :   static MaybeLocal<WasmCompiledModule> FromTransferrableModule(
    4068             :       Isolate* isolate, const TransferrableModule&);
    4069             : 
    4070             :   // Get the wasm-encoded bytes that were used to compile this module.
    4071             :   Local<String> GetWasmWireBytes();
    4072             : 
    4073             :   // Serialize the compiled module. The serialized data does not include the
    4074             :   // uncompiled bytes.
    4075             :   SerializedModule Serialize();
    4076             : 
    4077             :   // If possible, deserialize the module, otherwise compile it from the provided
    4078             :   // uncompiled bytes.
    4079             :   static MaybeLocal<WasmCompiledModule> DeserializeOrCompile(
    4080             :       Isolate* isolate, const CallerOwnedBuffer& serialized_module,
    4081             :       const CallerOwnedBuffer& wire_bytes);
    4082             :   V8_INLINE static WasmCompiledModule* Cast(Value* obj);
    4083             : 
    4084             :  private:
    4085             :   // TODO(ahaas): please remove the friend once streamed compilation is
    4086             :   // implemented
    4087             :   friend class WasmModuleObjectBuilder;
    4088             : 
    4089             :   static MaybeLocal<WasmCompiledModule> Deserialize(
    4090             :       Isolate* isolate, const CallerOwnedBuffer& serialized_module,
    4091             :       const CallerOwnedBuffer& wire_bytes);
    4092             :   static MaybeLocal<WasmCompiledModule> Compile(Isolate* isolate,
    4093             :                                                 const uint8_t* start,
    4094             :                                                 size_t length);
    4095             :   static CallerOwnedBuffer AsCallerOwned(
    4096             :       const TransferrableModule::OwnedBuffer& buff) {
    4097          22 :     return {buff.first.get(), buff.second};
    4098             :   }
    4099             : 
    4100             :   WasmCompiledModule();
    4101             :   static void CheckCast(Value* obj);
    4102             : };
    4103             : 
    4104             : class V8_EXPORT WasmModuleObjectBuilder final {
    4105             :  public:
    4106             :   WasmModuleObjectBuilder(Isolate* isolate) : isolate_(isolate) {}
    4107             :   // The buffer passed into OnBytesReceived is owned by the caller.
    4108             :   void OnBytesReceived(const uint8_t*, size_t size);
    4109             :   MaybeLocal<WasmCompiledModule> Finish();
    4110             : 
    4111             :  private:
    4112             :   Isolate* isolate_ = nullptr;
    4113             :   // TODO(ahaas): We probably need none of this below here once streamed
    4114             :   // compilation is implemented.
    4115             :   typedef std::pair<std::unique_ptr<const uint8_t[]>, size_t> Buffer;
    4116             : 
    4117             :   // Disable copy semantics *in this implementation*. We can choose to
    4118             :   // relax this, albeit it's not clear why.
    4119             :   WasmModuleObjectBuilder(const WasmModuleObjectBuilder&) = delete;
    4120             :   WasmModuleObjectBuilder(WasmModuleObjectBuilder&&) = default;
    4121             :   WasmModuleObjectBuilder& operator=(const WasmModuleObjectBuilder&) = delete;
    4122             :   WasmModuleObjectBuilder& operator=(WasmModuleObjectBuilder&&) = default;
    4123             : 
    4124             :   std::vector<Buffer> received_buffers_;
    4125             :   size_t total_size_ = 0;
    4126             : };
    4127             : 
    4128             : #ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT
    4129             : // The number of required internal fields can be defined by embedder.
    4130             : #define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2
    4131             : #endif
    4132             : 
    4133             : 
    4134             : enum class ArrayBufferCreationMode { kInternalized, kExternalized };
    4135             : 
    4136             : 
    4137             : /**
    4138             :  * An instance of the built-in ArrayBuffer constructor (ES6 draft 15.13.5).
    4139             :  */
    4140             : class V8_EXPORT ArrayBuffer : public Object {
    4141             :  public:
    4142             :   /**
    4143             :    * A thread-safe allocator that V8 uses to allocate |ArrayBuffer|'s memory.
    4144             :    * The allocator is a global V8 setting. It has to be set via
    4145             :    * Isolate::CreateParams.
    4146             :    *
    4147             :    * Memory allocated through this allocator by V8 is accounted for as external
    4148             :    * memory by V8. Note that V8 keeps track of the memory for all internalized
    4149             :    * |ArrayBuffer|s. Responsibility for tracking external memory (using
    4150             :    * Isolate::AdjustAmountOfExternalAllocatedMemory) is handed over to the
    4151             :    * embedder upon externalization and taken over upon internalization (creating
    4152             :    * an internalized buffer from an existing buffer).
    4153             :    *
    4154             :    * Note that it is unsafe to call back into V8 from any of the allocator
    4155             :    * functions.
    4156             :    */
    4157        3829 :   class V8_EXPORT Allocator { // NOLINT
    4158             :    public:
    4159       59728 :     virtual ~Allocator() {}
    4160             : 
    4161             :     /**
    4162             :      * Allocate |length| bytes. Return NULL if allocation is not successful.
    4163             :      * Memory should be initialized to zeroes.
    4164             :      */
    4165             :     virtual void* Allocate(size_t length) = 0;
    4166             : 
    4167             :     /**
    4168             :      * Allocate |length| bytes. Return NULL if allocation is not successful.
    4169             :      * Memory does not have to be initialized.
    4170             :      */
    4171             :     virtual void* AllocateUninitialized(size_t length) = 0;
    4172             : 
    4173             :     /**
    4174             :      * Free the memory block of size |length|, pointed to by |data|.
    4175             :      * That memory is guaranteed to be previously allocated by |Allocate|.
    4176             :      */
    4177             :     virtual void Free(void* data, size_t length) = 0;
    4178             : 
    4179             :     /**
    4180             :      * malloc/free based convenience allocator.
    4181             :      *
    4182             :      * Caller takes ownership, i.e. the returned object needs to be freed using
    4183             :      * |delete allocator| once it is no longer in use.
    4184             :      */
    4185             :     static Allocator* NewDefaultAllocator();
    4186             :   };
    4187             : 
    4188             :   /**
    4189             :    * The contents of an |ArrayBuffer|. Externalization of |ArrayBuffer|
    4190             :    * returns an instance of this class, populated, with a pointer to data
    4191             :    * and byte length.
    4192             :    *
    4193             :    * The Data pointer of ArrayBuffer::Contents is always allocated with
    4194             :    * Allocator::Allocate that is set via Isolate::CreateParams.
    4195             :    */
    4196             :   class V8_EXPORT Contents { // NOLINT
    4197             :    public:
    4198             :     Contents() : data_(NULL), byte_length_(0) {}
    4199             : 
    4200             :     void* Data() const { return data_; }
    4201             :     size_t ByteLength() const { return byte_length_; }
    4202             : 
    4203             :    private:
    4204             :     void* data_;
    4205             :     size_t byte_length_;
    4206             : 
    4207             :     friend class ArrayBuffer;
    4208             :   };
    4209             : 
    4210             : 
    4211             :   /**
    4212             :    * Data length in bytes.
    4213             :    */
    4214             :   size_t ByteLength() const;
    4215             : 
    4216             :   /**
    4217             :    * Create a new ArrayBuffer. Allocate |byte_length| bytes.
    4218             :    * Allocated memory will be owned by a created ArrayBuffer and
    4219             :    * will be deallocated when it is garbage-collected,
    4220             :    * unless the object is externalized.
    4221             :    */
    4222             :   static Local<ArrayBuffer> New(Isolate* isolate, size_t byte_length);
    4223             : 
    4224             :   /**
    4225             :    * Create a new ArrayBuffer over an existing memory block.
    4226             :    * The created array buffer is by default immediately in externalized state.
    4227             :    * In externalized state, the memory block will not be reclaimed when a
    4228             :    * created ArrayBuffer is garbage-collected.
    4229             :    * In internalized state, the memory block will be released using
    4230             :    * |Allocator::Free| once all ArrayBuffers referencing it are collected by
    4231             :    * the garbage collector.
    4232             :    */
    4233             :   static Local<ArrayBuffer> New(
    4234             :       Isolate* isolate, void* data, size_t byte_length,
    4235             :       ArrayBufferCreationMode mode = ArrayBufferCreationMode::kExternalized);
    4236             : 
    4237             :   /**
    4238             :    * Returns true if ArrayBuffer is externalized, that is, does not
    4239             :    * own its memory block.
    4240             :    */
    4241             :   bool IsExternal() const;
    4242             : 
    4243             :   /**
    4244             :    * Returns true if this ArrayBuffer may be neutered.
    4245             :    */
    4246             :   bool IsNeuterable() const;
    4247             : 
    4248             :   /**
    4249             :    * Neuters this ArrayBuffer and all its views (typed arrays).
    4250             :    * Neutering sets the byte length of the buffer and all typed arrays to zero,
    4251             :    * preventing JavaScript from ever accessing underlying backing store.
    4252             :    * ArrayBuffer should have been externalized and must be neuterable.
    4253             :    */
    4254             :   void Neuter();
    4255             : 
    4256             :   /**
    4257             :    * Make this ArrayBuffer external. The pointer to underlying memory block
    4258             :    * and byte length are returned as |Contents| structure. After ArrayBuffer
    4259             :    * had been externalized, it does no longer own the memory block. The caller
    4260             :    * should take steps to free memory when it is no longer needed.
    4261             :    *
    4262             :    * The memory block is guaranteed to be allocated with |Allocator::Allocate|
    4263             :    * that has been set via Isolate::CreateParams.
    4264             :    */
    4265             :   Contents Externalize();
    4266             : 
    4267             :   /**
    4268             :    * Get a pointer to the ArrayBuffer's underlying memory block without
    4269             :    * externalizing it. If the ArrayBuffer is not externalized, this pointer
    4270             :    * will become invalid as soon as the ArrayBuffer gets garbage collected.
    4271             :    *
    4272             :    * The embedder should make sure to hold a strong reference to the
    4273             :    * ArrayBuffer while accessing this pointer.
    4274             :    *
    4275             :    * The memory block is guaranteed to be allocated with |Allocator::Allocate|.
    4276             :    */
    4277             :   Contents GetContents();
    4278             : 
    4279             :   V8_INLINE static ArrayBuffer* Cast(Value* obj);
    4280             : 
    4281             :   static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
    4282             :   static const int kEmbedderFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
    4283             : 
    4284             :  private:
    4285             :   ArrayBuffer();
    4286             :   static void CheckCast(Value* obj);
    4287             : };
    4288             : 
    4289             : 
    4290             : #ifndef V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT
    4291             : // The number of required internal fields can be defined by embedder.
    4292             : #define V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT 2
    4293             : #endif
    4294             : 
    4295             : 
    4296             : /**
    4297             :  * A base class for an instance of one of "views" over ArrayBuffer,
    4298             :  * including TypedArrays and DataView (ES6 draft 15.13).
    4299             :  */
    4300             : class V8_EXPORT ArrayBufferView : public Object {
    4301             :  public:
    4302             :   /**
    4303             :    * Returns underlying ArrayBuffer.
    4304             :    */
    4305             :   Local<ArrayBuffer> Buffer();
    4306             :   /**
    4307             :    * Byte offset in |Buffer|.
    4308             :    */
    4309             :   size_t ByteOffset();
    4310             :   /**
    4311             :    * Size of a view in bytes.
    4312             :    */
    4313             :   size_t ByteLength();
    4314             : 
    4315             :   /**
    4316             :    * Copy the contents of the ArrayBufferView's buffer to an embedder defined
    4317             :    * memory without additional overhead that calling ArrayBufferView::Buffer
    4318             :    * might incur.
    4319             :    *
    4320             :    * Will write at most min(|byte_length|, ByteLength) bytes starting at
    4321             :    * ByteOffset of the underlying buffer to the memory starting at |dest|.
    4322             :    * Returns the number of bytes actually written.
    4323             :    */
    4324             :   size_t CopyContents(void* dest, size_t byte_length);
    4325             : 
    4326             :   /**
    4327             :    * Returns true if ArrayBufferView's backing ArrayBuffer has already been
    4328             :    * allocated.
    4329             :    */
    4330             :   bool HasBuffer() const;
    4331             : 
    4332             :   V8_INLINE static ArrayBufferView* Cast(Value* obj);
    4333             : 
    4334             :   static const int kInternalFieldCount =
    4335             :       V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT;
    4336             :   static const int kEmbedderFieldCount =
    4337             :       V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT;
    4338             : 
    4339             :  private:
    4340             :   ArrayBufferView();
    4341             :   static void CheckCast(Value* obj);
    4342             : };
    4343             : 
    4344             : 
    4345             : /**
    4346             :  * A base class for an instance of TypedArray series of constructors
    4347             :  * (ES6 draft 15.13.6).
    4348             :  */
    4349             : class V8_EXPORT TypedArray : public ArrayBufferView {
    4350             :  public:
    4351             :   /**
    4352             :    * Number of elements in this typed array
    4353             :    * (e.g. for Int16Array, |ByteLength|/2).
    4354             :    */
    4355             :   size_t Length();
    4356             : 
    4357             :   V8_INLINE static TypedArray* Cast(Value* obj);
    4358             : 
    4359             :  private:
    4360             :   TypedArray();
    4361             :   static void CheckCast(Value* obj);
    4362             : };
    4363             : 
    4364             : 
    4365             : /**
    4366             :  * An instance of Uint8Array constructor (ES6 draft 15.13.6).
    4367             :  */
    4368             : class V8_EXPORT Uint8Array : public TypedArray {
    4369             :  public:
    4370             :   static Local<Uint8Array> New(Local<ArrayBuffer> array_buffer,
    4371             :                                size_t byte_offset, size_t length);
    4372             :   static Local<Uint8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
    4373             :                                size_t byte_offset, size_t length);
    4374             :   V8_INLINE static Uint8Array* Cast(Value* obj);
    4375             : 
    4376             :  private:
    4377             :   Uint8Array();
    4378             :   static void CheckCast(Value* obj);
    4379             : };
    4380             : 
    4381             : 
    4382             : /**
    4383             :  * An instance of Uint8ClampedArray constructor (ES6 draft 15.13.6).
    4384             :  */
    4385             : class V8_EXPORT Uint8ClampedArray : public TypedArray {
    4386             :  public:
    4387             :   static Local<Uint8ClampedArray> New(Local<ArrayBuffer> array_buffer,
    4388             :                                       size_t byte_offset, size_t length);
    4389             :   static Local<Uint8ClampedArray> New(
    4390             :       Local<SharedArrayBuffer> shared_array_buffer, size_t byte_offset,
    4391             :       size_t length);
    4392             :   V8_INLINE static Uint8ClampedArray* Cast(Value* obj);
    4393             : 
    4394             :  private:
    4395             :   Uint8ClampedArray();
    4396             :   static void CheckCast(Value* obj);
    4397             : };
    4398             : 
    4399             : /**
    4400             :  * An instance of Int8Array constructor (ES6 draft 15.13.6).
    4401             :  */
    4402             : class V8_EXPORT Int8Array : public TypedArray {
    4403             :  public:
    4404             :   static Local<Int8Array> New(Local<ArrayBuffer> array_buffer,
    4405             :                               size_t byte_offset, size_t length);
    4406             :   static Local<Int8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
    4407             :                               size_t byte_offset, size_t length);
    4408             :   V8_INLINE static Int8Array* Cast(Value* obj);
    4409             : 
    4410             :  private:
    4411             :   Int8Array();
    4412             :   static void CheckCast(Value* obj);
    4413             : };
    4414             : 
    4415             : 
    4416             : /**
    4417             :  * An instance of Uint16Array constructor (ES6 draft 15.13.6).
    4418             :  */
    4419             : class V8_EXPORT Uint16Array : public TypedArray {
    4420             :  public:
    4421             :   static Local<Uint16Array> New(Local<ArrayBuffer> array_buffer,
    4422             :                                 size_t byte_offset, size_t length);
    4423             :   static Local<Uint16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
    4424             :                                 size_t byte_offset, size_t length);
    4425             :   V8_INLINE static Uint16Array* Cast(Value* obj);
    4426             : 
    4427             :  private:
    4428             :   Uint16Array();
    4429             :   static void CheckCast(Value* obj);
    4430             : };
    4431             : 
    4432             : 
    4433             : /**
    4434             :  * An instance of Int16Array constructor (ES6 draft 15.13.6).
    4435             :  */
    4436             : class V8_EXPORT Int16Array : public TypedArray {
    4437             :  public:
    4438             :   static Local<Int16Array> New(Local<ArrayBuffer> array_buffer,
    4439             :                                size_t byte_offset, size_t length);
    4440             :   static Local<Int16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
    4441             :                                size_t byte_offset, size_t length);
    4442             :   V8_INLINE static Int16Array* Cast(Value* obj);
    4443             : 
    4444             :  private:
    4445             :   Int16Array();
    4446             :   static void CheckCast(Value* obj);
    4447             : };
    4448             : 
    4449             : 
    4450             : /**
    4451             :  * An instance of Uint32Array constructor (ES6 draft 15.13.6).
    4452             :  */
    4453             : class V8_EXPORT Uint32Array : public TypedArray {
    4454             :  public:
    4455             :   static Local<Uint32Array> New(Local<ArrayBuffer> array_buffer,
    4456             :                                 size_t byte_offset, size_t length);
    4457             :   static Local<Uint32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
    4458             :                                 size_t byte_offset, size_t length);
    4459             :   V8_INLINE static Uint32Array* Cast(Value* obj);
    4460             : 
    4461             :  private:
    4462             :   Uint32Array();
    4463             :   static void CheckCast(Value* obj);
    4464             : };
    4465             : 
    4466             : 
    4467             : /**
    4468             :  * An instance of Int32Array constructor (ES6 draft 15.13.6).
    4469             :  */
    4470             : class V8_EXPORT Int32Array : public TypedArray {
    4471             :  public:
    4472             :   static Local<Int32Array> New(Local<ArrayBuffer> array_buffer,
    4473             :                                size_t byte_offset, size_t length);
    4474             :   static Local<Int32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
    4475             :                                size_t byte_offset, size_t length);
    4476             :   V8_INLINE static Int32Array* Cast(Value* obj);
    4477             : 
    4478             :  private:
    4479             :   Int32Array();
    4480             :   static void CheckCast(Value* obj);
    4481             : };
    4482             : 
    4483             : 
    4484             : /**
    4485             :  * An instance of Float32Array constructor (ES6 draft 15.13.6).
    4486             :  */
    4487             : class V8_EXPORT Float32Array : public TypedArray {
    4488             :  public:
    4489             :   static Local<Float32Array> New(Local<ArrayBuffer> array_buffer,
    4490             :                                  size_t byte_offset, size_t length);
    4491             :   static Local<Float32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
    4492             :                                  size_t byte_offset, size_t length);
    4493             :   V8_INLINE static Float32Array* Cast(Value* obj);
    4494             : 
    4495             :  private:
    4496             :   Float32Array();
    4497             :   static void CheckCast(Value* obj);
    4498             : };
    4499             : 
    4500             : 
    4501             : /**
    4502             :  * An instance of Float64Array constructor (ES6 draft 15.13.6).
    4503             :  */
    4504             : class V8_EXPORT Float64Array : public TypedArray {
    4505             :  public:
    4506             :   static Local<Float64Array> New(Local<ArrayBuffer> array_buffer,
    4507             :                                  size_t byte_offset, size_t length);
    4508             :   static Local<Float64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
    4509             :                                  size_t byte_offset, size_t length);
    4510             :   V8_INLINE static Float64Array* Cast(Value* obj);
    4511             : 
    4512             :  private:
    4513             :   Float64Array();
    4514             :   static void CheckCast(Value* obj);
    4515             : };
    4516             : 
    4517             : 
    4518             : /**
    4519             :  * An instance of DataView constructor (ES6 draft 15.13.7).
    4520             :  */
    4521             : class V8_EXPORT DataView : public ArrayBufferView {
    4522             :  public:
    4523             :   static Local<DataView> New(Local<ArrayBuffer> array_buffer,
    4524             :                              size_t byte_offset, size_t length);
    4525             :   static Local<DataView> New(Local<SharedArrayBuffer> shared_array_buffer,
    4526             :                              size_t byte_offset, size_t length);
    4527             :   V8_INLINE static DataView* Cast(Value* obj);
    4528             : 
    4529             :  private:
    4530             :   DataView();
    4531             :   static void CheckCast(Value* obj);
    4532             : };
    4533             : 
    4534             : 
    4535             : /**
    4536             :  * An instance of the built-in SharedArrayBuffer constructor.
    4537             :  * This API is experimental and may change significantly.
    4538             :  */
    4539             : class V8_EXPORT SharedArrayBuffer : public Object {
    4540             :  public:
    4541             :   /**
    4542             :    * The contents of an |SharedArrayBuffer|. Externalization of
    4543             :    * |SharedArrayBuffer| returns an instance of this class, populated, with a
    4544             :    * pointer to data and byte length.
    4545             :    *
    4546             :    * The Data pointer of SharedArrayBuffer::Contents is always allocated with
    4547             :    * |ArrayBuffer::Allocator::Allocate| by the allocator specified in
    4548             :    * v8::Isolate::CreateParams::array_buffer_allocator.
    4549             :    *
    4550             :    * This API is experimental and may change significantly.
    4551             :    */
    4552             :   class V8_EXPORT Contents {  // NOLINT
    4553             :    public:
    4554             :     Contents() : data_(NULL), byte_length_(0) {}
    4555             : 
    4556             :     void* Data() const { return data_; }
    4557             :     size_t ByteLength() const { return byte_length_; }
    4558             : 
    4559             :    private:
    4560             :     void* data_;
    4561             :     size_t byte_length_;
    4562             : 
    4563             :     friend class SharedArrayBuffer;
    4564             :   };
    4565             : 
    4566             : 
    4567             :   /**
    4568             :    * Data length in bytes.
    4569             :    */
    4570             :   size_t ByteLength() const;
    4571             : 
    4572             :   /**
    4573             :    * Create a new SharedArrayBuffer. Allocate |byte_length| bytes.
    4574             :    * Allocated memory will be owned by a created SharedArrayBuffer and
    4575             :    * will be deallocated when it is garbage-collected,
    4576             :    * unless the object is externalized.
    4577             :    */
    4578             :   static Local<SharedArrayBuffer> New(Isolate* isolate, size_t byte_length);
    4579             : 
    4580             :   /**
    4581             :    * Create a new SharedArrayBuffer over an existing memory block.  The created
    4582             :    * array buffer is immediately in externalized state unless otherwise
    4583             :    * specified. The memory block will not be reclaimed when a created
    4584             :    * SharedArrayBuffer is garbage-collected.
    4585             :    */
    4586             :   static Local<SharedArrayBuffer> New(
    4587             :       Isolate* isolate, void* data, size_t byte_length,
    4588             :       ArrayBufferCreationMode mode = ArrayBufferCreationMode::kExternalized);
    4589             : 
    4590             :   /**
    4591             :    * Returns true if SharedArrayBuffer is externalized, that is, does not
    4592             :    * own its memory block.
    4593             :    */
    4594             :   bool IsExternal() const;
    4595             : 
    4596             :   /**
    4597             :    * Make this SharedArrayBuffer external. The pointer to underlying memory
    4598             :    * block and byte length are returned as |Contents| structure. After
    4599             :    * SharedArrayBuffer had been externalized, it does no longer own the memory
    4600             :    * block. The caller should take steps to free memory when it is no longer
    4601             :    * needed.
    4602             :    *
    4603             :    * The memory block is guaranteed to be allocated with |Allocator::Allocate|
    4604             :    * by the allocator specified in
    4605             :    * v8::Isolate::CreateParams::array_buffer_allocator.
    4606             :    *
    4607             :    */
    4608             :   Contents Externalize();
    4609             : 
    4610             :   /**
    4611             :    * Get a pointer to the ArrayBuffer's underlying memory block without
    4612             :    * externalizing it. If the ArrayBuffer is not externalized, this pointer
    4613             :    * will become invalid as soon as the ArrayBuffer became garbage collected.
    4614             :    *
    4615             :    * The embedder should make sure to hold a strong reference to the
    4616             :    * ArrayBuffer while accessing this pointer.
    4617             :    *
    4618             :    * The memory block is guaranteed to be allocated with |Allocator::Allocate|
    4619             :    * by the allocator specified in
    4620             :    * v8::Isolate::CreateParams::array_buffer_allocator.
    4621             :    */
    4622             :   Contents GetContents();
    4623             : 
    4624             :   V8_INLINE static SharedArrayBuffer* Cast(Value* obj);
    4625             : 
    4626             :   static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
    4627             : 
    4628             :  private:
    4629             :   SharedArrayBuffer();
    4630             :   static void CheckCast(Value* obj);
    4631             : };
    4632             : 
    4633             : 
    4634             : /**
    4635             :  * An instance of the built-in Date constructor (ECMA-262, 15.9).
    4636             :  */
    4637             : class V8_EXPORT Date : public Object {
    4638             :  public:
    4639             :   static V8_DEPRECATE_SOON("Use maybe version.",
    4640             :                            Local<Value> New(Isolate* isolate, double time));
    4641             :   static V8_WARN_UNUSED_RESULT MaybeLocal<Value> New(Local<Context> context,
    4642             :                                                      double time);
    4643             : 
    4644             :   /**
    4645             :    * A specialization of Value::NumberValue that is more efficient
    4646             :    * because we know the structure of this object.
    4647             :    */
    4648             :   double ValueOf() const;
    4649             : 
    4650             :   V8_INLINE static Date* Cast(Value* obj);
    4651             : 
    4652             :   /**
    4653             :    * Notification that the embedder has changed the time zone,
    4654             :    * daylight savings time, or other date / time configuration
    4655             :    * parameters.  V8 keeps a cache of various values used for
    4656             :    * date / time computation.  This notification will reset
    4657             :    * those cached values for the current context so that date /
    4658             :    * time configuration changes would be reflected in the Date
    4659             :    * object.
    4660             :    *
    4661             :    * This API should not be called more than needed as it will
    4662             :    * negatively impact the performance of date operations.
    4663             :    */
    4664             :   static void DateTimeConfigurationChangeNotification(Isolate* isolate);
    4665             : 
    4666             :  private:
    4667             :   static void CheckCast(Value* obj);
    4668             : };
    4669             : 
    4670             : 
    4671             : /**
    4672             :  * A Number object (ECMA-262, 4.3.21).
    4673             :  */
    4674             : class V8_EXPORT NumberObject : public Object {
    4675             :  public:
    4676             :   static Local<Value> New(Isolate* isolate, double value);
    4677             : 
    4678             :   double ValueOf() const;
    4679             : 
    4680             :   V8_INLINE static NumberObject* Cast(Value* obj);
    4681             : 
    4682             :  private:
    4683             :   static void CheckCast(Value* obj);
    4684             : };
    4685             : 
    4686             : 
    4687             : /**
    4688             :  * A Boolean object (ECMA-262, 4.3.15).
    4689             :  */
    4690             : class V8_EXPORT BooleanObject : public Object {
    4691             :  public:
    4692             :   static Local<Value> New(Isolate* isolate, bool value);
    4693             :   V8_DEPRECATED("Pass an isolate", static Local<Value> New(bool value));
    4694             : 
    4695             :   bool ValueOf() const;
    4696             : 
    4697             :   V8_INLINE static BooleanObject* Cast(Value* obj);
    4698             : 
    4699             :  private:
    4700             :   static void CheckCast(Value* obj);
    4701             : };
    4702             : 
    4703             : 
    4704             : /**
    4705             :  * A String object (ECMA-262, 4.3.18).
    4706             :  */
    4707             : class V8_EXPORT StringObject : public Object {
    4708             :  public:
    4709             :   static Local<Value> New(Local<String> value);
    4710             : 
    4711             :   Local<String> ValueOf() const;
    4712             : 
    4713             :   V8_INLINE static StringObject* Cast(Value* obj);
    4714             : 
    4715             :  private:
    4716             :   static void CheckCast(Value* obj);
    4717             : };
    4718             : 
    4719             : 
    4720             : /**
    4721             :  * A Symbol object (ECMA-262 edition 6).
    4722             :  */
    4723             : class V8_EXPORT SymbolObject : public Object {
    4724             :  public:
    4725             :   static Local<Value> New(Isolate* isolate, Local<Symbol> value);
    4726             : 
    4727             :   Local<Symbol> ValueOf() const;
    4728             : 
    4729             :   V8_INLINE static SymbolObject* Cast(Value* obj);
    4730             : 
    4731             :  private:
    4732             :   static void CheckCast(Value* obj);
    4733             : };
    4734             : 
    4735             : 
    4736             : /**
    4737             :  * An instance of the built-in RegExp constructor (ECMA-262, 15.10).
    4738             :  */
    4739             : class V8_EXPORT RegExp : public Object {
    4740             :  public:
    4741             :   /**
    4742             :    * Regular expression flag bits. They can be or'ed to enable a set
    4743             :    * of flags.
    4744             :    */
    4745             :   enum Flags {
    4746             :     kNone = 0,
    4747             :     kGlobal = 1 << 0,
    4748             :     kIgnoreCase = 1 << 1,
    4749             :     kMultiline = 1 << 2,
    4750             :     kSticky = 1 << 3,
    4751             :     kUnicode = 1 << 4,
    4752             :     kDotAll = 1 << 5,
    4753             :   };
    4754             : 
    4755             :   /**
    4756             :    * Creates a regular expression from the given pattern string and
    4757             :    * the flags bit field. May throw a JavaScript exception as
    4758             :    * described in ECMA-262, 15.10.4.1.
    4759             :    *
    4760             :    * For example,
    4761             :    *   RegExp::New(v8::String::New("foo"),
    4762             :    *               static_cast<RegExp::Flags>(kGlobal | kMultiline))
    4763             :    * is equivalent to evaluating "/foo/gm".
    4764             :    */
    4765             :   static V8_DEPRECATE_SOON("Use maybe version",
    4766             :                            Local<RegExp> New(Local<String> pattern,
    4767             :                                              Flags flags));
    4768             :   static V8_WARN_UNUSED_RESULT MaybeLocal<RegExp> New(Local<Context> context,
    4769             :                                                       Local<String> pattern,
    4770             :                                                       Flags flags);
    4771             : 
    4772             :   /**
    4773             :    * Returns the value of the source property: a string representing
    4774             :    * the regular expression.
    4775             :    */
    4776             :   Local<String> GetSource() const;
    4777             : 
    4778             :   /**
    4779             :    * Returns the flags bit field.
    4780             :    */
    4781             :   Flags GetFlags() const;
    4782             : 
    4783             :   V8_INLINE static RegExp* Cast(Value* obj);
    4784             : 
    4785             :  private:
    4786             :   static void CheckCast(Value* obj);
    4787             : };
    4788             : 
    4789             : 
    4790             : /**
    4791             :  * A JavaScript value that wraps a C++ void*. This type of value is mainly used
    4792             :  * to associate C++ data structures with JavaScript objects.
    4793             :  */
    4794             : class V8_EXPORT External : public Value {
    4795             :  public:
    4796             :   static Local<External> New(Isolate* isolate, void* value);
    4797             :   V8_INLINE static External* Cast(Value* obj);
    4798             :   void* Value() const;
    4799             :  private:
    4800             :   static void CheckCast(v8::Value* obj);
    4801             : };
    4802             : 
    4803             : #define V8_INTRINSICS_LIST(F)                    \
    4804             :   F(ArrayProto_entries, array_entries_iterator)  \
    4805             :   F(ArrayProto_forEach, array_for_each_iterator) \
    4806             :   F(ArrayProto_keys, array_keys_iterator)        \
    4807             :   F(ArrayProto_values, array_values_iterator)    \
    4808             :   F(IteratorPrototype, initial_iterator_prototype)
    4809             : 
    4810             : enum Intrinsic {
    4811             : #define V8_DECL_INTRINSIC(name, iname) k##name,
    4812             :   V8_INTRINSICS_LIST(V8_DECL_INTRINSIC)
    4813             : #undef V8_DECL_INTRINSIC
    4814             : };
    4815             : 
    4816             : 
    4817             : // --- Templates ---
    4818             : 
    4819             : 
    4820             : /**
    4821             :  * The superclass of object and function templates.
    4822             :  */
    4823             : class V8_EXPORT Template : public Data {
    4824             :  public:
    4825             :   /**
    4826             :    * Adds a property to each instance created by this template.
    4827             :    *
    4828             :    * The property must be defined either as a primitive value, or a template.
    4829             :    */
    4830             :   void Set(Local<Name> name, Local<Data> value,
    4831             :            PropertyAttribute attributes = None);
    4832             :   void SetPrivate(Local<Private> name, Local<Data> value,
    4833             :                   PropertyAttribute attributes = None);
    4834             :   V8_INLINE void Set(Isolate* isolate, const char* name, Local<Data> value);
    4835             : 
    4836             :   void SetAccessorProperty(
    4837             :      Local<Name> name,
    4838             :      Local<FunctionTemplate> getter = Local<FunctionTemplate>(),
    4839             :      Local<FunctionTemplate> setter = Local<FunctionTemplate>(),
    4840             :      PropertyAttribute attribute = None,
    4841             :      AccessControl settings = DEFAULT);
    4842             : 
    4843             :   /**
    4844             :    * Whenever the property with the given name is accessed on objects
    4845             :    * created from this Template the getter and setter callbacks
    4846             :    * are called instead of getting and setting the property directly
    4847             :    * on the JavaScript object.
    4848             :    *
    4849             :    * \param name The name of the property for which an accessor is added.
    4850             :    * \param getter The callback to invoke when getting the property.
    4851             :    * \param setter The callback to invoke when setting the property.
    4852             :    * \param data A piece of data that will be passed to the getter and setter
    4853             :    *   callbacks whenever they are invoked.
    4854             :    * \param settings Access control settings for the accessor. This is a bit
    4855             :    *   field consisting of one of more of
    4856             :    *   DEFAULT = 0, ALL_CAN_READ = 1, or ALL_CAN_WRITE = 2.
    4857             :    *   The default is to not allow cross-context access.
    4858             :    *   ALL_CAN_READ means that all cross-context reads are allowed.
    4859             :    *   ALL_CAN_WRITE means that all cross-context writes are allowed.
    4860             :    *   The combination ALL_CAN_READ | ALL_CAN_WRITE can be used to allow all
    4861             :    *   cross-context access.
    4862             :    * \param attribute The attributes of the property for which an accessor
    4863             :    *   is added.
    4864             :    * \param signature The signature describes valid receivers for the accessor
    4865             :    *   and is used to perform implicit instance checks against them. If the
    4866             :    *   receiver is incompatible (i.e. is not an instance of the constructor as
    4867             :    *   defined by FunctionTemplate::HasInstance()), an implicit TypeError is
    4868             :    *   thrown and no callback is invoked.
    4869             :    */
    4870             :   void SetNativeDataProperty(
    4871             :       Local<String> name, AccessorGetterCallback getter,
    4872             :       AccessorSetterCallback setter = 0,
    4873             :       // TODO(dcarney): gcc can't handle Local below
    4874             :       Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
    4875             :       Local<AccessorSignature> signature = Local<AccessorSignature>(),
    4876             :       AccessControl settings = DEFAULT);
    4877             :   void SetNativeDataProperty(
    4878             :       Local<Name> name, AccessorNameGetterCallback getter,
    4879             :       AccessorNameSetterCallback setter = 0,
    4880             :       // TODO(dcarney): gcc can't handle Local below
    4881             :       Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
    4882             :       Local<AccessorSignature> signature = Local<AccessorSignature>(),
    4883             :       AccessControl settings = DEFAULT);
    4884             : 
    4885             :   /**
    4886             :    * Like SetNativeDataProperty, but V8 will replace the native data property
    4887             :    * with a real data property on first access.
    4888             :    */
    4889             :   void SetLazyDataProperty(Local<Name> name, AccessorNameGetterCallback getter,
    4890             :                            Local<Value> data = Local<Value>(),
    4891             :                            PropertyAttribute attribute = None);
    4892             : 
    4893             :   /**
    4894             :    * During template instantiation, sets the value with the intrinsic property
    4895             :    * from the correct context.
    4896             :    */
    4897             :   void SetIntrinsicDataProperty(Local<Name> name, Intrinsic intrinsic,
    4898             :                                 PropertyAttribute attribute = None);
    4899             : 
    4900             :  private:
    4901             :   Template();
    4902             : 
    4903             :   friend class ObjectTemplate;
    4904             :   friend class FunctionTemplate;
    4905             : };
    4906             : 
    4907             : 
    4908             : /**
    4909             :  * NamedProperty[Getter|Setter] are used as interceptors on object.
    4910             :  * See ObjectTemplate::SetNamedPropertyHandler.
    4911             :  */
    4912             : typedef void (*NamedPropertyGetterCallback)(
    4913             :     Local<String> property,
    4914             :     const PropertyCallbackInfo<Value>& info);
    4915             : 
    4916             : 
    4917             : /**
    4918             :  * Returns the value if the setter intercepts the request.
    4919             :  * Otherwise, returns an empty handle.
    4920             :  */
    4921             : typedef void (*NamedPropertySetterCallback)(
    4922             :     Local<String> property,
    4923             :     Local<Value> value,
    4924             :     const PropertyCallbackInfo<Value>& info);
    4925             : 
    4926             : 
    4927             : /**
    4928             :  * Returns a non-empty handle if the interceptor intercepts the request.
    4929             :  * The result is an integer encoding property attributes (like v8::None,
    4930             :  * v8::DontEnum, etc.)
    4931             :  */
    4932             : typedef void (*NamedPropertyQueryCallback)(
    4933             :     Local<String> property,
    4934             :     const PropertyCallbackInfo<Integer>& info);
    4935             : 
    4936             : 
    4937             : /**
    4938             :  * Returns a non-empty handle if the deleter intercepts the request.
    4939             :  * The return value is true if the property could be deleted and false
    4940             :  * otherwise.
    4941             :  */
    4942             : typedef void (*NamedPropertyDeleterCallback)(
    4943             :     Local<String> property,
    4944             :     const PropertyCallbackInfo<Boolean>& info);
    4945             : 
    4946             : 
    4947             : /**
    4948             :  * Returns an array containing the names of the properties the named
    4949             :  * property getter intercepts.
    4950             :  */
    4951             : typedef void (*NamedPropertyEnumeratorCallback)(
    4952             :     const PropertyCallbackInfo<Array>& info);
    4953             : 
    4954             : 
    4955             : // TODO(dcarney): Deprecate and remove previous typedefs, and replace
    4956             : // GenericNamedPropertyFooCallback with just NamedPropertyFooCallback.
    4957             : 
    4958             : /**
    4959             :  * Interceptor for get requests on an object.
    4960             :  *
    4961             :  * Use `info.GetReturnValue().Set()` to set the return value of the
    4962             :  * intercepted get request.
    4963             :  *
    4964             :  * \param property The name of the property for which the request was
    4965             :  * intercepted.
    4966             :  * \param info Information about the intercepted request, such as
    4967             :  * isolate, receiver, return value, or whether running in `'use strict`' mode.
    4968             :  * See `PropertyCallbackInfo`.
    4969             :  *
    4970             :  * \code
    4971             :  *  void GetterCallback(
    4972             :  *    Local<Name> name,
    4973             :  *    const v8::PropertyCallbackInfo<v8::Value>& info) {
    4974             :  *      info.GetReturnValue().Set(v8_num(42));
    4975             :  *  }
    4976             :  *
    4977             :  *  v8::Local<v8::FunctionTemplate> templ =
    4978             :  *      v8::FunctionTemplate::New(isolate);
    4979             :  *  templ->InstanceTemplate()->SetHandler(
    4980             :  *      v8::NamedPropertyHandlerConfiguration(GetterCallback));
    4981             :  *  LocalContext env;
    4982             :  *  env->Global()
    4983             :  *      ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local())
    4984             :  *                                             .ToLocalChecked()
    4985             :  *                                             ->NewInstance(env.local())
    4986             :  *                                             .ToLocalChecked())
    4987             :  *      .FromJust();
    4988             :  *  v8::Local<v8::Value> result = CompileRun("obj.a = 17; obj.a");
    4989             :  *  CHECK(v8_num(42)->Equals(env.local(), result).FromJust());
    4990             :  * \endcode
    4991             :  *
    4992             :  * See also `ObjectTemplate::SetHandler`.
    4993             :  */
    4994             : typedef void (*GenericNamedPropertyGetterCallback)(
    4995             :     Local<Name> property, const PropertyCallbackInfo<Value>& info);
    4996             : 
    4997             : /**
    4998             :  * Interceptor for set requests on an object.
    4999             :  *
    5000             :  * Use `info.GetReturnValue()` to indicate whether the request was intercepted
    5001             :  * or not. If the setter successfully intercepts the request, i.e., if the
    5002             :  * request should not be further executed, call
    5003             :  * `info.GetReturnValue().Set(value)`. If the setter
    5004             :  * did not intercept the request, i.e., if the request should be handled as
    5005             :  * if no interceptor is present, do not not call `Set()`.
    5006             :  *
    5007             :  * \param property The name of the property for which the request was
    5008             :  * intercepted.
    5009             :  * \param value The value which the property will have if the request
    5010             :  * is not intercepted.
    5011             :  * \param info Information about the intercepted request, such as
    5012             :  * isolate, receiver, return value, or whether running in `'use strict'` mode.
    5013             :  * See `PropertyCallbackInfo`.
    5014             :  *
    5015             :  * See also
    5016             :  * `ObjectTemplate::SetHandler.`
    5017             :  */
    5018             : typedef void (*GenericNamedPropertySetterCallback)(
    5019             :     Local<Name> property, Local<Value> value,
    5020             :     const PropertyCallbackInfo<Value>& info);
    5021             : 
    5022             : /**
    5023             :  * Intercepts all requests that query the attributes of the
    5024             :  * property, e.g., getOwnPropertyDescriptor(), propertyIsEnumerable(), and
    5025             :  * defineProperty().
    5026             :  *
    5027             :  * Use `info.GetReturnValue().Set(value)` to set the property attributes. The
    5028             :  * value is an interger encoding a `v8::PropertyAttribute`.
    5029             :  *
    5030             :  * \param property The name of the property for which the request was
    5031             :  * intercepted.
    5032             :  * \param info Information about the intercepted request, such as
    5033             :  * isolate, receiver, return value, or whether running in `'use strict'` mode.
    5034             :  * See `PropertyCallbackInfo`.
    5035             :  *
    5036             :  * \note Some functions query the property attributes internally, even though
    5037             :  * they do not return the attributes. For example, `hasOwnProperty()` can
    5038             :  * trigger this interceptor depending on the state of the object.
    5039             :  *
    5040             :  * See also
    5041             :  * `ObjectTemplate::SetHandler.`
    5042             :  */
    5043             : typedef void (*GenericNamedPropertyQueryCallback)(
    5044             :     Local<Name> property, const PropertyCallbackInfo<Integer>& info);
    5045             : 
    5046             : /**
    5047             :  * Interceptor for delete requests on an object.
    5048             :  *
    5049             :  * Use `info.GetReturnValue()` to indicate whether the request was intercepted
    5050             :  * or not. If the deleter successfully intercepts the request, i.e., if the
    5051             :  * request should not be further executed, call
    5052             :  * `info.GetReturnValue().Set(value)` with a boolean `value`. The `value` is
    5053             :  * used as the return value of `delete`.
    5054             :  *
    5055             :  * \param property The name of the property for which the request was
    5056             :  * intercepted.
    5057             :  * \param info Information about the intercepted request, such as
    5058             :  * isolate, receiver, return value, or whether running in `'use strict'` mode.
    5059             :  * See `PropertyCallbackInfo`.
    5060             :  *
    5061             :  * \note If you need to mimic the behavior of `delete`, i.e., throw in strict
    5062             :  * mode instead of returning false, use `info.ShouldThrowOnError()` to determine
    5063             :  * if you are in strict mode.
    5064             :  *
    5065             :  * See also `ObjectTemplate::SetHandler.`
    5066             :  */
    5067             : typedef void (*GenericNamedPropertyDeleterCallback)(
    5068             :     Local<Name> property, const PropertyCallbackInfo<Boolean>& info);
    5069             : 
    5070             : 
    5071             : /**
    5072             :  * Returns an array containing the names of the properties the named
    5073             :  * property getter intercepts.
    5074             :  */
    5075             : typedef void (*GenericNamedPropertyEnumeratorCallback)(
    5076             :     const PropertyCallbackInfo<Array>& info);
    5077             : 
    5078             : /**
    5079             :  * Interceptor for defineProperty requests on an object.
    5080             :  *
    5081             :  * Use `info.GetReturnValue()` to indicate whether the request was intercepted
    5082             :  * or not. If the definer successfully intercepts the request, i.e., if the
    5083             :  * request should not be further executed, call
    5084             :  * `info.GetReturnValue().Set(value)`. If the definer
    5085             :  * did not intercept the request, i.e., if the request should be handled as
    5086             :  * if no interceptor is present, do not not call `Set()`.
    5087             :  *
    5088             :  * \param property The name of the property for which the request was
    5089             :  * intercepted.
    5090             :  * \param desc The property descriptor which is used to define the
    5091             :  * property if the request is not intercepted.
    5092             :  * \param info Information about the intercepted request, such as
    5093             :  * isolate, receiver, return value, or whether running in `'use strict'` mode.
    5094             :  * See `PropertyCallbackInfo`.
    5095             :  *
    5096             :  * See also `ObjectTemplate::SetHandler`.
    5097             :  */
    5098             : typedef void (*GenericNamedPropertyDefinerCallback)(
    5099             :     Local<Name> property, const PropertyDescriptor& desc,
    5100             :     const PropertyCallbackInfo<Value>& info);
    5101             : 
    5102             : /**
    5103             :  * Interceptor for getOwnPropertyDescriptor requests on an object.
    5104             :  *
    5105             :  * Use `info.GetReturnValue().Set()` to set the return value of the
    5106             :  * intercepted request. The return value must be an object that
    5107             :  * can be converted to a PropertyDescriptor, e.g., a `v8::value` returned from
    5108             :  * `v8::Object::getOwnPropertyDescriptor`.
    5109             :  *
    5110             :  * \param property The name of the property for which the request was
    5111             :  * intercepted.
    5112             :  * \info Information about the intercepted request, such as
    5113             :  * isolate, receiver, return value, or whether running in `'use strict'` mode.
    5114             :  * See `PropertyCallbackInfo`.
    5115             :  *
    5116             :  * \note If GetOwnPropertyDescriptor is intercepted, it will
    5117             :  * always return true, i.e., indicate that the property was found.
    5118             :  *
    5119             :  * See also `ObjectTemplate::SetHandler`.
    5120             :  */
    5121             : typedef void (*GenericNamedPropertyDescriptorCallback)(
    5122             :     Local<Name> property, const PropertyCallbackInfo<Value>& info);
    5123             : 
    5124             : /**
    5125             :  * See `v8::GenericNamedPropertyGetterCallback`.
    5126             :  */
    5127             : typedef void (*IndexedPropertyGetterCallback)(
    5128             :     uint32_t index,
    5129             :     const PropertyCallbackInfo<Value>& info);
    5130             : 
    5131             : /**
    5132             :  * See `v8::GenericNamedPropertySetterCallback`.
    5133             :  */
    5134             : typedef void (*IndexedPropertySetterCallback)(
    5135             :     uint32_t index,
    5136             :     Local<Value> value,
    5137             :     const PropertyCallbackInfo<Value>& info);
    5138             : 
    5139             : /**
    5140             :  * See `v8::GenericNamedPropertyQueryCallback`.
    5141             :  */
    5142             : typedef void (*IndexedPropertyQueryCallback)(
    5143             :     uint32_t index,
    5144             :     const PropertyCallbackInfo<Integer>& info);
    5145             : 
    5146             : /**
    5147             :  * See `v8::GenericNamedPropertyDeleterCallback`.
    5148             :  */
    5149             : typedef void (*IndexedPropertyDeleterCallback)(
    5150             :     uint32_t index,
    5151             :     const PropertyCallbackInfo<Boolean>& info);
    5152             : 
    5153             : /**
    5154             :  * See `v8::GenericNamedPropertyEnumeratorCallback`.
    5155             :  */
    5156             : typedef void (*IndexedPropertyEnumeratorCallback)(
    5157             :     const PropertyCallbackInfo<Array>& info);
    5158             : 
    5159             : /**
    5160             :  * See `v8::GenericNamedPropertyDefinerCallback`.
    5161             :  */
    5162             : typedef void (*IndexedPropertyDefinerCallback)(
    5163             :     uint32_t index, const PropertyDescriptor& desc,
    5164             :     const PropertyCallbackInfo<Value>& info);
    5165             : 
    5166             : /**
    5167             :  * See `v8::GenericNamedPropertyDescriptorCallback`.
    5168             :  */
    5169             : typedef void (*IndexedPropertyDescriptorCallback)(
    5170             :     uint32_t index, const PropertyCallbackInfo<Value>& info);
    5171             : 
    5172             : /**
    5173             :  * Access type specification.
    5174             :  */
    5175             : enum AccessType {
    5176             :   ACCESS_GET,
    5177             :   ACCESS_SET,
    5178             :   ACCESS_HAS,
    5179             :   ACCESS_DELETE,
    5180             :   ACCESS_KEYS
    5181             : };
    5182             : 
    5183             : 
    5184             : /**
    5185             :  * Returns true if the given context should be allowed to access the given
    5186             :  * object.
    5187             :  */
    5188             : typedef bool (*AccessCheckCallback)(Local<Context> accessing_context,
    5189             :                                     Local<Object> accessed_object,
    5190             :                                     Local<Value> data);
    5191             : 
    5192             : /**
    5193             :  * A FunctionTemplate is used to create functions at runtime. There
    5194             :  * can only be one function created from a FunctionTemplate in a
    5195             :  * context.  The lifetime of the created function is equal to the
    5196             :  * lifetime of the context.  So in case the embedder needs to create
    5197             :  * temporary functions that can be collected using Scripts is
    5198             :  * preferred.
    5199             :  *
    5200             :  * Any modification of a FunctionTemplate after first instantiation will trigger
    5201             :  * a crash.
    5202             :  *
    5203             :  * A FunctionTemplate can have properties, these properties are added to the
    5204             :  * function object when it is created.
    5205             :  *
    5206             :  * A FunctionTemplate has a corresponding instance template which is
    5207             :  * used to create object instances when the function is used as a
    5208             :  * constructor. Properties added to the instance template are added to
    5209             :  * each object instance.
    5210             :  *
    5211             :  * A FunctionTemplate can have a prototype template. The prototype template
    5212             :  * is used to create the prototype object of the function.
    5213             :  *
    5214             :  * The following example shows how to use a FunctionTemplate:
    5215             :  *
    5216             :  * \code
    5217             :  *    v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate);
    5218             :  *    t->Set(isolate, "func_property", v8::Number::New(isolate, 1));
    5219             :  *
    5220             :  *    v8::Local<v8::Template> proto_t = t->PrototypeTemplate();
    5221             :  *    proto_t->Set(isolate,
    5222             :  *                 "proto_method",
    5223             :  *                 v8::FunctionTemplate::New(isolate, InvokeCallback));
    5224             :  *    proto_t->Set(isolate, "proto_const", v8::Number::New(isolate, 2));
    5225             :  *
    5226             :  *    v8::Local<v8::ObjectTemplate> instance_t = t->InstanceTemplate();
    5227             :  *    instance_t->SetAccessor(String::NewFromUtf8(isolate, "instance_accessor"),
    5228             :  *                            InstanceAccessorCallback);
    5229             :  *    instance_t->SetNamedPropertyHandler(PropertyHandlerCallback);
    5230             :  *    instance_t->Set(String::NewFromUtf8(isolate, "instance_property"),
    5231             :  *                    Number::New(isolate, 3));
    5232             :  *
    5233             :  *    v8::Local<v8::Function> function = t->GetFunction();
    5234             :  *    v8::Local<v8::Object> instance = function->NewInstance();
    5235             :  * \endcode
    5236             :  *
    5237             :  * Let's use "function" as the JS variable name of the function object
    5238             :  * and "instance" for the instance object created above.  The function
    5239             :  * and the instance will have the following properties:
    5240             :  *
    5241             :  * \code
    5242             :  *   func_property in function == true;
    5243             :  *   function.func_property == 1;
    5244             :  *
    5245             :  *   function.prototype.proto_method() invokes 'InvokeCallback'
    5246             :  *   function.prototype.proto_const == 2;
    5247             :  *
    5248             :  *   instance instanceof function == true;
    5249             :  *   instance.instance_accessor calls 'InstanceAccessorCallback'
    5250             :  *   instance.instance_property == 3;
    5251             :  * \endcode
    5252             :  *
    5253             :  * A FunctionTemplate can inherit from another one by calling the
    5254             :  * FunctionTemplate::Inherit method.  The following graph illustrates
    5255             :  * the semantics of inheritance:
    5256             :  *
    5257             :  * \code
    5258             :  *   FunctionTemplate Parent  -> Parent() . prototype -> { }
    5259             :  *     ^                                                  ^
    5260             :  *     | Inherit(Parent)                                  | .__proto__
    5261             :  *     |                                                  |
    5262             :  *   FunctionTemplate Child   -> Child()  . prototype -> { }
    5263             :  * \endcode
    5264             :  *
    5265             :  * A FunctionTemplate 'Child' inherits from 'Parent', the prototype
    5266             :  * object of the Child() function has __proto__ pointing to the
    5267             :  * Parent() function's prototype object. An instance of the Child
    5268             :  * function has all properties on Parent's instance templates.
    5269             :  *
    5270             :  * Let Parent be the FunctionTemplate initialized in the previous
    5271             :  * section and create a Child FunctionTemplate by:
    5272             :  *
    5273             :  * \code
    5274             :  *   Local<FunctionTemplate> parent = t;
    5275             :  *   Local<FunctionTemplate> child = FunctionTemplate::New();
    5276             :  *   child->Inherit(parent);
    5277             :  *
    5278             :  *   Local<Function> child_function = child->GetFunction();
    5279             :  *   Local<Object> child_instance = child_function->NewInstance();
    5280             :  * \endcode
    5281             :  *
    5282             :  * The Child function and Child instance will have the following
    5283             :  * properties:
    5284             :  *
    5285             :  * \code
    5286             :  *   child_func.prototype.__proto__ == function.prototype;
    5287             :  *   child_instance.instance_accessor calls 'InstanceAccessorCallback'
    5288             :  *   child_instance.instance_property == 3;
    5289             :  * \endcode
    5290             :  */
    5291             : class V8_EXPORT FunctionTemplate : public Template {
    5292             :  public:
    5293             :   /** Creates a function template.*/
    5294             :   static Local<FunctionTemplate> New(
    5295             :       Isolate* isolate, FunctionCallback callback = 0,
    5296             :       Local<Value> data = Local<Value>(),
    5297             :       Local<Signature> signature = Local<Signature>(), int length = 0,
    5298             :       ConstructorBehavior behavior = ConstructorBehavior::kAllow);
    5299             : 
    5300             :   /** Get a template included in the snapshot by index. */
    5301             :   static MaybeLocal<FunctionTemplate> FromSnapshot(Isolate* isolate,
    5302             :                                                    size_t index);
    5303             : 
    5304             :   /**
    5305             :    * Creates a function template backed/cached by a private property.
    5306             :    */
    5307             :   static Local<FunctionTemplate> NewWithCache(
    5308             :       Isolate* isolate, FunctionCallback callback,
    5309             :       Local<Private> cache_property, Local<Value> data = Local<Value>(),
    5310             :       Local<Signature> signature = Local<Signature>(), int length = 0);
    5311             : 
    5312             :   /** Returns the unique function instance in the current execution context.*/
    5313             :   V8_DEPRECATE_SOON("Use maybe version", Local<Function> GetFunction());
    5314             :   V8_WARN_UNUSED_RESULT MaybeLocal<Function> GetFunction(
    5315             :       Local<Context> context);
    5316             : 
    5317             :   /**
    5318             :    * Similar to Context::NewRemoteContext, this creates an instance that
    5319             :    * isn't backed by an actual object.
    5320             :    *
    5321             :    * The InstanceTemplate of this FunctionTemplate must have access checks with
    5322             :    * handlers installed.
    5323             :    */
    5324             :   V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewRemoteInstance();
    5325             : 
    5326             :   /**
    5327             :    * Set the call-handler callback for a FunctionTemplate.  This
    5328             :    * callback is called whenever the function created from this
    5329             :    * FunctionTemplate is called.
    5330             :    */
    5331             :   void SetCallHandler(FunctionCallback callback,
    5332             :                       Local<Value> data = Local<Value>());
    5333             : 
    5334             :   /** Set the predefined length property for the FunctionTemplate. */
    5335             :   void SetLength(int length);
    5336             : 
    5337             :   /** Get the InstanceTemplate. */
    5338             :   Local<ObjectTemplate> InstanceTemplate();
    5339             : 
    5340             :   /**
    5341             :    * Causes the function template to inherit from a parent function template.
    5342             :    * This means the the function's prototype.__proto__ is set to the parent
    5343             :    * function's prototype.
    5344             :    **/
    5345             :   void Inherit(Local<FunctionTemplate> parent);
    5346             : 
    5347             :   /**
    5348             :    * A PrototypeTemplate is the template used to create the prototype object
    5349             :    * of the function created by this template.
    5350             :    */
    5351             :   Local<ObjectTemplate> PrototypeTemplate();
    5352             : 
    5353             :   /**
    5354             :    * A PrototypeProviderTemplate is another function template whose prototype
    5355             :    * property is used for this template. This is mutually exclusive with setting
    5356             :    * a prototype template indirectly by calling PrototypeTemplate() or using
    5357             :    * Inherit().
    5358             :    **/
    5359             :   void SetPrototypeProviderTemplate(Local<FunctionTemplate> prototype_provider);
    5360             : 
    5361             :   /**
    5362             :    * Set the class name of the FunctionTemplate.  This is used for
    5363             :    * printing objects created with the function created from the
    5364             :    * FunctionTemplate as its constructor.
    5365             :    */
    5366             :   void SetClassName(Local<String> name);
    5367             : 
    5368             : 
    5369             :   /**
    5370             :    * When set to true, no access check will be performed on the receiver of a
    5371             :    * function call.  Currently defaults to true, but this is subject to change.
    5372             :    */
    5373             :   void SetAcceptAnyReceiver(bool value);
    5374             : 
    5375             :   /**
    5376             :    * Determines whether the __proto__ accessor ignores instances of
    5377             :    * the function template.  If instances of the function template are
    5378             :    * ignored, __proto__ skips all instances and instead returns the
    5379             :    * next object in the prototype chain.
    5380             :    *
    5381             :    * Call with a value of true to make the __proto__ accessor ignore
    5382             :    * instances of the function template.  Call with a value of false
    5383             :    * to make the __proto__ accessor not ignore instances of the
    5384             :    * function template.  By default, instances of a function template
    5385             :    * are not ignored.
    5386             :    */
    5387             :   void SetHiddenPrototype(bool value);
    5388             : 
    5389             :   /**
    5390             :    * Sets the ReadOnly flag in the attributes of the 'prototype' property
    5391             :    * of functions created from this FunctionTemplate to true.
    5392             :    */
    5393             :   void ReadOnlyPrototype();
    5394             : 
    5395             :   /**
    5396             :    * Removes the prototype property from functions created from this
    5397             :    * FunctionTemplate.
    5398             :    */
    5399             :   void RemovePrototype();
    5400             : 
    5401             :   /**
    5402             :    * Returns true if the given object is an instance of this function
    5403             :    * template.
    5404             :    */
    5405             :   bool HasInstance(Local<Value> object);
    5406             : 
    5407             :  private:
    5408             :   FunctionTemplate();
    5409             :   friend class Context;
    5410             :   friend class ObjectTemplate;
    5411             : };
    5412             : 
    5413             : /**
    5414             :  * Configuration flags for v8::NamedPropertyHandlerConfiguration or
    5415             :  * v8::IndexedPropertyHandlerConfiguration.
    5416             :  */
    5417             : enum class PropertyHandlerFlags {
    5418             :   /**
    5419             :    * None.
    5420             :    */
    5421             :   kNone = 0,
    5422             : 
    5423             :   /**
    5424             :    * See ALL_CAN_READ above.
    5425             :    */
    5426             :   kAllCanRead = 1,
    5427             : 
    5428             :   /** Will not call into interceptor for properties on the receiver or prototype
    5429             :    * chain, i.e., only call into interceptor for properties that do not exist.
    5430             :    * Currently only valid for named interceptors.
    5431             :    */
    5432             :   kNonMasking = 1 << 1,
    5433             : 
    5434             :   /**
    5435             :    * Will not call into interceptor for symbol lookup.  Only meaningful for
    5436             :    * named interceptors.
    5437             :    */
    5438             :   kOnlyInterceptStrings = 1 << 2,
    5439             : };
    5440             : 
    5441             : struct NamedPropertyHandlerConfiguration {
    5442             :   NamedPropertyHandlerConfiguration(
    5443             :       /** Note: getter is required */
    5444             :       GenericNamedPropertyGetterCallback getter = 0,
    5445             :       GenericNamedPropertySetterCallback setter = 0,
    5446             :       GenericNamedPropertyQueryCallback query = 0,
    5447             :       GenericNamedPropertyDeleterCallback deleter = 0,
    5448             :       GenericNamedPropertyEnumeratorCallback enumerator = 0,
    5449             :       Local<Value> data = Local<Value>(),
    5450             :       PropertyHandlerFlags flags = PropertyHandlerFlags::kNone)
    5451             :       : getter(getter),
    5452             :         setter(setter),
    5453             :         query(query),
    5454             :         deleter(deleter),
    5455             :         enumerator(enumerator),
    5456             :         definer(0),
    5457             :         descriptor(0),
    5458             :         data(data),
    5459             :         flags(flags) {}
    5460             : 
    5461             :   NamedPropertyHandlerConfiguration(
    5462             :       GenericNamedPropertyGetterCallback getter,
    5463             :       GenericNamedPropertySetterCallback setter,
    5464             :       GenericNamedPropertyDescriptorCallback descriptor,
    5465             :       GenericNamedPropertyDeleterCallback deleter,
    5466             :       GenericNamedPropertyEnumeratorCallback enumerator,
    5467             :       GenericNamedPropertyDefinerCallback definer,
    5468             :       Local<Value> data = Local<Value>(),
    5469             :       PropertyHandlerFlags flags = PropertyHandlerFlags::kNone)
    5470             :       : getter(getter),
    5471             :         setter(setter),
    5472             :         query(0),
    5473             :         deleter(deleter),
    5474             :         enumerator(enumerator),
    5475             :         definer(definer),
    5476             :         descriptor(descriptor),
    5477             :         data(data),
    5478             :         flags(flags) {}
    5479             : 
    5480             :   GenericNamedPropertyGetterCallback getter;
    5481             :   GenericNamedPropertySetterCallback setter;
    5482             :   GenericNamedPropertyQueryCallback query;
    5483             :   GenericNamedPropertyDeleterCallback deleter;
    5484             :   GenericNamedPropertyEnumeratorCallback enumerator;
    5485             :   GenericNamedPropertyDefinerCallback definer;
    5486             :   GenericNamedPropertyDescriptorCallback descriptor;
    5487             :   Local<Value> data;
    5488             :   PropertyHandlerFlags flags;
    5489             : };
    5490             : 
    5491             : 
    5492             : struct IndexedPropertyHandlerConfiguration {
    5493             :   IndexedPropertyHandlerConfiguration(
    5494             :       /** Note: getter is required */
    5495             :       IndexedPropertyGetterCallback getter = 0,
    5496             :       IndexedPropertySetterCallback setter = 0,
    5497             :       IndexedPropertyQueryCallback query = 0,
    5498             :       IndexedPropertyDeleterCallback deleter = 0,
    5499             :       IndexedPropertyEnumeratorCallback enumerator = 0,
    5500             :       Local<Value> data = Local<Value>(),
    5501             :       PropertyHandlerFlags flags = PropertyHandlerFlags::kNone)
    5502             :       : getter(getter),
    5503             :         setter(setter),
    5504             :         query(query),
    5505             :         deleter(deleter),
    5506             :         enumerator(enumerator),
    5507             :         definer(0),
    5508             :         descriptor(0),
    5509             :         data(data),
    5510             :         flags(flags) {}
    5511             : 
    5512             :   IndexedPropertyHandlerConfiguration(
    5513             :       IndexedPropertyGetterCallback getter,
    5514             :       IndexedPropertySetterCallback setter,
    5515             :       IndexedPropertyDescriptorCallback descriptor,
    5516             :       IndexedPropertyDeleterCallback deleter,
    5517             :       IndexedPropertyEnumeratorCallback enumerator,
    5518             :       IndexedPropertyDefinerCallback definer,
    5519             :       Local<Value> data = Local<Value>(),
    5520             :       PropertyHandlerFlags flags = PropertyHandlerFlags::kNone)
    5521             :       : getter(getter),
    5522             :         setter(setter),
    5523             :         query(0),
    5524             :         deleter(deleter),
    5525             :         enumerator(enumerator),
    5526             :         definer(definer),
    5527             :         descriptor(descriptor),
    5528             :         data(data),
    5529             :         flags(flags) {}
    5530             : 
    5531             :   IndexedPropertyGetterCallback getter;
    5532             :   IndexedPropertySetterCallback setter;
    5533             :   IndexedPropertyQueryCallback query;
    5534             :   IndexedPropertyDeleterCallback deleter;
    5535             :   IndexedPropertyEnumeratorCallback enumerator;
    5536             :   IndexedPropertyDefinerCallback definer;
    5537             :   IndexedPropertyDescriptorCallback descriptor;
    5538             :   Local<Value> data;
    5539             :   PropertyHandlerFlags flags;
    5540             : };
    5541             : 
    5542             : 
    5543             : /**
    5544             :  * An ObjectTemplate is used to create objects at runtime.
    5545             :  *
    5546             :  * Properties added to an ObjectTemplate are added to each object
    5547             :  * created from the ObjectTemplate.
    5548             :  */
    5549             : class V8_EXPORT ObjectTemplate : public Template {
    5550             :  public:
    5551             :   /** Creates an ObjectTemplate. */
    5552             :   static Local<ObjectTemplate> New(
    5553             :       Isolate* isolate,
    5554             :       Local<FunctionTemplate> constructor = Local<FunctionTemplate>());
    5555             :   static V8_DEPRECATED("Use isolate version", Local<ObjectTemplate> New());
    5556             : 
    5557             :   /** Get a template included in the snapshot by index. */
    5558             :   static MaybeLocal<ObjectTemplate> FromSnapshot(Isolate* isolate,
    5559             :                                                  size_t index);
    5560             : 
    5561             :   /** Creates a new instance of this template.*/
    5562             :   V8_DEPRECATE_SOON("Use maybe version", Local<Object> NewInstance());
    5563             :   V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance(Local<Context> context);
    5564             : 
    5565             :   /**
    5566             :    * Sets an accessor on the object template.
    5567             :    *
    5568             :    * Whenever the property with the given name is accessed on objects
    5569             :    * created from this ObjectTemplate the getter and setter callbacks
    5570             :    * are called instead of getting and setting the property directly
    5571             :    * on the JavaScript object.
    5572             :    *
    5573             :    * \param name The name of the property for which an accessor is added.
    5574             :    * \param getter The callback to invoke when getting the property.
    5575             :    * \param setter The callback to invoke when setting the property.
    5576             :    * \param data A piece of data that will be passed to the getter and setter
    5577             :    *   callbacks whenever they are invoked.
    5578             :    * \param settings Access control settings for the accessor. This is a bit
    5579             :    *   field consisting of one of more of
    5580             :    *   DEFAULT = 0, ALL_CAN_READ = 1, or ALL_CAN_WRITE = 2.
    5581             :    *   The default is to not allow cross-context access.
    5582             :    *   ALL_CAN_READ means that all cross-context reads are allowed.
    5583             :    *   ALL_CAN_WRITE means that all cross-context writes are allowed.
    5584             :    *   The combination ALL_CAN_READ | ALL_CAN_WRITE can be used to allow all
    5585             :    *   cross-context access.
    5586             :    * \param attribute The attributes of the property for which an accessor
    5587             :    *   is added.
    5588             :    * \param signature The signature describes valid receivers for the accessor
    5589             :    *   and is used to perform implicit instance checks against them. If the
    5590             :    *   receiver is incompatible (i.e. is not an instance of the constructor as
    5591             :    *   defined by FunctionTemplate::HasInstance()), an implicit TypeError is
    5592             :    *   thrown and no callback is invoked.
    5593             :    */
    5594             :   void SetAccessor(
    5595             :       Local<String> name, AccessorGetterCallback getter,
    5596             :       AccessorSetterCallback setter = 0, Local<Value> data = Local<Value>(),
    5597             :       AccessControl settings = DEFAULT, PropertyAttribute attribute = None,
    5598             :       Local<AccessorSignature> signature = Local<AccessorSignature>());
    5599             :   void SetAccessor(
    5600             :       Local<Name> name, AccessorNameGetterCallback getter,
    5601             :       AccessorNameSetterCallback setter = 0, Local<Value> data = Local<Value>(),
    5602             :       AccessControl settings = DEFAULT, PropertyAttribute attribute = None,
    5603             :       Local<AccessorSignature> signature = Local<AccessorSignature>());
    5604             : 
    5605             :   /**
    5606             :    * Sets a named property handler on the object template.
    5607             :    *
    5608             :    * Whenever a property whose name is a string is accessed on objects created
    5609             :    * from this object template, the provided callback is invoked instead of
    5610             :    * accessing the property directly on the JavaScript object.
    5611             :    *
    5612             :    * SetNamedPropertyHandler() is different from SetHandler(), in
    5613             :    * that the latter can intercept symbol-named properties as well as
    5614             :    * string-named properties when called with a
    5615             :    * NamedPropertyHandlerConfiguration. New code should use SetHandler().
    5616             :    *
    5617             :    * \param getter The callback to invoke when getting a property.
    5618             :    * \param setter The callback to invoke when setting a property.
    5619             :    * \param query The callback to invoke to check if a property is present,
    5620             :    *   and if present, get its attributes.
    5621             :    * \param deleter The callback to invoke when deleting a property.
    5622             :    * \param enumerator The callback to invoke to enumerate all the named
    5623             :    *   properties of an object.
    5624             :    * \param data A piece of data that will be passed to the callbacks
    5625             :    *   whenever they are invoked.
    5626             :    */
    5627             :   // TODO(dcarney): deprecate
    5628             :   void SetNamedPropertyHandler(NamedPropertyGetterCallback getter,
    5629             :                                NamedPropertySetterCallback setter = 0,
    5630             :                                NamedPropertyQueryCallback query = 0,
    5631             :                                NamedPropertyDeleterCallback deleter = 0,
    5632             :                                NamedPropertyEnumeratorCallback enumerator = 0,
    5633             :                                Local<Value> data = Local<Value>());
    5634             : 
    5635             :   /**
    5636             :    * Sets a named property handler on the object template.
    5637             :    *
    5638             :    * Whenever a property whose name is a string or a symbol is accessed on
    5639             :    * objects created from this object template, the provided callback is
    5640             :    * invoked instead of accessing the property directly on the JavaScript
    5641             :    * object.
    5642             :    *
    5643             :    * @param configuration The NamedPropertyHandlerConfiguration that defines the
    5644             :    * callbacks to invoke when accessing a property.
    5645             :    */
    5646             :   void SetHandler(const NamedPropertyHandlerConfiguration& configuration);
    5647             : 
    5648             :   /**
    5649             :    * Sets an indexed property handler on the object template.
    5650             :    *
    5651             :    * Whenever an indexed property is accessed on objects created from
    5652             :    * this object template, the provided callback is invoked instead of
    5653             :    * accessing the property directly on the JavaScript object.
    5654             :    *
    5655             :    * \param getter The callback to invoke when getting a property.
    5656             :    * \param setter The callback to invoke when setting a property.
    5657             :    * \param query The callback to invoke to check if an object has a property.
    5658             :    * \param deleter The callback to invoke when deleting a property.
    5659             :    * \param enumerator The callback to invoke to enumerate all the indexed
    5660             :    *   properties of an object.
    5661             :    * \param data A piece of data that will be passed to the callbacks
    5662             :    *   whenever they are invoked.
    5663             :    */
    5664             :   // TODO(dcarney): deprecate
    5665             :   void SetIndexedPropertyHandler(
    5666             :       IndexedPropertyGetterCallback getter,
    5667             :       IndexedPropertySetterCallback setter = 0,
    5668             :       IndexedPropertyQueryCallback query = 0,
    5669             :       IndexedPropertyDeleterCallback deleter = 0,
    5670             :       IndexedPropertyEnumeratorCallback enumerator = 0,
    5671             :       Local<Value> data = Local<Value>()) {
    5672             :     SetHandler(IndexedPropertyHandlerConfiguration(getter, setter, query,
    5673             :                                                    deleter, enumerator, data));
    5674             :   }
    5675             : 
    5676             :   /**
    5677             :    * Sets an indexed property handler on the object template.
    5678             :    *
    5679             :    * Whenever an indexed property is accessed on objects created from
    5680             :    * this object template, the provided callback is invoked instead of
    5681             :    * accessing the property directly on the JavaScript object.
    5682             :    *
    5683             :    * @param configuration The IndexedPropertyHandlerConfiguration that defines
    5684             :    * the callbacks to invoke when accessing a property.
    5685             :    */
    5686             :   void SetHandler(const IndexedPropertyHandlerConfiguration& configuration);
    5687             : 
    5688             :   /**
    5689             :    * Sets the callback to be used when calling instances created from
    5690             :    * this template as a function.  If no callback is set, instances
    5691             :    * behave like normal JavaScript objects that cannot be called as a
    5692             :    * function.
    5693             :    */
    5694             :   void SetCallAsFunctionHandler(FunctionCallback callback,
    5695             :                                 Local<Value> data = Local<Value>());
    5696             : 
    5697             :   /**
    5698             :    * Mark object instances of the template as undetectable.
    5699             :    *
    5700             :    * In many ways, undetectable objects behave as though they are not
    5701             :    * there.  They behave like 'undefined' in conditionals and when
    5702             :    * printed.  However, properties can be accessed and called as on
    5703             :    * normal objects.
    5704             :    */
    5705             :   void MarkAsUndetectable();
    5706             : 
    5707             :   /**
    5708             :    * Sets access check callback on the object template and enables access
    5709             :    * checks.
    5710             :    *
    5711             :    * When accessing properties on instances of this object template,
    5712             :    * the access check callback will be called to determine whether or
    5713             :    * not to allow cross-context access to the properties.
    5714             :    */
    5715             :   void SetAccessCheckCallback(AccessCheckCallback callback,
    5716             :                               Local<Value> data = Local<Value>());
    5717             : 
    5718             :   /**
    5719             :    * Like SetAccessCheckCallback but invokes an interceptor on failed access
    5720             :    * checks instead of looking up all-can-read properties. You can only use
    5721             :    * either this method or SetAccessCheckCallback, but not both at the same
    5722             :    * time.
    5723             :    */
    5724             :   void SetAccessCheckCallbackAndHandler(
    5725             :       AccessCheckCallback callback,
    5726             :       const NamedPropertyHandlerConfiguration& named_handler,
    5727             :       const IndexedPropertyHandlerConfiguration& indexed_handler,
    5728             :       Local<Value> data = Local<Value>());
    5729             : 
    5730             :   /**
    5731             :    * Gets the number of internal fields for objects generated from
    5732             :    * this template.
    5733             :    */
    5734             :   int InternalFieldCount();
    5735             : 
    5736             :   /**
    5737             :    * Sets the number of internal fields for objects generated from
    5738             :    * this template.
    5739             :    */
    5740             :   void SetInternalFieldCount(int value);
    5741             : 
    5742             :   /**
    5743             :    * Returns true if the object will be an immutable prototype exotic object.
    5744             :    */
    5745             :   bool IsImmutableProto();
    5746             : 
    5747             :   /**
    5748             :    * Makes the ObjectTempate for an immutable prototype exotic object, with an
    5749             :    * immutable __proto__.
    5750             :    */
    5751             :   void SetImmutableProto();
    5752             : 
    5753             :  private:
    5754             :   ObjectTemplate();
    5755             :   static Local<ObjectTemplate> New(internal::Isolate* isolate,
    5756             :                                    Local<FunctionTemplate> constructor);
    5757             :   friend class FunctionTemplate;
    5758             : };
    5759             : 
    5760             : 
    5761             : /**
    5762             :  * A Signature specifies which receiver is valid for a function.
    5763             :  */
    5764             : class V8_EXPORT Signature : public Data {
    5765             :  public:
    5766             :   static Local<Signature> New(
    5767             :       Isolate* isolate,
    5768             :       Local<FunctionTemplate> receiver = Local<FunctionTemplate>());
    5769             : 
    5770             :  private:
    5771             :   Signature();
    5772             : };
    5773             : 
    5774             : 
    5775             : /**
    5776             :  * An AccessorSignature specifies which receivers are valid parameters
    5777             :  * to an accessor callback.
    5778             :  */
    5779             : class V8_EXPORT AccessorSignature : public Data {
    5780             :  public:
    5781             :   static Local<AccessorSignature> New(
    5782             :       Isolate* isolate,
    5783             :       Local<FunctionTemplate> receiver = Local<FunctionTemplate>());
    5784             : 
    5785             :  private:
    5786             :   AccessorSignature();
    5787             : };
    5788             : 
    5789             : 
    5790             : // --- Extensions ---
    5791             : 
    5792      194688 : class V8_EXPORT ExternalOneByteStringResourceImpl
    5793             :     : public String::ExternalOneByteStringResource {
    5794             :  public:
    5795             :   ExternalOneByteStringResourceImpl() : data_(0), length_(0) {}
    5796             :   ExternalOneByteStringResourceImpl(const char* data, size_t length)
    5797      435923 :       : data_(data), length_(length) {}
    5798        6450 :   const char* data() const { return data_; }
    5799        3832 :   size_t length() const { return length_; }
    5800             : 
    5801             :  private:
    5802             :   const char* data_;
    5803             :   size_t length_;
    5804             : };
    5805             : 
    5806             : /**
    5807             :  * Ignore
    5808             :  */
    5809             : class V8_EXPORT Extension {  // NOLINT
    5810             :  public:
    5811             :   // Note that the strings passed into this constructor must live as long
    5812             :   // as the Extension itself.
    5813             :   Extension(const char* name,
    5814             :             const char* source = 0,
    5815             :             int dep_count = 0,
    5816             :             const char** deps = 0,
    5817             :             int source_length = -1);
    5818      194688 :   virtual ~Extension() { }
    5819           0 :   virtual Local<FunctionTemplate> GetNativeFunctionTemplate(
    5820             :       Isolate* isolate, Local<String> name) {
    5821           0 :     return Local<FunctionTemplate>();
    5822             :   }
    5823             : 
    5824             :   const char* name() const { return name_; }
    5825             :   size_t source_length() const { return source_length_; }
    5826             :   const String::ExternalOneByteStringResource* source() const {
    5827             :     return &source_; }
    5828             :   int dependency_count() { return dep_count_; }
    5829             :   const char** dependencies() { return deps_; }
    5830             :   void set_auto_enable(bool value) { auto_enable_ = value; }
    5831             :   bool auto_enable() { return auto_enable_; }
    5832             : 
    5833             :   // Disallow copying and assigning.
    5834             :   Extension(const Extension&) = delete;
    5835             :   void operator=(const Extension&) = delete;
    5836             : 
    5837             :  private:
    5838             :   const char* name_;
    5839             :   size_t source_length_;  // expected to initialize before source_
    5840             :   ExternalOneByteStringResourceImpl source_;
    5841             :   int dep_count_;
    5842             :   const char** deps_;
    5843             :   bool auto_enable_;
    5844             : };
    5845             : 
    5846             : 
    5847             : void V8_EXPORT RegisterExtension(Extension* extension);
    5848             : 
    5849             : 
    5850             : // --- Statics ---
    5851             : 
    5852             : V8_INLINE Local<Primitive> Undefined(Isolate* isolate);
    5853             : V8_INLINE Local<Primitive> Null(Isolate* isolate);
    5854             : V8_INLINE Local<Boolean> True(Isolate* isolate);
    5855             : V8_INLINE Local<Boolean> False(Isolate* isolate);
    5856             : 
    5857             : /**
    5858             :  * A set of constraints that specifies the limits of the runtime's memory use.
    5859             :  * You must set the heap size before initializing the VM - the size cannot be
    5860             :  * adjusted after the VM is initialized.
    5861             :  *
    5862             :  * If you are using threads then you should hold the V8::Locker lock while
    5863             :  * setting the stack limit and you must set a non-default stack limit separately
    5864             :  * for each thread.
    5865             :  *
    5866             :  * The arguments for set_max_semi_space_size, set_max_old_space_size,
    5867             :  * set_max_executable_size, set_code_range_size specify limits in MB.
    5868             :  */
    5869             : class V8_EXPORT ResourceConstraints {
    5870             :  public:
    5871             :   ResourceConstraints();
    5872             : 
    5873             :   /**
    5874             :    * Configures the constraints with reasonable default values based on the
    5875             :    * capabilities of the current device the VM is running on.
    5876             :    *
    5877             :    * \param physical_memory The total amount of physical memory on the current
    5878             :    *   device, in bytes.
    5879             :    * \param virtual_memory_limit The amount of virtual memory on the current
    5880             :    *   device, in bytes, or zero, if there is no limit.
    5881             :    */
    5882             :   void ConfigureDefaults(uint64_t physical_memory,
    5883             :                          uint64_t virtual_memory_limit);
    5884             : 
    5885             :   int max_semi_space_size() const { return max_semi_space_size_; }
    5886             :   void set_max_semi_space_size(int limit_in_mb) {
    5887       28618 :     max_semi_space_size_ = limit_in_mb;
    5888             :   }
    5889             :   int max_old_space_size() const { return max_old_space_size_; }
    5890             :   void set_max_old_space_size(int limit_in_mb) {
    5891       28618 :     max_old_space_size_ = limit_in_mb;
    5892             :   }
    5893             :   int max_executable_size() const { return max_executable_size_; }
    5894             :   void set_max_executable_size(int limit_in_mb) {
    5895       28618 :     max_executable_size_ = limit_in_mb;
    5896             :   }
    5897             :   uint32_t* stack_limit() const { return stack_limit_; }
    5898             :   // Sets an address beyond which the VM's stack may not grow.
    5899             :   void set_stack_limit(uint32_t* value) { stack_limit_ = value; }
    5900             :   size_t code_range_size() const { return code_range_size_; }
    5901             :   void set_code_range_size(size_t limit_in_mb) {
    5902           0 :     code_range_size_ = limit_in_mb;
    5903             :   }
    5904             :   size_t max_zone_pool_size() const { return max_zone_pool_size_; }
    5905             :   void set_max_zone_pool_size(const size_t bytes) {
    5906       28618 :     max_zone_pool_size_ = bytes;
    5907             :   }
    5908             : 
    5909             :  private:
    5910             :   int max_semi_space_size_;
    5911             :   int max_old_space_size_;
    5912             :   int max_executable_size_;
    5913             :   uint32_t* stack_limit_;
    5914             :   size_t code_range_size_;
    5915             :   size_t max_zone_pool_size_;
    5916             : };
    5917             : 
    5918             : 
    5919             : // --- Exceptions ---
    5920             : 
    5921             : 
    5922             : typedef void (*FatalErrorCallback)(const char* location, const char* message);
    5923             : 
    5924             : typedef void (*OOMErrorCallback)(const char* location, bool is_heap_oom);
    5925             : 
    5926             : typedef void (*MessageCallback)(Local<Message> message, Local<Value> data);
    5927             : 
    5928             : // --- Tracing ---
    5929             : 
    5930             : typedef void (*LogEventCallback)(const char* name, int event);
    5931             : 
    5932             : /**
    5933             :  * Create new error objects by calling the corresponding error object
    5934             :  * constructor with the message.
    5935             :  */
    5936             : class V8_EXPORT Exception {
    5937             :  public:
    5938             :   static Local<Value> RangeError(Local<String> message);
    5939             :   static Local<Value> ReferenceError(Local<String> message);
    5940             :   static Local<Value> SyntaxError(Local<String> message);
    5941             :   static Local<Value> TypeError(Local<String> message);
    5942             :   static Local<Value> Error(Local<String> message);
    5943             : 
    5944             :   /**
    5945             :    * Creates an error message for the given exception.
    5946             :    * Will try to reconstruct the original stack trace from the exception value,
    5947             :    * or capture the current stack trace if not available.
    5948             :    */
    5949             :   static Local<Message> CreateMessage(Isolate* isolate, Local<Value> exception);
    5950             :   V8_DEPRECATED("Use version with an Isolate*",
    5951             :                 static Local<Message> CreateMessage(Local<Value> exception));
    5952             : 
    5953             :   /**
    5954             :    * Returns the original stack trace that was captured at the creation time
    5955             :    * of a given exception, or an empty handle if not available.
    5956             :    */
    5957             :   static Local<StackTrace> GetStackTrace(Local<Value> exception);
    5958             : };
    5959             : 
    5960             : 
    5961             : // --- Counters Callbacks ---
    5962             : 
    5963             : typedef int* (*CounterLookupCallback)(const char* name);
    5964             : 
    5965             : typedef void* (*CreateHistogramCallback)(const char* name,
    5966             :                                          int min,
    5967             :                                          int max,
    5968             :                                          size_t buckets);
    5969             : 
    5970             : typedef void (*AddHistogramSampleCallback)(void* histogram, int sample);
    5971             : 
    5972             : // --- Memory Allocation Callback ---
    5973             : enum ObjectSpace {
    5974             :   kObjectSpaceNewSpace = 1 << 0,
    5975             :   kObjectSpaceOldSpace = 1 << 1,
    5976             :   kObjectSpaceCodeSpace = 1 << 2,
    5977             :   kObjectSpaceMapSpace = 1 << 3,
    5978             :   kObjectSpaceLoSpace = 1 << 4,
    5979             :   kObjectSpaceAll = kObjectSpaceNewSpace | kObjectSpaceOldSpace |
    5980             :                     kObjectSpaceCodeSpace | kObjectSpaceMapSpace |
    5981             :                     kObjectSpaceLoSpace
    5982             : };
    5983             : 
    5984             :   enum AllocationAction {
    5985             :     kAllocationActionAllocate = 1 << 0,
    5986             :     kAllocationActionFree = 1 << 1,
    5987             :     kAllocationActionAll = kAllocationActionAllocate | kAllocationActionFree
    5988             :   };
    5989             : 
    5990             : // --- Enter/Leave Script Callback ---
    5991             : typedef void (*BeforeCallEnteredCallback)(Isolate*);
    5992             : typedef void (*CallCompletedCallback)(Isolate*);
    5993             : typedef void (*DeprecatedCallCompletedCallback)();
    5994             : 
    5995             : /**
    5996             :  * HostImportDynamicallyCallback is called when we require the
    5997             :  * embedder to load a module. This is used as part of the dynamic
    5998             :  * import syntax. The behavior of this callback is not specified in
    5999             :  * EcmaScript.
    6000             :  *
    6001             :  * The referrer is the name of the file which calls the dynamic
    6002             :  * import. The referrer can be used to resolve the module location.
    6003             :  *
    6004             :  * The specifier is the name of the module that should be imported.
    6005             :  *
    6006             :  * The DynamicImportResult object is used to signal success or failure
    6007             :  * by calling it's respective methods.
    6008             :  *
    6009             :  */
    6010             : typedef void (*HostImportModuleDynamicallyCallback)(
    6011             :     Isolate* isolate, Local<String> referrer, Local<String> specifier,
    6012             :     Local<DynamicImportResult> result);
    6013             : 
    6014             : /**
    6015             :  * PromiseHook with type kInit is called when a new promise is
    6016             :  * created. When a new promise is created as part of the chain in the
    6017             :  * case of Promise.then or in the intermediate promises created by
    6018             :  * Promise.{race, all}/AsyncFunctionAwait, we pass the parent promise
    6019             :  * otherwise we pass undefined.
    6020             :  *
    6021             :  * PromiseHook with type kResolve is called at the beginning of
    6022             :  * resolve or reject function defined by CreateResolvingFunctions.
    6023             :  *
    6024             :  * PromiseHook with type kBefore is called at the beginning of the
    6025             :  * PromiseReactionJob.
    6026             :  *
    6027             :  * PromiseHook with type kAfter is called right at the end of the
    6028             :  * PromiseReactionJob.
    6029             :  */
    6030             : enum class PromiseHookType { kInit, kResolve, kBefore, kAfter };
    6031             : 
    6032             : typedef void (*PromiseHook)(PromiseHookType type, Local<Promise> promise,
    6033             :                             Local<Value> parent);
    6034             : 
    6035             : // --- Promise Reject Callback ---
    6036             : enum PromiseRejectEvent {
    6037             :   kPromiseRejectWithNoHandler = 0,
    6038             :   kPromiseHandlerAddedAfterReject = 1
    6039             : };
    6040             : 
    6041             : class PromiseRejectMessage {
    6042             :  public:
    6043             :   PromiseRejectMessage(Local<Promise> promise, PromiseRejectEvent event,
    6044             :                        Local<Value> value, Local<StackTrace> stack_trace)
    6045             :       : promise_(promise),
    6046             :         event_(event),
    6047             :         value_(value),
    6048         132 :         stack_trace_(stack_trace) {}
    6049             : 
    6050             :   V8_INLINE Local<Promise> GetPromise() const { return promise_; }
    6051             :   V8_INLINE PromiseRejectEvent GetEvent() const { return event_; }
    6052             :   V8_INLINE Local<Value> GetValue() const { return value_; }
    6053             : 
    6054             :   V8_DEPRECATED("Use v8::Exception::CreateMessage(GetValue())->GetStackTrace()",
    6055             :                 V8_INLINE Local<StackTrace> GetStackTrace() const) {
    6056             :     return stack_trace_;
    6057             :   }
    6058             : 
    6059             :  private:
    6060             :   Local<Promise> promise_;
    6061             :   PromiseRejectEvent event_;
    6062             :   Local<Value> value_;
    6063             :   Local<StackTrace> stack_trace_;
    6064             : };
    6065             : 
    6066             : typedef void (*PromiseRejectCallback)(PromiseRejectMessage message);
    6067             : 
    6068             : // --- Microtasks Callbacks ---
    6069             : typedef void (*MicrotasksCompletedCallback)(Isolate*);
    6070             : typedef void (*MicrotaskCallback)(void* data);
    6071             : 
    6072             : 
    6073             : /**
    6074             :  * Policy for running microtasks:
    6075             :  *   - explicit: microtasks are invoked with Isolate::RunMicrotasks() method;
    6076             :  *   - scoped: microtasks invocation is controlled by MicrotasksScope objects;
    6077             :  *   - auto: microtasks are invoked when the script call depth decrements
    6078             :  *           to zero.
    6079             :  */
    6080             : enum class MicrotasksPolicy { kExplicit, kScoped, kAuto };
    6081             : 
    6082             : 
    6083             : /**
    6084             :  * This scope is used to control microtasks when kScopeMicrotasksInvocation
    6085             :  * is used on Isolate. In this mode every non-primitive call to V8 should be
    6086             :  * done inside some MicrotasksScope.
    6087             :  * Microtasks are executed when topmost MicrotasksScope marked as kRunMicrotasks
    6088             :  * exits.
    6089             :  * kDoNotRunMicrotasks should be used to annotate calls not intended to trigger
    6090             :  * microtasks.
    6091             :  */
    6092             : class V8_EXPORT MicrotasksScope {
    6093             :  public:
    6094             :   enum Type { kRunMicrotasks, kDoNotRunMicrotasks };
    6095             : 
    6096             :   MicrotasksScope(Isolate* isolate, Type type);
    6097             :   ~MicrotasksScope();
    6098             : 
    6099             :   /**
    6100             :    * Runs microtasks if no kRunMicrotasks scope is currently active.
    6101             :    */
    6102             :   static void PerformCheckpoint(Isolate* isolate);
    6103             : 
    6104             :   /**
    6105             :    * Returns current depth of nested kRunMicrotasks scopes.
    6106             :    */
    6107             :   static int GetCurrentDepth(Isolate* isolate);
    6108             : 
    6109             :   /**
    6110             :    * Returns true while microtasks are being executed.
    6111             :    */
    6112             :   static bool IsRunningMicrotasks(Isolate* isolate);
    6113             : 
    6114             :   // Prevent copying.
    6115             :   MicrotasksScope(const MicrotasksScope&) = delete;
    6116             :   MicrotasksScope& operator=(const MicrotasksScope&) = delete;
    6117             : 
    6118             :  private:
    6119             :   internal::Isolate* const isolate_;
    6120             :   bool run_;
    6121             : };
    6122             : 
    6123             : 
    6124             : // --- Failed Access Check Callback ---
    6125             : typedef void (*FailedAccessCheckCallback)(Local<Object> target,
    6126             :                                           AccessType type,
    6127             :                                           Local<Value> data);
    6128             : 
    6129             : // --- AllowCodeGenerationFromStrings callbacks ---
    6130             : 
    6131             : /**
    6132             :  * Callback to check if code generation from strings is allowed. See
    6133             :  * Context::AllowCodeGenerationFromStrings.
    6134             :  */
    6135             : typedef bool (*AllowCodeGenerationFromStringsCallback)(Local<Context> context);
    6136             : 
    6137             : // --- WASM compilation callbacks ---
    6138             : typedef bool (*ExtensionCallback)(const FunctionCallbackInfo<Value>&);
    6139             : 
    6140             : // --- Garbage Collection Callbacks ---
    6141             : 
    6142             : /**
    6143             :  * Applications can register callback functions which will be called before and
    6144             :  * after certain garbage collection operations.  Allocations are not allowed in
    6145             :  * the callback functions, you therefore cannot manipulate objects (set or
    6146             :  * delete properties for example) since it is possible such operations will
    6147             :  * result in the allocation of objects.
    6148             :  */
    6149             : enum GCType {
    6150             :   kGCTypeScavenge = 1 << 0,
    6151             :   kGCTypeMarkSweepCompact = 1 << 1,
    6152             :   kGCTypeIncrementalMarking = 1 << 2,
    6153             :   kGCTypeProcessWeakCallbacks = 1 << 3,
    6154             :   kGCTypeAll = kGCTypeScavenge | kGCTypeMarkSweepCompact |
    6155             :                kGCTypeIncrementalMarking | kGCTypeProcessWeakCallbacks
    6156             : };
    6157             : 
    6158             : /**
    6159             :  * GCCallbackFlags is used to notify additional information about the GC
    6160             :  * callback.
    6161             :  *   - kGCCallbackFlagConstructRetainedObjectInfos: The GC callback is for
    6162             :  *     constructing retained object infos.
    6163             :  *   - kGCCallbackFlagForced: The GC callback is for a forced GC for testing.
    6164             :  *   - kGCCallbackFlagSynchronousPhantomCallbackProcessing: The GC callback
    6165             :  *     is called synchronously without getting posted to an idle task.
    6166             :  *   - kGCCallbackFlagCollectAllAvailableGarbage: The GC callback is called
    6167             :  *     in a phase where V8 is trying to collect all available garbage
    6168             :  *     (e.g., handling a low memory notification).
    6169             :  */
    6170             : enum GCCallbackFlags {
    6171             :   kNoGCCallbackFlags = 0,
    6172             :   kGCCallbackFlagConstructRetainedObjectInfos = 1 << 1,
    6173             :   kGCCallbackFlagForced = 1 << 2,
    6174             :   kGCCallbackFlagSynchronousPhantomCallbackProcessing = 1 << 3,
    6175             :   kGCCallbackFlagCollectAllAvailableGarbage = 1 << 4,
    6176             :   kGCCallbackFlagCollectAllExternalMemory = 1 << 5,
    6177             : };
    6178             : 
    6179             : typedef void (*GCCallback)(GCType type, GCCallbackFlags flags);
    6180             : 
    6181             : typedef void (*InterruptCallback)(Isolate* isolate, void* data);
    6182             : 
    6183             : 
    6184             : /**
    6185             :  * Collection of V8 heap information.
    6186             :  *
    6187             :  * Instances of this class can be passed to v8::V8::HeapStatistics to
    6188             :  * get heap statistics from V8.
    6189             :  */
    6190             : class V8_EXPORT HeapStatistics {
    6191             :  public:
    6192             :   HeapStatistics();
    6193             :   size_t total_heap_size() { return total_heap_size_; }
    6194             :   size_t total_heap_size_executable() { return total_heap_size_executable_; }
    6195             :   size_t total_physical_size() { return total_physical_size_; }
    6196             :   size_t total_available_size() { return total_available_size_; }
    6197             :   size_t used_heap_size() { return used_heap_size_; }
    6198             :   size_t heap_size_limit() { return heap_size_limit_; }
    6199             :   size_t malloced_memory() { return malloced_memory_; }
    6200             :   size_t peak_malloced_memory() { return peak_malloced_memory_; }
    6201             : 
    6202             :   /**
    6203             :    * Returns a 0/1 boolean, which signifies whether the |--zap_code_space|
    6204             :    * option is enabled or not, which makes V8 overwrite heap garbage with a bit
    6205             :    * pattern.
    6206             :    */
    6207             :   size_t does_zap_garbage() { return does_zap_garbage_; }
    6208             : 
    6209             :  private:
    6210             :   size_t total_heap_size_;
    6211             :   size_t total_heap_size_executable_;
    6212             :   size_t total_physical_size_;
    6213             :   size_t total_available_size_;
    6214             :   size_t used_heap_size_;
    6215             :   size_t heap_size_limit_;
    6216             :   size_t malloced_memory_;
    6217             :   size_t peak_malloced_memory_;
    6218             :   bool does_zap_garbage_;
    6219             : 
    6220             :   friend class V8;
    6221             :   friend class Isolate;
    6222             : };
    6223             : 
    6224             : 
    6225             : class V8_EXPORT HeapSpaceStatistics {
    6226             :  public:
    6227             :   HeapSpaceStatistics();
    6228             :   const char* space_name() { return space_name_; }
    6229             :   size_t space_size() { return space_size_; }
    6230             :   size_t space_used_size() { return space_used_size_; }
    6231             :   size_t space_available_size() { return space_available_size_; }
    6232             :   size_t physical_space_size() { return physical_space_size_; }
    6233             : 
    6234             :  private:
    6235             :   const char* space_name_;
    6236             :   size_t space_size_;
    6237             :   size_t space_used_size_;
    6238             :   size_t space_available_size_;
    6239             :   size_t physical_space_size_;
    6240             : 
    6241             :   friend class Isolate;
    6242             : };
    6243             : 
    6244             : 
    6245             : class V8_EXPORT HeapObjectStatistics {
    6246             :  public:
    6247             :   HeapObjectStatistics();
    6248             :   const char* object_type() { return object_type_; }
    6249             :   const char* object_sub_type() { return object_sub_type_; }
    6250             :   size_t object_count() { return object_count_; }
    6251             :   size_t object_size() { return object_size_; }
    6252             : 
    6253             :  private:
    6254             :   const char* object_type_;
    6255             :   const char* object_sub_type_;
    6256             :   size_t object_count_;
    6257             :   size_t object_size_;
    6258             : 
    6259             :   friend class Isolate;
    6260             : };
    6261             : 
    6262             : class V8_EXPORT HeapCodeStatistics {
    6263             :  public:
    6264             :   HeapCodeStatistics();
    6265             :   size_t code_and_metadata_size() { return code_and_metadata_size_; }
    6266             :   size_t bytecode_and_metadata_size() { return bytecode_and_metadata_size_; }
    6267             : 
    6268             :  private:
    6269             :   size_t code_and_metadata_size_;
    6270             :   size_t bytecode_and_metadata_size_;
    6271             : 
    6272             :   friend class Isolate;
    6273             : };
    6274             : 
    6275             : class RetainedObjectInfo;
    6276             : 
    6277             : 
    6278             : /**
    6279             :  * FunctionEntryHook is the type of the profile entry hook called at entry to
    6280             :  * any generated function when function-level profiling is enabled.
    6281             :  *
    6282             :  * \param function the address of the function that's being entered.
    6283             :  * \param return_addr_location points to a location on stack where the machine
    6284             :  *    return address resides. This can be used to identify the caller of
    6285             :  *    \p function, and/or modified to divert execution when \p function exits.
    6286             :  *
    6287             :  * \note the entry hook must not cause garbage collection.
    6288             :  */
    6289             : typedef void (*FunctionEntryHook)(uintptr_t function,
    6290             :                                   uintptr_t return_addr_location);
    6291             : 
    6292             : /**
    6293             :  * A JIT code event is issued each time code is added, moved or removed.
    6294             :  *
    6295             :  * \note removal events are not currently issued.
    6296             :  */
    6297             : struct JitCodeEvent {
    6298             :   enum EventType {
    6299             :     CODE_ADDED,
    6300             :     CODE_MOVED,
    6301             :     CODE_REMOVED,
    6302             :     CODE_ADD_LINE_POS_INFO,
    6303             :     CODE_START_LINE_INFO_RECORDING,
    6304             :     CODE_END_LINE_INFO_RECORDING
    6305             :   };
    6306             :   // Definition of the code position type. The "POSITION" type means the place
    6307             :   // in the source code which are of interest when making stack traces to
    6308             :   // pin-point the source location of a stack frame as close as possible.
    6309             :   // The "STATEMENT_POSITION" means the place at the beginning of each
    6310             :   // statement, and is used to indicate possible break locations.
    6311             :   enum PositionType { POSITION, STATEMENT_POSITION };
    6312             : 
    6313             :   // Type of event.
    6314             :   EventType type;
    6315             :   // Start of the instructions.
    6316             :   void* code_start;
    6317             :   // Size of the instructions.
    6318             :   size_t code_len;
    6319             :   // Script info for CODE_ADDED event.
    6320             :   Local<UnboundScript> script;
    6321             :   // User-defined data for *_LINE_INFO_* event. It's used to hold the source
    6322             :   // code line information which is returned from the
    6323             :   // CODE_START_LINE_INFO_RECORDING event. And it's passed to subsequent
    6324             :   // CODE_ADD_LINE_POS_INFO and CODE_END_LINE_INFO_RECORDING events.
    6325             :   void* user_data;
    6326             : 
    6327             :   struct name_t {
    6328             :     // Name of the object associated with the code, note that the string is not
    6329             :     // zero-terminated.
    6330             :     const char* str;
    6331             :     // Number of chars in str.
    6332             :     size_t len;
    6333             :   };
    6334             : 
    6335             :   struct line_info_t {
    6336             :     // PC offset
    6337             :     size_t offset;
    6338             :     // Code postion
    6339             :     size_t pos;
    6340             :     // The position type.
    6341             :     PositionType position_type;
    6342             :   };
    6343             : 
    6344             :   union {
    6345             :     // Only valid for CODE_ADDED.
    6346             :     struct name_t name;
    6347             : 
    6348             :     // Only valid for CODE_ADD_LINE_POS_INFO
    6349             :     struct line_info_t line_info;
    6350             : 
    6351             :     // New location of instructions. Only valid for CODE_MOVED.
    6352             :     void* new_code_start;
    6353             :   };
    6354             : };
    6355             : 
    6356             : /**
    6357             :  * Option flags passed to the SetRAILMode function.
    6358             :  * See documentation https://developers.google.com/web/tools/chrome-devtools/
    6359             :  * profile/evaluate-performance/rail
    6360             :  */
    6361             : enum RAILMode {
    6362             :   // Response performance mode: In this mode very low virtual machine latency
    6363             :   // is provided. V8 will try to avoid JavaScript execution interruptions.
    6364             :   // Throughput may be throttled.
    6365             :   PERFORMANCE_RESPONSE,
    6366             :   // Animation performance mode: In this mode low virtual machine latency is
    6367             :   // provided. V8 will try to avoid as many JavaScript execution interruptions
    6368             :   // as possible. Throughput may be throttled. This is the default mode.
    6369             :   PERFORMANCE_ANIMATION,
    6370             :   // Idle performance mode: The embedder is idle. V8 can complete deferred work
    6371             :   // in this mode.
    6372             :   PERFORMANCE_IDLE,
    6373             :   // Load performance mode: In this mode high throughput is provided. V8 may
    6374             :   // turn off latency optimizations.
    6375             :   PERFORMANCE_LOAD
    6376             : };
    6377             : 
    6378             : /**
    6379             :  * Option flags passed to the SetJitCodeEventHandler function.
    6380             :  */
    6381             : enum JitCodeEventOptions {
    6382             :   kJitCodeEventDefault = 0,
    6383             :   // Generate callbacks for already existent code.
    6384             :   kJitCodeEventEnumExisting = 1
    6385             : };
    6386             : 
    6387             : 
    6388             : /**
    6389             :  * Callback function passed to SetJitCodeEventHandler.
    6390             :  *
    6391             :  * \param event code add, move or removal event.
    6392             :  */
    6393             : typedef void (*JitCodeEventHandler)(const JitCodeEvent* event);
    6394             : 
    6395             : 
    6396             : /**
    6397             :  * Interface for iterating through all external resources in the heap.
    6398             :  */
    6399             : class V8_EXPORT ExternalResourceVisitor {  // NOLINT
    6400             :  public:
    6401           0 :   virtual ~ExternalResourceVisitor() {}
    6402           0 :   virtual void VisitExternalString(Local<String> string) {}
    6403             : };
    6404             : 
    6405             : 
    6406             : /**
    6407             :  * Interface for iterating through all the persistent handles in the heap.
    6408             :  */
    6409         365 : class V8_EXPORT PersistentHandleVisitor {  // NOLINT
    6410             :  public:
    6411         365 :   virtual ~PersistentHandleVisitor() {}
    6412           0 :   virtual void VisitPersistentHandle(Persistent<Value>* value,
    6413           0 :                                      uint16_t class_id) {}
    6414             : };
    6415             : 
    6416             : /**
    6417             :  * Memory pressure level for the MemoryPressureNotification.
    6418             :  * kNone hints V8 that there is no memory pressure.
    6419             :  * kModerate hints V8 to speed up incremental garbage collection at the cost of
    6420             :  * of higher latency due to garbage collection pauses.
    6421             :  * kCritical hints V8 to free memory as soon as possible. Garbage collection
    6422             :  * pauses at this level will be large.
    6423             :  */
    6424             : enum class MemoryPressureLevel { kNone, kModerate, kCritical };
    6425             : 
    6426             : /**
    6427             :  * Interface for tracing through the embedder heap. During a v8 garbage
    6428             :  * collection, v8 collects hidden fields of all potential wrappers, and at the
    6429             :  * end of its marking phase iterates the collection and asks the embedder to
    6430             :  * trace through its heap and use reporter to report each JavaScript object
    6431             :  * reachable from any of the given wrappers.
    6432             :  *
    6433             :  * Before the first call to the TraceWrappersFrom function TracePrologue will be
    6434             :  * called. When the garbage collection cycle is finished, TraceEpilogue will be
    6435             :  * called.
    6436             :  */
    6437             : class V8_EXPORT EmbedderHeapTracer {
    6438             :  public:
    6439             :   enum ForceCompletionAction { FORCE_COMPLETION, DO_NOT_FORCE_COMPLETION };
    6440             : 
    6441             :   struct AdvanceTracingActions {
    6442             :     explicit AdvanceTracingActions(ForceCompletionAction force_completion_)
    6443           0 :         : force_completion(force_completion_) {}
    6444             : 
    6445             :     ForceCompletionAction force_completion;
    6446             :   };
    6447             : 
    6448             :   /**
    6449             :    * Called by v8 to register internal fields of found wrappers.
    6450             :    *
    6451             :    * The embedder is expected to store them somewhere and trace reachable
    6452             :    * wrappers from them when called through |AdvanceTracing|.
    6453             :    */
    6454             :   virtual void RegisterV8References(
    6455             :       const std::vector<std::pair<void*, void*> >& embedder_fields) = 0;
    6456             : 
    6457             :   /**
    6458             :    * Called at the beginning of a GC cycle.
    6459             :    */
    6460             :   virtual void TracePrologue() = 0;
    6461             : 
    6462             :   /**
    6463             :    * Called to to make a tracing step in the embedder.
    6464             :    *
    6465             :    * The embedder is expected to trace its heap starting from wrappers reported
    6466             :    * by RegisterV8References method, and report back all reachable wrappers.
    6467             :    * Furthermore, the embedder is expected to stop tracing by the given
    6468             :    * deadline.
    6469             :    *
    6470             :    * Returns true if there is still work to do.
    6471             :    */
    6472             :   virtual bool AdvanceTracing(double deadline_in_ms,
    6473             :                               AdvanceTracingActions actions) = 0;
    6474             : 
    6475             :   /**
    6476             :    * Called at the end of a GC cycle.
    6477             :    *
    6478             :    * Note that allocation is *not* allowed within |TraceEpilogue|.
    6479             :    */
    6480             :   virtual void TraceEpilogue() = 0;
    6481             : 
    6482             :   /**
    6483             :    * Called upon entering the final marking pause. No more incremental marking
    6484             :    * steps will follow this call.
    6485             :    */
    6486             :   virtual void EnterFinalPause() = 0;
    6487             : 
    6488             :   /**
    6489             :    * Called when tracing is aborted.
    6490             :    *
    6491             :    * The embedder is expected to throw away all intermediate data and reset to
    6492             :    * the initial state.
    6493             :    */
    6494             :   virtual void AbortTracing() = 0;
    6495             : 
    6496             :   /**
    6497             :    * Returns the number of wrappers that are still to be traced by the embedder.
    6498             :    */
    6499           0 :   virtual size_t NumberOfWrappersToTrace() { return 0; }
    6500             : 
    6501             :  protected:
    6502             :   virtual ~EmbedderHeapTracer() = default;
    6503             : };
    6504             : 
    6505             : /**
    6506             :  * Callback and supporting data used in SnapshotCreator to implement embedder
    6507             :  * logic to serialize internal fields.
    6508             :  */
    6509             : struct SerializeInternalFieldsCallback {
    6510             :   typedef StartupData (*CallbackFunction)(Local<Object> holder, int index,
    6511             :                                           void* data);
    6512             :   SerializeInternalFieldsCallback(CallbackFunction function = nullptr,
    6513             :                                   void* data_arg = nullptr)
    6514          97 :       : callback(function), data(data_arg) {}
    6515             :   CallbackFunction callback;
    6516             :   void* data;
    6517             : };
    6518             : // Note that these fields are called "internal fields" in the API and called
    6519             : // "embedder fields" within V8.
    6520             : typedef SerializeInternalFieldsCallback SerializeEmbedderFieldsCallback;
    6521             : 
    6522             : /**
    6523             :  * Callback and supporting data used to implement embedder logic to deserialize
    6524             :  * internal fields.
    6525             :  */
    6526             : struct DeserializeInternalFieldsCallback {
    6527             :   typedef void (*CallbackFunction)(Local<Object> holder, int index,
    6528             :                                    StartupData payload, void* data);
    6529             :   DeserializeInternalFieldsCallback(CallbackFunction function = nullptr,
    6530             :                                     void* data_arg = nullptr)
    6531      107218 :       : callback(function), data(data_arg) {}
    6532             :   void (*callback)(Local<Object> holder, int index, StartupData payload,
    6533             :                    void* data);
    6534             :   void* data;
    6535             : };
    6536             : typedef DeserializeInternalFieldsCallback DeserializeEmbedderFieldsCallback;
    6537             : 
    6538             : /**
    6539             :  * Isolate represents an isolated instance of the V8 engine.  V8 isolates have
    6540             :  * completely separate states.  Objects from one isolate must not be used in
    6541             :  * other isolates.  The embedder can create multiple isolates and use them in
    6542             :  * parallel in multiple threads.  An isolate can be entered by at most one
    6543             :  * thread at any given time.  The Locker/Unlocker API must be used to
    6544             :  * synchronize.
    6545             :  */
    6546             : class V8_EXPORT Isolate {
    6547             :  public:
    6548             :   /**
    6549             :    * Initial configuration parameters for a new Isolate.
    6550             :    */
    6551             :   struct CreateParams {
    6552             :     CreateParams()
    6553             :         : entry_hook(nullptr),
    6554             :           code_event_handler(nullptr),
    6555             :           snapshot_blob(nullptr),
    6556             :           counter_lookup_callback(nullptr),
    6557             :           create_histogram_callback(nullptr),
    6558             :           add_histogram_sample_callback(nullptr),
    6559             :           array_buffer_allocator(nullptr),
    6560             :           external_references(nullptr),
    6561             :           allow_atomics_wait(true),
    6562       29457 :           host_import_module_dynamically_callback_(nullptr) {}
    6563             : 
    6564             :     /**
    6565             :      * The optional entry_hook allows the host application to provide the
    6566             :      * address of a function that's invoked on entry to every V8-generated
    6567             :      * function.  Note that entry_hook is invoked at the very start of each
    6568             :      * generated function.
    6569             :      * An entry_hook can only be provided in no-snapshot builds; in snapshot
    6570             :      * builds it must be nullptr.
    6571             :      */
    6572             :     FunctionEntryHook entry_hook;
    6573             : 
    6574             :     /**
    6575             :      * Allows the host application to provide the address of a function that is
    6576             :      * notified each time code is added, moved or removed.
    6577             :      */
    6578             :     JitCodeEventHandler code_event_handler;
    6579             : 
    6580             :     /**
    6581             :      * ResourceConstraints to use for the new Isolate.
    6582             :      */
    6583             :     ResourceConstraints constraints;
    6584             : 
    6585             :     /**
    6586             :      * Explicitly specify a startup snapshot blob. The embedder owns the blob.
    6587             :      */
    6588             :     StartupData* snapshot_blob;
    6589             : 
    6590             : 
    6591             :     /**
    6592             :      * Enables the host application to provide a mechanism for recording
    6593             :      * statistics counters.
    6594             :      */
    6595             :     CounterLookupCallback counter_lookup_callback;
    6596             : 
    6597             :     /**
    6598             :      * Enables the host application to provide a mechanism for recording
    6599             :      * histograms. The CreateHistogram function returns a
    6600             :      * histogram which will later be passed to the AddHistogramSample
    6601             :      * function.
    6602             :      */
    6603             :     CreateHistogramCallback create_histogram_callback;
    6604             :     AddHistogramSampleCallback add_histogram_sample_callback;
    6605             : 
    6606             :     /**
    6607             :      * The ArrayBuffer::Allocator to use for allocating and freeing the backing
    6608             :      * store of ArrayBuffers.
    6609             :      */
    6610             :     ArrayBuffer::Allocator* array_buffer_allocator;
    6611             : 
    6612             :     /**
    6613             :      * Specifies an optional nullptr-terminated array of raw addresses in the
    6614             :      * embedder that V8 can match against during serialization and use for
    6615             :      * deserialization. This array and its content must stay valid for the
    6616             :      * entire lifetime of the isolate.
    6617             :      */
    6618             :     intptr_t* external_references;
    6619             : 
    6620             :     /**
    6621             :      * Whether calling Atomics.wait (a function that may block) is allowed in
    6622             :      * this isolate. This can also be configured via SetAllowAtomicsWait.
    6623             :      */
    6624             :     bool allow_atomics_wait;
    6625             : 
    6626             :     /**
    6627             :      * This is an unfinished experimental feature, and is only exposed
    6628             :      * here for internal testing purposes. DO NOT USE.
    6629             :      *
    6630             :      * This specifies the callback called by the upcoming dynamic
    6631             :      * import() language feature to load modules.
    6632             :      */
    6633             :     HostImportModuleDynamicallyCallback
    6634             :         host_import_module_dynamically_callback_;
    6635             :   };
    6636             : 
    6637             : 
    6638             :   /**
    6639             :    * Stack-allocated class which sets the isolate for all operations
    6640             :    * executed within a local scope.
    6641             :    */
    6642             :   class V8_EXPORT Scope {
    6643             :    public:
    6644             :     explicit Scope(Isolate* isolate) : isolate_(isolate) {
    6645       29457 :       isolate->Enter();
    6646             :     }
    6647             : 
    6648       29457 :     ~Scope() { isolate_->Exit(); }
    6649             : 
    6650             :     // Prevent copying of Scope objects.
    6651             :     Scope(const Scope&) = delete;
    6652             :     Scope& operator=(const Scope&) = delete;
    6653             : 
    6654             :    private:
    6655             :     Isolate* const isolate_;
    6656             :   };
    6657             : 
    6658             : 
    6659             :   /**
    6660             :    * Assert that no Javascript code is invoked.
    6661             :    */
    6662             :   class V8_EXPORT DisallowJavascriptExecutionScope {
    6663             :    public:
    6664             :     enum OnFailure { CRASH_ON_FAILURE, THROW_ON_FAILURE };
    6665             : 
    6666             :     DisallowJavascriptExecutionScope(Isolate* isolate, OnFailure on_failure);
    6667             :     ~DisallowJavascriptExecutionScope();
    6668             : 
    6669             :     // Prevent copying of Scope objects.
    6670             :     DisallowJavascriptExecutionScope(const DisallowJavascriptExecutionScope&) =
    6671             :         delete;
    6672             :     DisallowJavascriptExecutionScope& operator=(
    6673             :         const DisallowJavascriptExecutionScope&) = delete;
    6674             : 
    6675             :    private:
    6676             :     bool on_failure_;
    6677             :     void* internal_;
    6678             :   };
    6679             : 
    6680             : 
    6681             :   /**
    6682             :    * Introduce exception to DisallowJavascriptExecutionScope.
    6683             :    */
    6684             :   class V8_EXPORT AllowJavascriptExecutionScope {
    6685             :    public:
    6686             :     explicit AllowJavascriptExecutionScope(Isolate* isolate);
    6687             :     ~AllowJavascriptExecutionScope();
    6688             : 
    6689             :     // Prevent copying of Scope objects.
    6690             :     AllowJavascriptExecutionScope(const AllowJavascriptExecutionScope&) =
    6691             :         delete;
    6692             :     AllowJavascriptExecutionScope& operator=(
    6693             :         const AllowJavascriptExecutionScope&) = delete;
    6694             : 
    6695             :    private:
    6696             :     void* internal_throws_;
    6697             :     void* internal_assert_;
    6698             :   };
    6699             : 
    6700             :   /**
    6701             :    * Do not run microtasks while this scope is active, even if microtasks are
    6702             :    * automatically executed otherwise.
    6703             :    */
    6704             :   class V8_EXPORT SuppressMicrotaskExecutionScope {
    6705             :    public:
    6706             :     explicit SuppressMicrotaskExecutionScope(Isolate* isolate);
    6707             :     ~SuppressMicrotaskExecutionScope();
    6708             : 
    6709             :     // Prevent copying of Scope objects.
    6710             :     SuppressMicrotaskExecutionScope(const SuppressMicrotaskExecutionScope&) =
    6711             :         delete;
    6712             :     SuppressMicrotaskExecutionScope& operator=(
    6713             :         const SuppressMicrotaskExecutionScope&) = delete;
    6714             : 
    6715             :    private:
    6716             :     internal::Isolate* const isolate_;
    6717             :   };
    6718             : 
    6719             :   /**
    6720             :    * Types of garbage collections that can be requested via
    6721             :    * RequestGarbageCollectionForTesting.
    6722             :    */
    6723             :   enum GarbageCollectionType {
    6724             :     kFullGarbageCollection,
    6725             :     kMinorGarbageCollection
    6726             :   };
    6727             : 
    6728             :   /**
    6729             :    * Features reported via the SetUseCounterCallback callback. Do not change
    6730             :    * assigned numbers of existing items; add new features to the end of this
    6731             :    * list.
    6732             :    */
    6733             :   enum UseCounterFeature {
    6734             :     kUseAsm = 0,
    6735             :     kBreakIterator = 1,
    6736             :     kLegacyConst = 2,
    6737             :     kMarkDequeOverflow = 3,
    6738             :     kStoreBufferOverflow = 4,
    6739             :     kSlotsBufferOverflow = 5,
    6740             :     kObjectObserve = 6,
    6741             :     kForcedGC = 7,
    6742             :     kSloppyMode = 8,
    6743             :     kStrictMode = 9,
    6744             :     kStrongMode = 10,
    6745             :     kRegExpPrototypeStickyGetter = 11,
    6746             :     kRegExpPrototypeToString = 12,
    6747             :     kRegExpPrototypeUnicodeGetter = 13,
    6748             :     kIntlV8Parse = 14,
    6749             :     kIntlPattern = 15,
    6750             :     kIntlResolved = 16,
    6751             :     kPromiseChain = 17,
    6752             :     kPromiseAccept = 18,
    6753             :     kPromiseDefer = 19,
    6754             :     kHtmlCommentInExternalScript = 20,
    6755             :     kHtmlComment = 21,
    6756             :     kSloppyModeBlockScopedFunctionRedefinition = 22,
    6757             :     kForInInitializer = 23,
    6758             :     kArrayProtectorDirtied = 24,
    6759             :     kArraySpeciesModified = 25,
    6760             :     kArrayPrototypeConstructorModified = 26,
    6761             :     kArrayInstanceProtoModified = 27,
    6762             :     kArrayInstanceConstructorModified = 28,
    6763             :     kLegacyFunctionDeclaration = 29,
    6764             :     kRegExpPrototypeSourceGetter = 30,
    6765             :     kRegExpPrototypeOldFlagGetter = 31,
    6766             :     kDecimalWithLeadingZeroInStrictMode = 32,
    6767             :     kLegacyDateParser = 33,
    6768             :     kDefineGetterOrSetterWouldThrow = 34,
    6769             :     kFunctionConstructorReturnedUndefined = 35,
    6770             :     kAssigmentExpressionLHSIsCallInSloppy = 36,
    6771             :     kAssigmentExpressionLHSIsCallInStrict = 37,
    6772             :     kPromiseConstructorReturnedUndefined = 38,
    6773             : 
    6774             :     // If you add new values here, you'll also need to update Chromium's:
    6775             :     // UseCounter.h, V8PerIsolateData.cpp, histograms.xml
    6776             :     kUseCounterFeatureCount  // This enum value must be last.
    6777             :   };
    6778             : 
    6779             :   enum MessageErrorLevel {
    6780             :     kMessageLog = (1 << 0),
    6781             :     kMessageDebug = (1 << 1),
    6782             :     kMessageInfo = (1 << 2),
    6783             :     kMessageError = (1 << 3),
    6784             :     kMessageWarning = (1 << 4),
    6785             :     kMessageAll = kMessageLog | kMessageDebug | kMessageInfo | kMessageError |
    6786             :                   kMessageWarning,
    6787             :   };
    6788             : 
    6789             :   typedef void (*UseCounterCallback)(Isolate* isolate,
    6790             :                                      UseCounterFeature feature);
    6791             : 
    6792             : 
    6793             :   /**
    6794             :    * Creates a new isolate.  Does not change the currently entered
    6795             :    * isolate.
    6796             :    *
    6797             :    * When an isolate is no longer used its resources should be freed
    6798             :    * by calling Dispose().  Using the delete operator is not allowed.
    6799             :    *
    6800             :    * V8::Initialize() must have run prior to this.
    6801             :    */
    6802             :   static Isolate* New(const CreateParams& params);
    6803             : 
    6804             :   /**
    6805             :    * Returns the entered isolate for the current thread or NULL in
    6806             :    * case there is no current isolate.
    6807             :    *
    6808             :    * This method must not be invoked before V8::Initialize() was invoked.
    6809             :    */
    6810             :   static Isolate* GetCurrent();
    6811             : 
    6812             :   /**
    6813             :    * Custom callback used by embedders to help V8 determine if it should abort
    6814             :    * when it throws and no internal handler is predicted to catch the
    6815             :    * exception. If --abort-on-uncaught-exception is used on the command line,
    6816             :    * then V8 will abort if either:
    6817             :    * - no custom callback is set.
    6818             :    * - the custom callback set returns true.
    6819             :    * Otherwise, the custom callback will not be called and V8 will not abort.
    6820             :    */
    6821             :   typedef bool (*AbortOnUncaughtExceptionCallback)(Isolate*);
    6822             :   void SetAbortOnUncaughtExceptionCallback(
    6823             :       AbortOnUncaughtExceptionCallback callback);
    6824             : 
    6825             :   /**
    6826             :    * Optional notification that the system is running low on memory.
    6827             :    * V8 uses these notifications to guide heuristics.
    6828             :    * It is allowed to call this function from another thread while
    6829             :    * the isolate is executing long running JavaScript code.
    6830             :    */
    6831             :   void MemoryPressureNotification(MemoryPressureLevel level);
    6832             : 
    6833             :   /**
    6834             :    * Methods below this point require holding a lock (using Locker) in
    6835             :    * a multi-threaded environment.
    6836             :    */
    6837             : 
    6838             :   /**
    6839             :    * Sets this isolate as the entered one for the current thread.
    6840             :    * Saves the previously entered one (if any), so that it can be
    6841             :    * restored when exiting.  Re-entering an isolate is allowed.
    6842             :    */
    6843             :   void Enter();
    6844             : 
    6845             :   /**
    6846             :    * Exits this isolate by restoring the previously entered one in the
    6847             :    * current thread.  The isolate may still stay the same, if it was
    6848             :    * entered more than once.
    6849             :    *
    6850             :    * Requires: this == Isolate::GetCurrent().
    6851             :    */
    6852             :   void Exit();
    6853             : 
    6854             :   /**
    6855             :    * Disposes the isolate.  The isolate must not be entered by any
    6856             :    * thread to be disposable.
    6857             :    */
    6858             :   void Dispose();
    6859             : 
    6860             :   /**
    6861             :    * Dumps activated low-level V8 internal stats. This can be used instead
    6862             :    * of performing a full isolate disposal.
    6863             :    */
    6864             :   void DumpAndResetStats();
    6865             : 
    6866             :   /**
    6867             :    * Discards all V8 thread-specific data for the Isolate. Should be used
    6868             :    * if a thread is terminating and it has used an Isolate that will outlive
    6869             :    * the thread -- all thread-specific data for an Isolate is discarded when
    6870             :    * an Isolate is disposed so this call is pointless if an Isolate is about
    6871             :    * to be Disposed.
    6872             :    */
    6873             :   void DiscardThreadSpecificMetadata();
    6874             : 
    6875             :   /**
    6876             :    * Associate embedder-specific data with the isolate. |slot| has to be
    6877             :    * between 0 and GetNumberOfDataSlots() - 1.
    6878             :    */
    6879             :   V8_INLINE void SetData(uint32_t slot, void* data);
    6880             : 
    6881             :   /**
    6882             :    * Retrieve embedder-specific data from the isolate.
    6883             :    * Returns NULL if SetData has never been called for the given |slot|.
    6884             :    */
    6885             :   V8_INLINE void* GetData(uint32_t slot);
    6886             : 
    6887             :   /**
    6888             :    * Returns the maximum number of available embedder data slots. Valid slots
    6889             :    * are in the range of 0 - GetNumberOfDataSlots() - 1.
    6890             :    */
    6891             :   V8_INLINE static uint32_t GetNumberOfDataSlots();
    6892             : 
    6893             :   /**
    6894             :    * Get statistics about the heap memory usage.
    6895             :    */
    6896             :   void GetHeapStatistics(HeapStatistics* heap_statistics);
    6897             : 
    6898             :   /**
    6899             :    * Returns the number of spaces in the heap.
    6900             :    */
    6901             :   size_t NumberOfHeapSpaces();
    6902             : 
    6903             :   /**
    6904             :    * Get the memory usage of a space in the heap.
    6905             :    *
    6906             :    * \param space_statistics The HeapSpaceStatistics object to fill in
    6907             :    *   statistics.
    6908             :    * \param index The index of the space to get statistics from, which ranges
    6909             :    *   from 0 to NumberOfHeapSpaces() - 1.
    6910             :    * \returns true on success.
    6911             :    */
    6912             :   bool GetHeapSpaceStatistics(HeapSpaceStatistics* space_statistics,
    6913             :                               size_t index);
    6914             : 
    6915             :   /**
    6916             :    * Returns the number of types of objects tracked in the heap at GC.
    6917             :    */
    6918             :   size_t NumberOfTrackedHeapObjectTypes();
    6919             : 
    6920             :   /**
    6921             :    * Get statistics about objects in the heap.
    6922             :    *
    6923             :    * \param object_statistics The HeapObjectStatistics object to fill in
    6924             :    *   statistics of objects of given type, which were live in the previous GC.
    6925             :    * \param type_index The index of the type of object to fill details about,
    6926             :    *   which ranges from 0 to NumberOfTrackedHeapObjectTypes() - 1.
    6927             :    * \returns true on success.
    6928             :    */
    6929             :   bool GetHeapObjectStatisticsAtLastGC(HeapObjectStatistics* object_statistics,
    6930             :                                        size_t type_index);
    6931             : 
    6932             :   /**
    6933             :    * Get statistics about code and its metadata in the heap.
    6934             :    *
    6935             :    * \param object_statistics The HeapCodeStatistics object to fill in
    6936             :    *   statistics of code, bytecode and their metadata.
    6937             :    * \returns true on success.
    6938             :    */
    6939             :   bool GetHeapCodeAndMetadataStatistics(HeapCodeStatistics* object_statistics);
    6940             : 
    6941             :   /**
    6942             :    * Get a call stack sample from the isolate.
    6943             :    * \param state Execution state.
    6944             :    * \param frames Caller allocated buffer to store stack frames.
    6945             :    * \param frames_limit Maximum number of frames to capture. The buffer must
    6946             :    *                     be large enough to hold the number of frames.
    6947             :    * \param sample_info The sample info is filled up by the function
    6948             :    *                    provides number of actual captured stack frames and
    6949             :    *                    the current VM state.
    6950             :    * \note GetStackSample should only be called when the JS thread is paused or
    6951             :    *       interrupted. Otherwise the behavior is undefined.
    6952             :    */
    6953             :   void GetStackSample(const RegisterState& state, void** frames,
    6954             :                       size_t frames_limit, SampleInfo* sample_info);
    6955             : 
    6956             :   /**
    6957             :    * Adjusts the amount of registered external memory. Used to give V8 an
    6958             :    * indication of the amount of externally allocated memory that is kept alive
    6959             :    * by JavaScript objects. V8 uses this to decide when to perform global
    6960             :    * garbage collections. Registering externally allocated memory will trigger
    6961             :    * global garbage collections more often than it would otherwise in an attempt
    6962             :    * to garbage collect the JavaScript objects that keep the externally
    6963             :    * allocated memory alive.
    6964             :    *
    6965             :    * \param change_in_bytes the change in externally allocated memory that is
    6966             :    *   kept alive by JavaScript objects.
    6967             :    * \returns the adjusted value.
    6968             :    */
    6969             :   V8_INLINE int64_t
    6970             :       AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes);
    6971             : 
    6972             :   /**
    6973             :    * Returns the number of phantom handles without callbacks that were reset
    6974             :    * by the garbage collector since the last call to this function.
    6975             :    */
    6976             :   size_t NumberOfPhantomHandleResetsSinceLastCall();
    6977             : 
    6978             :   /**
    6979             :    * Returns heap profiler for this isolate. Will return NULL until the isolate
    6980             :    * is initialized.
    6981             :    */
    6982             :   HeapProfiler* GetHeapProfiler();
    6983             : 
    6984             :   /**
    6985             :    * Returns CPU profiler for this isolate. Will return NULL unless the isolate
    6986             :    * is initialized. It is the embedder's responsibility to stop all CPU
    6987             :    * profiling activities if it has started any.
    6988             :    */
    6989             :   V8_DEPRECATE_SOON("CpuProfiler should be created with CpuProfiler::New call.",
    6990             :                     CpuProfiler* GetCpuProfiler());
    6991             : 
    6992             :   /** Returns true if this isolate has a current context. */
    6993             :   bool InContext();
    6994             : 
    6995             :   /**
    6996             :    * Returns the context of the currently running JavaScript, or the context
    6997             :    * on the top of the stack if no JavaScript is running.
    6998             :    */
    6999             :   Local<Context> GetCurrentContext();
    7000             : 
    7001             :   /**
    7002             :    * Returns the context of the calling JavaScript code.  That is the
    7003             :    * context of the top-most JavaScript frame.  If there are no
    7004             :    * JavaScript frames an empty handle is returned.
    7005             :    */
    7006             :   V8_DEPRECATE_SOON(
    7007             :       "Calling context concept is not compatible with tail calls, and will be "
    7008             :       "removed.",
    7009             :       Local<Context> GetCallingContext());
    7010             : 
    7011             :   /** Returns the last context entered through V8's C++ API. */
    7012             :   Local<Context> GetEnteredContext();
    7013             : 
    7014             :   /**
    7015             :    * Returns either the last context entered through V8's C++ API, or the
    7016             :    * context of the currently running microtask while processing microtasks.
    7017             :    * If a context is entered while executing a microtask, that context is
    7018             :    * returned.
    7019             :    */
    7020             :   Local<Context> GetEnteredOrMicrotaskContext();
    7021             : 
    7022             :   /**
    7023             :    * Schedules an exception to be thrown when returning to JavaScript.  When an
    7024             :    * exception has been scheduled it is illegal to invoke any JavaScript
    7025             :    * operation; the caller must return immediately and only after the exception
    7026             :    * has been handled does it become legal to invoke JavaScript operations.
    7027             :    */
    7028             :   Local<Value> ThrowException(Local<Value> exception);
    7029             : 
    7030             :   typedef void (*GCCallback)(Isolate* isolate, GCType type,
    7031             :                              GCCallbackFlags flags);
    7032             : 
    7033             :   /**
    7034             :    * Enables the host application to receive a notification before a
    7035             :    * garbage collection. Allocations are allowed in the callback function,
    7036             :    * but the callback is not re-entrant: if the allocation inside it will
    7037             :    * trigger the garbage collection, the callback won't be called again.
    7038             :    * It is possible to specify the GCType filter for your callback. But it is
    7039             :    * not possible to register the same callback function two times with
    7040             :    * different GCType filters.
    7041             :    */
    7042             :   void AddGCPrologueCallback(GCCallback callback,
    7043             :                              GCType gc_type_filter = kGCTypeAll);
    7044             : 
    7045             :   /**
    7046             :    * This function removes callback which was installed by
    7047             :    * AddGCPrologueCallback function.
    7048             :    */
    7049             :   void RemoveGCPrologueCallback(GCCallback callback);
    7050             : 
    7051             :   /**
    7052             :    * Sets the embedder heap tracer for the isolate.
    7053             :    */
    7054             :   void SetEmbedderHeapTracer(EmbedderHeapTracer* tracer);
    7055             : 
    7056             :   /**
    7057             :    * Enables the host application to receive a notification after a
    7058             :    * garbage collection. Allocations are allowed in the callback function,
    7059             :    * but the callback is not re-entrant: if the allocation inside it will
    7060             :    * trigger the garbage collection, the callback won't be called again.
    7061             :    * It is possible to specify the GCType filter for your callback. But it is
    7062             :    * not possible to register the same callback function two times with
    7063             :    * different GCType filters.
    7064             :    */
    7065             :   void AddGCEpilogueCallback(GCCallback callback,
    7066             :                              GCType gc_type_filter = kGCTypeAll);
    7067             : 
    7068             :   /**
    7069             :    * This function removes callback which was installed by
    7070             :    * AddGCEpilogueCallback function.
    7071             :    */
    7072             :   void RemoveGCEpilogueCallback(GCCallback callback);
    7073             : 
    7074             :   /**
    7075             :    * Forcefully terminate the current thread of JavaScript execution
    7076             :    * in the given isolate.
    7077             :    *
    7078             :    * This method can be used by any thread even if that thread has not
    7079             :    * acquired the V8 lock with a Locker object.
    7080             :    */
    7081             :   void TerminateExecution();
    7082             : 
    7083             :   /**
    7084             :    * Is V8 terminating JavaScript execution.
    7085             :    *
    7086             :    * Returns true if JavaScript execution is currently terminating
    7087             :    * because of a call to TerminateExecution.  In that case there are
    7088             :    * still JavaScript frames on the stack and the termination
    7089             :    * exception is still active.
    7090             :    */
    7091             :   bool IsExecutionTerminating();
    7092             : 
    7093             :   /**
    7094             :    * Resume execution capability in the given isolate, whose execution
    7095             :    * was previously forcefully terminated using TerminateExecution().
    7096             :    *
    7097             :    * When execution is forcefully terminated using TerminateExecution(),
    7098             :    * the isolate can not resume execution until all JavaScript frames
    7099             :    * have propagated the uncatchable exception which is generated.  This
    7100             :    * method allows the program embedding the engine to handle the
    7101             :    * termination event and resume execution capability, even if
    7102             :    * JavaScript frames remain on the stack.
    7103             :    *
    7104             :    * This method can be used by any thread even if that thread has not
    7105             :    * acquired the V8 lock with a Locker object.
    7106             :    */
    7107             :   void CancelTerminateExecution();
    7108             : 
    7109             :   /**
    7110             :    * Request V8 to interrupt long running JavaScript code and invoke
    7111             :    * the given |callback| passing the given |data| to it. After |callback|
    7112             :    * returns control will be returned to the JavaScript code.
    7113             :    * There may be a number of interrupt requests in flight.
    7114             :    * Can be called from another thread without acquiring a |Locker|.
    7115             :    * Registered |callback| must not reenter interrupted Isolate.
    7116             :    */
    7117             :   void RequestInterrupt(InterruptCallback callback, void* data);
    7118             : 
    7119             :   /**
    7120             :    * Request garbage collection in this Isolate. It is only valid to call this
    7121             :    * function if --expose_gc was specified.
    7122             :    *
    7123             :    * This should only be used for testing purposes and not to enforce a garbage
    7124             :    * collection schedule. It has strong negative impact on the garbage
    7125             :    * collection performance. Use IdleNotificationDeadline() or
    7126             :    * LowMemoryNotification() instead to influence the garbage collection
    7127             :    * schedule.
    7128             :    */
    7129             :   void RequestGarbageCollectionForTesting(GarbageCollectionType type);
    7130             : 
    7131             :   /**
    7132             :    * Set the callback to invoke for logging event.
    7133             :    */
    7134             :   void SetEventLogger(LogEventCallback that);
    7135             : 
    7136             :   /**
    7137             :    * Adds a callback to notify the host application right before a script
    7138             :    * is about to run. If a script re-enters the runtime during executing, the
    7139             :    * BeforeCallEnteredCallback is invoked for each re-entrance.
    7140             :    * Executing scripts inside the callback will re-trigger the callback.
    7141             :    */
    7142             :   void AddBeforeCallEnteredCallback(BeforeCallEnteredCallback callback);
    7143             : 
    7144             :   /**
    7145             :    * Removes callback that was installed by AddBeforeCallEnteredCallback.
    7146             :    */
    7147             :   void RemoveBeforeCallEnteredCallback(BeforeCallEnteredCallback callback);
    7148             : 
    7149             :   /**
    7150             :    * Adds a callback to notify the host application when a script finished
    7151             :    * running.  If a script re-enters the runtime during executing, the
    7152             :    * CallCompletedCallback is only invoked when the outer-most script
    7153             :    * execution ends.  Executing scripts inside the callback do not trigger
    7154             :    * further callbacks.
    7155             :    */
    7156             :   void AddCallCompletedCallback(CallCompletedCallback callback);
    7157             :   V8_DEPRECATE_SOON(
    7158             :       "Use callback with parameter",
    7159             :       void AddCallCompletedCallback(DeprecatedCallCompletedCallback callback));
    7160             : 
    7161             :   /**
    7162             :    * Removes callback that was installed by AddCallCompletedCallback.
    7163             :    */
    7164             :   void RemoveCallCompletedCallback(CallCompletedCallback callback);
    7165             :   V8_DEPRECATE_SOON(
    7166             :       "Use callback with parameter",
    7167             :       void RemoveCallCompletedCallback(
    7168             :           DeprecatedCallCompletedCallback callback));
    7169             : 
    7170             :   /**
    7171             :    * Experimental: Set the PromiseHook callback for various promise
    7172             :    * lifecycle events.
    7173             :    */
    7174             :   void SetPromiseHook(PromiseHook hook);
    7175             : 
    7176             :   /**
    7177             :    * Set callback to notify about promise reject with no handler, or
    7178             :    * revocation of such a previous notification once the handler is added.
    7179             :    */
    7180             :   void SetPromiseRejectCallback(PromiseRejectCallback callback);
    7181             : 
    7182             :   /**
    7183             :    * Experimental: Runs the Microtask Work Queue until empty
    7184             :    * Any exceptions thrown by microtask callbacks are swallowed.
    7185             :    */
    7186             :   void RunMicrotasks();
    7187             : 
    7188             :   /**
    7189             :    * Experimental: Enqueues the callback to the Microtask Work Queue
    7190             :    */
    7191             :   void EnqueueMicrotask(Local<Function> microtask);
    7192             : 
    7193             :   /**
    7194             :    * Experimental: Enqueues the callback to the Microtask Work Queue
    7195             :    */
    7196             :   void EnqueueMicrotask(MicrotaskCallback microtask, void* data = NULL);
    7197             : 
    7198             :   /**
    7199             :    * Experimental: Controls how Microtasks are invoked. See MicrotasksPolicy
    7200             :    * for details.
    7201             :    */
    7202             :   void SetMicrotasksPolicy(MicrotasksPolicy policy);
    7203             :   V8_DEPRECATE_SOON("Use SetMicrotasksPolicy",
    7204             :                     void SetAutorunMicrotasks(bool autorun));
    7205             : 
    7206             :   /**
    7207             :    * Experimental: Returns the policy controlling how Microtasks are invoked.
    7208             :    */
    7209             :   MicrotasksPolicy GetMicrotasksPolicy() const;
    7210             :   V8_DEPRECATE_SOON("Use GetMicrotasksPolicy",
    7211             :                     bool WillAutorunMicrotasks() const);
    7212             : 
    7213             :   /**
    7214             :    * Experimental: adds a callback to notify the host application after
    7215             :    * microtasks were run. The callback is triggered by explicit RunMicrotasks
    7216             :    * call or automatic microtasks execution (see SetAutorunMicrotasks).
    7217             :    *
    7218             :    * Callback will trigger even if microtasks were attempted to run,
    7219             :    * but the microtasks queue was empty and no single microtask was actually
    7220             :    * executed.
    7221             :    *
    7222             :    * Executing scriptsinside the callback will not re-trigger microtasks and
    7223             :    * the callback.
    7224             :    */
    7225             :   void AddMicrotasksCompletedCallback(MicrotasksCompletedCallback callback);
    7226             : 
    7227             :   /**
    7228             :    * Removes callback that was installed by AddMicrotasksCompletedCallback.
    7229             :    */
    7230             :   void RemoveMicrotasksCompletedCallback(MicrotasksCompletedCallback callback);
    7231             : 
    7232             :   /**
    7233             :    * Sets a callback for counting the number of times a feature of V8 is used.
    7234             :    */
    7235             :   void SetUseCounterCallback(UseCounterCallback callback);
    7236             : 
    7237             :   /**
    7238             :    * Enables the host application to provide a mechanism for recording
    7239             :    * statistics counters.
    7240             :    */
    7241             :   void SetCounterFunction(CounterLookupCallback);
    7242             : 
    7243             :   /**
    7244             :    * Enables the host application to provide a mechanism for recording
    7245             :    * histograms. The CreateHistogram function returns a
    7246             :    * histogram which will later be passed to the AddHistogramSample
    7247             :    * function.
    7248             :    */
    7249             :   void SetCreateHistogramFunction(CreateHistogramCallback);
    7250             :   void SetAddHistogramSampleFunction(AddHistogramSampleCallback);
    7251             : 
    7252             :   /**
    7253             :    * Optional notification that the embedder is idle.
    7254             :    * V8 uses the notification to perform garbage collection.
    7255             :    * This call can be used repeatedly if the embedder remains idle.
    7256             :    * Returns true if the embedder should stop calling IdleNotificationDeadline
    7257             :    * until real work has been done.  This indicates that V8 has done
    7258             :    * as much cleanup as it will be able to do.
    7259             :    *
    7260             :    * The deadline_in_seconds argument specifies the deadline V8 has to finish
    7261             :    * garbage collection work. deadline_in_seconds is compared with
    7262             :    * MonotonicallyIncreasingTime() and should be based on the same timebase as
    7263             :    * that function. There is no guarantee that the actual work will be done
    7264             :    * within the time limit.
    7265             :    */
    7266             :   bool IdleNotificationDeadline(double deadline_in_seconds);
    7267             : 
    7268             :   V8_DEPRECATED("use IdleNotificationDeadline()",
    7269             :                 bool IdleNotification(int idle_time_in_ms));
    7270             : 
    7271             :   /**
    7272             :    * Optional notification that the system is running low on memory.
    7273             :    * V8 uses these notifications to attempt to free memory.
    7274             :    */
    7275             :   void LowMemoryNotification();
    7276             : 
    7277             :   /**
    7278             :    * Optional notification that a context has been disposed. V8 uses
    7279             :    * these notifications to guide the GC heuristic. Returns the number
    7280             :    * of context disposals - including this one - since the last time
    7281             :    * V8 had a chance to clean up.
    7282             :    *
    7283             :    * The optional parameter |dependant_context| specifies whether the disposed
    7284             :    * context was depending on state from other contexts or not.
    7285             :    */
    7286             :   int ContextDisposedNotification(bool dependant_context = true);
    7287             : 
    7288             :   /**
    7289             :    * Optional notification that the isolate switched to the foreground.
    7290             :    * V8 uses these notifications to guide heuristics.
    7291             :    */
    7292             :   void IsolateInForegroundNotification();
    7293             : 
    7294             :   /**
    7295             :    * Optional notification that the isolate switched to the background.
    7296             :    * V8 uses these notifications to guide heuristics.
    7297             :    */
    7298             :   void IsolateInBackgroundNotification();
    7299             : 
    7300             :   /**
    7301             :    * Optional notification to tell V8 the current performance requirements
    7302             :    * of the embedder based on RAIL.
    7303             :    * V8 uses these notifications to guide heuristics.
    7304             :    * This is an unfinished experimental feature. Semantics and implementation
    7305             :    * may change frequently.
    7306             :    */
    7307             :   void SetRAILMode(RAILMode rail_mode);
    7308             : 
    7309             :   /**
    7310             :    * Optional notification to tell V8 the current isolate is used for debugging
    7311             :    * and requires higher heap limit.
    7312             :    */
    7313             :   void IncreaseHeapLimitForDebugging();
    7314             : 
    7315             :   /**
    7316             :    * Restores the original heap limit after IncreaseHeapLimitForDebugging().
    7317             :    */
    7318             :   void RestoreOriginalHeapLimit();
    7319             : 
    7320             :   /**
    7321             :    * Returns true if the heap limit was increased for debugging and the
    7322             :    * original heap limit was not restored yet.
    7323             :    */
    7324             :   bool IsHeapLimitIncreasedForDebugging();
    7325             : 
    7326             :   /**
    7327             :    * Allows the host application to provide the address of a function that is
    7328             :    * notified each time code is added, moved or removed.
    7329             :    *
    7330             :    * \param options options for the JIT code event handler.
    7331             :    * \param event_handler the JIT code event handler, which will be invoked
    7332             :    *     each time code is added, moved or removed.
    7333             :    * \note \p event_handler won't get notified of existent code.
    7334             :    * \note since code removal notifications are not currently issued, the
    7335             :    *     \p event_handler may get notifications of code that overlaps earlier
    7336             :    *     code notifications. This happens when code areas are reused, and the
    7337             :    *     earlier overlapping code areas should therefore be discarded.
    7338             :    * \note the events passed to \p event_handler and the strings they point to
    7339             :    *     are not guaranteed to live past each call. The \p event_handler must
    7340             :    *     copy strings and other parameters it needs to keep around.
    7341             :    * \note the set of events declared in JitCodeEvent::EventType is expected to
    7342             :    *     grow over time, and the JitCodeEvent structure is expected to accrue
    7343             :    *     new members. The \p event_handler function must ignore event codes
    7344             :    *     it does not recognize to maintain future compatibility.
    7345             :    * \note Use Isolate::CreateParams to get events for code executed during
    7346             :    *     Isolate setup.
    7347             :    */
    7348             :   void SetJitCodeEventHandler(JitCodeEventOptions options,
    7349             :                               JitCodeEventHandler event_handler);
    7350             : 
    7351             :   /**
    7352             :    * Modifies the stack limit for this Isolate.
    7353             :    *
    7354             :    * \param stack_limit An address beyond which the Vm's stack may not grow.
    7355             :    *
    7356             :    * \note  If you are using threads then you should hold the V8::Locker lock
    7357             :    *     while setting the stack limit and you must set a non-default stack
    7358             :    *     limit separately for each thread.
    7359             :    */
    7360             :   void SetStackLimit(uintptr_t stack_limit);
    7361             : 
    7362             :   /**
    7363             :    * Returns a memory range that can potentially contain jitted code.
    7364             :    *
    7365             :    * On Win64, embedders are advised to install function table callbacks for
    7366             :    * these ranges, as default SEH won't be able to unwind through jitted code.
    7367             :    *
    7368             :    * The first page of the code range is reserved for the embedder and is
    7369             :    * committed, writable, and executable.
    7370             :    *
    7371             :    * Might be empty on other platforms.
    7372             :    *
    7373             :    * https://code.google.com/p/v8/issues/detail?id=3598
    7374             :    */
    7375             :   void GetCodeRange(void** start, size_t* length_in_bytes);
    7376             : 
    7377             :   /** Set the callback to invoke in case of fatal errors. */
    7378             :   void SetFatalErrorHandler(FatalErrorCallback that);
    7379             : 
    7380             :   /** Set the callback to invoke in case of OOM errors. */
    7381             :   void SetOOMErrorHandler(OOMErrorCallback that);
    7382             : 
    7383             :   /**
    7384             :    * Set the callback to invoke to check if code generation from
    7385             :    * strings should be allowed.
    7386             :    */
    7387             :   void SetAllowCodeGenerationFromStringsCallback(
    7388             :       AllowCodeGenerationFromStringsCallback callback);
    7389             : 
    7390             :   /**
    7391             :    * Embedder over{ride|load} injection points for wasm APIs.
    7392             :    */
    7393             :   void SetWasmModuleCallback(ExtensionCallback callback);
    7394             :   void SetWasmCompileCallback(ExtensionCallback callback);
    7395             :   void SetWasmInstanceCallback(ExtensionCallback callback);
    7396             :   void SetWasmInstantiateCallback(ExtensionCallback callback);
    7397             : 
    7398             :   /**
    7399             :   * Check if V8 is dead and therefore unusable.  This is the case after
    7400             :   * fatal errors such as out-of-memory situations.
    7401             :   */
    7402             :   bool IsDead();
    7403             : 
    7404             :   /**
    7405             :    * Adds a message listener (errors only).
    7406             :    *
    7407             :    * The same message listener can be added more than once and in that
    7408             :    * case it will be called more than once for each message.
    7409             :    *
    7410             :    * If data is specified, it will be passed to the callback when it is called.
    7411             :    * Otherwise, the exception object will be passed to the callback instead.
    7412             :    */
    7413             :   bool AddMessageListener(MessageCallback that,
    7414             :                           Local<Value> data = Local<Value>());
    7415             : 
    7416             :   /**
    7417             :    * Adds a message listener.
    7418             :    *
    7419             :    * The same message listener can be added more than once and in that
    7420             :    * case it will be called more than once for each message.
    7421             :    *
    7422             :    * If data is specified, it will be passed to the callback when it is called.
    7423             :    * Otherwise, the exception object will be passed to the callback instead.
    7424             :    *
    7425             :    * A listener can listen for particular error levels by providing a mask.
    7426             :    */
    7427             :   bool AddMessageListenerWithErrorLevel(MessageCallback that,
    7428             :                                         int message_levels,
    7429             :                                         Local<Value> data = Local<Value>());
    7430             : 
    7431             :   /**
    7432             :    * Remove all message listeners from the specified callback function.
    7433             :    */
    7434             :   void RemoveMessageListeners(MessageCallback that);
    7435             : 
    7436             :   /** Callback function for reporting failed access checks.*/
    7437             :   void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback);
    7438             : 
    7439             :   /**
    7440             :    * Tells V8 to capture current stack trace when uncaught exception occurs
    7441             :    * and report it to the message listeners. The option is off by default.
    7442             :    */
    7443             :   void SetCaptureStackTraceForUncaughtExceptions(
    7444             :       bool capture, int frame_limit = 10,
    7445             :       StackTrace::StackTraceOptions options = StackTrace::kOverview);
    7446             : 
    7447             :   /**
    7448             :    * Iterates through all external resources referenced from current isolate
    7449             :    * heap.  GC is not invoked prior to iterating, therefore there is no
    7450             :    * guarantee that visited objects are still alive.
    7451             :    */
    7452             :   void VisitExternalResources(ExternalResourceVisitor* visitor);
    7453             : 
    7454             :   /**
    7455             :    * Iterates through all the persistent handles in the current isolate's heap
    7456             :    * that have class_ids.
    7457             :    */
    7458             :   void VisitHandlesWithClassIds(PersistentHandleVisitor* visitor);
    7459             : 
    7460             :   /**
    7461             :    * Iterates through all the persistent handles in the current isolate's heap
    7462             :    * that have class_ids and are candidates to be marked as partially dependent
    7463             :    * handles. This will visit handles to young objects created since the last
    7464             :    * garbage collection but is free to visit an arbitrary superset of these
    7465             :    * objects.
    7466             :    */
    7467             :   void VisitHandlesForPartialDependence(PersistentHandleVisitor* visitor);
    7468             : 
    7469             :   /**
    7470             :    * Iterates through all the persistent handles in the current isolate's heap
    7471             :    * that have class_ids and are weak to be marked as inactive if there is no
    7472             :    * pending activity for the handle.
    7473             :    */
    7474             :   void VisitWeakHandles(PersistentHandleVisitor* visitor);
    7475             : 
    7476             :   /**
    7477             :    * Check if this isolate is in use.
    7478             :    * True if at least one thread Enter'ed this isolate.
    7479             :    */
    7480             :   bool IsInUse();
    7481             : 
    7482             :   /**
    7483             :    * Set whether calling Atomics.wait (a function that may block) is allowed in
    7484             :    * this isolate. This can also be configured via
    7485             :    * CreateParams::allow_atomics_wait.
    7486             :    */
    7487             :   void SetAllowAtomicsWait(bool allow);
    7488             : 
    7489             :   Isolate() = delete;
    7490             :   ~Isolate() = delete;
    7491             :   Isolate(const Isolate&) = delete;
    7492             :   Isolate& operator=(const Isolate&) = delete;
    7493             :   void* operator new(size_t size) = delete;
    7494             :   void operator delete(void*, size_t) = delete;
    7495             : 
    7496             :  private:
    7497             :   template <class K, class V, class Traits>
    7498             :   friend class PersistentValueMapBase;
    7499             : 
    7500             :   void ReportExternalAllocationLimitReached();
    7501             : };
    7502             : 
    7503             : class V8_EXPORT StartupData {
    7504             :  public:
    7505             :   const char* data;
    7506             :   int raw_size;
    7507             : };
    7508             : 
    7509             : 
    7510             : /**
    7511             :  * EntropySource is used as a callback function when v8 needs a source
    7512             :  * of entropy.
    7513             :  */
    7514             : typedef bool (*EntropySource)(unsigned char* buffer, size_t length);
    7515             : 
    7516             : /**
    7517             :  * ReturnAddressLocationResolver is used as a callback function when v8 is
    7518             :  * resolving the location of a return address on the stack. Profilers that
    7519             :  * change the return address on the stack can use this to resolve the stack
    7520             :  * location to whereever the profiler stashed the original return address.
    7521             :  *
    7522             :  * \param return_addr_location A location on stack where a machine
    7523             :  *    return address resides.
    7524             :  * \returns Either return_addr_location, or else a pointer to the profiler's
    7525             :  *    copy of the original return address.
    7526             :  *
    7527             :  * \note The resolver function must not cause garbage collection.
    7528             :  */
    7529             : typedef uintptr_t (*ReturnAddressLocationResolver)(
    7530             :     uintptr_t return_addr_location);
    7531             : 
    7532             : 
    7533             : /**
    7534             :  * Container class for static utility functions.
    7535             :  */
    7536             : class V8_EXPORT V8 {
    7537             :  public:
    7538             :   /** Set the callback to invoke in case of fatal errors. */
    7539             :   V8_INLINE static V8_DEPRECATED(
    7540             :       "Use isolate version",
    7541             :       void SetFatalErrorHandler(FatalErrorCallback that));
    7542             : 
    7543             :   /**
    7544             :    * Set the callback to invoke to check if code generation from
    7545             :    * strings should be allowed.
    7546             :    */
    7547             :   V8_INLINE static V8_DEPRECATED(
    7548             :       "Use isolate version", void SetAllowCodeGenerationFromStringsCallback(
    7549             :                                  AllowCodeGenerationFromStringsCallback that));
    7550             : 
    7551             :   /**
    7552             :   * Check if V8 is dead and therefore unusable.  This is the case after
    7553             :   * fatal errors such as out-of-memory situations.
    7554             :   */
    7555             :   V8_INLINE static V8_DEPRECATED("Use isolate version", bool IsDead());
    7556             : 
    7557             :   /**
    7558             :    * Hand startup data to V8, in case the embedder has chosen to build
    7559             :    * V8 with external startup data.
    7560             :    *
    7561             :    * Note:
    7562             :    * - By default the startup data is linked into the V8 library, in which
    7563             :    *   case this function is not meaningful.
    7564             :    * - If this needs to be called, it needs to be called before V8
    7565             :    *   tries to make use of its built-ins.
    7566             :    * - To avoid unnecessary copies of data, V8 will point directly into the
    7567             :    *   given data blob, so pretty please keep it around until V8 exit.
    7568             :    * - Compression of the startup blob might be useful, but needs to
    7569             :    *   handled entirely on the embedders' side.
    7570             :    * - The call will abort if the data is invalid.
    7571             :    */
    7572             :   static void SetNativesDataBlob(StartupData* startup_blob);
    7573             :   static void SetSnapshotDataBlob(StartupData* startup_blob);
    7574             : 
    7575             :   /**
    7576             :    * Bootstrap an isolate and a context from scratch to create a startup
    7577             :    * snapshot. Include the side-effects of running the optional script.
    7578             :    * Returns { NULL, 0 } on failure.
    7579             :    * The caller acquires ownership of the data array in the return value.
    7580             :    */
    7581             :   static StartupData CreateSnapshotDataBlob(const char* embedded_source = NULL);
    7582             : 
    7583             :   /**
    7584             :    * Bootstrap an isolate and a context from the cold startup blob, run the
    7585             :    * warm-up script to trigger code compilation. The side effects are then
    7586             :    * discarded. The resulting startup snapshot will include compiled code.
    7587             :    * Returns { NULL, 0 } on failure.
    7588             :    * The caller acquires ownership of the data array in the return value.
    7589             :    * The argument startup blob is untouched.
    7590             :    */
    7591             :   static StartupData WarmUpSnapshotDataBlob(StartupData cold_startup_blob,
    7592             :                                             const char* warmup_source);
    7593             : 
    7594             :   /**
    7595             :    * Adds a message listener.
    7596             :    *
    7597             :    * The same message listener can be added more than once and in that
    7598             :    * case it will be called more than once for each message.
    7599             :    *
    7600             :    * If data is specified, it will be passed to the callback when it is called.
    7601             :    * Otherwise, the exception object will be passed to the callback instead.
    7602             :    */
    7603             :   V8_INLINE static V8_DEPRECATED(
    7604             :       "Use isolate version",
    7605             :       bool AddMessageListener(MessageCallback that,
    7606             :                               Local<Value> data = Local<Value>()));
    7607             : 
    7608             :   /**
    7609             :    * Remove all message listeners from the specified callback function.
    7610             :    */
    7611             :   V8_INLINE static V8_DEPRECATED(
    7612             :       "Use isolate version", void RemoveMessageListeners(MessageCallback that));
    7613             : 
    7614             :   /**
    7615             :    * Tells V8 to capture current stack trace when uncaught exception occurs
    7616             :    * and report it to the message listeners. The option is off by default.
    7617             :    */
    7618             :   V8_INLINE static V8_DEPRECATED(
    7619             :       "Use isolate version",
    7620             :       void SetCaptureStackTraceForUncaughtExceptions(
    7621             :           bool capture, int frame_limit = 10,
    7622             :           StackTrace::StackTraceOptions options = StackTrace::kOverview));
    7623             : 
    7624             :   /**
    7625             :    * Sets V8 flags from a string.
    7626             :    */
    7627             :   static void SetFlagsFromString(const char* str, int length);
    7628             : 
    7629             :   /**
    7630             :    * Sets V8 flags from the command line.
    7631             :    */
    7632             :   static void SetFlagsFromCommandLine(int* argc,
    7633             :                                       char** argv,
    7634             :                                       bool remove_flags);
    7635             : 
    7636             :   /** Get the version string. */
    7637             :   static const char* GetVersion();
    7638             : 
    7639             :   /** Callback function for reporting failed access checks.*/
    7640             :   V8_INLINE static V8_DEPRECATED(
    7641             :       "Use isolate version",
    7642             :       void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback));
    7643             : 
    7644             :   /**
    7645             :    * Enables the host application to receive a notification before a
    7646             :    * garbage collection.  Allocations are not allowed in the
    7647             :    * callback function, you therefore cannot manipulate objects (set
    7648             :    * or delete properties for example) since it is possible such
    7649             :    * operations will result in the allocation of objects. It is possible
    7650             :    * to specify the GCType filter for your callback. But it is not possible to
    7651             :    * register the same callback function two times with different
    7652             :    * GCType filters.
    7653             :    */
    7654             :   static V8_DEPRECATED(
    7655             :       "Use isolate version",
    7656             :       void AddGCPrologueCallback(GCCallback callback,
    7657             :                                  GCType gc_type_filter = kGCTypeAll));
    7658             : 
    7659             :   /**
    7660             :    * This function removes callback which was installed by
    7661             :    * AddGCPrologueCallback function.
    7662             :    */
    7663             :   V8_INLINE static V8_DEPRECATED(
    7664             :       "Use isolate version",
    7665             :       void RemoveGCPrologueCallback(GCCallback callback));
    7666             : 
    7667             :   /**
    7668             :    * Enables the host application to receive a notification after a
    7669             :    * garbage collection.  Allocations are not allowed in the
    7670             :    * callback function, you therefore cannot manipulate objects (set
    7671             :    * or delete properties for example) since it is possible such
    7672             :    * operations will result in the allocation of objects. It is possible
    7673             :    * to specify the GCType filter for your callback. But it is not possible to
    7674             :    * register the same callback function two times with different
    7675             :    * GCType filters.
    7676             :    */
    7677             :   static V8_DEPRECATED(
    7678             :       "Use isolate version",
    7679             :       void AddGCEpilogueCallback(GCCallback callback,
    7680             :                                  GCType gc_type_filter = kGCTypeAll));
    7681             : 
    7682             :   /**
    7683             :    * This function removes callback which was installed by
    7684             :    * AddGCEpilogueCallback function.
    7685             :    */
    7686             :   V8_INLINE static V8_DEPRECATED(
    7687             :       "Use isolate version",
    7688             :       void RemoveGCEpilogueCallback(GCCallback callback));
    7689             : 
    7690             :   /**
    7691             :    * Initializes V8. This function needs to be called before the first Isolate
    7692             :    * is created. It always returns true.
    7693             :    */
    7694             :   static bool Initialize();
    7695             : 
    7696             :   /**
    7697             :    * Allows the host application to provide a callback which can be used
    7698             :    * as a source of entropy for random number generators.
    7699             :    */
    7700             :   static void SetEntropySource(EntropySource source);
    7701             : 
    7702             :   /**
    7703             :    * Allows the host application to provide a callback that allows v8 to
    7704             :    * cooperate with a profiler that rewrites return addresses on stack.
    7705             :    */
    7706             :   static void SetReturnAddressLocationResolver(
    7707             :       ReturnAddressLocationResolver return_address_resolver);
    7708             : 
    7709             :   /**
    7710             :    * Forcefully terminate the current thread of JavaScript execution
    7711             :    * in the given isolate.
    7712             :    *
    7713             :    * This method can be used by any thread even if that thread has not
    7714             :    * acquired the V8 lock with a Locker object.
    7715             :    *
    7716             :    * \param isolate The isolate in which to terminate the current JS execution.
    7717             :    */
    7718             :   V8_INLINE static V8_DEPRECATED("Use isolate version",
    7719             :                                  void TerminateExecution(Isolate* isolate));
    7720             : 
    7721             :   /**
    7722             :    * Is V8 terminating JavaScript execution.
    7723             :    *
    7724             :    * Returns true if JavaScript execution is currently terminating
    7725             :    * because of a call to TerminateExecution.  In that case there are
    7726             :    * still JavaScript frames on the stack and the termination
    7727             :    * exception is still active.
    7728             :    *
    7729             :    * \param isolate The isolate in which to check.
    7730             :    */
    7731             :   V8_INLINE static V8_DEPRECATED(
    7732             :       "Use isolate version",
    7733             :       bool IsExecutionTerminating(Isolate* isolate = NULL));
    7734             : 
    7735             :   /**
    7736             :    * Resume execution capability in the given isolate, whose execution
    7737             :    * was previously forcefully terminated using TerminateExecution().
    7738             :    *
    7739             :    * When execution is forcefully terminated using TerminateExecution(),
    7740             :    * the isolate can not resume execution until all JavaScript frames
    7741             :    * have propagated the uncatchable exception which is generated.  This
    7742             :    * method allows the program embedding the engine to handle the
    7743             :    * termination event and resume execution capability, even if
    7744             :    * JavaScript frames remain on the stack.
    7745             :    *
    7746             :    * This method can be used by any thread even if that thread has not
    7747             :    * acquired the V8 lock with a Locker object.
    7748             :    *
    7749             :    * \param isolate The isolate in which to resume execution capability.
    7750             :    */
    7751             :   V8_INLINE static V8_DEPRECATED(
    7752             :       "Use isolate version", void CancelTerminateExecution(Isolate* isolate));
    7753             : 
    7754             :   /**
    7755             :    * Releases any resources used by v8 and stops any utility threads
    7756             :    * that may be running.  Note that disposing v8 is permanent, it
    7757             :    * cannot be reinitialized.
    7758             :    *
    7759             :    * It should generally not be necessary to dispose v8 before exiting
    7760             :    * a process, this should happen automatically.  It is only necessary
    7761             :    * to use if the process needs the resources taken up by v8.
    7762             :    */
    7763             :   static bool Dispose();
    7764             : 
    7765             :   /**
    7766             :    * Iterates through all external resources referenced from current isolate
    7767             :    * heap.  GC is not invoked prior to iterating, therefore there is no
    7768             :    * guarantee that visited objects are still alive.
    7769             :    */
    7770             :   V8_INLINE static V8_DEPRECATED(
    7771             :       "Use isolate version",
    7772             :       void VisitExternalResources(ExternalResourceVisitor* visitor));
    7773             : 
    7774             :   /**
    7775             :    * Iterates through all the persistent handles in the current isolate's heap
    7776             :    * that have class_ids.
    7777             :    */
    7778             :   V8_INLINE static V8_DEPRECATED(
    7779             :       "Use isolate version",
    7780             :       void VisitHandlesWithClassIds(PersistentHandleVisitor* visitor));
    7781             : 
    7782             :   /**
    7783             :    * Iterates through all the persistent handles in isolate's heap that have
    7784             :    * class_ids.
    7785             :    */
    7786             :   V8_INLINE static V8_DEPRECATED(
    7787             :       "Use isolate version",
    7788             :       void VisitHandlesWithClassIds(Isolate* isolate,
    7789             :                                     PersistentHandleVisitor* visitor));
    7790             : 
    7791             :   /**
    7792             :    * Iterates through all the persistent handles in the current isolate's heap
    7793             :    * that have class_ids and are candidates to be marked as partially dependent
    7794             :    * handles. This will visit handles to young objects created since the last
    7795             :    * garbage collection but is free to visit an arbitrary superset of these
    7796             :    * objects.
    7797             :    */
    7798             :   V8_INLINE static V8_DEPRECATED(
    7799             :       "Use isolate version",
    7800             :       void VisitHandlesForPartialDependence(Isolate* isolate,
    7801             :                                             PersistentHandleVisitor* visitor));
    7802             : 
    7803             :   /**
    7804             :    * Initialize the ICU library bundled with V8. The embedder should only
    7805             :    * invoke this method when using the bundled ICU. Returns true on success.
    7806             :    *
    7807             :    * If V8 was compiled with the ICU data in an external file, the location
    7808             :    * of the data file has to be provided.
    7809             :    */
    7810             :   V8_DEPRECATE_SOON(
    7811             :       "Use version with default location.",
    7812             :       static bool InitializeICU(const char* icu_data_file = nullptr));
    7813             : 
    7814             :   /**
    7815             :    * Initialize the ICU library bundled with V8. The embedder should only
    7816             :    * invoke this method when using the bundled ICU. If V8 was compiled with
    7817             :    * the ICU data in an external file and when the default location of that
    7818             :    * file should be used, a path to the executable must be provided.
    7819             :    * Returns true on success.
    7820             :    *
    7821             :    * The default is a file called icudtl.dat side-by-side with the executable.
    7822             :    *
    7823             :    * Optionally, the location of the data file can be provided to override the
    7824             :    * default.
    7825             :    */
    7826             :   static bool InitializeICUDefaultLocation(const char* exec_path,
    7827             :                                            const char* icu_data_file = nullptr);
    7828             : 
    7829             :   /**
    7830             :    * Initialize the external startup data. The embedder only needs to
    7831             :    * invoke this method when external startup data was enabled in a build.
    7832             :    *
    7833             :    * If V8 was compiled with the startup data in an external file, then
    7834             :    * V8 needs to be given those external files during startup. There are
    7835             :    * three ways to do this:
    7836             :    * - InitializeExternalStartupData(const char*)
    7837             :    *   This will look in the given directory for files "natives_blob.bin"
    7838             :    *   and "snapshot_blob.bin" - which is what the default build calls them.
    7839             :    * - InitializeExternalStartupData(const char*, const char*)
    7840             :    *   As above, but will directly use the two given file names.
    7841             :    * - Call SetNativesDataBlob, SetNativesDataBlob.
    7842             :    *   This will read the blobs from the given data structures and will
    7843             :    *   not perform any file IO.
    7844             :    */
    7845             :   static void InitializeExternalStartupData(const char* directory_path);
    7846             :   static void InitializeExternalStartupData(const char* natives_blob,
    7847             :                                             const char* snapshot_blob);
    7848             :   /**
    7849             :    * Sets the v8::Platform to use. This should be invoked before V8 is
    7850             :    * initialized.
    7851             :    */
    7852             :   static void InitializePlatform(Platform* platform);
    7853             : 
    7854             :   /**
    7855             :    * Clears all references to the v8::Platform. This should be invoked after
    7856             :    * V8 was disposed.
    7857             :    */
    7858             :   static void ShutdownPlatform();
    7859             : 
    7860             : #if V8_OS_LINUX && V8_TARGET_ARCH_X64 && !V8_OS_ANDROID
    7861             :   /**
    7862             :    * Give the V8 signal handler a chance to handle a fault.
    7863             :    *
    7864             :    * This function determines whether a memory access violation can be recovered
    7865             :    * by V8. If so, it will return true and modify context to return to a code
    7866             :    * fragment that can recover from the fault. Otherwise, TryHandleSignal will
    7867             :    * return false.
    7868             :    *
    7869             :    * The parameters to this function correspond to those passed to a Linux
    7870             :    * signal handler.
    7871             :    *
    7872             :    * \param signal_number The signal number.
    7873             :    *
    7874             :    * \param info A pointer to the siginfo_t structure provided to the signal
    7875             :    * handler.
    7876             :    *
    7877             :    * \param context The third argument passed to the Linux signal handler, which
    7878             :    * points to a ucontext_t structure.
    7879             :    */
    7880             :   static bool TryHandleSignal(int signal_number, void* info, void* context);
    7881             : #endif  // V8_OS_LINUX
    7882             : 
    7883             :   /**
    7884             :    * Enable the default signal handler rather than using one provided by the
    7885             :    * embedder.
    7886             :    */
    7887             :   static bool RegisterDefaultSignalHandler();
    7888             : 
    7889             :  private:
    7890             :   V8();
    7891             : 
    7892             :   static internal::Object** GlobalizeReference(internal::Isolate* isolate,
    7893             :                                                internal::Object** handle);
    7894             :   static internal::Object** CopyPersistent(internal::Object** handle);
    7895             :   static void DisposeGlobal(internal::Object** global_handle);
    7896             :   static void MakeWeak(internal::Object** location, void* data,
    7897             :                        WeakCallbackInfo<void>::Callback weak_callback,
    7898             :                        WeakCallbackType type);
    7899             :   static void MakeWeak(internal::Object** location, void* data,
    7900             :                        // Must be 0 or -1.
    7901             :                        int internal_field_index1,
    7902             :                        // Must be 1 or -1.
    7903             :                        int internal_field_index2,
    7904             :                        WeakCallbackInfo<void>::Callback weak_callback);
    7905             :   static void MakeWeak(internal::Object*** location_addr);
    7906             :   static void* ClearWeak(internal::Object** location);
    7907             :   static Value* Eternalize(Isolate* isolate, Value* handle);
    7908             : 
    7909             :   static void RegisterExternallyReferencedObject(internal::Object** object,
    7910             :                                                  internal::Isolate* isolate);
    7911             : 
    7912             :   template <class K, class V, class T>
    7913             :   friend class PersistentValueMapBase;
    7914             : 
    7915             :   static void FromJustIsNothing();
    7916             :   static void ToLocalEmpty();
    7917             :   static void InternalFieldOutOfBounds(int index);
    7918             :   template <class T> friend class Local;
    7919             :   template <class T>
    7920             :   friend class MaybeLocal;
    7921             :   template <class T>
    7922             :   friend class Maybe;
    7923             :   template <class T>
    7924             :   friend class WeakCallbackInfo;
    7925             :   template <class T> friend class Eternal;
    7926             :   template <class T> friend class PersistentBase;
    7927             :   template <class T, class M> friend class Persistent;
    7928             :   friend class Context;
    7929             : };
    7930             : 
    7931             : /**
    7932             :  * Helper class to create a snapshot data blob.
    7933             :  */
    7934             : class V8_EXPORT SnapshotCreator {
    7935             :  public:
    7936             :   enum class FunctionCodeHandling { kClear, kKeep };
    7937             : 
    7938             :   /**
    7939             :    * Create and enter an isolate, and set it up for serialization.
    7940             :    * The isolate is either created from scratch or from an existing snapshot.
    7941             :    * The caller keeps ownership of the argument snapshot.
    7942             :    * \param existing_blob existing snapshot from which to create this one.
    7943             :    * \param external_references a null-terminated array of external references
    7944             :    *        that must be equivalent to CreateParams::external_references.
    7945             :    */
    7946             :   SnapshotCreator(intptr_t* external_references = nullptr,
    7947             :                   StartupData* existing_blob = nullptr);
    7948             : 
    7949             :   ~SnapshotCreator();
    7950             : 
    7951             :   /**
    7952             :    * \returns the isolate prepared by the snapshot creator.
    7953             :    */
    7954             :   Isolate* GetIsolate();
    7955             : 
    7956             :   /**
    7957             :    * Set the default context to be included in the snapshot blob.
    7958             :    * The snapshot will not contain the global proxy, and we expect one or a
    7959             :    * global object template to create one, to be provided upon deserialization.
    7960             :    */
    7961             :   void SetDefaultContext(Local<Context> context);
    7962             : 
    7963             :   /**
    7964             :    * Add additional context to be included in the snapshot blob.
    7965             :    * The snapshot will include the global proxy.
    7966             :    *
    7967             :    * \param callback optional callback to serialize internal fields.
    7968             :    *
    7969             :    * \returns the index of the context in the snapshot blob.
    7970             :    */
    7971             :   size_t AddContext(Local<Context> context,
    7972             :                     SerializeInternalFieldsCallback callback =
    7973             :                         SerializeInternalFieldsCallback());
    7974             : 
    7975             :   /**
    7976             :    * Add a template to be included in the snapshot blob.
    7977             :    * \returns the index of the template in the snapshot blob.
    7978             :    */
    7979             :   size_t AddTemplate(Local<Template> template_obj);
    7980             : 
    7981             :   /**
    7982             :    * Created a snapshot data blob.
    7983             :    * This must not be called from within a handle scope.
    7984             :    * \param function_code_handling whether to include compiled function code
    7985             :    *        in the snapshot.
    7986             :    * \returns { nullptr, 0 } on failure, and a startup snapshot on success. The
    7987             :    *        caller acquires ownership of the data array in the return value.
    7988             :    */
    7989             :   StartupData CreateBlob(FunctionCodeHandling function_code_handling);
    7990             : 
    7991             :   // Disallow copying and assigning.
    7992             :   SnapshotCreator(const SnapshotCreator&) = delete;
    7993             :   void operator=(const SnapshotCreator&) = delete;
    7994             : 
    7995             :  private:
    7996             :   void* data_;
    7997             : };
    7998             : 
    7999             : /**
    8000             :  * A simple Maybe type, representing an object which may or may not have a
    8001             :  * value, see https://hackage.haskell.org/package/base/docs/Data-Maybe.html.
    8002             :  *
    8003             :  * If an API method returns a Maybe<>, the API method can potentially fail
    8004             :  * either because an exception is thrown, or because an exception is pending,
    8005             :  * e.g. because a previous API call threw an exception that hasn't been caught
    8006             :  * yet, or because a TerminateExecution exception was thrown. In that case, a
    8007             :  * "Nothing" value is returned.
    8008             :  */
    8009             : template <class T>
    8010             : class Maybe {
    8011             :  public:
    8012          30 :   V8_INLINE bool IsNothing() const { return !has_value_; }
    8013             :   V8_INLINE bool IsJust() const { return has_value_; }
    8014             : 
    8015             :   /**
    8016             :    * An alias for |FromJust|. Will crash if the Maybe<> is nothing.
    8017             :    */
    8018             :   V8_INLINE T ToChecked() const { return FromJust(); }
    8019             : 
    8020             :   /**
    8021             :    * Converts this Maybe<> to a value of type T. If this Maybe<> is
    8022             :    * nothing (empty), |false| is returned and |out| is left untouched.
    8023             :    */
    8024      154059 :   V8_WARN_UNUSED_RESULT V8_INLINE bool To(T* out) const {
    8025      146804 :     if (V8_LIKELY(IsJust())) *out = value_;
    8026             :     return IsJust();
    8027             :   }
    8028             : 
    8029             :   /**
    8030             :    * Converts this Maybe<> to a value of type T. If this Maybe<> is
    8031             :    * nothing (empty), V8 will crash the process.
    8032             :    */
    8033     3880491 :   V8_INLINE T FromJust() const {
    8034   153684366 :     if (V8_UNLIKELY(!IsJust())) V8::FromJustIsNothing();
    8035   136236258 :     return value_;
    8036             :   }
    8037             : 
    8038             :   /**
    8039             :    * Converts this Maybe<> to a value of type T, using a default value if this
    8040             :    * Maybe<> is nothing (empty).
    8041             :    */
    8042             :   V8_INLINE T FromMaybe(const T& default_value) const {
    8043    11061759 :     return has_value_ ? value_ : default_value;
    8044             :   }
    8045             : 
    8046             :   V8_INLINE bool operator==(const Maybe& other) const {
    8047             :     return (IsJust() == other.IsJust()) &&
    8048             :            (!IsJust() || FromJust() == other.FromJust());
    8049             :   }
    8050             : 
    8051             :   V8_INLINE bool operator!=(const Maybe& other) const {
    8052             :     return !operator==(other);
    8053             :   }
    8054             : 
    8055             :  private:
    8056           0 :   Maybe() : has_value_(false) {}
    8057     3838531 :   explicit Maybe(const T& t) : has_value_(true), value_(t) {}
    8058             : 
    8059             :   bool has_value_;
    8060             :   T value_;
    8061             : 
    8062             :   template <class U>
    8063             :   friend Maybe<U> Nothing();
    8064             :   template <class U>
    8065             :   friend Maybe<U> Just(const U& u);
    8066             : };
    8067             : 
    8068             : 
    8069             : template <class T>
    8070             : inline Maybe<T> Nothing() {
    8071             :   return Maybe<T>();
    8072             : }
    8073             : 
    8074             : 
    8075             : template <class T>
    8076             : inline Maybe<T> Just(const T& t) {
    8077             :   return Maybe<T>(t);
    8078             : }
    8079             : 
    8080             : 
    8081             : /**
    8082             :  * An external exception handler.
    8083             :  */
    8084             : class V8_EXPORT TryCatch {
    8085             :  public:
    8086             :   /**
    8087             :    * Creates a new try/catch block and registers it with v8.  Note that
    8088             :    * all TryCatch blocks should be stack allocated because the memory
    8089             :    * location itself is compared against JavaScript try/catch blocks.
    8090             :    */
    8091             :   V8_DEPRECATED("Use isolate version", TryCatch());
    8092             : 
    8093             :   /**
    8094             :    * Creates a new try/catch block and registers it with v8.  Note that
    8095             :    * all TryCatch blocks should be stack allocated because the memory
    8096             :    * location itself is compared against JavaScript try/catch blocks.
    8097             :    */
    8098             :   TryCatch(Isolate* isolate);
    8099             : 
    8100             :   /**
    8101             :    * Unregisters and deletes this try/catch block.
    8102             :    */
    8103             :   ~TryCatch();
    8104             : 
    8105             :   /**
    8106             :    * Returns true if an exception has been caught by this try/catch block.
    8107             :    */
    8108             :   bool HasCaught() const;
    8109             : 
    8110             :   /**
    8111             :    * For certain types of exceptions, it makes no sense to continue execution.
    8112             :    *
    8113             :    * If CanContinue returns false, the correct action is to perform any C++
    8114             :    * cleanup needed and then return.  If CanContinue returns false and
    8115             :    * HasTerminated returns true, it is possible to call
    8116             :    * CancelTerminateExecution in order to continue calling into the engine.
    8117             :    */
    8118             :   bool CanContinue() const;
    8119             : 
    8120             :   /**
    8121             :    * Returns true if an exception has been caught due to script execution
    8122             :    * being terminated.
    8123             :    *
    8124             :    * There is no JavaScript representation of an execution termination
    8125             :    * exception.  Such exceptions are thrown when the TerminateExecution
    8126             :    * methods are called to terminate a long-running script.
    8127             :    *
    8128             :    * If such an exception has been thrown, HasTerminated will return true,
    8129             :    * indicating that it is possible to call CancelTerminateExecution in order
    8130             :    * to continue calling into the engine.
    8131             :    */
    8132             :   bool HasTerminated() const;
    8133             : 
    8134             :   /**
    8135             :    * Throws the exception caught by this TryCatch in a way that avoids
    8136             :    * it being caught again by this same TryCatch.  As with ThrowException
    8137             :    * it is illegal to execute any JavaScript operations after calling
    8138             :    * ReThrow; the caller must return immediately to where the exception
    8139             :    * is caught.
    8140             :    */
    8141             :   Local<Value> ReThrow();
    8142             : 
    8143             :   /**
    8144             :    * Returns the exception caught by this try/catch block.  If no exception has
    8145             :    * been caught an empty handle is returned.
    8146             :    *
    8147             :    * The returned handle is valid until this TryCatch block has been destroyed.
    8148             :    */
    8149             :   Local<Value> Exception() const;
    8150             : 
    8151             :   /**
    8152             :    * Returns the .stack property of the thrown object.  If no .stack
    8153             :    * property is present an empty handle is returned.
    8154             :    */
    8155             :   V8_DEPRECATE_SOON("Use maybe version.", Local<Value> StackTrace() const);
    8156             :   V8_WARN_UNUSED_RESULT MaybeLocal<Value> StackTrace(
    8157             :       Local<Context> context) const;
    8158             : 
    8159             :   /**
    8160             :    * Returns the message associated with this exception.  If there is
    8161             :    * no message associated an empty handle is returned.
    8162             :    *
    8163             :    * The returned handle is valid until this TryCatch block has been
    8164             :    * destroyed.
    8165             :    */
    8166             :   Local<v8::Message> Message() const;
    8167             : 
    8168             :   /**
    8169             :    * Clears any exceptions that may have been caught by this try/catch block.
    8170             :    * After this method has been called, HasCaught() will return false. Cancels
    8171             :    * the scheduled exception if it is caught and ReThrow() is not called before.
    8172             :    *
    8173             :    * It is not necessary to clear a try/catch block before using it again; if
    8174             :    * another exception is thrown the previously caught exception will just be
    8175             :    * overwritten.  However, it is often a good idea since it makes it easier
    8176             :    * to determine which operation threw a given exception.
    8177             :    */
    8178             :   void Reset();
    8179             : 
    8180             :   /**
    8181             :    * Set verbosity of the external exception handler.
    8182             :    *
    8183             :    * By default, exceptions that are caught by an external exception
    8184             :    * handler are not reported.  Call SetVerbose with true on an
    8185             :    * external exception handler to have exceptions caught by the
    8186             :    * handler reported as if they were not caught.
    8187             :    */
    8188             :   void SetVerbose(bool value);
    8189             : 
    8190             :   /**
    8191             :    * Set whether or not this TryCatch should capture a Message object
    8192             :    * which holds source information about where the exception
    8193             :    * occurred.  True by default.
    8194             :    */
    8195             :   void SetCaptureMessage(bool value);
    8196             : 
    8197             :   /**
    8198             :    * There are cases when the raw address of C++ TryCatch object cannot be
    8199             :    * used for comparisons with addresses into the JS stack. The cases are:
    8200             :    * 1) ARM, ARM64 and MIPS simulators which have separate JS stack.
    8201             :    * 2) Address sanitizer allocates local C++ object in the heap when
    8202             :    *    UseAfterReturn mode is enabled.
    8203             :    * This method returns address that can be used for comparisons with
    8204             :    * addresses into the JS stack. When neither simulator nor ASAN's
    8205             :    * UseAfterReturn is enabled, then the address returned will be the address
    8206             :    * of the C++ try catch handler itself.
    8207             :    */
    8208             :   static void* JSStackComparableAddress(TryCatch* handler) {
    8209      199840 :     if (handler == NULL) return NULL;
    8210      190465 :     return handler->js_stack_comparable_address_;
    8211             :   }
    8212             : 
    8213             :   TryCatch(const TryCatch&) = delete;
    8214             :   void operator=(const TryCatch&) = delete;
    8215             :   void* operator new(size_t size);
    8216             :   void operator delete(void*, size_t);
    8217             : 
    8218             :  private:
    8219             :   void ResetInternal();
    8220             : 
    8221             :   internal::Isolate* isolate_;
    8222             :   TryCatch* next_;
    8223             :   void* exception_;
    8224             :   void* message_obj_;
    8225             :   void* js_stack_comparable_address_;
    8226             :   bool is_verbose_ : 1;
    8227             :   bool can_continue_ : 1;
    8228             :   bool capture_message_ : 1;
    8229             :   bool rethrow_ : 1;
    8230             :   bool has_terminated_ : 1;
    8231             : 
    8232             :   friend class internal::Isolate;
    8233             : };
    8234             : 
    8235             : 
    8236             : // --- Context ---
    8237             : 
    8238             : 
    8239             : /**
    8240             :  * A container for extension names.
    8241             :  */
    8242             : class V8_EXPORT ExtensionConfiguration {
    8243             :  public:
    8244      107248 :   ExtensionConfiguration() : name_count_(0), names_(NULL) { }
    8245             :   ExtensionConfiguration(int name_count, const char* names[])
    8246             :       : name_count_(name_count), names_(names) { }
    8247             : 
    8248             :   const char** begin() const { return &names_[0]; }
    8249      107824 :   const char** end()  const { return &names_[name_count_]; }
    8250             : 
    8251             :  private:
    8252             :   const int name_count_;
    8253             :   const char** names_;
    8254             : };
    8255             : 
    8256             : /**
    8257             :  * A sandboxed execution context with its own set of built-in objects
    8258             :  * and functions.
    8259             :  */
    8260             : class V8_EXPORT Context {
    8261             :  public:
    8262             :   /**
    8263             :    * Returns the global proxy object.
    8264             :    *
    8265             :    * Global proxy object is a thin wrapper whose prototype points to actual
    8266             :    * context's global object with the properties like Object, etc. This is done
    8267             :    * that way for security reasons (for more details see
    8268             :    * https://wiki.mozilla.org/Gecko:SplitWindow).
    8269             :    *
    8270             :    * Please note that changes to global proxy object prototype most probably
    8271             :    * would break VM---v8 expects only global object as a prototype of global
    8272             :    * proxy object.
    8273             :    */
    8274             :   Local<Object> Global();
    8275             : 
    8276             :   /**
    8277             :    * Detaches the global object from its context before
    8278             :    * the global object can be reused to create a new context.
    8279             :    */
    8280             :   void DetachGlobal();
    8281             : 
    8282             :   /**
    8283             :    * Creates a new context and returns a handle to the newly allocated
    8284             :    * context.
    8285             :    *
    8286             :    * \param isolate The isolate in which to create the context.
    8287             :    *
    8288             :    * \param extensions An optional extension configuration containing
    8289             :    * the extensions to be installed in the newly created context.
    8290             :    *
    8291             :    * \param global_template An optional object template from which the
    8292             :    * global object for the newly created context will be created.
    8293             :    *
    8294             :    * \param global_object An optional global object to be reused for
    8295             :    * the newly created context. This global object must have been
    8296             :    * created by a previous call to Context::New with the same global
    8297             :    * template. The state of the global object will be completely reset
    8298             :    * and only object identify will remain.
    8299             :    */
    8300             :   static Local<Context> New(
    8301             :       Isolate* isolate, ExtensionConfiguration* extensions = NULL,
    8302             :       MaybeLocal<ObjectTemplate> global_template = MaybeLocal<ObjectTemplate>(),
    8303             :       MaybeLocal<Value> global_object = MaybeLocal<Value>());
    8304             : 
    8305             :   /**
    8306             :    * Create a new context from a (non-default) context snapshot. There
    8307             :    * is no way to provide a global object template since we do not create
    8308             :    * a new global object from template, but we can reuse a global object.
    8309             :    *
    8310             :    * \param isolate See v8::Context::New.
    8311             :    *
    8312             :    * \param context_snapshot_index The index of the context snapshot to
    8313             :    * deserialize from. Use v8::Context::New for the default snapshot.
    8314             :    *
    8315             :    * \param embedder_fields_deserializer Optional callback to deserialize
    8316             :    * internal fields. It should match the SerializeInternalFieldCallback used
    8317             :    * to serialize.
    8318             :    *
    8319             :    * \param extensions See v8::Context::New.
    8320             :    *
    8321             :    * \param global_object See v8::Context::New.
    8322             :    */
    8323             : 
    8324             :   static MaybeLocal<Context> FromSnapshot(
    8325             :       Isolate* isolate, size_t context_snapshot_index,
    8326             :       DeserializeInternalFieldsCallback embedder_fields_deserializer =
    8327             :           DeserializeInternalFieldsCallback(),
    8328             :       ExtensionConfiguration* extensions = nullptr,
    8329             :       MaybeLocal<Value> global_object = MaybeLocal<Value>());
    8330             : 
    8331             :   /**
    8332             :    * Returns an global object that isn't backed by an actual context.
    8333             :    *
    8334             :    * The global template needs to have access checks with handlers installed.
    8335             :    * If an existing global object is passed in, the global object is detached
    8336             :    * from its context.
    8337             :    *
    8338             :    * Note that this is different from a detached context where all accesses to
    8339             :    * the global proxy will fail. Instead, the access check handlers are invoked.
    8340             :    *
    8341             :    * It is also not possible to detach an object returned by this method.
    8342             :    * Instead, the access check handlers need to return nothing to achieve the
    8343             :    * same effect.
    8344             :    *
    8345             :    * It is possible, however, to create a new context from the global object
    8346             :    * returned by this method.
    8347             :    */
    8348             :   static MaybeLocal<Object> NewRemoteContext(
    8349             :       Isolate* isolate, Local<ObjectTemplate> global_template,
    8350             :       MaybeLocal<Value> global_object = MaybeLocal<Value>());
    8351             : 
    8352             :   /**
    8353             :    * Sets the security token for the context.  To access an object in
    8354             :    * another context, the security tokens must match.
    8355             :    */
    8356             :   void SetSecurityToken(Local<Value> token);
    8357             : 
    8358             :   /** Restores the security token to the default value. */
    8359             :   void UseDefaultSecurityToken();
    8360             : 
    8361             :   /** Returns the security token of this context.*/
    8362             :   Local<Value> GetSecurityToken();
    8363             : 
    8364             :   /**
    8365             :    * Enter this context.  After entering a context, all code compiled
    8366             :    * and run is compiled and run in this context.  If another context
    8367             :    * is already entered, this old context is saved so it can be
    8368             :    * restored when the new context is exited.
    8369             :    */
    8370             :   void Enter();
    8371             : 
    8372             :   /**
    8373             :    * Exit this context.  Exiting the current context restores the
    8374             :    * context that was in place when entering the current context.
    8375             :    */
    8376             :   void Exit();
    8377             : 
    8378             :   /** Returns an isolate associated with a current context. */
    8379             :   Isolate* GetIsolate();
    8380             : 
    8381             :   /**
    8382             :    * The field at kDebugIdIndex used to be reserved for the inspector.
    8383             :    * It now serves no purpose.
    8384             :    */
    8385             :   enum EmbedderDataFields { kDebugIdIndex = 0 };
    8386             : 
    8387             :   /**
    8388             :    * Gets the embedder data with the given index, which must have been set by a
    8389             :    * previous call to SetEmbedderData with the same index.
    8390             :    */
    8391             :   V8_INLINE Local<Value> GetEmbedderData(int index);
    8392             : 
    8393             :   /**
    8394             :    * Gets the binding object used by V8 extras. Extra natives get a reference
    8395             :    * to this object and can use it to "export" functionality by adding
    8396             :    * properties. Extra natives can also "import" functionality by accessing
    8397             :    * properties added by the embedder using the V8 API.
    8398             :    */
    8399             :   Local<Object> GetExtrasBindingObject();
    8400             : 
    8401             :   /**
    8402             :    * Sets the embedder data with the given index, growing the data as
    8403             :    * needed. Note that index 0 currently has a special meaning for Chrome's
    8404             :    * debugger.
    8405             :    */
    8406             :   void SetEmbedderData(int index, Local<Value> value);
    8407             : 
    8408             :   /**
    8409             :    * Gets a 2-byte-aligned native pointer from the embedder data with the given
    8410             :    * index, which must have been set by a previous call to
    8411             :    * SetAlignedPointerInEmbedderData with the same index. Note that index 0
    8412             :    * currently has a special meaning for Chrome's debugger.
    8413             :    */
    8414             :   V8_INLINE void* GetAlignedPointerFromEmbedderData(int index);
    8415             : 
    8416             :   /**
    8417             :    * Sets a 2-byte-aligned native pointer in the embedder data with the given
    8418             :    * index, growing the data as needed. Note that index 0 currently has a
    8419             :    * special meaning for Chrome's debugger.
    8420             :    */
    8421             :   void SetAlignedPointerInEmbedderData(int index, void* value);
    8422             : 
    8423             :   /**
    8424             :    * Control whether code generation from strings is allowed. Calling
    8425             :    * this method with false will disable 'eval' and the 'Function'
    8426             :    * constructor for code running in this context. If 'eval' or the
    8427             :    * 'Function' constructor are used an exception will be thrown.
    8428             :    *
    8429             :    * If code generation from strings is not allowed the
    8430             :    * V8::AllowCodeGenerationFromStrings callback will be invoked if
    8431             :    * set before blocking the call to 'eval' or the 'Function'
    8432             :    * constructor. If that callback returns true, the call will be
    8433             :    * allowed, otherwise an exception will be thrown. If no callback is
    8434             :    * set an exception will be thrown.
    8435             :    */
    8436             :   void AllowCodeGenerationFromStrings(bool allow);
    8437             : 
    8438             :   /**
    8439             :    * Returns true if code generation from strings is allowed for the context.
    8440             :    * For more details see AllowCodeGenerationFromStrings(bool) documentation.
    8441             :    */
    8442             :   bool IsCodeGenerationFromStringsAllowed();
    8443             : 
    8444             :   /**
    8445             :    * Sets the error description for the exception that is thrown when
    8446             :    * code generation from strings is not allowed and 'eval' or the 'Function'
    8447             :    * constructor are called.
    8448             :    */
    8449             :   void SetErrorMessageForCodeGenerationFromStrings(Local<String> message);
    8450             : 
    8451             :   /**
    8452             :    * Estimate the memory in bytes retained by this context.
    8453             :    */
    8454             :   V8_DEPRECATED("no longer supported", size_t EstimatedSize());
    8455             : 
    8456             :   /**
    8457             :    * Stack-allocated class which sets the execution context for all
    8458             :    * operations executed within a local scope.
    8459             :    */
    8460             :   class Scope {
    8461             :    public:
    8462          18 :     explicit V8_INLINE Scope(Local<Context> context) : context_(context) {
    8463      749375 :       context_->Enter();
    8464             :     }
    8465      749376 :     V8_INLINE ~Scope() { context_->Exit(); }
    8466             : 
    8467             :    private:
    8468             :     Local<Context> context_;
    8469             :   };
    8470             : 
    8471             :  private:
    8472             :   friend class Value;
    8473             :   friend class Script;
    8474             :   friend class Object;
    8475             :   friend class Function;
    8476             : 
    8477             :   Local<Value> SlowGetEmbedderData(int index);
    8478             :   void* SlowGetAlignedPointerFromEmbedderData(int index);
    8479             : };
    8480             : 
    8481             : 
    8482             : /**
    8483             :  * Multiple threads in V8 are allowed, but only one thread at a time is allowed
    8484             :  * to use any given V8 isolate, see the comments in the Isolate class. The
    8485             :  * definition of 'using a V8 isolate' includes accessing handles or holding onto
    8486             :  * object pointers obtained from V8 handles while in the particular V8 isolate.
    8487             :  * It is up to the user of V8 to ensure, perhaps with locking, that this
    8488             :  * constraint is not violated. In addition to any other synchronization
    8489             :  * mechanism that may be used, the v8::Locker and v8::Unlocker classes must be
    8490             :  * used to signal thread switches to V8.
    8491             :  *
    8492             :  * v8::Locker is a scoped lock object. While it's active, i.e. between its
    8493             :  * construction and destruction, the current thread is allowed to use the locked
    8494             :  * isolate. V8 guarantees that an isolate can be locked by at most one thread at
    8495             :  * any time. In other words, the scope of a v8::Locker is a critical section.
    8496             :  *
    8497             :  * Sample usage:
    8498             : * \code
    8499             :  * ...
    8500             :  * {
    8501             :  *   v8::Locker locker(isolate);
    8502             :  *   v8::Isolate::Scope isolate_scope(isolate);
    8503             :  *   ...
    8504             :  *   // Code using V8 and isolate goes here.
    8505             :  *   ...
    8506             :  * } // Destructor called here
    8507             :  * \endcode
    8508             :  *
    8509             :  * If you wish to stop using V8 in a thread A you can do this either by
    8510             :  * destroying the v8::Locker object as above or by constructing a v8::Unlocker
    8511             :  * object:
    8512             :  *
    8513             :  * \code
    8514             :  * {
    8515             :  *   isolate->Exit();
    8516             :  *   v8::Unlocker unlocker(isolate);
    8517             :  *   ...
    8518             :  *   // Code not using V8 goes here while V8 can run in another thread.
    8519             :  *   ...
    8520             :  * } // Destructor called here.
    8521             :  * isolate->Enter();
    8522             :  * \endcode
    8523             :  *
    8524             :  * The Unlocker object is intended for use in a long-running callback from V8,
    8525             :  * where you want to release the V8 lock for other threads to use.
    8526             :  *
    8527             :  * The v8::Locker is a recursive lock, i.e. you can lock more than once in a
    8528             :  * given thread. This can be useful if you have code that can be called either
    8529             :  * from code that holds the lock or from code that does not. The Unlocker is
    8530             :  * not recursive so you can not have several Unlockers on the stack at once, and
    8531             :  * you can not use an Unlocker in a thread that is not inside a Locker's scope.
    8532             :  *
    8533             :  * An unlocker will unlock several lockers if it has to and reinstate the
    8534             :  * correct depth of locking on its destruction, e.g.:
    8535             :  *
    8536             :  * \code
    8537             :  * // V8 not locked.
    8538             :  * {
    8539             :  *   v8::Locker locker(isolate);
    8540             :  *   Isolate::Scope isolate_scope(isolate);
    8541             :  *   // V8 locked.
    8542             :  *   {
    8543             :  *     v8::Locker another_locker(isolate);
    8544             :  *     // V8 still locked (2 levels).
    8545             :  *     {
    8546             :  *       isolate->Exit();
    8547             :  *       v8::Unlocker unlocker(isolate);
    8548             :  *       // V8 not locked.
    8549             :  *     }
    8550             :  *     isolate->Enter();
    8551             :  *     // V8 locked again (2 levels).
    8552             :  *   }
    8553             :  *   // V8 still locked (1 level).
    8554             :  * }
    8555             :  * // V8 Now no longer locked.
    8556             :  * \endcode
    8557             :  */
    8558             : class V8_EXPORT Unlocker {
    8559             :  public:
    8560             :   /**
    8561             :    * Initialize Unlocker for a given Isolate.
    8562             :    */
    8563             :   V8_INLINE explicit Unlocker(Isolate* isolate) { Initialize(isolate); }
    8564             : 
    8565             :   ~Unlocker();
    8566             :  private:
    8567             :   void Initialize(Isolate* isolate);
    8568             : 
    8569             :   internal::Isolate* isolate_;
    8570             : };
    8571             : 
    8572             : 
    8573             : class V8_EXPORT Locker {
    8574             :  public:
    8575             :   /**
    8576             :    * Initialize Locker for a given Isolate.
    8577             :    */
    8578             :   V8_INLINE explicit Locker(Isolate* isolate) { Initialize(isolate); }
    8579             : 
    8580             :   ~Locker();
    8581             : 
    8582             :   /**
    8583             :    * Returns whether or not the locker for a given isolate, is locked by the
    8584             :    * current thread.
    8585             :    */
    8586             :   static bool IsLocked(Isolate* isolate);
    8587             : 
    8588             :   /**
    8589             :    * Returns whether v8::Locker is being used by this V8 instance.
    8590             :    */
    8591             :   static bool IsActive();
    8592             : 
    8593             :   // Disallow copying and assigning.
    8594             :   Locker(const Locker&) = delete;
    8595             :   void operator=(const Locker&) = delete;
    8596             : 
    8597             :  private:
    8598             :   void Initialize(Isolate* isolate);
    8599             : 
    8600             :   bool has_lock_;
    8601             :   bool top_level_;
    8602             :   internal::Isolate* isolate_;
    8603             : };
    8604             : 
    8605             : 
    8606             : // --- Implementation ---
    8607             : 
    8608             : 
    8609             : namespace internal {
    8610             : 
    8611             : const int kApiPointerSize = sizeof(void*);  // NOLINT
    8612             : const int kApiIntSize = sizeof(int);  // NOLINT
    8613             : const int kApiInt64Size = sizeof(int64_t);  // NOLINT
    8614             : 
    8615             : // Tag information for HeapObject.
    8616             : const int kHeapObjectTag = 1;
    8617             : const int kHeapObjectTagSize = 2;
    8618             : const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1;
    8619             : 
    8620             : // Tag information for Smi.
    8621             : const int kSmiTag = 0;
    8622             : const int kSmiTagSize = 1;
    8623             : const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1;
    8624             : 
    8625             : template <size_t ptr_size> struct SmiTagging;
    8626             : 
    8627             : template<int kSmiShiftSize>
    8628             : V8_INLINE internal::Object* IntToSmi(int value) {
    8629             :   int smi_shift_bits = kSmiTagSize + kSmiShiftSize;
    8630             :   uintptr_t tagged_value =
    8631  2047974235 :       (static_cast<uintptr_t>(value) << smi_shift_bits) | kSmiTag;
    8632   842695147 :   return reinterpret_cast<internal::Object*>(tagged_value);
    8633             : }
    8634             : 
    8635             : // Smi constants for 32-bit systems.
    8636             : template <> struct SmiTagging<4> {
    8637             :   enum { kSmiShiftSize = 0, kSmiValueSize = 31 };
    8638             :   static int SmiShiftSize() { return kSmiShiftSize; }
    8639             :   static int SmiValueSize() { return kSmiValueSize; }
    8640             :   V8_INLINE static int SmiToInt(const internal::Object* value) {
    8641             :     int shift_bits = kSmiTagSize + kSmiShiftSize;
    8642             :     // Throw away top 32 bits and shift down (requires >> to be sign extending).
    8643             :     return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits;
    8644             :   }
    8645             :   V8_INLINE static internal::Object* IntToSmi(int value) {
    8646             :     return internal::IntToSmi<kSmiShiftSize>(value);
    8647             :   }
    8648             :   V8_INLINE static bool IsValidSmi(intptr_t value) {
    8649             :     // To be representable as an tagged small integer, the two
    8650             :     // most-significant bits of 'value' must be either 00 or 11 due to
    8651             :     // sign-extension. To check this we add 01 to the two
    8652             :     // most-significant bits, and check if the most-significant bit is 0
    8653             :     //
    8654             :     // CAUTION: The original code below:
    8655             :     // bool result = ((value + 0x40000000) & 0x80000000) == 0;
    8656             :     // may lead to incorrect results according to the C language spec, and
    8657             :     // in fact doesn't work correctly with gcc4.1.1 in some cases: The
    8658             :     // compiler may produce undefined results in case of signed integer
    8659             :     // overflow. The computation must be done w/ unsigned ints.
    8660             :     return static_cast<uintptr_t>(value + 0x40000000U) < 0x80000000U;
    8661             :   }
    8662             : };
    8663             : 
    8664             : // Smi constants for 64-bit systems.
    8665             : template <> struct SmiTagging<8> {
    8666             :   enum { kSmiShiftSize = 31, kSmiValueSize = 32 };
    8667             :   static int SmiShiftSize() { return kSmiShiftSize; }
    8668             :   static int SmiValueSize() { return kSmiValueSize; }
    8669             :   V8_INLINE static int SmiToInt(const internal::Object* value) {
    8670             :     int shift_bits = kSmiTagSize + kSmiShiftSize;
    8671             :     // Shift down and throw away top 32 bits.
    8672 36039382464 :     return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits);
    8673             :   }
    8674             :   V8_INLINE static internal::Object* IntToSmi(int value) {
    8675             :     return internal::IntToSmi<kSmiShiftSize>(value);
    8676             :   }
    8677             :   V8_INLINE static bool IsValidSmi(intptr_t value) {
    8678             :     // To be representable as a long smi, the value must be a 32-bit integer.
    8679         129 :     return (value == static_cast<int32_t>(value));
    8680             :   }
    8681             : };
    8682             : 
    8683             : typedef SmiTagging<kApiPointerSize> PlatformSmiTagging;
    8684             : const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize;
    8685             : const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize;
    8686             : V8_INLINE static bool SmiValuesAre31Bits() { return kSmiValueSize == 31; }
    8687             : V8_INLINE static bool SmiValuesAre32Bits() { return kSmiValueSize == 32; }
    8688             : 
    8689             : /**
    8690             :  * This class exports constants and functionality from within v8 that
    8691             :  * is necessary to implement inline functions in the v8 api.  Don't
    8692             :  * depend on functions and constants defined here.
    8693             :  */
    8694             : class Internals {
    8695             :  public:
    8696             :   // These values match non-compiler-dependent values defined within
    8697             :   // the implementation of v8.
    8698             :   static const int kHeapObjectMapOffset = 0;
    8699             :   static const int kMapInstanceTypeAndBitFieldOffset =
    8700             :       1 * kApiPointerSize + kApiIntSize;
    8701             :   static const int kStringResourceOffset = 3 * kApiPointerSize;
    8702             : 
    8703             :   static const int kOddballKindOffset = 4 * kApiPointerSize + sizeof(double);
    8704             :   static const int kForeignAddressOffset = kApiPointerSize;
    8705             :   static const int kJSObjectHeaderSize = 3 * kApiPointerSize;
    8706             :   static const int kFixedArrayHeaderSize = 2 * kApiPointerSize;
    8707             :   static const int kContextHeaderSize = 2 * kApiPointerSize;
    8708             :   static const int kContextEmbedderDataIndex = 5;
    8709             :   static const int kFullStringRepresentationMask = 0x0f;
    8710             :   static const int kStringEncodingMask = 0x8;
    8711             :   static const int kExternalTwoByteRepresentationTag = 0x02;
    8712             :   static const int kExternalOneByteRepresentationTag = 0x0a;
    8713             : 
    8714             :   static const int kIsolateEmbedderDataOffset = 0 * kApiPointerSize;
    8715             :   static const int kExternalMemoryOffset = 4 * kApiPointerSize;
    8716             :   static const int kExternalMemoryLimitOffset =
    8717             :       kExternalMemoryOffset + kApiInt64Size;
    8718             :   static const int kIsolateRootsOffset = kExternalMemoryLimitOffset +
    8719             :                                          kApiInt64Size + kApiInt64Size +
    8720             :                                          kApiPointerSize + kApiPointerSize;
    8721             :   static const int kUndefinedValueRootIndex = 4;
    8722             :   static const int kTheHoleValueRootIndex = 5;
    8723             :   static const int kNullValueRootIndex = 6;
    8724             :   static const int kTrueValueRootIndex = 7;
    8725             :   static const int kFalseValueRootIndex = 8;
    8726             :   static const int kEmptyStringRootIndex = 9;
    8727             : 
    8728             :   static const int kNodeClassIdOffset = 1 * kApiPointerSize;
    8729             :   static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3;
    8730             :   static const int kNodeStateMask = 0x7;
    8731             :   static const int kNodeStateIsWeakValue = 2;
    8732             :   static const int kNodeStateIsPendingValue = 3;
    8733             :   static const int kNodeStateIsNearDeathValue = 4;
    8734             :   static const int kNodeIsIndependentShift = 3;
    8735             :   static const int kNodeIsActiveShift = 4;
    8736             : 
    8737             :   static const int kJSApiObjectType = 0xbb;
    8738             :   static const int kJSObjectType = 0xbc;
    8739             :   static const int kFirstNonstringType = 0x80;
    8740             :   static const int kOddballType = 0x82;
    8741             :   static const int kForeignType = 0x86;
    8742             : 
    8743             :   static const int kUndefinedOddballKind = 5;
    8744             :   static const int kNullOddballKind = 3;
    8745             : 
    8746             :   static const uint32_t kNumIsolateDataSlots = 4;
    8747             : 
    8748             :   V8_EXPORT static void CheckInitializedImpl(v8::Isolate* isolate);
    8749             :   V8_INLINE static void CheckInitialized(v8::Isolate* isolate) {
    8750             : #ifdef V8_ENABLE_CHECKS
    8751             :     CheckInitializedImpl(isolate);
    8752             : #endif
    8753             :   }
    8754             : 
    8755             :   V8_INLINE static bool HasHeapObjectTag(const internal::Object* value) {
    8756   230058379 :     return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) ==
    8757             :             kHeapObjectTag);
    8758             :   }
    8759             : 
    8760             :   V8_INLINE static int SmiValue(const internal::Object* value) {
    8761             :     return PlatformSmiTagging::SmiToInt(value);
    8762             :   }
    8763             : 
    8764             :   V8_INLINE static internal::Object* IntToSmi(int value) {
    8765             :     return PlatformSmiTagging::IntToSmi(value);
    8766             :   }
    8767             : 
    8768             :   V8_INLINE static bool IsValidSmi(intptr_t value) {
    8769             :     return PlatformSmiTagging::IsValidSmi(value);
    8770             :   }
    8771             : 
    8772             :   V8_INLINE static int GetInstanceType(const internal::Object* obj) {
    8773             :     typedef internal::Object O;
    8774             :     O* map = ReadField<O*>(obj, kHeapObjectMapOffset);
    8775             :     // Map::InstanceType is defined so that it will always be loaded into
    8776             :     // the LS 8 bits of one 16-bit word, regardless of endianess.
    8777   273084758 :     return ReadField<uint16_t>(map, kMapInstanceTypeAndBitFieldOffset) & 0xff;
    8778             :   }
    8779             : 
    8780             :   V8_INLINE static int GetOddballKind(const internal::Object* obj) {
    8781             :     typedef internal::Object O;
    8782             :     return SmiValue(ReadField<O*>(obj, kOddballKindOffset));
    8783             :   }
    8784             : 
    8785             :   V8_INLINE static bool IsExternalTwoByteString(int instance_type) {
    8786             :     int representation = (instance_type & kFullStringRepresentationMask);
    8787             :     return representation == kExternalTwoByteRepresentationTag;
    8788             :   }
    8789             : 
    8790             :   V8_INLINE static uint8_t GetNodeFlag(internal::Object** obj, int shift) {
    8791             :       uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
    8792             :       return *addr & static_cast<uint8_t>(1U << shift);
    8793             :   }
    8794             : 
    8795             :   V8_INLINE static void UpdateNodeFlag(internal::Object** obj,
    8796             :                                        bool value, int shift) {
    8797             :       uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
    8798             :       uint8_t mask = static_cast<uint8_t>(1U << shift);
    8799       40693 :       *addr = static_cast<uint8_t>((*addr & ~mask) | (value << shift));
    8800             :   }
    8801             : 
    8802             :   V8_INLINE static uint8_t GetNodeState(internal::Object** obj) {
    8803             :     uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
    8804             :     return *addr & kNodeStateMask;
    8805             :   }
    8806             : 
    8807             :   V8_INLINE static void UpdateNodeState(internal::Object** obj,
    8808             :                                         uint8_t value) {
    8809             :     uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
    8810             :     *addr = static_cast<uint8_t>((*addr & ~kNodeStateMask) | value);
    8811             :   }
    8812             : 
    8813             :   V8_INLINE static void SetEmbedderData(v8::Isolate* isolate,
    8814             :                                         uint32_t slot,
    8815             :                                         void* data) {
    8816             :     uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) +
    8817             :                     kIsolateEmbedderDataOffset + slot * kApiPointerSize;
    8818       58290 :     *reinterpret_cast<void**>(addr) = data;
    8819             :   }
    8820             : 
    8821             :   V8_INLINE static void* GetEmbedderData(const v8::Isolate* isolate,
    8822             :                                          uint32_t slot) {
    8823             :     const uint8_t* addr = reinterpret_cast<const uint8_t*>(isolate) +
    8824             :         kIsolateEmbedderDataOffset + slot * kApiPointerSize;
    8825      235710 :     return *reinterpret_cast<void* const*>(addr);
    8826             :   }
    8827             : 
    8828             :   V8_INLINE static internal::Object** GetRoot(v8::Isolate* isolate,
    8829             :                                               int index) {
    8830        2364 :     uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset;
    8831        2364 :     return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize);
    8832             :   }
    8833             : 
    8834             :   template <typename T>
    8835             :   V8_INLINE static T ReadField(const internal::Object* ptr, int offset) {
    8836             :     const uint8_t* addr =
    8837             :         reinterpret_cast<const uint8_t*>(ptr) + offset - kHeapObjectTag;
    8838   301150412 :     return *reinterpret_cast<const T*>(addr);
    8839             :   }
    8840             : 
    8841             :   template <typename T>
    8842             :   V8_INLINE static T ReadEmbedderData(const v8::Context* context, int index) {
    8843             :     typedef internal::Object O;
    8844             :     typedef internal::Internals I;
    8845      258796 :     O* ctx = *reinterpret_cast<O* const*>(context);
    8846             :     int embedder_data_offset = I::kContextHeaderSize +
    8847             :         (internal::kApiPointerSize * I::kContextEmbedderDataIndex);
    8848             :     O* embedder_data = I::ReadField<O*>(ctx, embedder_data_offset);
    8849             :     int value_offset =
    8850             :         I::kFixedArrayHeaderSize + (internal::kApiPointerSize * index);
    8851             :     return I::ReadField<T>(embedder_data, value_offset);
    8852             :   }
    8853             : };
    8854             : 
    8855             : }  // namespace internal
    8856             : 
    8857             : 
    8858             : template <class T>
    8859             : Local<T> Local<T>::New(Isolate* isolate, Local<T> that) {
    8860             :   return New(isolate, that.val_);
    8861             : }
    8862             : 
    8863             : template <class T>
    8864             : Local<T> Local<T>::New(Isolate* isolate, const PersistentBase<T>& that) {
    8865     3655507 :   return New(isolate, that.val_);
    8866             : }
    8867             : 
    8868             : 
    8869             : template <class T>
    8870             : Local<T> Local<T>::New(Isolate* isolate, T* that) {
    8871     3668295 :   if (that == NULL) return Local<T>();
    8872             :   T* that_ptr = that;
    8873             :   internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr);
    8874             :   return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(
    8875     3668295 :       reinterpret_cast<internal::Isolate*>(isolate), *p)));
    8876             : }
    8877             : 
    8878             : 
    8879             : template<class T>
    8880             : template<class S>
    8881             : void Eternal<T>::Set(Isolate* isolate, Local<S> handle) {
    8882             :   TYPE_CHECK(T, S);
    8883             :   val_ = reinterpret_cast<T*>(
    8884             :       V8::Eternalize(isolate, reinterpret_cast<Value*>(*handle)));
    8885             : }
    8886             : 
    8887             : template <class T>
    8888             : Local<T> Eternal<T>::Get(Isolate* isolate) const {
    8889             :   // The eternal handle will never go away, so as with the roots, we don't even
    8890             :   // need to open a handle.
    8891             :   return Local<T>(val_);
    8892             : }
    8893             : 
    8894             : 
    8895             : template <class T>
    8896             : Local<T> MaybeLocal<T>::ToLocalChecked() {
    8897    29276519 :   if (V8_UNLIKELY(val_ == nullptr)) V8::ToLocalEmpty();
    8898             :   return Local<T>(val_);
    8899             : }
    8900             : 
    8901             : 
    8902             : template <class T>
    8903             : void* WeakCallbackInfo<T>::GetInternalField(int index) const {
    8904             : #ifdef V8_ENABLE_CHECKS
    8905             :   if (index < 0 || index >= kEmbedderFieldsInWeakCallback) {
    8906             :     V8::InternalFieldOutOfBounds(index);
    8907             :   }
    8908             : #endif
    8909             :   return embedder_fields_[index];
    8910             : }
    8911             : 
    8912             : 
    8913             : template <class T>
    8914             : T* PersistentBase<T>::New(Isolate* isolate, T* that) {
    8915     4356743 :   if (that == NULL) return NULL;
    8916             :   internal::Object** p = reinterpret_cast<internal::Object**>(that);
    8917             :   return reinterpret_cast<T*>(
    8918             :       V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate),
    8919     4356743 :                              p));
    8920             : }
    8921             : 
    8922             : 
    8923             : template <class T, class M>
    8924             : template <class S, class M2>
    8925             : void Persistent<T, M>::Copy(const Persistent<S, M2>& that) {
    8926             :   TYPE_CHECK(T, S);
    8927             :   this->Reset();
    8928             :   if (that.IsEmpty()) return;
    8929             :   internal::Object** p = reinterpret_cast<internal::Object**>(that.val_);
    8930             :   this->val_ = reinterpret_cast<T*>(V8::CopyPersistent(p));
    8931             :   M::Copy(that, this);
    8932             : }
    8933             : 
    8934             : 
    8935             : template <class T>
    8936             : bool PersistentBase<T>::IsIndependent() const {
    8937             :   typedef internal::Internals I;
    8938             :   if (this->IsEmpty()) return false;
    8939             :   return I::GetNodeFlag(reinterpret_cast<internal::Object**>(this->val_),
    8940             :                         I::kNodeIsIndependentShift);
    8941             : }
    8942             : 
    8943             : 
    8944             : template <class T>
    8945             : bool PersistentBase<T>::IsNearDeath() const {
    8946             :   typedef internal::Internals I;
    8947             :   if (this->IsEmpty()) return false;
    8948             :   uint8_t node_state =
    8949             :       I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_));
    8950             :   return node_state == I::kNodeStateIsNearDeathValue ||
    8951             :       node_state == I::kNodeStateIsPendingValue;
    8952             : }
    8953             : 
    8954             : 
    8955             : template <class T>
    8956             : bool PersistentBase<T>::IsWeak() const {
    8957             :   typedef internal::Internals I;
    8958             :   if (this->IsEmpty()) return false;
    8959             :   return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) ==
    8960             :       I::kNodeStateIsWeakValue;
    8961             : }
    8962             : 
    8963             : 
    8964             : template <class T>
    8965             : void PersistentBase<T>::Reset() {
    8966     8477310 :   if (this->IsEmpty()) return;
    8967     4356379 :   V8::DisposeGlobal(reinterpret_cast<internal::Object**>(this->val_));
    8968     4344243 :   val_ = 0;
    8969             : }
    8970             : 
    8971             : 
    8972             : template <class T>
    8973             : template <class S>
    8974             : void PersistentBase<T>::Reset(Isolate* isolate, const Local<S>& other) {
    8975             :   TYPE_CHECK(T, S);
    8976             :   Reset();
    8977      117119 :   if (other.IsEmpty()) return;
    8978      117119 :   this->val_ = New(isolate, other.val_);
    8979             : }
    8980             : 
    8981             : 
    8982             : template <class T>
    8983             : template <class S>
    8984             : void PersistentBase<T>::Reset(Isolate* isolate,
    8985             :                               const PersistentBase<S>& other) {
    8986             :   TYPE_CHECK(T, S);
    8987             :   Reset();
    8988        5047 :   if (other.IsEmpty()) return;
    8989        1207 :   this->val_ = New(isolate, other.val_);
    8990             : }
    8991             : 
    8992             : 
    8993             : template <class T>
    8994             : template <typename P>
    8995             : V8_INLINE void PersistentBase<T>::SetWeak(
    8996             :     P* parameter, typename WeakCallbackInfo<P>::Callback callback,
    8997             :     WeakCallbackType type) {
    8998             :   typedef typename WeakCallbackInfo<void>::Callback Callback;
    8999       41119 :   V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), parameter,
    9000       40693 :                reinterpret_cast<Callback>(callback), type);
    9001             : }
    9002             : 
    9003             : template <class T>
    9004             : void PersistentBase<T>::SetWeak() {
    9005             :   V8::MakeWeak(reinterpret_cast<internal::Object***>(&this->val_));
    9006             : }
    9007             : 
    9008             : template <class T>
    9009             : template <typename P>
    9010             : P* PersistentBase<T>::ClearWeak() {
    9011             :   return reinterpret_cast<P*>(
    9012             :     V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_)));
    9013             : }
    9014             : 
    9015             : template <class T>
    9016             : void PersistentBase<T>::RegisterExternalReference(Isolate* isolate) const {
    9017             :   if (IsEmpty()) return;
    9018             :   V8::RegisterExternallyReferencedObject(
    9019             :       reinterpret_cast<internal::Object**>(this->val_),
    9020             :       reinterpret_cast<internal::Isolate*>(isolate));
    9021             : }
    9022             : 
    9023             : template <class T>
    9024             : void PersistentBase<T>::MarkIndependent() {
    9025             :   typedef internal::Internals I;
    9026       40693 :   if (this->IsEmpty()) return;
    9027             :   I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_),
    9028             :                     true,
    9029             :                     I::kNodeIsIndependentShift);
    9030             : }
    9031             : 
    9032             : template <class T>
    9033             : void PersistentBase<T>::MarkActive() {
    9034             :   typedef internal::Internals I;
    9035             :   if (this->IsEmpty()) return;
    9036             :   I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), true,
    9037             :                     I::kNodeIsActiveShift);
    9038             : }
    9039             : 
    9040             : 
    9041             : template <class T>
    9042             : void PersistentBase<T>::SetWrapperClassId(uint16_t class_id) {
    9043             :   typedef internal::Internals I;
    9044             :   if (this->IsEmpty()) return;
    9045             :   internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_);
    9046             :   uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset;
    9047             :   *reinterpret_cast<uint16_t*>(addr) = class_id;
    9048             : }
    9049             : 
    9050             : 
    9051             : template <class T>
    9052             : uint16_t PersistentBase<T>::WrapperClassId() const {
    9053             :   typedef internal::Internals I;
    9054             :   if (this->IsEmpty()) return 0;
    9055             :   internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_);
    9056             :   uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset;
    9057             :   return *reinterpret_cast<uint16_t*>(addr);
    9058             : }
    9059             : 
    9060             : 
    9061             : template<typename T>
    9062             : ReturnValue<T>::ReturnValue(internal::Object** slot) : value_(slot) {}
    9063             : 
    9064             : template<typename T>
    9065             : template<typename S>
    9066             : void ReturnValue<T>::Set(const Persistent<S>& handle) {
    9067             :   TYPE_CHECK(T, S);
    9068             :   if (V8_UNLIKELY(handle.IsEmpty())) {
    9069             :     *value_ = GetDefaultValue();
    9070             :   } else {
    9071             :     *value_ = *reinterpret_cast<internal::Object**>(*handle);
    9072             :   }
    9073             : }
    9074             : 
    9075             : template <typename T>
    9076             : template <typename S>
    9077             : void ReturnValue<T>::Set(const Global<S>& handle) {
    9078             :   TYPE_CHECK(T, S);
    9079        8513 :   if (V8_UNLIKELY(handle.IsEmpty())) {
    9080           0 :     *value_ = GetDefaultValue();
    9081             :   } else {
    9082        8513 :     *value_ = *reinterpret_cast<internal::Object**>(*handle);
    9083             :   }
    9084             : }
    9085             : 
    9086             : template <typename T>
    9087             : template <typename S>
    9088             : void ReturnValue<T>::Set(const Local<S> handle) {
    9089             :   TYPE_CHECK(T, S);
    9090    12847514 :   if (V8_UNLIKELY(handle.IsEmpty())) {
    9091           0 :     *value_ = GetDefaultValue();
    9092             :   } else {
    9093    12847514 :     *value_ = *reinterpret_cast<internal::Object**>(*handle);
    9094             :   }
    9095             : }
    9096             : 
    9097             : template<typename T>
    9098             : void ReturnValue<T>::Set(double i) {
    9099             :   TYPE_CHECK(T, Number);
    9100           3 :   Set(Number::New(GetIsolate(), i));
    9101             : }
    9102             : 
    9103             : template<typename T>
    9104             : void ReturnValue<T>::Set(int32_t i) {
    9105             :   TYPE_CHECK(T, Integer);
    9106             :   typedef internal::Internals I;
    9107             :   if (V8_LIKELY(I::IsValidSmi(i))) {
    9108     3782681 :     *value_ = I::IntToSmi(i);
    9109             :     return;
    9110             :   }
    9111             :   Set(Integer::New(GetIsolate(), i));
    9112             : }
    9113             : 
    9114             : template<typename T>
    9115             : void ReturnValue<T>::Set(uint32_t i) {
    9116             :   TYPE_CHECK(T, Integer);
    9117             :   // Can't simply use INT32_MAX here for whatever reason.
    9118             :   bool fits_into_int32_t = (i & (1U << 31)) == 0;
    9119             :   if (V8_LIKELY(fits_into_int32_t)) {
    9120             :     Set(static_cast<int32_t>(i));
    9121             :     return;
    9122             :   }
    9123             :   Set(Integer::NewFromUnsigned(GetIsolate(), i));
    9124             : }
    9125             : 
    9126             : template<typename T>
    9127             : void ReturnValue<T>::Set(bool value) {
    9128             :   TYPE_CHECK(T, Boolean);
    9129             :   typedef internal::Internals I;
    9130             :   int root_index;
    9131        2364 :   if (value) {
    9132             :     root_index = I::kTrueValueRootIndex;
    9133             :   } else {
    9134             :     root_index = I::kFalseValueRootIndex;
    9135             :   }
    9136     2914178 :   *value_ = *I::GetRoot(GetIsolate(), root_index);
    9137             : }
    9138             : 
    9139             : template<typename T>
    9140             : void ReturnValue<T>::SetNull() {
    9141             :   TYPE_CHECK(T, Primitive);
    9142             :   typedef internal::Internals I;
    9143             :   *value_ = *I::GetRoot(GetIsolate(), I::kNullValueRootIndex);
    9144             : }
    9145             : 
    9146             : template<typename T>
    9147             : void ReturnValue<T>::SetUndefined() {
    9148             :   TYPE_CHECK(T, Primitive);
    9149             :   typedef internal::Internals I;
    9150             :   *value_ = *I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex);
    9151             : }
    9152             : 
    9153             : template<typename T>
    9154             : void ReturnValue<T>::SetEmptyString() {
    9155             :   TYPE_CHECK(T, String);
    9156             :   typedef internal::Internals I;
    9157             :   *value_ = *I::GetRoot(GetIsolate(), I::kEmptyStringRootIndex);
    9158             : }
    9159             : 
    9160             : template <typename T>
    9161             : Isolate* ReturnValue<T>::GetIsolate() const {
    9162             :   // Isolate is always the pointer below the default value on the stack.
    9163     2914166 :   return *reinterpret_cast<Isolate**>(&value_[-2]);
    9164             : }
    9165             : 
    9166             : template <typename T>
    9167             : Local<Value> ReturnValue<T>::Get() const {
    9168             :   typedef internal::Internals I;
    9169             :   if (*value_ == *I::GetRoot(GetIsolate(), I::kTheHoleValueRootIndex))
    9170             :     return Local<Value>(*Undefined(GetIsolate()));
    9171             :   return Local<Value>::New(GetIsolate(), reinterpret_cast<Value*>(value_));
    9172             : }
    9173             : 
    9174             : template <typename T>
    9175             : template <typename S>
    9176             : void ReturnValue<T>::Set(S* whatever) {
    9177             :   // Uncompilable to prevent inadvertent misuse.
    9178             :   TYPE_CHECK(S*, Primitive);
    9179             : }
    9180             : 
    9181             : template<typename T>
    9182             : internal::Object* ReturnValue<T>::GetDefaultValue() {
    9183             :   // Default value is always the pointer below value_ on the stack.
    9184           0 :   return value_[-1];
    9185             : }
    9186             : 
    9187             : template <typename T>
    9188             : FunctionCallbackInfo<T>::FunctionCallbackInfo(internal::Object** implicit_args,
    9189             :                                               internal::Object** values,
    9190             :                                               int length)
    9191    51875069 :     : implicit_args_(implicit_args), values_(values), length_(length) {}
    9192             : 
    9193             : template<typename T>
    9194       11732 : Local<Value> FunctionCallbackInfo<T>::operator[](int i) const {
    9195    57099128 :   if (i < 0 || length_ <= i) return Local<Value>(*Undefined(GetIsolate()));
    9196    57087396 :   return Local<Value>(reinterpret_cast<Value*>(values_ - i));
    9197             : }
    9198             : 
    9199             : 
    9200             : template<typename T>
    9201             : Local<Function> FunctionCallbackInfo<T>::Callee() const {
    9202             :   return Local<Function>(reinterpret_cast<Function*>(
    9203             :       &implicit_args_[kCalleeIndex]));
    9204             : }
    9205             : 
    9206             : 
    9207             : template<typename T>
    9208             : Local<Object> FunctionCallbackInfo<T>::This() const {
    9209       48654 :   return Local<Object>(reinterpret_cast<Object*>(values_ + 1));
    9210             : }
    9211             : 
    9212             : 
    9213             : template<typename T>
    9214             : Local<Object> FunctionCallbackInfo<T>::Holder() const {
    9215             :   return Local<Object>(reinterpret_cast<Object*>(
    9216             :       &implicit_args_[kHolderIndex]));
    9217             : }
    9218             : 
    9219             : template <typename T>
    9220             : Local<Value> FunctionCallbackInfo<T>::NewTarget() const {
    9221             :   return Local<Value>(
    9222             :       reinterpret_cast<Value*>(&implicit_args_[kNewTargetIndex]));
    9223             : }
    9224             : 
    9225             : template <typename T>
    9226             : Local<Value> FunctionCallbackInfo<T>::Data() const {
    9227    10152016 :   return Local<Value>(reinterpret_cast<Value*>(&implicit_args_[kDataIndex]));
    9228             : }
    9229             : 
    9230             : 
    9231             : template<typename T>
    9232             : Isolate* FunctionCallbackInfo<T>::GetIsolate() const {
    9233    34870316 :   return *reinterpret_cast<Isolate**>(&implicit_args_[kIsolateIndex]);
    9234             : }
    9235             : 
    9236             : 
    9237             : template<typename T>
    9238             : ReturnValue<T> FunctionCallbackInfo<T>::GetReturnValue() const {
    9239    14322350 :   return ReturnValue<T>(&implicit_args_[kReturnValueIndex]);
    9240             : }
    9241             : 
    9242             : 
    9243             : template<typename T>
    9244         556 : bool FunctionCallbackInfo<T>::IsConstructCall() const {
    9245             :   return !NewTarget()->IsUndefined();
    9246             : }
    9247             : 
    9248             : 
    9249             : template<typename T>
    9250             : int FunctionCallbackInfo<T>::Length() const {
    9251             :   return length_;
    9252             : }
    9253             : 
    9254             : ScriptOrigin::ScriptOrigin(Local<Value> resource_name,
    9255             :                            Local<Integer> resource_line_offset,
    9256             :                            Local<Integer> resource_column_offset,
    9257             :                            Local<Boolean> resource_is_shared_cross_origin,
    9258             :                            Local<Integer> script_id,
    9259             :                            Local<Value> source_map_url,
    9260             :                            Local<Boolean> resource_is_opaque,
    9261             :                            Local<Boolean> is_wasm, Local<Boolean> is_module)
    9262             :     : resource_name_(resource_name),
    9263             :       resource_line_offset_(resource_line_offset),
    9264             :       resource_column_offset_(resource_column_offset),
    9265       61662 :       options_(!resource_is_shared_cross_origin.IsEmpty() &&
    9266       30831 :                    resource_is_shared_cross_origin->IsTrue(),
    9267       30831 :                !resource_is_opaque.IsEmpty() && resource_is_opaque->IsTrue(),
    9268       25576 :                !is_wasm.IsEmpty() && is_wasm->IsTrue(),
    9269       27157 :                !is_module.IsEmpty() && is_module->IsTrue()),
    9270             :       script_id_(script_id),
    9271       51152 :       source_map_url_(source_map_url) {}
    9272             : 
    9273             : Local<Value> ScriptOrigin::ResourceName() const { return resource_name_; }
    9274             : 
    9275             : 
    9276             : Local<Integer> ScriptOrigin::ResourceLineOffset() const {
    9277             :   return resource_line_offset_;
    9278             : }
    9279             : 
    9280             : 
    9281             : Local<Integer> ScriptOrigin::ResourceColumnOffset() const {
    9282             :   return resource_column_offset_;
    9283             : }
    9284             : 
    9285             : 
    9286             : Local<Integer> ScriptOrigin::ScriptID() const { return script_id_; }
    9287             : 
    9288             : 
    9289             : Local<Value> ScriptOrigin::SourceMapUrl() const { return source_map_url_; }
    9290             : 
    9291             : 
    9292             : ScriptCompiler::Source::Source(Local<String> string, const ScriptOrigin& origin,
    9293             :                                CachedData* data)
    9294             :     : source_string(string),
    9295             :       resource_name(origin.ResourceName()),
    9296             :       resource_line_offset(origin.ResourceLineOffset()),
    9297             :       resource_column_offset(origin.ResourceColumnOffset()),
    9298             :       resource_options(origin.Options()),
    9299             :       source_map_url(origin.SourceMapUrl()),
    9300      160877 :       cached_data(data) {}
    9301             : 
    9302             : 
    9303             : ScriptCompiler::Source::Source(Local<String> string,
    9304             :                                CachedData* data)
    9305      228850 :     : source_string(string), cached_data(data) {}
    9306             : 
    9307             : 
    9308             : ScriptCompiler::Source::~Source() {
    9309      274661 :   delete cached_data;
    9310             : }
    9311             : 
    9312             : 
    9313             : const ScriptCompiler::CachedData* ScriptCompiler::Source::GetCachedData()
    9314             :     const {
    9315             :   return cached_data;
    9316             : }
    9317             : 
    9318             : const ScriptOriginOptions& ScriptCompiler::Source::GetResourceOptions() const {
    9319             :   return resource_options;
    9320             : }
    9321             : 
    9322             : Local<Boolean> Boolean::New(Isolate* isolate, bool value) {
    9323      116562 :   return value ? True(isolate) : False(isolate);
    9324             : }
    9325             : 
    9326             : void Template::Set(Isolate* isolate, const char* name, Local<Data> value) {
    9327             :   Set(String::NewFromUtf8(isolate, name, NewStringType::kInternalized)
    9328             :           .ToLocalChecked(),
    9329             :       value);
    9330             : }
    9331             : 
    9332             : 
    9333             : Local<Value> Object::GetInternalField(int index) {
    9334             : #ifndef V8_ENABLE_CHECKS
    9335             :   typedef internal::Object O;
    9336             :   typedef internal::HeapObject HO;
    9337             :   typedef internal::Internals I;
    9338             :   O* obj = *reinterpret_cast<O**>(this);
    9339             :   // Fast path: If the object is a plain JSObject, which is the common case, we
    9340             :   // know where to find the internal fields and can return the value directly.
    9341             :   auto instance_type = I::GetInstanceType(obj);
    9342             :   if (instance_type == I::kJSObjectType ||
    9343             :       instance_type == I::kJSApiObjectType) {
    9344             :     int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
    9345             :     O* value = I::ReadField<O*>(obj, offset);
    9346             :     O** result = HandleScope::CreateHandle(reinterpret_cast<HO*>(obj), value);
    9347             :     return Local<Value>(reinterpret_cast<Value*>(result));
    9348             :   }
    9349             : #endif
    9350             :   return SlowGetInternalField(index);
    9351             : }
    9352             : 
    9353             : 
    9354             : void* Object::GetAlignedPointerFromInternalField(int index) {
    9355             : #ifndef V8_ENABLE_CHECKS
    9356             :   typedef internal::Object O;
    9357             :   typedef internal::Internals I;
    9358        1476 :   O* obj = *reinterpret_cast<O**>(this);
    9359             :   // Fast path: If the object is a plain JSObject, which is the common case, we
    9360             :   // know where to find the internal fields and can return the value directly.
    9361             :   auto instance_type = I::GetInstanceType(obj);
    9362        1476 :   if (V8_LIKELY(instance_type == I::kJSObjectType ||
    9363             :                 instance_type == I::kJSApiObjectType)) {
    9364             :     int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
    9365             :     return I::ReadField<void*>(obj, offset);
    9366             :   }
    9367             : #endif
    9368           0 :   return SlowGetAlignedPointerFromInternalField(index);
    9369             : }
    9370             : 
    9371             : String* String::Cast(v8::Value* value) {
    9372             : #ifdef V8_ENABLE_CHECKS
    9373             :   CheckCast(value);
    9374             : #endif
    9375             :   return static_cast<String*>(value);
    9376             : }
    9377             : 
    9378             : 
    9379             : Local<String> String::Empty(Isolate* isolate) {
    9380             :   typedef internal::Object* S;
    9381             :   typedef internal::Internals I;
    9382             :   I::CheckInitialized(isolate);
    9383       76193 :   S* slot = I::GetRoot(isolate, I::kEmptyStringRootIndex);
    9384             :   return Local<String>(reinterpret_cast<String*>(slot));
    9385             : }
    9386             : 
    9387             : 
    9388             : String::ExternalStringResource* String::GetExternalStringResource() const {
    9389             :   typedef internal::Object O;
    9390             :   typedef internal::Internals I;
    9391             :   O* obj = *reinterpret_cast<O* const*>(this);
    9392             :   String::ExternalStringResource* result;
    9393             :   if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) {
    9394             :     void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
    9395             :     result = reinterpret_cast<String::ExternalStringResource*>(value);
    9396             :   } else {
    9397             :     result = NULL;
    9398             :   }
    9399             : #ifdef V8_ENABLE_CHECKS
    9400             :   VerifyExternalStringResource(result);
    9401             : #endif
    9402             :   return result;
    9403             : }
    9404             : 
    9405             : 
    9406             : String::ExternalStringResourceBase* String::GetExternalStringResourceBase(
    9407             :     String::Encoding* encoding_out) const {
    9408             :   typedef internal::Object O;
    9409             :   typedef internal::Internals I;
    9410             :   O* obj = *reinterpret_cast<O* const*>(this);
    9411             :   int type = I::GetInstanceType(obj) & I::kFullStringRepresentationMask;
    9412             :   *encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask);
    9413             :   ExternalStringResourceBase* resource = NULL;
    9414             :   if (type == I::kExternalOneByteRepresentationTag ||
    9415             :       type == I::kExternalTwoByteRepresentationTag) {
    9416             :     void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
    9417             :     resource = static_cast<ExternalStringResourceBase*>(value);
    9418             :   }
    9419             : #ifdef V8_ENABLE_CHECKS
    9420             :     VerifyExternalStringResourceBase(resource, *encoding_out);
    9421             : #endif
    9422             :   return resource;
    9423             : }
    9424             : 
    9425             : 
    9426             : bool Value::IsUndefined() const {
    9427             : #ifdef V8_ENABLE_CHECKS
    9428             :   return FullIsUndefined();
    9429             : #else
    9430             :   return QuickIsUndefined();
    9431             : #endif
    9432             : }
    9433             : 
    9434             : bool Value::QuickIsUndefined() const {
    9435             :   typedef internal::Object O;
    9436             :   typedef internal::Internals I;
    9437       42296 :   O* obj = *reinterpret_cast<O* const*>(this);
    9438    45951380 :   if (!I::HasHeapObjectTag(obj)) return false;
    9439    44509582 :   if (I::GetInstanceType(obj) != I::kOddballType) return false;
    9440    13903296 :   return (I::GetOddballKind(obj) == I::kUndefinedOddballKind);
    9441             : }
    9442             : 
    9443             : 
    9444             : bool Value::IsNull() const {
    9445             : #ifdef V8_ENABLE_CHECKS
    9446             :   return FullIsNull();
    9447             : #else
    9448             :   return QuickIsNull();
    9449             : #endif
    9450             : }
    9451             : 
    9452             : bool Value::QuickIsNull() const {
    9453             :   typedef internal::Object O;
    9454             :   typedef internal::Internals I;
    9455    45912780 :   O* obj = *reinterpret_cast<O* const*>(this);
    9456    45912780 :   if (!I::HasHeapObjectTag(obj)) return false;
    9457    44470997 :   if (I::GetInstanceType(obj) != I::kOddballType) return false;
    9458    13902086 :   return (I::GetOddballKind(obj) == I::kNullOddballKind);
    9459             : }
    9460             : 
    9461             : bool Value::IsNullOrUndefined() const {
    9462             : #ifdef V8_ENABLE_CHECKS
    9463             :   return FullIsNull() || FullIsUndefined();
    9464             : #else
    9465             :   return QuickIsNullOrUndefined();
    9466             : #endif
    9467             : }
    9468             : 
    9469             : bool Value::QuickIsNullOrUndefined() const {
    9470             :   typedef internal::Object O;
    9471             :   typedef internal::Internals I;
    9472    66615265 :   O* obj = *reinterpret_cast<O* const*>(this);
    9473    66615265 :   if (!I::HasHeapObjectTag(obj)) return false;
    9474    66615265 :   if (I::GetInstanceType(obj) != I::kOddballType) return false;
    9475             :   int kind = I::GetOddballKind(obj);
    9476           0 :   return kind == I::kNullOddballKind || kind == I::kUndefinedOddballKind;
    9477             : }
    9478             : 
    9479             : bool Value::IsString() const {
    9480             : #ifdef V8_ENABLE_CHECKS
    9481             :   return FullIsString();
    9482             : #else
    9483             :   return QuickIsString();
    9484             : #endif
    9485             : }
    9486             : 
    9487             : bool Value::QuickIsString() const {
    9488             :   typedef internal::Object O;
    9489             :   typedef internal::Internals I;
    9490   117488038 :   O* obj = *reinterpret_cast<O* const*>(this);
    9491   117488038 :   if (!I::HasHeapObjectTag(obj)) return false;
    9492   117487438 :   return (I::GetInstanceType(obj) < I::kFirstNonstringType);
    9493             : }
    9494             : 
    9495             : 
    9496             : template <class T> Value* Value::Cast(T* value) {
    9497             :   return static_cast<Value*>(value);
    9498             : }
    9499             : 
    9500             : 
    9501             : Local<Boolean> Value::ToBoolean() const {
    9502             :   return ToBoolean(Isolate::GetCurrent()->GetCurrentContext())
    9503             :       .FromMaybe(Local<Boolean>());
    9504             : }
    9505             : 
    9506             : 
    9507             : Local<Number> Value::ToNumber() const {
    9508             :   return ToNumber(Isolate::GetCurrent()->GetCurrentContext())
    9509             :       .FromMaybe(Local<Number>());
    9510             : }
    9511             : 
    9512             : 
    9513             : Local<String> Value::ToString() const {
    9514             :   return ToString(Isolate::GetCurrent()->GetCurrentContext())
    9515             :       .FromMaybe(Local<String>());
    9516             : }
    9517             : 
    9518             : 
    9519             : Local<String> Value::ToDetailString() const {
    9520             :   return ToDetailString(Isolate::GetCurrent()->GetCurrentContext())
    9521             :       .FromMaybe(Local<String>());
    9522             : }
    9523             : 
    9524             : 
    9525             : Local<Object> Value::ToObject() const {
    9526             :   return ToObject(Isolate::GetCurrent()->GetCurrentContext())
    9527             :       .FromMaybe(Local<Object>());
    9528             : }
    9529             : 
    9530             : 
    9531             : Local<Integer> Value::ToInteger() const {
    9532             :   return ToInteger(Isolate::GetCurrent()->GetCurrentContext())
    9533             :       .FromMaybe(Local<Integer>());
    9534             : }
    9535             : 
    9536             : 
    9537             : Local<Uint32> Value::ToUint32() const {
    9538             :   return ToUint32(Isolate::GetCurrent()->GetCurrentContext())
    9539             :       .FromMaybe(Local<Uint32>());
    9540             : }
    9541             : 
    9542             : 
    9543             : Local<Int32> Value::ToInt32() const {
    9544             :   return ToInt32(Isolate::GetCurrent()->GetCurrentContext())
    9545             :       .FromMaybe(Local<Int32>());
    9546             : }
    9547             : 
    9548             : 
    9549             : Boolean* Boolean::Cast(v8::Value* value) {
    9550             : #ifdef V8_ENABLE_CHECKS
    9551             :   CheckCast(value);
    9552             : #endif
    9553             :   return static_cast<Boolean*>(value);
    9554             : }
    9555             : 
    9556             : 
    9557             : Name* Name::Cast(v8::Value* value) {
    9558             : #ifdef V8_ENABLE_CHECKS
    9559             :   CheckCast(value);
    9560             : #endif
    9561             :   return static_cast<Name*>(value);
    9562             : }
    9563             : 
    9564             : 
    9565             : Symbol* Symbol::Cast(v8::Value* value) {
    9566             : #ifdef V8_ENABLE_CHECKS
    9567             :   CheckCast(value);
    9568             : #endif
    9569             :   return static_cast<Symbol*>(value);
    9570             : }
    9571             : 
    9572             : 
    9573             : Number* Number::Cast(v8::Value* value) {
    9574             : #ifdef V8_ENABLE_CHECKS
    9575             :   CheckCast(value);
    9576             : #endif
    9577             :   return static_cast<Number*>(value);
    9578             : }
    9579             : 
    9580             : 
    9581             : Integer* Integer::Cast(v8::Value* value) {
    9582             : #ifdef V8_ENABLE_CHECKS
    9583             :   CheckCast(value);
    9584             : #endif
    9585             :   return static_cast<Integer*>(value);
    9586             : }
    9587             : 
    9588             : 
    9589             : Int32* Int32::Cast(v8::Value* value) {
    9590             : #ifdef V8_ENABLE_CHECKS
    9591             :   CheckCast(value);
    9592             : #endif
    9593             :   return static_cast<Int32*>(value);
    9594             : }
    9595             : 
    9596             : 
    9597             : Uint32* Uint32::Cast(v8::Value* value) {
    9598             : #ifdef V8_ENABLE_CHECKS
    9599             :   CheckCast(value);
    9600             : #endif
    9601             :   return static_cast<Uint32*>(value);
    9602             : }
    9603             : 
    9604             : 
    9605             : Date* Date::Cast(v8::Value* value) {
    9606             : #ifdef V8_ENABLE_CHECKS
    9607             :   CheckCast(value);
    9608             : #endif
    9609             :   return static_cast<Date*>(value);
    9610             : }
    9611             : 
    9612             : 
    9613             : StringObject* StringObject::Cast(v8::Value* value) {
    9614             : #ifdef V8_ENABLE_CHECKS
    9615             :   CheckCast(value);
    9616             : #endif
    9617             :   return static_cast<StringObject*>(value);
    9618             : }
    9619             : 
    9620             : 
    9621             : SymbolObject* SymbolObject::Cast(v8::Value* value) {
    9622             : #ifdef V8_ENABLE_CHECKS
    9623             :   CheckCast(value);
    9624             : #endif
    9625             :   return static_cast<SymbolObject*>(value);
    9626             : }
    9627             : 
    9628             : 
    9629             : NumberObject* NumberObject::Cast(v8::Value* value) {
    9630             : #ifdef V8_ENABLE_CHECKS
    9631             :   CheckCast(value);
    9632             : #endif
    9633             :   return static_cast<NumberObject*>(value);
    9634             : }
    9635             : 
    9636             : 
    9637             : BooleanObject* BooleanObject::Cast(v8::Value* value) {
    9638             : #ifdef V8_ENABLE_CHECKS
    9639             :   CheckCast(value);
    9640             : #endif
    9641             :   return static_cast<BooleanObject*>(value);
    9642             : }
    9643             : 
    9644             : 
    9645             : RegExp* RegExp::Cast(v8::Value* value) {
    9646             : #ifdef V8_ENABLE_CHECKS
    9647             :   CheckCast(value);
    9648             : #endif
    9649             :   return static_cast<RegExp*>(value);
    9650             : }
    9651             : 
    9652             : 
    9653             : Object* Object::Cast(v8::Value* value) {
    9654             : #ifdef V8_ENABLE_CHECKS
    9655             :   CheckCast(value);
    9656             : #endif
    9657             :   return static_cast<Object*>(value);
    9658             : }
    9659             : 
    9660             : 
    9661             : Array* Array::Cast(v8::Value* value) {
    9662             : #ifdef V8_ENABLE_CHECKS
    9663             :   CheckCast(value);
    9664             : #endif
    9665             :   return static_cast<Array*>(value);
    9666             : }
    9667             : 
    9668             : 
    9669             : Map* Map::Cast(v8::Value* value) {
    9670             : #ifdef V8_ENABLE_CHECKS
    9671             :   CheckCast(value);
    9672             : #endif
    9673             :   return static_cast<Map*>(value);
    9674             : }
    9675             : 
    9676             : 
    9677             : Set* Set::Cast(v8::Value* value) {
    9678             : #ifdef V8_ENABLE_CHECKS
    9679             :   CheckCast(value);
    9680             : #endif
    9681             :   return static_cast<Set*>(value);
    9682             : }
    9683             : 
    9684             : 
    9685             : Promise* Promise::Cast(v8::Value* value) {
    9686             : #ifdef V8_ENABLE_CHECKS
    9687             :   CheckCast(value);
    9688             : #endif
    9689             :   return static_cast<Promise*>(value);
    9690             : }
    9691             : 
    9692             : 
    9693             : Proxy* Proxy::Cast(v8::Value* value) {
    9694             : #ifdef V8_ENABLE_CHECKS
    9695             :   CheckCast(value);
    9696             : #endif
    9697             :   return static_cast<Proxy*>(value);
    9698             : }
    9699             : 
    9700             : WasmCompiledModule* WasmCompiledModule::Cast(v8::Value* value) {
    9701             : #ifdef V8_ENABLE_CHECKS
    9702             :   CheckCast(value);
    9703             : #endif
    9704             :   return static_cast<WasmCompiledModule*>(value);
    9705             : }
    9706             : 
    9707             : Promise::Resolver* Promise::Resolver::Cast(v8::Value* value) {
    9708             : #ifdef V8_ENABLE_CHECKS
    9709             :   CheckCast(value);
    9710             : #endif
    9711             :   return static_cast<Promise::Resolver*>(value);
    9712             : }
    9713             : 
    9714             : 
    9715             : ArrayBuffer* ArrayBuffer::Cast(v8::Value* value) {
    9716             : #ifdef V8_ENABLE_CHECKS
    9717             :   CheckCast(value);
    9718             : #endif
    9719             :   return static_cast<ArrayBuffer*>(value);
    9720             : }
    9721             : 
    9722             : 
    9723             : ArrayBufferView* ArrayBufferView::Cast(v8::Value* value) {
    9724             : #ifdef V8_ENABLE_CHECKS
    9725             :   CheckCast(value);
    9726             : #endif
    9727             :   return static_cast<ArrayBufferView*>(value);
    9728             : }
    9729             : 
    9730             : 
    9731             : TypedArray* TypedArray::Cast(v8::Value* value) {
    9732             : #ifdef V8_ENABLE_CHECKS
    9733             :   CheckCast(value);
    9734             : #endif
    9735             :   return static_cast<TypedArray*>(value);
    9736             : }
    9737             : 
    9738             : 
    9739             : Uint8Array* Uint8Array::Cast(v8::Value* value) {
    9740             : #ifdef V8_ENABLE_CHECKS
    9741             :   CheckCast(value);
    9742             : #endif
    9743             :   return static_cast<Uint8Array*>(value);
    9744             : }
    9745             : 
    9746             : 
    9747             : Int8Array* Int8Array::Cast(v8::Value* value) {
    9748             : #ifdef V8_ENABLE_CHECKS
    9749             :   CheckCast(value);
    9750             : #endif
    9751             :   return static_cast<Int8Array*>(value);
    9752             : }
    9753             : 
    9754             : 
    9755             : Uint16Array* Uint16Array::Cast(v8::Value* value) {
    9756             : #ifdef V8_ENABLE_CHECKS
    9757             :   CheckCast(value);
    9758             : #endif
    9759             :   return static_cast<Uint16Array*>(value);
    9760             : }
    9761             : 
    9762             : 
    9763             : Int16Array* Int16Array::Cast(v8::Value* value) {
    9764             : #ifdef V8_ENABLE_CHECKS
    9765             :   CheckCast(value);
    9766             : #endif
    9767             :   return static_cast<Int16Array*>(value);
    9768             : }
    9769             : 
    9770             : 
    9771             : Uint32Array* Uint32Array::Cast(v8::Value* value) {
    9772             : #ifdef V8_ENABLE_CHECKS
    9773             :   CheckCast(value);
    9774             : #endif
    9775             :   return static_cast<Uint32Array*>(value);
    9776             : }
    9777             : 
    9778             : 
    9779             : Int32Array* Int32Array::Cast(v8::Value* value) {
    9780             : #ifdef V8_ENABLE_CHECKS
    9781             :   CheckCast(value);
    9782             : #endif
    9783             :   return static_cast<Int32Array*>(value);
    9784             : }
    9785             : 
    9786             : 
    9787             : Float32Array* Float32Array::Cast(v8::Value* value) {
    9788             : #ifdef V8_ENABLE_CHECKS
    9789             :   CheckCast(value);
    9790             : #endif
    9791             :   return static_cast<Float32Array*>(value);
    9792             : }
    9793             : 
    9794             : 
    9795             : Float64Array* Float64Array::Cast(v8::Value* value) {
    9796             : #ifdef V8_ENABLE_CHECKS
    9797             :   CheckCast(value);
    9798             : #endif
    9799             :   return static_cast<Float64Array*>(value);
    9800             : }
    9801             : 
    9802             : 
    9803             : Uint8ClampedArray* Uint8ClampedArray::Cast(v8::Value* value) {
    9804             : #ifdef V8_ENABLE_CHECKS
    9805             :   CheckCast(value);
    9806             : #endif
    9807             :   return static_cast<Uint8ClampedArray*>(value);
    9808             : }
    9809             : 
    9810             : 
    9811             : DataView* DataView::Cast(v8::Value* value) {
    9812             : #ifdef V8_ENABLE_CHECKS
    9813             :   CheckCast(value);
    9814             : #endif
    9815             :   return static_cast<DataView*>(value);
    9816             : }
    9817             : 
    9818             : 
    9819             : SharedArrayBuffer* SharedArrayBuffer::Cast(v8::Value* value) {
    9820             : #ifdef V8_ENABLE_CHECKS
    9821             :   CheckCast(value);
    9822             : #endif
    9823             :   return static_cast<SharedArrayBuffer*>(value);
    9824             : }
    9825             : 
    9826             : 
    9827             : Function* Function::Cast(v8::Value* value) {
    9828             : #ifdef V8_ENABLE_CHECKS
    9829             :   CheckCast(value);
    9830             : #endif
    9831             :   return static_cast<Function*>(value);
    9832             : }
    9833             : 
    9834             : 
    9835             : External* External::Cast(v8::Value* value) {
    9836             : #ifdef V8_ENABLE_CHECKS
    9837             :   CheckCast(value);
    9838             : #endif
    9839             :   return static_cast<External*>(value);
    9840             : }
    9841             : 
    9842             : 
    9843             : template<typename T>
    9844             : Isolate* PropertyCallbackInfo<T>::GetIsolate() const {
    9845     5239880 :   return *reinterpret_cast<Isolate**>(&args_[kIsolateIndex]);
    9846             : }
    9847             : 
    9848             : 
    9849             : template<typename T>
    9850             : Local<Value> PropertyCallbackInfo<T>::Data() const {
    9851        8844 :   return Local<Value>(reinterpret_cast<Value*>(&args_[kDataIndex]));
    9852             : }
    9853             : 
    9854             : 
    9855             : template<typename T>
    9856             : Local<Object> PropertyCallbackInfo<T>::This() const {
    9857     1561810 :   return Local<Object>(reinterpret_cast<Object*>(&args_[kThisIndex]));
    9858             : }
    9859             : 
    9860             : 
    9861             : template<typename T>
    9862             : Local<Object> PropertyCallbackInfo<T>::Holder() const {
    9863     5175728 :   return Local<Object>(reinterpret_cast<Object*>(&args_[kHolderIndex]));
    9864             : }
    9865             : 
    9866             : 
    9867             : template<typename T>
    9868             : ReturnValue<T> PropertyCallbackInfo<T>::GetReturnValue() const {
    9869     5230761 :   return ReturnValue<T>(&args_[kReturnValueIndex]);
    9870             : }
    9871             : 
    9872             : template <typename T>
    9873             : bool PropertyCallbackInfo<T>::ShouldThrowOnError() const {
    9874             :   typedef internal::Internals I;
    9875         148 :   return args_[kShouldThrowOnErrorIndex] != I::IntToSmi(0);
    9876             : }
    9877             : 
    9878             : 
    9879             : Local<Primitive> Undefined(Isolate* isolate) {
    9880             :   typedef internal::Object* S;
    9881             :   typedef internal::Internals I;
    9882             :   I::CheckInitialized(isolate);
    9883     4240273 :   S* slot = I::GetRoot(isolate, I::kUndefinedValueRootIndex);
    9884             :   return Local<Primitive>(reinterpret_cast<Primitive*>(slot));
    9885             : }
    9886             : 
    9887             : 
    9888             : Local<Primitive> Null(Isolate* isolate) {
    9889             :   typedef internal::Object* S;
    9890             :   typedef internal::Internals I;
    9891             :   I::CheckInitialized(isolate);
    9892    13753642 :   S* slot = I::GetRoot(isolate, I::kNullValueRootIndex);
    9893             :   return Local<Primitive>(reinterpret_cast<Primitive*>(slot));
    9894             : }
    9895             : 
    9896             : 
    9897             : Local<Boolean> True(Isolate* isolate) {
    9898             :   typedef internal::Object* S;
    9899             :   typedef internal::Internals I;
    9900             :   I::CheckInitialized(isolate);
    9901      312861 :   S* slot = I::GetRoot(isolate, I::kTrueValueRootIndex);
    9902             :   return Local<Boolean>(reinterpret_cast<Boolean*>(slot));
    9903             : }
    9904             : 
    9905             : 
    9906             : Local<Boolean> False(Isolate* isolate) {
    9907             :   typedef internal::Object* S;
    9908             :   typedef internal::Internals I;
    9909             :   I::CheckInitialized(isolate);
    9910     1176234 :   S* slot = I::GetRoot(isolate, I::kFalseValueRootIndex);
    9911             :   return Local<Boolean>(reinterpret_cast<Boolean*>(slot));
    9912             : }
    9913             : 
    9914             : 
    9915             : void Isolate::SetData(uint32_t slot, void* data) {
    9916             :   typedef internal::Internals I;
    9917             :   I::SetEmbedderData(this, slot, data);
    9918             : }
    9919             : 
    9920             : 
    9921             : void* Isolate::GetData(uint32_t slot) {
    9922             :   typedef internal::Internals I;
    9923             :   return I::GetEmbedderData(this, slot);
    9924             : }
    9925             : 
    9926             : 
    9927             : uint32_t Isolate::GetNumberOfDataSlots() {
    9928             :   typedef internal::Internals I;
    9929             :   return I::kNumIsolateDataSlots;
    9930             : }
    9931             : 
    9932             : 
    9933             : int64_t Isolate::AdjustAmountOfExternalAllocatedMemory(
    9934             :     int64_t change_in_bytes) {
    9935             :   typedef internal::Internals I;
    9936             :   int64_t* external_memory = reinterpret_cast<int64_t*>(
    9937             :       reinterpret_cast<uint8_t*>(this) + I::kExternalMemoryOffset);
    9938             :   const int64_t external_memory_limit = *reinterpret_cast<int64_t*>(
    9939      132658 :       reinterpret_cast<uint8_t*>(this) + I::kExternalMemoryLimitOffset);
    9940      132658 :   const int64_t amount = *external_memory + change_in_bytes;
    9941      132658 :   *external_memory = amount;
    9942      132658 :   if (change_in_bytes > 0 && amount > external_memory_limit) {
    9943         607 :     ReportExternalAllocationLimitReached();
    9944             :   }
    9945             :   return *external_memory;
    9946             : }
    9947             : 
    9948             : Local<Value> Context::GetEmbedderData(int index) {
    9949             : #ifndef V8_ENABLE_CHECKS
    9950             :   typedef internal::Object O;
    9951             :   typedef internal::HeapObject HO;
    9952             :   typedef internal::Internals I;
    9953             :   HO* context = *reinterpret_cast<HO**>(this);
    9954             :   O** result =
    9955             :       HandleScope::CreateHandle(context, I::ReadEmbedderData<O*>(this, index));
    9956             :   return Local<Value>(reinterpret_cast<Value*>(result));
    9957             : #else
    9958             :   return SlowGetEmbedderData(index);
    9959             : #endif
    9960             : }
    9961             : 
    9962             : 
    9963             : void* Context::GetAlignedPointerFromEmbedderData(int index) {
    9964             : #ifndef V8_ENABLE_CHECKS
    9965             :   typedef internal::Internals I;
    9966             :   return I::ReadEmbedderData<void*>(this, index);
    9967             : #else
    9968             :   return SlowGetAlignedPointerFromEmbedderData(index);
    9969             : #endif
    9970             : }
    9971             : 
    9972             : 
    9973             : void V8::SetAllowCodeGenerationFromStringsCallback(
    9974             :     AllowCodeGenerationFromStringsCallback callback) {
    9975             :   Isolate* isolate = Isolate::GetCurrent();
    9976             :   isolate->SetAllowCodeGenerationFromStringsCallback(callback);
    9977             : }
    9978             : 
    9979             : 
    9980             : bool V8::IsDead() {
    9981             :   Isolate* isolate = Isolate::GetCurrent();
    9982             :   return isolate->IsDead();
    9983             : }
    9984             : 
    9985             : 
    9986             : bool V8::AddMessageListener(MessageCallback that, Local<Value> data) {
    9987             :   Isolate* isolate = Isolate::GetCurrent();
    9988             :   return isolate->AddMessageListener(that, data);
    9989             : }
    9990             : 
    9991             : 
    9992             : void V8::RemoveMessageListeners(MessageCallback that) {
    9993             :   Isolate* isolate = Isolate::GetCurrent();
    9994             :   isolate->RemoveMessageListeners(that);
    9995             : }
    9996             : 
    9997             : 
    9998             : void V8::SetFailedAccessCheckCallbackFunction(
    9999             :     FailedAccessCheckCallback callback) {
   10000             :   Isolate* isolate = Isolate::GetCurrent();
   10001             :   isolate->SetFailedAccessCheckCallbackFunction(callback);
   10002             : }
   10003             : 
   10004             : 
   10005             : void V8::SetCaptureStackTraceForUncaughtExceptions(
   10006             :     bool capture, int frame_limit, StackTrace::StackTraceOptions options) {
   10007             :   Isolate* isolate = Isolate::GetCurrent();
   10008             :   isolate->SetCaptureStackTraceForUncaughtExceptions(capture, frame_limit,
   10009             :                                                      options);
   10010             : }
   10011             : 
   10012             : 
   10013             : void V8::SetFatalErrorHandler(FatalErrorCallback callback) {
   10014             :   Isolate* isolate = Isolate::GetCurrent();
   10015             :   isolate->SetFatalErrorHandler(callback);
   10016             : }
   10017             : 
   10018             : void V8::RemoveGCPrologueCallback(GCCallback callback) {
   10019             :   Isolate* isolate = Isolate::GetCurrent();
   10020             :   isolate->RemoveGCPrologueCallback(
   10021             :       reinterpret_cast<Isolate::GCCallback>(callback));
   10022             : }
   10023             : 
   10024             : 
   10025             : void V8::RemoveGCEpilogueCallback(GCCallback callback) {
   10026             :   Isolate* isolate = Isolate::GetCurrent();
   10027             :   isolate->RemoveGCEpilogueCallback(
   10028             :       reinterpret_cast<Isolate::GCCallback>(callback));
   10029             : }
   10030             : 
   10031             : void V8::TerminateExecution(Isolate* isolate) { isolate->TerminateExecution(); }
   10032             : 
   10033             : 
   10034             : bool V8::IsExecutionTerminating(Isolate* isolate) {
   10035             :   if (isolate == NULL) {
   10036             :     isolate = Isolate::GetCurrent();
   10037             :   }
   10038             :   return isolate->IsExecutionTerminating();
   10039             : }
   10040             : 
   10041             : 
   10042             : void V8::CancelTerminateExecution(Isolate* isolate) {
   10043             :   isolate->CancelTerminateExecution();
   10044             : }
   10045             : 
   10046             : 
   10047             : void V8::VisitExternalResources(ExternalResourceVisitor* visitor) {
   10048             :   Isolate* isolate = Isolate::GetCurrent();
   10049             :   isolate->VisitExternalResources(visitor);
   10050             : }
   10051             : 
   10052             : 
   10053             : void V8::VisitHandlesWithClassIds(PersistentHandleVisitor* visitor) {
   10054             :   Isolate* isolate = Isolate::GetCurrent();
   10055             :   isolate->VisitHandlesWithClassIds(visitor);
   10056             : }
   10057             : 
   10058             : 
   10059             : void V8::VisitHandlesWithClassIds(Isolate* isolate,
   10060             :                                   PersistentHandleVisitor* visitor) {
   10061             :   isolate->VisitHandlesWithClassIds(visitor);
   10062             : }
   10063             : 
   10064             : 
   10065             : void V8::VisitHandlesForPartialDependence(Isolate* isolate,
   10066             :                                           PersistentHandleVisitor* visitor) {
   10067             :   isolate->VisitHandlesForPartialDependence(visitor);
   10068             : }
   10069             : 
   10070             : /**
   10071             :  * \example shell.cc
   10072             :  * A simple shell that takes a list of expressions on the
   10073             :  * command-line and executes them.
   10074             :  */
   10075             : 
   10076             : 
   10077             : /**
   10078             :  * \example process.cc
   10079             :  */
   10080             : 
   10081             : 
   10082             : }  // namespace v8
   10083             : 
   10084             : 
   10085             : #undef TYPE_CHECK
   10086             : 
   10087             : 
   10088             : #endif  // INCLUDE_V8_H_

Generated by: LCOV version 1.10