Home | History | Annotate | Download | only in include
      1 // Copyright 2012 the V8 project authors. All rights reserved.
      2 // Redistribution and use in source and binary forms, with or without
      3 // modification, are permitted provided that the following conditions are
      4 // met:
      5 //
      6 //     * Redistributions of source code must retain the above copyright
      7 //       notice, this list of conditions and the following disclaimer.
      8 //     * Redistributions in binary form must reproduce the above
      9 //       copyright notice, this list of conditions and the following
     10 //       disclaimer in the documentation and/or other materials provided
     11 //       with the distribution.
     12 //     * Neither the name of Google Inc. nor the names of its
     13 //       contributors may be used to endorse or promote products derived
     14 //       from this software without specific prior written permission.
     15 //
     16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 
     28 /** \mainpage V8 API Reference Guide
     29  *
     30  * V8 is Google's open source JavaScript engine.
     31  *
     32  * This set of documents provides reference material generated from the
     33  * V8 header file, include/v8.h.
     34  *
     35  * For other documentation see http://code.google.com/apis/v8/
     36  */
     37 
     38 #ifndef V8_H_
     39 #define V8_H_
     40 
     41 #include "v8stdint.h"
     42 
     43 // We reserve the V8_* prefix for macros defined in V8 public API and
     44 // assume there are no name conflicts with the embedder's code.
     45 
     46 #ifdef _WIN32
     47 
     48 // Setup for Windows DLL export/import. When building the V8 DLL the
     49 // BUILDING_V8_SHARED needs to be defined. When building a program which uses
     50 // the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8
     51 // static library or building a program which uses the V8 static library neither
     52 // BUILDING_V8_SHARED nor USING_V8_SHARED should be defined.
     53 #if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED)
     54 #error both BUILDING_V8_SHARED and USING_V8_SHARED are set - please check the\
     55   build configuration to ensure that at most one of these is set
     56 #endif
     57 
     58 #ifdef BUILDING_V8_SHARED
     59 #define V8_EXPORT __declspec(dllexport)
     60 #elif USING_V8_SHARED
     61 #define V8_EXPORT __declspec(dllimport)
     62 #else
     63 #define V8_EXPORT
     64 #endif  // BUILDING_V8_SHARED
     65 
     66 #else  // _WIN32
     67 
     68 // Setup for Linux shared library export.
     69 #if defined(__GNUC__) && ((__GNUC__ >= 4) || \
     70     (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) && defined(V8_SHARED)
     71 #ifdef BUILDING_V8_SHARED
     72 #define V8_EXPORT __attribute__ ((visibility("default")))
     73 #else
     74 #define V8_EXPORT
     75 #endif
     76 #else
     77 #define V8_EXPORT
     78 #endif
     79 
     80 #endif  // _WIN32
     81 
     82 #if defined(__GNUC__) && !defined(DEBUG)
     83 #define V8_INLINE(declarator) inline __attribute__((always_inline)) declarator
     84 #elif defined(_MSC_VER) && !defined(DEBUG)
     85 #define V8_INLINE(declarator) __forceinline declarator
     86 #else
     87 #define V8_INLINE(declarator) inline declarator
     88 #endif
     89 
     90 #if defined(__GNUC__) && !V8_DISABLE_DEPRECATIONS
     91 #define V8_DEPRECATED(declarator) declarator __attribute__ ((deprecated))
     92 #elif defined(_MSC_VER) && !V8_DISABLE_DEPRECATIONS
     93 #define V8_DEPRECATED(declarator) __declspec(deprecated) declarator
     94 #else
     95 #define V8_DEPRECATED(declarator) declarator
     96 #endif
     97 
     98 #if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))
     99   #define V8_UNLIKELY(condition) __builtin_expect((condition), 0)
    100   #define V8_LIKELY(condition) __builtin_expect((condition), 1)
    101 #else
    102   #define V8_UNLIKELY(condition) (condition)
    103   #define V8_LIKELY(condition) (condition)
    104 #endif
    105 
    106 /**
    107  * The v8 JavaScript engine.
    108  */
    109 namespace v8 {
    110 
    111 class AccessorInfo;
    112 class AccessorSignature;
    113 class Array;
    114 class Boolean;
    115 class BooleanObject;
    116 class Context;
    117 class CpuProfiler;
    118 class Data;
    119 class Date;
    120 class DeclaredAccessorDescriptor;
    121 class External;
    122 class Function;
    123 class FunctionTemplate;
    124 class HeapProfiler;
    125 class ImplementationUtilities;
    126 class Int32;
    127 class Integer;
    128 class Isolate;
    129 class Number;
    130 class NumberObject;
    131 class Object;
    132 class ObjectOperationDescriptor;
    133 class ObjectTemplate;
    134 class Primitive;
    135 class RawOperationDescriptor;
    136 class Signature;
    137 class StackFrame;
    138 class StackTrace;
    139 class String;
    140 class StringObject;
    141 class Symbol;
    142 class SymbolObject;
    143 class Uint32;
    144 class Utils;
    145 class Value;
    146 template <class T> class Handle;
    147 template <class T> class Local;
    148 template <class T> class Persistent;
    149 class FunctionTemplate;
    150 class ObjectTemplate;
    151 class Data;
    152 class AccessorInfo;
    153 template<typename T> class PropertyCallbackInfo;
    154 class StackTrace;
    155 class StackFrame;
    156 class Isolate;
    157 class DeclaredAccessorDescriptor;
    158 class ObjectOperationDescriptor;
    159 class RawOperationDescriptor;
    160 class CallHandlerHelper;
    161 
    162 namespace internal {
    163 class Arguments;
    164 class Heap;
    165 class HeapObject;
    166 class Isolate;
    167 class Object;
    168 template<typename T> class CustomArguments;
    169 class PropertyCallbackArguments;
    170 class FunctionCallbackArguments;
    171 }
    172 
    173 
    174 /**
    175  * General purpose unique identifier.
    176  */
    177 class UniqueId {
    178  public:
    179   explicit UniqueId(intptr_t data)
    180       : data_(data) {}
    181 
    182   bool operator==(const UniqueId& other) const {
    183     return data_ == other.data_;
    184   }
    185 
    186   bool operator!=(const UniqueId& other) const {
    187     return data_ != other.data_;
    188   }
    189 
    190   bool operator<(const UniqueId& other) const {
    191     return data_ < other.data_;
    192   }
    193 
    194  private:
    195   intptr_t data_;
    196 };
    197 
    198 
    199 // --- Weak Handles ---
    200 
    201 
    202 /**
    203  * A weak reference callback function.
    204  *
    205  * This callback should either explicitly invoke Dispose on |object| if
    206  * V8 wrapper is not needed anymore, or 'revive' it by invocation of MakeWeak.
    207  *
    208  * \param object the weak global object to be reclaimed by the garbage collector
    209  * \param parameter the value passed in when making the weak global object
    210  */
    211 template<typename T, typename P>
    212 class WeakReferenceCallbacks {
    213  public:
    214   typedef void (*Revivable)(Isolate* isolate,
    215                             Persistent<T>* object,
    216                             P* parameter);
    217 };
    218 
    219 // --- Handles ---
    220 
    221 #define TYPE_CHECK(T, S)                                       \
    222   while (false) {                                              \
    223     *(static_cast<T* volatile*>(0)) = static_cast<S*>(0);      \
    224   }
    225 
    226 
    227 /**
    228  * An object reference managed by the v8 garbage collector.
    229  *
    230  * All objects returned from v8 have to be tracked by the garbage
    231  * collector so that it knows that the objects are still alive.  Also,
    232  * because the garbage collector may move objects, it is unsafe to
    233  * point directly to an object.  Instead, all objects are stored in
    234  * handles which are known by the garbage collector and updated
    235  * whenever an object moves.  Handles should always be passed by value
    236  * (except in cases like out-parameters) and they should never be
    237  * allocated on the heap.
    238  *
    239  * There are two types of handles: local and persistent handles.
    240  * Local handles are light-weight and transient and typically used in
    241  * local operations.  They are managed by HandleScopes.  Persistent
    242  * handles can be used when storing objects across several independent
    243  * operations and have to be explicitly deallocated when they're no
    244  * longer used.
    245  *
    246  * It is safe to extract the object stored in the handle by
    247  * dereferencing the handle (for instance, to extract the Object* from
    248  * a Handle<Object>); the value will still be governed by a handle
    249  * behind the scenes and the same rules apply to these values as to
    250  * their handles.
    251  */
    252 template <class T> class Handle {
    253  public:
    254   /**
    255    * Creates an empty handle.
    256    */
    257   V8_INLINE(Handle()) : val_(0) {}
    258 
    259 #ifdef V8_USE_UNSAFE_HANDLES
    260   /**
    261    * Creates a new handle for the specified value.
    262    */
    263   V8_INLINE(explicit Handle(T* val)) : val_(val) {}
    264 #endif
    265 
    266   /**
    267    * Creates a handle for the contents of the specified handle.  This
    268    * constructor allows you to pass handles as arguments by value and
    269    * to assign between handles.  However, if you try to assign between
    270    * incompatible handles, for instance from a Handle<String> to a
    271    * Handle<Number> it will cause a compile-time error.  Assigning
    272    * between compatible handles, for instance assigning a
    273    * Handle<String> to a variable declared as Handle<Value>, is legal
    274    * because String is a subclass of Value.
    275    */
    276   template <class S> V8_INLINE(Handle(Handle<S> that))
    277       : val_(reinterpret_cast<T*>(*that)) {
    278     /**
    279      * This check fails when trying to convert between incompatible
    280      * handles. For example, converting from a Handle<String> to a
    281      * Handle<Number>.
    282      */
    283     TYPE_CHECK(T, S);
    284   }
    285 
    286   /**
    287    * Returns true if the handle is empty.
    288    */
    289   V8_INLINE(bool IsEmpty() const) { return val_ == 0; }
    290 
    291   /**
    292    * Sets the handle to be empty. IsEmpty() will then return true.
    293    */
    294   V8_INLINE(void Clear()) { val_ = 0; }
    295 
    296   V8_INLINE(T* operator->() const) { return val_; }
    297 
    298   V8_INLINE(T* operator*() const) { return val_; }
    299 
    300   /**
    301    * Checks whether two handles are the same.
    302    * Returns true if both are empty, or if the objects
    303    * to which they refer are identical.
    304    * The handles' references are not checked.
    305    */
    306   template <class S> V8_INLINE(bool operator==(const Handle<S> that) const) {
    307     internal::Object** a = reinterpret_cast<internal::Object**>(**this);
    308     internal::Object** b = reinterpret_cast<internal::Object**>(*that);
    309     if (a == 0) return b == 0;
    310     if (b == 0) return false;
    311     return *a == *b;
    312   }
    313 
    314 #ifndef V8_USE_UNSAFE_HANDLES
    315   template <class S> V8_INLINE(
    316       bool operator==(const Persistent<S>& that) const) {
    317     internal::Object** a = reinterpret_cast<internal::Object**>(**this);
    318     internal::Object** b = reinterpret_cast<internal::Object**>(*that);
    319     if (a == 0) return b == 0;
    320     if (b == 0) return false;
    321     return *a == *b;
    322   }
    323 #endif
    324 
    325   /**
    326    * Checks whether two handles are different.
    327    * Returns true if only one of the handles is empty, or if
    328    * the objects to which they refer are different.
    329    * The handles' references are not checked.
    330    */
    331   template <class S> V8_INLINE(bool operator!=(Handle<S> that) const) {
    332     return !operator==(that);
    333   }
    334 
    335   template <class S> V8_INLINE(static Handle<T> Cast(Handle<S> that)) {
    336 #ifdef V8_ENABLE_CHECKS
    337     // If we're going to perform the type check then we have to check
    338     // that the handle isn't empty before doing the checked cast.
    339     if (that.IsEmpty()) return Handle<T>();
    340 #endif
    341     return Handle<T>(T::Cast(*that));
    342   }
    343 
    344   template <class S> V8_INLINE(Handle<S> As()) {
    345     return Handle<S>::Cast(*this);
    346   }
    347 
    348 #ifndef V8_USE_UNSAFE_HANDLES
    349   V8_INLINE(static Handle<T> New(Isolate* isolate, Handle<T> that)) {
    350     return New(isolate, that.val_);
    351   }
    352   // TODO(dcarney): remove before cutover
    353   V8_INLINE(static Handle<T> New(Isolate* isolate, const Persistent<T>& that)) {
    354     return New(isolate, that.val_);
    355   }
    356 
    357 #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR
    358 
    359  private:
    360 #endif
    361   /**
    362    * Creates a new handle for the specified value.
    363    */
    364   V8_INLINE(explicit Handle(T* val)) : val_(val) {}
    365 #endif
    366 
    367  private:
    368   friend class Utils;
    369   template<class F> friend class Persistent;
    370   template<class F> friend class Local;
    371   friend class Arguments;
    372   template<class F> friend class FunctionCallbackInfo;
    373   template<class F> friend class PropertyCallbackInfo;
    374   template<class F> friend class internal::CustomArguments;
    375   friend class AccessorInfo;
    376   friend Handle<Primitive> Undefined(Isolate* isolate);
    377   friend Handle<Primitive> Null(Isolate* isolate);
    378   friend Handle<Boolean> True(Isolate* isolate);
    379   friend Handle<Boolean> False(Isolate* isolate);
    380   friend class Context;
    381   friend class HandleScope;
    382 
    383 #ifndef V8_USE_UNSAFE_HANDLES
    384   V8_INLINE(static Handle<T> New(Isolate* isolate, T* that));
    385 #endif
    386 
    387   T* val_;
    388 };
    389 
    390 
    391 // A value which will never be returned by Local::Eternalize
    392 // Useful for static initialization
    393 const int kUninitializedEternalIndex = -1;
    394 
    395 
    396 /**
    397  * A light-weight stack-allocated object handle.  All operations
    398  * that return objects from within v8 return them in local handles.  They
    399  * are created within HandleScopes, and all local handles allocated within a
    400  * handle scope are destroyed when the handle scope is destroyed.  Hence it
    401  * is not necessary to explicitly deallocate local handles.
    402  */
    403 // TODO(dcarney): deprecate entire class
    404 template <class T> class Local : public Handle<T> {
    405  public:
    406   V8_INLINE(Local());
    407   template <class S> V8_INLINE(Local(Local<S> that))
    408       : Handle<T>(reinterpret_cast<T*>(*that)) {
    409     /**
    410      * This check fails when trying to convert between incompatible
    411      * handles. For example, converting from a Handle<String> to a
    412      * Handle<Number>.
    413      */
    414     TYPE_CHECK(T, S);
    415   }
    416 
    417 
    418 #ifdef V8_USE_UNSAFE_HANDLES
    419   template <class S> V8_INLINE(Local(S* that) : Handle<T>(that)) { }
    420 #endif
    421 
    422   template <class S> V8_INLINE(static Local<T> Cast(Local<S> that)) {
    423 #ifdef V8_ENABLE_CHECKS
    424     // If we're going to perform the type check then we have to check
    425     // that the handle isn't empty before doing the checked cast.
    426     if (that.IsEmpty()) return Local<T>();
    427 #endif
    428     return Local<T>(T::Cast(*that));
    429   }
    430 #ifndef V8_USE_UNSAFE_HANDLES
    431   template <class S> V8_INLINE(Local(Handle<S> that))
    432       : Handle<T>(reinterpret_cast<T*>(*that)) {
    433     TYPE_CHECK(T, S);
    434   }
    435 #endif
    436 
    437   template <class S> V8_INLINE(Local<S> As()) {
    438     return Local<S>::Cast(*this);
    439   }
    440 
    441   // Keep this Local alive for the lifetime of the Isolate.
    442   // It remains retrievable via the returned index,
    443   V8_INLINE(int Eternalize(Isolate* isolate));
    444   V8_INLINE(static Local<T> GetEternal(Isolate* isolate, int index));
    445 
    446   /**
    447    * Create a local handle for the content of another handle.
    448    * The referee is kept alive by the local handle even when
    449    * the original handle is destroyed/disposed.
    450    */
    451   V8_INLINE(static Local<T> New(Handle<T> that));
    452   V8_INLINE(static Local<T> New(Isolate* isolate, Handle<T> that));
    453 #ifndef V8_USE_UNSAFE_HANDLES
    454   // TODO(dcarney): remove before cutover
    455   V8_INLINE(static Local<T> New(Isolate* isolate, const Persistent<T>& that));
    456 
    457 #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR
    458 
    459  private:
    460 #endif
    461   template <class S> V8_INLINE(Local(S* that) : Handle<T>(that)) { }
    462 #endif
    463 
    464  private:
    465   friend class Utils;
    466   template<class F> friend class Persistent;
    467   template<class F> friend class Handle;
    468   friend class Arguments;
    469   template<class F> friend class FunctionCallbackInfo;
    470   template<class F> friend class PropertyCallbackInfo;
    471   friend class String;
    472   friend class Object;
    473   friend class AccessorInfo;
    474   friend class Context;
    475   template<class F> friend class internal::CustomArguments;
    476   friend class HandleScope;
    477 
    478   V8_INLINE(static Local<T> New(Isolate* isolate, T* that));
    479 };
    480 
    481 /**
    482  * An object reference that is independent of any handle scope.  Where
    483  * a Local handle only lives as long as the HandleScope in which it was
    484  * allocated, a Persistent handle remains valid until it is explicitly
    485  * disposed.
    486  *
    487  * A persistent handle contains a reference to a storage cell within
    488  * the v8 engine which holds an object value and which is updated by
    489  * the garbage collector whenever the object is moved.  A new storage
    490  * cell can be created using Persistent::New and existing handles can
    491  * be disposed using Persistent::Dispose.  Since persistent handles
    492  * are passed by value you may have many persistent handle objects
    493  * that point to the same storage cell.  For instance, if you pass a
    494  * persistent handle as an argument to a function you will not get two
    495  * different storage cells but rather two references to the same
    496  * storage cell.
    497  */
    498 template <class T> class Persistent // NOLINT
    499 #ifdef V8_USE_UNSAFE_HANDLES
    500     : public Handle<T> {
    501 #else
    502   { // NOLINT
    503 #endif
    504  public:
    505 #ifndef V8_USE_UNSAFE_HANDLES
    506   V8_INLINE(Persistent()) : val_(0) { }
    507   // TODO(dcarney): add this back before cutover.
    508 //  V8_INLINE(~Persistent()) {
    509 //  Dispose();
    510 //  }
    511   V8_INLINE(bool IsEmpty() const) { return val_ == 0; }
    512   // TODO(dcarney): remove somehow before cutover
    513   // The handle should either be 0, or a pointer to a live cell.
    514   V8_INLINE(void Clear()) { val_ = 0; }
    515 
    516   /**
    517    * A constructor that creates a new global cell pointing to that. In contrast
    518    * to the copy constructor, this creates a new persistent handle which needs
    519    * to be separately disposed.
    520    */
    521   template <class S> V8_INLINE(Persistent(Isolate* isolate, Handle<S> that))
    522       : val_(New(isolate, *that)) { }
    523 
    524   template <class S> V8_INLINE(Persistent(Isolate* isolate,
    525                                           const Persistent<S>& that)) // NOLINT
    526       : val_(New(isolate, *that)) { }
    527 
    528 #else
    529   /**
    530    * Creates an empty persistent handle that doesn't point to any
    531    * storage cell.
    532    */
    533   V8_INLINE(Persistent()) : Handle<T>() { }
    534 
    535   /**
    536    * Creates a persistent handle for the same storage cell as the
    537    * specified handle.  This constructor allows you to pass persistent
    538    * handles as arguments by value and to assign between persistent
    539    * handles.  However, attempting to assign between incompatible
    540    * persistent handles, for instance from a Persistent<String> to a
    541    * Persistent<Number> will cause a compile-time error.  Assigning
    542    * between compatible persistent handles, for instance assigning a
    543    * Persistent<String> to a variable declared as Persistent<Value>,
    544    * is allowed as String is a subclass of Value.
    545    */
    546   template <class S> V8_INLINE(Persistent(Persistent<S> that))
    547       : Handle<T>(reinterpret_cast<T*>(*that)) {
    548     /**
    549      * This check fails when trying to convert between incompatible
    550      * handles. For example, converting from a Handle<String> to a
    551      * Handle<Number>.
    552      */
    553     TYPE_CHECK(T, S);
    554   }
    555 
    556   template <class S> V8_INLINE(Persistent(S* that)) : Handle<T>(that) { }
    557 
    558   /**
    559    * A constructor that creates a new global cell pointing to that. In contrast
    560    * to the copy constructor, this creates a new persistent handle which needs
    561    * to be separately disposed.
    562    */
    563   template <class S> V8_INLINE(Persistent(Isolate* isolate, Handle<S> that))
    564       : Handle<T>(New(isolate, that)) { }
    565 
    566   /**
    567    * "Casts" a plain handle which is known to be a persistent handle
    568    * to a persistent handle.
    569    */
    570   template <class S> explicit V8_INLINE(Persistent(Handle<S> that))
    571       : Handle<T>(*that) { }
    572 
    573 #endif
    574 
    575 #ifdef V8_USE_UNSAFE_HANDLES
    576   template <class S> V8_INLINE(static Persistent<T> Cast(Persistent<S> that)) {
    577 #ifdef V8_ENABLE_CHECKS
    578     // If we're going to perform the type check then we have to check
    579     // that the handle isn't empty before doing the checked cast.
    580     if (that.IsEmpty()) return Persistent<T>();
    581 #endif
    582     return Persistent<T>(T::Cast(*that));
    583   }
    584 
    585   template <class S> V8_INLINE(Persistent<S> As()) {
    586     return Persistent<S>::Cast(*this);
    587   }
    588 
    589 #else
    590   template <class S>
    591   V8_INLINE(static Persistent<T>& Cast(Persistent<S>& that)) { // NOLINT
    592 #ifdef V8_ENABLE_CHECKS
    593     // If we're going to perform the type check then we have to check
    594     // that the handle isn't empty before doing the checked cast.
    595     if (!that.IsEmpty()) T::Cast(*that);
    596 #endif
    597     return reinterpret_cast<Persistent<T>&>(that);
    598   }
    599 
    600   template <class S> V8_INLINE(Persistent<S>& As()) { // NOLINT
    601     return Persistent<S>::Cast(*this);
    602   }
    603 #endif
    604 
    605 #ifdef V8_USE_UNSAFE_HANDLES
    606   V8_DEPRECATED(static Persistent<T> New(Handle<T> that));
    607   V8_INLINE(static Persistent<T> New(Isolate* isolate, Handle<T> that));
    608   V8_INLINE(static Persistent<T> New(Isolate* isolate, Persistent<T> that));
    609 #endif
    610 
    611 #ifndef V8_USE_UNSAFE_HANDLES
    612   template <class S> V8_INLINE(
    613       bool operator==(const Persistent<S>& that) const) {
    614     internal::Object** a = reinterpret_cast<internal::Object**>(**this);
    615     internal::Object** b = reinterpret_cast<internal::Object**>(*that);
    616     if (a == 0) return b == 0;
    617     if (b == 0) return false;
    618     return *a == *b;
    619   }
    620 
    621   template <class S> V8_INLINE(bool operator==(const Handle<S> that) const) {
    622     internal::Object** a = reinterpret_cast<internal::Object**>(**this);
    623     internal::Object** b = reinterpret_cast<internal::Object**>(*that);
    624     if (a == 0) return b == 0;
    625     if (b == 0) return false;
    626     return *a == *b;
    627   }
    628 #endif
    629 
    630   V8_INLINE(void Dispose());
    631 
    632   /**
    633    * Releases the storage cell referenced by this persistent handle.
    634    * Does not remove the reference to the cell from any handles.
    635    * This handle's reference, and any other references to the storage
    636    * cell remain and IsEmpty will still return false.
    637    */
    638   // TODO(dcarney): deprecate
    639   V8_INLINE(void Dispose(Isolate* isolate)) { Dispose(); }
    640 
    641   /**
    642    * Make the reference to this object weak.  When only weak handles
    643    * refer to the object, the garbage collector will perform a
    644    * callback to the given V8::NearDeathCallback function, passing
    645    * it the object reference and the given parameters.
    646    */
    647   template<typename S, typename P>
    648   V8_INLINE(void MakeWeak(
    649       P* parameters,
    650       typename WeakReferenceCallbacks<S, P>::Revivable callback));
    651 
    652   template<typename P>
    653   V8_INLINE(void MakeWeak(
    654       P* parameters,
    655       typename WeakReferenceCallbacks<T, P>::Revivable callback));
    656 
    657   template<typename S, typename P>
    658   V8_DEPRECATED(void MakeWeak(
    659       Isolate* isolate,
    660       P* parameters,
    661       typename WeakReferenceCallbacks<S, P>::Revivable callback));
    662 
    663   template<typename P>
    664   V8_DEPRECATED(void MakeWeak(
    665       Isolate* isolate,
    666       P* parameters,
    667       typename WeakReferenceCallbacks<T, P>::Revivable callback));
    668 
    669   V8_INLINE(void ClearWeak());
    670 
    671   // TODO(dcarney): deprecate
    672   V8_INLINE(void ClearWeak(Isolate* isolate)) { ClearWeak(); }
    673 
    674   /**
    675    * Marks the reference to this object independent. Garbage collector is free
    676    * to ignore any object groups containing this object. Weak callback for an
    677    * independent handle should not assume that it will be preceded by a global
    678    * GC prologue callback or followed by a global GC epilogue callback.
    679    */
    680   V8_INLINE(void MarkIndependent());
    681 
    682   // TODO(dcarney): deprecate
    683   V8_INLINE(void MarkIndependent(Isolate* isolate)) { MarkIndependent(); }
    684 
    685   /**
    686    * Marks the reference to this object partially dependent. Partially dependent
    687    * handles only depend on other partially dependent handles and these
    688    * dependencies are provided through object groups. It provides a way to build
    689    * smaller object groups for young objects that represent only a subset of all
    690    * external dependencies. This mark is automatically cleared after each
    691    * garbage collection.
    692    */
    693   V8_INLINE(void MarkPartiallyDependent());
    694 
    695   // TODO(dcarney): deprecate
    696   V8_INLINE(void MarkPartiallyDependent(Isolate* isolate)) {
    697     MarkPartiallyDependent();
    698   }
    699 
    700   V8_INLINE(bool IsIndependent() const);
    701 
    702   // TODO(dcarney): deprecate
    703   V8_INLINE(bool IsIndependent(Isolate* isolate) const) {
    704     return IsIndependent();
    705   }
    706 
    707   /** Checks if the handle holds the only reference to an object. */
    708   V8_INLINE(bool IsNearDeath() const);
    709 
    710   // TODO(dcarney): deprecate
    711   V8_INLINE(bool IsNearDeath(Isolate* isolate) const) { return IsNearDeath(); }
    712 
    713   /** Returns true if the handle's reference is weak.  */
    714   V8_INLINE(bool IsWeak() const);
    715 
    716   // TODO(dcarney): deprecate
    717   V8_INLINE(bool IsWeak(Isolate* isolate) const) { return IsWeak(); }
    718 
    719   /**
    720    * Assigns a wrapper class ID to the handle. See RetainedObjectInfo interface
    721    * description in v8-profiler.h for details.
    722    */
    723   V8_INLINE(void SetWrapperClassId(uint16_t class_id));
    724 
    725   // TODO(dcarney): deprecate
    726   V8_INLINE(void SetWrapperClassId(Isolate* isolate, uint16_t class_id)) {
    727     SetWrapperClassId(class_id);
    728   }
    729 
    730   /**
    731    * Returns the class ID previously assigned to this handle or 0 if no class ID
    732    * was previously assigned.
    733    */
    734   V8_INLINE(uint16_t WrapperClassId() const);
    735 
    736   // TODO(dcarney): deprecate
    737   V8_INLINE(uint16_t WrapperClassId(Isolate* isolate) const) {
    738     return WrapperClassId();
    739   }
    740 
    741   /**
    742    * Disposes the current contents of the handle and replaces it.
    743    */
    744   V8_INLINE(void Reset(Isolate* isolate, const Handle<T>& other));
    745 
    746 #ifndef V8_USE_UNSAFE_HANDLES
    747   V8_INLINE(void Reset(Isolate* isolate, const Persistent<T>& other));
    748 #endif
    749 
    750   /**
    751    * Returns the underlying raw pointer and clears the handle. The caller is
    752    * responsible of eventually destroying the underlying object (by creating a
    753    * Persistent handle which points to it and Disposing it). In the future,
    754    * destructing a Persistent will also Dispose it. With this function, the
    755    * embedder can let the Persistent go out of scope without it getting
    756    * disposed.
    757    */
    758   V8_INLINE(T* ClearAndLeak());
    759 
    760 #ifndef V8_USE_UNSAFE_HANDLES
    761 
    762  private:
    763   // TODO(dcarney): make unlinkable before cutover
    764   V8_INLINE(Persistent(const Persistent& that)) : val_(that.val_) {}
    765   // TODO(dcarney): make unlinkable before cutover
    766   V8_INLINE(Persistent& operator=(const Persistent& that)) {  // NOLINT
    767     this->val_ = that.val_;
    768     return *this;
    769   }
    770 
    771  public:
    772 #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR
    773 
    774  private:
    775 #endif
    776   // TODO(dcarney): remove before cutover
    777   template <class S> V8_INLINE(Persistent(S* that)) : val_(that) { }
    778 
    779   // TODO(dcarney): remove before cutover
    780   V8_INLINE(T* operator*() const) { return val_; }
    781 
    782  private:
    783   // TODO(dcarney): remove before cutover
    784   V8_INLINE(T* operator->() const) { return val_; }
    785  public:
    786 #endif
    787 
    788  private:
    789   friend class Utils;
    790   template<class F> friend class Handle;
    791   template<class F> friend class Local;
    792   template<class F> friend class Persistent;
    793   template<class F> friend class ReturnValue;
    794 
    795   V8_INLINE(static T* New(Isolate* isolate, T* that));
    796 
    797 #ifndef V8_USE_UNSAFE_HANDLES
    798   T* val_;
    799 #endif
    800 };
    801 
    802 
    803  /**
    804  * A stack-allocated class that governs a number of local handles.
    805  * After a handle scope has been created, all local handles will be
    806  * allocated within that handle scope until either the handle scope is
    807  * deleted or another handle scope is created.  If there is already a
    808  * handle scope and a new one is created, all allocations will take
    809  * place in the new handle scope until it is deleted.  After that,
    810  * new handles will again be allocated in the original handle scope.
    811  *
    812  * After the handle scope of a local handle has been deleted the
    813  * garbage collector will no longer track the object stored in the
    814  * handle and may deallocate it.  The behavior of accessing a handle
    815  * for which the handle scope has been deleted is undefined.
    816  */
    817 class V8_EXPORT HandleScope {
    818  public:
    819   // TODO(svenpanne) Deprecate me when Chrome is fixed!
    820   HandleScope();
    821 
    822   HandleScope(Isolate* isolate);
    823 
    824   ~HandleScope();
    825 
    826   /**
    827    * Closes the handle scope and returns the value as a handle in the
    828    * previous scope, which is the new current scope after the call.
    829    */
    830   template <class T> Local<T> Close(Handle<T> value);
    831 
    832   /**
    833    * Counts the number of allocated handles.
    834    */
    835   static int NumberOfHandles();
    836 
    837   /**
    838    * Creates a new handle with the given value.
    839    */
    840   static internal::Object** CreateHandle(internal::Object* value);
    841   static internal::Object** CreateHandle(internal::Isolate* isolate,
    842                                          internal::Object* value);
    843   // Faster version, uses HeapObject to obtain the current Isolate.
    844   static internal::Object** CreateHandle(internal::HeapObject* value);
    845 
    846  private:
    847   // Make it hard to create heap-allocated or illegal handle scopes by
    848   // disallowing certain operations.
    849   HandleScope(const HandleScope&);
    850   void operator=(const HandleScope&);
    851   void* operator new(size_t size);
    852   void operator delete(void*, size_t);
    853 
    854   // This Data class is accessible internally as HandleScopeData through a
    855   // typedef in the ImplementationUtilities class.
    856   class V8_EXPORT Data {
    857    public:
    858     internal::Object** next;
    859     internal::Object** limit;
    860     int level;
    861     V8_INLINE(void Initialize()) {
    862       next = limit = NULL;
    863       level = 0;
    864     }
    865   };
    866 
    867   void Initialize(Isolate* isolate);
    868   void Leave();
    869 
    870   internal::Isolate* isolate_;
    871   internal::Object** prev_next_;
    872   internal::Object** prev_limit_;
    873 
    874   // Allow for the active closing of HandleScopes which allows to pass a handle
    875   // from the HandleScope being closed to the next top most HandleScope.
    876   bool is_closed_;
    877   internal::Object** RawClose(internal::Object** value);
    878 
    879   friend class ImplementationUtilities;
    880 };
    881 
    882 
    883 // --- Special objects ---
    884 
    885 
    886 /**
    887  * The superclass of values and API object templates.
    888  */
    889 class V8_EXPORT Data {
    890  private:
    891   Data();
    892 };
    893 
    894 
    895 /**
    896  * Pre-compilation data that can be associated with a script.  This
    897  * data can be calculated for a script in advance of actually
    898  * compiling it, and can be stored between compilations.  When script
    899  * data is given to the compile method compilation will be faster.
    900  */
    901 class V8_EXPORT ScriptData {  // NOLINT
    902  public:
    903   virtual ~ScriptData() { }
    904 
    905   /**
    906    * Pre-compiles the specified script (context-independent).
    907    *
    908    * \param input Pointer to UTF-8 script source code.
    909    * \param length Length of UTF-8 script source code.
    910    */
    911   static ScriptData* PreCompile(const char* input, int length);
    912 
    913   /**
    914    * Pre-compiles the specified script (context-independent).
    915    *
    916    * NOTE: Pre-compilation using this method cannot happen on another thread
    917    * without using Lockers.
    918    *
    919    * \param source Script source code.
    920    */
    921   static ScriptData* PreCompile(Handle<String> source);
    922 
    923   /**
    924    * Load previous pre-compilation data.
    925    *
    926    * \param data Pointer to data returned by a call to Data() of a previous
    927    *   ScriptData. Ownership is not transferred.
    928    * \param length Length of data.
    929    */
    930   static ScriptData* New(const char* data, int length);
    931 
    932   /**
    933    * Returns the length of Data().
    934    */
    935   virtual int Length() = 0;
    936 
    937   /**
    938    * Returns a serialized representation of this ScriptData that can later be
    939    * passed to New(). NOTE: Serialized data is platform-dependent.
    940    */
    941   virtual const char* Data() = 0;
    942 
    943   /**
    944    * Returns true if the source code could not be parsed.
    945    */
    946   virtual bool HasError() = 0;
    947 };
    948 
    949 
    950 /**
    951  * The origin, within a file, of a script.
    952  */
    953 class ScriptOrigin {
    954  public:
    955   V8_INLINE(ScriptOrigin(
    956       Handle<Value> resource_name,
    957       Handle<Integer> resource_line_offset = Handle<Integer>(),
    958       Handle<Integer> resource_column_offset = Handle<Integer>(),
    959       Handle<Boolean> resource_is_shared_cross_origin = Handle<Boolean>()))
    960       : resource_name_(resource_name),
    961         resource_line_offset_(resource_line_offset),
    962         resource_column_offset_(resource_column_offset),
    963         resource_is_shared_cross_origin_(resource_is_shared_cross_origin) { }
    964   V8_INLINE(Handle<Value> ResourceName() const);
    965   V8_INLINE(Handle<Integer> ResourceLineOffset() const);
    966   V8_INLINE(Handle<Integer> ResourceColumnOffset() const);
    967   V8_INLINE(Handle<Boolean> ResourceIsSharedCrossOrigin() const);
    968  private:
    969   Handle<Value> resource_name_;
    970   Handle<Integer> resource_line_offset_;
    971   Handle<Integer> resource_column_offset_;
    972   Handle<Boolean> resource_is_shared_cross_origin_;
    973 };
    974 
    975 
    976 /**
    977  * A compiled JavaScript script.
    978  */
    979 class V8_EXPORT Script {
    980  public:
    981   /**
    982    * Compiles the specified script (context-independent).
    983    *
    984    * \param source Script source code.
    985    * \param origin Script origin, owned by caller, no references are kept
    986    *   when New() returns
    987    * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile()
    988    *   using pre_data speeds compilation if it's done multiple times.
    989    *   Owned by caller, no references are kept when New() returns.
    990    * \param script_data Arbitrary data associated with script. Using
    991    *   this has same effect as calling SetData(), but allows data to be
    992    *   available to compile event handlers.
    993    * \return Compiled script object (context independent; when run it
    994    *   will use the currently entered context).
    995    */
    996   static Local<Script> New(Handle<String> source,
    997                            ScriptOrigin* origin = NULL,
    998                            ScriptData* pre_data = NULL,
    999                            Handle<String> script_data = Handle<String>());
   1000 
   1001   /**
   1002    * Compiles the specified script using the specified file name
   1003    * object (typically a string) as the script's origin.
   1004    *
   1005    * \param source Script source code.
   1006    * \param file_name file name object (typically a string) to be used
   1007    *   as the script's origin.
   1008    * \return Compiled script object (context independent; when run it
   1009    *   will use the currently entered context).
   1010    */
   1011   static Local<Script> New(Handle<String> source,
   1012                            Handle<Value> file_name);
   1013 
   1014   /**
   1015    * Compiles the specified script (bound to current context).
   1016    *
   1017    * \param source Script source code.
   1018    * \param origin Script origin, owned by caller, no references are kept
   1019    *   when Compile() returns
   1020    * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile()
   1021    *   using pre_data speeds compilation if it's done multiple times.
   1022    *   Owned by caller, no references are kept when Compile() returns.
   1023    * \param script_data Arbitrary data associated with script. Using
   1024    *   this has same effect as calling SetData(), but makes data available
   1025    *   earlier (i.e. to compile event handlers).
   1026    * \return Compiled script object, bound to the context that was active
   1027    *   when this function was called.  When run it will always use this
   1028    *   context.
   1029    */
   1030   static Local<Script> Compile(Handle<String> source,
   1031                                ScriptOrigin* origin = NULL,
   1032                                ScriptData* pre_data = NULL,
   1033                                Handle<String> script_data = Handle<String>());
   1034 
   1035   /**
   1036    * Compiles the specified script using the specified file name
   1037    * object (typically a string) as the script's origin.
   1038    *
   1039    * \param source Script source code.
   1040    * \param file_name File name to use as script's origin
   1041    * \param script_data Arbitrary data associated with script. Using
   1042    *   this has same effect as calling SetData(), but makes data available
   1043    *   earlier (i.e. to compile event handlers).
   1044    * \return Compiled script object, bound to the context that was active
   1045    *   when this function was called.  When run it will always use this
   1046    *   context.
   1047    */
   1048   static Local<Script> Compile(Handle<String> source,
   1049                                Handle<Value> file_name,
   1050                                Handle<String> script_data = Handle<String>());
   1051 
   1052   /**
   1053    * Runs the script returning the resulting value.  If the script is
   1054    * context independent (created using ::New) it will be run in the
   1055    * currently entered context.  If it is context specific (created
   1056    * using ::Compile) it will be run in the context in which it was
   1057    * compiled.
   1058    */
   1059   Local<Value> Run();
   1060 
   1061   /**
   1062    * Returns the script id value.
   1063    * DEPRECATED: Please use GetId().
   1064    */
   1065   Local<Value> Id();
   1066 
   1067   /**
   1068    * Returns the script id.
   1069    */
   1070   int GetId();
   1071 
   1072   /**
   1073    * Associate an additional data object with the script. This is mainly used
   1074    * with the debugger as this data object is only available through the
   1075    * debugger API.
   1076    */
   1077   void SetData(Handle<String> data);
   1078 
   1079   /**
   1080    * Returns the name value of one Script.
   1081    */
   1082   Handle<Value> GetScriptName();
   1083 
   1084   /**
   1085    * Returns zero based line number of the code_pos location in the script.
   1086    * -1 will be returned if no information available.
   1087    */
   1088   int GetLineNumber(int code_pos);
   1089 
   1090   static const int kNoScriptId = 0;
   1091 };
   1092 
   1093 
   1094 /**
   1095  * An error message.
   1096  */
   1097 class V8_EXPORT Message {
   1098  public:
   1099   Local<String> Get() const;
   1100   Local<String> GetSourceLine() const;
   1101 
   1102   /**
   1103    * Returns the resource name for the script from where the function causing
   1104    * the error originates.
   1105    */
   1106   Handle<Value> GetScriptResourceName() const;
   1107 
   1108   /**
   1109    * Returns the resource data for the script from where the function causing
   1110    * the error originates.
   1111    */
   1112   Handle<Value> GetScriptData() const;
   1113 
   1114   /**
   1115    * Exception stack trace. By default stack traces are not captured for
   1116    * uncaught exceptions. SetCaptureStackTraceForUncaughtExceptions allows
   1117    * to change this option.
   1118    */
   1119   Handle<StackTrace> GetStackTrace() const;
   1120 
   1121   /**
   1122    * Returns the number, 1-based, of the line where the error occurred.
   1123    */
   1124   int GetLineNumber() const;
   1125 
   1126   /**
   1127    * Returns the index within the script of the first character where
   1128    * the error occurred.
   1129    */
   1130   int GetStartPosition() const;
   1131 
   1132   /**
   1133    * Returns the index within the script of the last character where
   1134    * the error occurred.
   1135    */
   1136   int GetEndPosition() const;
   1137 
   1138   /**
   1139    * Returns the index within the line of the first character where
   1140    * the error occurred.
   1141    */
   1142   int GetStartColumn() const;
   1143 
   1144   /**
   1145    * Returns the index within the line of the last character where
   1146    * the error occurred.
   1147    */
   1148   int GetEndColumn() const;
   1149 
   1150   /**
   1151    * Passes on the value set by the embedder when it fed the script from which
   1152    * this Message was generated to V8.
   1153    */
   1154   bool IsSharedCrossOrigin() const;
   1155 
   1156   // TODO(1245381): Print to a string instead of on a FILE.
   1157   static void PrintCurrentStackTrace(FILE* out);
   1158 
   1159   static const int kNoLineNumberInfo = 0;
   1160   static const int kNoColumnInfo = 0;
   1161 };
   1162 
   1163 
   1164 /**
   1165  * Representation of a JavaScript stack trace. The information collected is a
   1166  * snapshot of the execution stack and the information remains valid after
   1167  * execution continues.
   1168  */
   1169 class V8_EXPORT StackTrace {
   1170  public:
   1171   /**
   1172    * Flags that determine what information is placed captured for each
   1173    * StackFrame when grabbing the current stack trace.
   1174    */
   1175   enum StackTraceOptions {
   1176     kLineNumber = 1,
   1177     kColumnOffset = 1 << 1 | kLineNumber,
   1178     kScriptName = 1 << 2,
   1179     kFunctionName = 1 << 3,
   1180     kIsEval = 1 << 4,
   1181     kIsConstructor = 1 << 5,
   1182     kScriptNameOrSourceURL = 1 << 6,
   1183     kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName,
   1184     kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL
   1185   };
   1186 
   1187   /**
   1188    * Returns a StackFrame at a particular index.
   1189    */
   1190   Local<StackFrame> GetFrame(uint32_t index) const;
   1191 
   1192   /**
   1193    * Returns the number of StackFrames.
   1194    */
   1195   int GetFrameCount() const;
   1196 
   1197   /**
   1198    * Returns StackTrace as a v8::Array that contains StackFrame objects.
   1199    */
   1200   Local<Array> AsArray();
   1201 
   1202   /**
   1203    * Grab a snapshot of the current JavaScript execution stack.
   1204    *
   1205    * \param frame_limit The maximum number of stack frames we want to capture.
   1206    * \param options Enumerates the set of things we will capture for each
   1207    *   StackFrame.
   1208    */
   1209   static Local<StackTrace> CurrentStackTrace(
   1210       int frame_limit,
   1211       StackTraceOptions options = kOverview);
   1212 };
   1213 
   1214 
   1215 /**
   1216  * A single JavaScript stack frame.
   1217  */
   1218 class V8_EXPORT StackFrame {
   1219  public:
   1220   /**
   1221    * Returns the number, 1-based, of the line for the associate function call.
   1222    * This method will return Message::kNoLineNumberInfo if it is unable to
   1223    * retrieve the line number, or if kLineNumber was not passed as an option
   1224    * when capturing the StackTrace.
   1225    */
   1226   int GetLineNumber() const;
   1227 
   1228   /**
   1229    * Returns the 1-based column offset on the line for the associated function
   1230    * call.
   1231    * This method will return Message::kNoColumnInfo if it is unable to retrieve
   1232    * the column number, or if kColumnOffset was not passed as an option when
   1233    * capturing the StackTrace.
   1234    */
   1235   int GetColumn() const;
   1236 
   1237   /**
   1238    * Returns the name of the resource that contains the script for the
   1239    * function for this StackFrame.
   1240    */
   1241   Local<String> GetScriptName() const;
   1242 
   1243   /**
   1244    * Returns the name of the resource that contains the script for the
   1245    * function for this StackFrame or sourceURL value if the script name
   1246    * is undefined and its source ends with //# sourceURL=... string or
   1247    * deprecated //@ sourceURL=... string.
   1248    */
   1249   Local<String> GetScriptNameOrSourceURL() const;
   1250 
   1251   /**
   1252    * Returns the name of the function associated with this stack frame.
   1253    */
   1254   Local<String> GetFunctionName() const;
   1255 
   1256   /**
   1257    * Returns whether or not the associated function is compiled via a call to
   1258    * eval().
   1259    */
   1260   bool IsEval() const;
   1261 
   1262   /**
   1263    * Returns whether or not the associated function is called as a
   1264    * constructor via "new".
   1265    */
   1266   bool IsConstructor() const;
   1267 };
   1268 
   1269 
   1270 /**
   1271  * A JSON Parser.
   1272  */
   1273 class V8_EXPORT JSON {
   1274  public:
   1275   /**
   1276    * Tries to parse the string |json_string| and returns it as value if
   1277    * successful.
   1278    *
   1279    * \param json_string The string to parse.
   1280    * \return The corresponding value if successfully parsed.
   1281    */
   1282   static Local<Value> Parse(Local<String> json_string);
   1283 };
   1284 
   1285 
   1286 // --- Value ---
   1287 
   1288 
   1289 /**
   1290  * The superclass of all JavaScript values and objects.
   1291  */
   1292 class V8_EXPORT Value : public Data {
   1293  public:
   1294   /**
   1295    * Returns true if this value is the undefined value.  See ECMA-262
   1296    * 4.3.10.
   1297    */
   1298   V8_INLINE(bool IsUndefined() const);
   1299 
   1300   /**
   1301    * Returns true if this value is the null value.  See ECMA-262
   1302    * 4.3.11.
   1303    */
   1304   V8_INLINE(bool IsNull() const);
   1305 
   1306    /**
   1307    * Returns true if this value is true.
   1308    */
   1309   bool IsTrue() const;
   1310 
   1311   /**
   1312    * Returns true if this value is false.
   1313    */
   1314   bool IsFalse() const;
   1315 
   1316   /**
   1317    * Returns true if this value is an instance of the String type.
   1318    * See ECMA-262 8.4.
   1319    */
   1320   V8_INLINE(bool IsString() const);
   1321 
   1322   /**
   1323    * Returns true if this value is a symbol.
   1324    * This is an experimental feature.
   1325    */
   1326   bool IsSymbol() const;
   1327 
   1328   /**
   1329    * Returns true if this value is a function.
   1330    */
   1331   bool IsFunction() const;
   1332 
   1333   /**
   1334    * Returns true if this value is an array.
   1335    */
   1336   bool IsArray() const;
   1337 
   1338   /**
   1339    * Returns true if this value is an object.
   1340    */
   1341   bool IsObject() const;
   1342 
   1343   /**
   1344    * Returns true if this value is boolean.
   1345    */
   1346   bool IsBoolean() const;
   1347 
   1348   /**
   1349    * Returns true if this value is a number.
   1350    */
   1351   bool IsNumber() const;
   1352 
   1353   /**
   1354    * Returns true if this value is external.
   1355    */
   1356   bool IsExternal() const;
   1357 
   1358   /**
   1359    * Returns true if this value is a 32-bit signed integer.
   1360    */
   1361   bool IsInt32() const;
   1362 
   1363   /**
   1364    * Returns true if this value is a 32-bit unsigned integer.
   1365    */
   1366   bool IsUint32() const;
   1367 
   1368   /**
   1369    * Returns true if this value is a Date.
   1370    */
   1371   bool IsDate() const;
   1372 
   1373   /**
   1374    * Returns true if this value is a Boolean object.
   1375    */
   1376   bool IsBooleanObject() const;
   1377 
   1378   /**
   1379    * Returns true if this value is a Number object.
   1380    */
   1381   bool IsNumberObject() const;
   1382 
   1383   /**
   1384    * Returns true if this value is a String object.
   1385    */
   1386   bool IsStringObject() const;
   1387 
   1388   /**
   1389    * Returns true if this value is a Symbol object.
   1390    * This is an experimental feature.
   1391    */
   1392   bool IsSymbolObject() const;
   1393 
   1394   /**
   1395    * Returns true if this value is a NativeError.
   1396    */
   1397   bool IsNativeError() const;
   1398 
   1399   /**
   1400    * Returns true if this value is a RegExp.
   1401    */
   1402   bool IsRegExp() const;
   1403 
   1404 
   1405   /**
   1406    * Returns true if this value is an ArrayBuffer.
   1407    * This is an experimental feature.
   1408    */
   1409   bool IsArrayBuffer() const;
   1410 
   1411   /**
   1412    * Returns true if this value is an ArrayBufferView.
   1413    * This is an experimental feature.
   1414    */
   1415   bool IsArrayBufferView() const;
   1416 
   1417   /**
   1418    * Returns true if this value is one of TypedArrays.
   1419    * This is an experimental feature.
   1420    */
   1421   bool IsTypedArray() const;
   1422 
   1423   /**
   1424    * Returns true if this value is an Uint8Array.
   1425    * This is an experimental feature.
   1426    */
   1427   bool IsUint8Array() const;
   1428 
   1429   /**
   1430    * Returns true if this value is an Uint8ClampedArray.
   1431    * This is an experimental feature.
   1432    */
   1433   bool IsUint8ClampedArray() const;
   1434 
   1435   /**
   1436    * Returns true if this value is an Int8Array.
   1437    * This is an experimental feature.
   1438    */
   1439   bool IsInt8Array() const;
   1440 
   1441   /**
   1442    * Returns true if this value is an Uint16Array.
   1443    * This is an experimental feature.
   1444    */
   1445   bool IsUint16Array() const;
   1446 
   1447   /**
   1448    * Returns true if this value is an Int16Array.
   1449    * This is an experimental feature.
   1450    */
   1451   bool IsInt16Array() const;
   1452 
   1453   /**
   1454    * Returns true if this value is an Uint32Array.
   1455    * This is an experimental feature.
   1456    */
   1457   bool IsUint32Array() const;
   1458 
   1459   /**
   1460    * Returns true if this value is an Int32Array.
   1461    * This is an experimental feature.
   1462    */
   1463   bool IsInt32Array() const;
   1464 
   1465   /**
   1466    * Returns true if this value is a Float32Array.
   1467    * This is an experimental feature.
   1468    */
   1469   bool IsFloat32Array() const;
   1470 
   1471   /**
   1472    * Returns true if this value is a Float64Array.
   1473    * This is an experimental feature.
   1474    */
   1475   bool IsFloat64Array() const;
   1476 
   1477   /**
   1478    * Returns true if this value is a DataView.
   1479    * This is an experimental feature.
   1480    */
   1481   bool IsDataView() const;
   1482 
   1483   Local<Boolean> ToBoolean() const;
   1484   Local<Number> ToNumber() const;
   1485   Local<String> ToString() const;
   1486   Local<String> ToDetailString() const;
   1487   Local<Object> ToObject() const;
   1488   Local<Integer> ToInteger() const;
   1489   Local<Uint32> ToUint32() const;
   1490   Local<Int32> ToInt32() const;
   1491 
   1492   /**
   1493    * Attempts to convert a string to an array index.
   1494    * Returns an empty handle if the conversion fails.
   1495    */
   1496   Local<Uint32> ToArrayIndex() const;
   1497 
   1498   bool BooleanValue() const;
   1499   double NumberValue() const;
   1500   int64_t IntegerValue() const;
   1501   uint32_t Uint32Value() const;
   1502   int32_t Int32Value() const;
   1503 
   1504   /** JS == */
   1505   bool Equals(Handle<Value> that) const;
   1506   bool StrictEquals(Handle<Value> that) const;
   1507 
   1508   template <class T> V8_INLINE(static Value* Cast(T* value));
   1509 
   1510  private:
   1511   V8_INLINE(bool QuickIsUndefined() const);
   1512   V8_INLINE(bool QuickIsNull() const);
   1513   V8_INLINE(bool QuickIsString() const);
   1514   bool FullIsUndefined() const;
   1515   bool FullIsNull() const;
   1516   bool FullIsString() const;
   1517 };
   1518 
   1519 
   1520 /**
   1521  * The superclass of primitive values.  See ECMA-262 4.3.2.
   1522  */
   1523 class V8_EXPORT Primitive : public Value { };
   1524 
   1525 
   1526 /**
   1527  * A primitive boolean value (ECMA-262, 4.3.14).  Either the true
   1528  * or false value.
   1529  */
   1530 class V8_EXPORT Boolean : public Primitive {
   1531  public:
   1532   bool Value() const;
   1533   V8_INLINE(static Handle<Boolean> New(bool value));
   1534 };
   1535 
   1536 
   1537 /**
   1538  * A JavaScript string value (ECMA-262, 4.3.17).
   1539  */
   1540 class V8_EXPORT String : public Primitive {
   1541  public:
   1542   enum Encoding {
   1543     UNKNOWN_ENCODING = 0x1,
   1544     TWO_BYTE_ENCODING = 0x0,
   1545     ASCII_ENCODING = 0x4,
   1546     ONE_BYTE_ENCODING = 0x4
   1547   };
   1548   /**
   1549    * Returns the number of characters in this string.
   1550    */
   1551   int Length() const;
   1552 
   1553   /**
   1554    * Returns the number of bytes in the UTF-8 encoded
   1555    * representation of this string.
   1556    */
   1557   int Utf8Length() const;
   1558 
   1559   /**
   1560    * This function is no longer useful.
   1561    */
   1562   V8_DEPRECATED(V8_INLINE(bool MayContainNonAscii()) const) { return true; }
   1563 
   1564   /**
   1565    * Returns whether this string is known to contain only one byte data.
   1566    * Does not read the string.
   1567    * False negatives are possible.
   1568    */
   1569   bool IsOneByte() const;
   1570 
   1571   /**
   1572    * Returns whether this string contain only one byte data.
   1573    * Will read the entire string in some cases.
   1574    */
   1575   bool ContainsOnlyOneByte() const;
   1576 
   1577   /**
   1578    * Write the contents of the string to an external buffer.
   1579    * If no arguments are given, expects the buffer to be large
   1580    * enough to hold the entire string and NULL terminator. Copies
   1581    * the contents of the string and the NULL terminator into the
   1582    * buffer.
   1583    *
   1584    * WriteUtf8 will not write partial UTF-8 sequences, preferring to stop
   1585    * before the end of the buffer.
   1586    *
   1587    * Copies up to length characters into the output buffer.
   1588    * Only null-terminates if there is enough space in the buffer.
   1589    *
   1590    * \param buffer The buffer into which the string will be copied.
   1591    * \param start The starting position within the string at which
   1592    * copying begins.
   1593    * \param length The number of characters to copy from the string.  For
   1594    *    WriteUtf8 the number of bytes in the buffer.
   1595    * \param nchars_ref The number of characters written, can be NULL.
   1596    * \param options Various options that might affect performance of this or
   1597    *    subsequent operations.
   1598    * \return The number of characters copied to the buffer excluding the null
   1599    *    terminator.  For WriteUtf8: The number of bytes copied to the buffer
   1600    *    including the null terminator (if written).
   1601    */
   1602   enum WriteOptions {
   1603     NO_OPTIONS = 0,
   1604     HINT_MANY_WRITES_EXPECTED = 1,
   1605     NO_NULL_TERMINATION = 2,
   1606     PRESERVE_ASCII_NULL = 4
   1607   };
   1608 
   1609   // 16-bit character codes.
   1610   int Write(uint16_t* buffer,
   1611             int start = 0,
   1612             int length = -1,
   1613             int options = NO_OPTIONS) const;
   1614   // ASCII characters.
   1615   V8_DEPRECATED(int WriteAscii(char* buffer,
   1616                                int start = 0,
   1617                                int length = -1,
   1618                                int options = NO_OPTIONS) const);
   1619   // One byte characters.
   1620   int WriteOneByte(uint8_t* buffer,
   1621                    int start = 0,
   1622                    int length = -1,
   1623                    int options = NO_OPTIONS) const;
   1624   // UTF-8 encoded characters.
   1625   int WriteUtf8(char* buffer,
   1626                 int length = -1,
   1627                 int* nchars_ref = NULL,
   1628                 int options = NO_OPTIONS) const;
   1629 
   1630   /**
   1631    * A zero length string.
   1632    */
   1633   static v8::Local<v8::String> Empty();
   1634   V8_INLINE(static v8::Local<v8::String> Empty(Isolate* isolate));
   1635 
   1636   /**
   1637    * Returns true if the string is external
   1638    */
   1639   bool IsExternal() const;
   1640 
   1641   /**
   1642    * Returns true if the string is both external and ASCII
   1643    */
   1644   bool IsExternalAscii() const;
   1645 
   1646   class V8_EXPORT ExternalStringResourceBase {  // NOLINT
   1647    public:
   1648     virtual ~ExternalStringResourceBase() {}
   1649 
   1650    protected:
   1651     ExternalStringResourceBase() {}
   1652 
   1653     /**
   1654      * Internally V8 will call this Dispose method when the external string
   1655      * resource is no longer needed. The default implementation will use the
   1656      * delete operator. This method can be overridden in subclasses to
   1657      * control how allocated external string resources are disposed.
   1658      */
   1659     virtual void Dispose() { delete this; }
   1660 
   1661    private:
   1662     // Disallow copying and assigning.
   1663     ExternalStringResourceBase(const ExternalStringResourceBase&);
   1664     void operator=(const ExternalStringResourceBase&);
   1665 
   1666     friend class v8::internal::Heap;
   1667   };
   1668 
   1669   /**
   1670    * An ExternalStringResource is a wrapper around a two-byte string
   1671    * buffer that resides outside V8's heap. Implement an
   1672    * ExternalStringResource to manage the life cycle of the underlying
   1673    * buffer.  Note that the string data must be immutable.
   1674    */
   1675   class V8_EXPORT ExternalStringResource
   1676       : public ExternalStringResourceBase {
   1677    public:
   1678     /**
   1679      * Override the destructor to manage the life cycle of the underlying
   1680      * buffer.
   1681      */
   1682     virtual ~ExternalStringResource() {}
   1683 
   1684     /**
   1685      * The string data from the underlying buffer.
   1686      */
   1687     virtual const uint16_t* data() const = 0;
   1688 
   1689     /**
   1690      * The length of the string. That is, the number of two-byte characters.
   1691      */
   1692     virtual size_t length() const = 0;
   1693 
   1694    protected:
   1695     ExternalStringResource() {}
   1696   };
   1697 
   1698   /**
   1699    * An ExternalAsciiStringResource is a wrapper around an ASCII
   1700    * string buffer that resides outside V8's heap. Implement an
   1701    * ExternalAsciiStringResource to manage the life cycle of the
   1702    * underlying buffer.  Note that the string data must be immutable
   1703    * and that the data must be strict (7-bit) ASCII, not Latin-1 or
   1704    * UTF-8, which would require special treatment internally in the
   1705    * engine and, in the case of UTF-8, do not allow efficient indexing.
   1706    * Use String::New or convert to 16 bit data for non-ASCII.
   1707    */
   1708 
   1709   class V8_EXPORT ExternalAsciiStringResource
   1710       : public ExternalStringResourceBase {
   1711    public:
   1712     /**
   1713      * Override the destructor to manage the life cycle of the underlying
   1714      * buffer.
   1715      */
   1716     virtual ~ExternalAsciiStringResource() {}
   1717     /** The string data from the underlying buffer.*/
   1718     virtual const char* data() const = 0;
   1719     /** The number of ASCII characters in the string.*/
   1720     virtual size_t length() const = 0;
   1721    protected:
   1722     ExternalAsciiStringResource() {}
   1723   };
   1724 
   1725   typedef ExternalAsciiStringResource ExternalOneByteStringResource;
   1726 
   1727   /**
   1728    * If the string is an external string, return the ExternalStringResourceBase
   1729    * regardless of the encoding, otherwise return NULL.  The encoding of the
   1730    * string is returned in encoding_out.
   1731    */
   1732   V8_INLINE(ExternalStringResourceBase* GetExternalStringResourceBase(
   1733       Encoding* encoding_out) const);
   1734 
   1735   /**
   1736    * Get the ExternalStringResource for an external string.  Returns
   1737    * NULL if IsExternal() doesn't return true.
   1738    */
   1739   V8_INLINE(ExternalStringResource* GetExternalStringResource() const);
   1740 
   1741   /**
   1742    * Get the ExternalAsciiStringResource for an external ASCII string.
   1743    * Returns NULL if IsExternalAscii() doesn't return true.
   1744    */
   1745   const ExternalAsciiStringResource* GetExternalAsciiStringResource() const;
   1746 
   1747   V8_INLINE(static String* Cast(v8::Value* obj));
   1748 
   1749   // TODO(dcarney): deprecate
   1750   /**
   1751    * Allocates a new string from either UTF-8 encoded or ASCII data.
   1752    * The second parameter 'length' gives the buffer length. If omitted,
   1753    * the function calls 'strlen' to determine the buffer length.
   1754    */
   1755   V8_INLINE(static Local<String> New(const char* data, int length = -1));
   1756 
   1757   // TODO(dcarney): deprecate
   1758   /** Allocates a new string from 16-bit character codes.*/
   1759   V8_INLINE(static Local<String> New(const uint16_t* data, int length = -1));
   1760 
   1761   // TODO(dcarney): deprecate
   1762   /**
   1763    * Creates an internalized string (historically called a "symbol",
   1764    * not to be confused with ES6 symbols). Returns one if it exists already.
   1765    */
   1766   V8_INLINE(static Local<String> NewSymbol(const char* data, int length = -1));
   1767 
   1768   enum NewStringType {
   1769     kNormalString, kInternalizedString, kUndetectableString
   1770   };
   1771 
   1772   /** Allocates a new string from UTF-8 data.*/
   1773   static Local<String> NewFromUtf8(Isolate* isolate,
   1774                                   const char* data,
   1775                                   NewStringType type = kNormalString,
   1776                                   int length = -1);
   1777 
   1778   /** Allocates a new string from Latin-1 data.*/
   1779   static Local<String> NewFromOneByte(
   1780       Isolate* isolate,
   1781       const uint8_t* data,
   1782       NewStringType type = kNormalString,
   1783       int length = -1);
   1784 
   1785   /** Allocates a new string from UTF-16 data.*/
   1786   static Local<String> NewFromTwoByte(
   1787       Isolate* isolate,
   1788       const uint16_t* data,
   1789       NewStringType type = kNormalString,
   1790       int length = -1);
   1791 
   1792   /**
   1793    * Creates a new string by concatenating the left and the right strings
   1794    * passed in as parameters.
   1795    */
   1796   static Local<String> Concat(Handle<String> left, Handle<String> right);
   1797 
   1798   /**
   1799    * Creates a new external string using the data defined in the given
   1800    * resource. When the external string is no longer live on V8's heap the
   1801    * resource will be disposed by calling its Dispose method. The caller of
   1802    * this function should not otherwise delete or modify the resource. Neither
   1803    * should the underlying buffer be deallocated or modified except through the
   1804    * destructor of the external string resource.
   1805    */
   1806   static Local<String> NewExternal(ExternalStringResource* resource);
   1807 
   1808   /**
   1809    * Associate an external string resource with this string by transforming it
   1810    * in place so that existing references to this string in the JavaScript heap
   1811    * will use the external string resource. The external string resource's
   1812    * character contents need to be equivalent to this string.
   1813    * Returns true if the string has been changed to be an external string.
   1814    * The string is not modified if the operation fails. See NewExternal for
   1815    * information on the lifetime of the resource.
   1816    */
   1817   bool MakeExternal(ExternalStringResource* resource);
   1818 
   1819   /**
   1820    * Creates a new external string using the ASCII data defined in the given
   1821    * resource. When the external string is no longer live on V8's heap the
   1822    * resource will be disposed by calling its Dispose method. The caller of
   1823    * this function should not otherwise delete or modify the resource. Neither
   1824    * should the underlying buffer be deallocated or modified except through the
   1825    * destructor of the external string resource.
   1826    */
   1827   static Local<String> NewExternal(ExternalAsciiStringResource* resource);
   1828 
   1829   /**
   1830    * Associate an external string resource with this string by transforming it
   1831    * in place so that existing references to this string in the JavaScript heap
   1832    * will use the external string resource. The external string resource's
   1833    * character contents need to be equivalent to this string.
   1834    * Returns true if the string has been changed to be an external string.
   1835    * The string is not modified if the operation fails. See NewExternal for
   1836    * information on the lifetime of the resource.
   1837    */
   1838   bool MakeExternal(ExternalAsciiStringResource* resource);
   1839 
   1840   /**
   1841    * Returns true if this string can be made external.
   1842    */
   1843   bool CanMakeExternal();
   1844 
   1845   // TODO(dcarney): deprecate
   1846   /** Creates an undetectable string from the supplied ASCII or UTF-8 data.*/
   1847   V8_INLINE(
   1848       static Local<String> NewUndetectable(const char* data, int length = -1));
   1849 
   1850   // TODO(dcarney): deprecate
   1851   /** Creates an undetectable string from the supplied 16-bit character codes.*/
   1852   V8_INLINE(static Local<String> NewUndetectable(
   1853       const uint16_t* data, int length = -1));
   1854 
   1855   /**
   1856    * Converts an object to a UTF-8-encoded character array.  Useful if
   1857    * you want to print the object.  If conversion to a string fails
   1858    * (e.g. due to an exception in the toString() method of the object)
   1859    * then the length() method returns 0 and the * operator returns
   1860    * NULL.
   1861    */
   1862   class V8_EXPORT Utf8Value {
   1863    public:
   1864     explicit Utf8Value(Handle<v8::Value> obj);
   1865     ~Utf8Value();
   1866     char* operator*() { return str_; }
   1867     const char* operator*() const { return str_; }
   1868     int length() const { return length_; }
   1869    private:
   1870     char* str_;
   1871     int length_;
   1872 
   1873     // Disallow copying and assigning.
   1874     Utf8Value(const Utf8Value&);
   1875     void operator=(const Utf8Value&);
   1876   };
   1877 
   1878   /**
   1879    * Converts an object to an ASCII string.
   1880    * Useful if you want to print the object.
   1881    * If conversion to a string fails (eg. due to an exception in the toString()
   1882    * method of the object) then the length() method returns 0 and the * operator
   1883    * returns NULL.
   1884    */
   1885   class V8_EXPORT AsciiValue {
   1886    public:
   1887     // TODO(dcarney): deprecate
   1888     explicit AsciiValue(Handle<v8::Value> obj);
   1889     ~AsciiValue();
   1890     char* operator*() { return str_; }
   1891     const char* operator*() const { return str_; }
   1892     int length() const { return length_; }
   1893    private:
   1894     char* str_;
   1895     int length_;
   1896 
   1897     // Disallow copying and assigning.
   1898     AsciiValue(const AsciiValue&);
   1899     void operator=(const AsciiValue&);
   1900   };
   1901 
   1902   /**
   1903    * Converts an object to a two-byte string.
   1904    * If conversion to a string fails (eg. due to an exception in the toString()
   1905    * method of the object) then the length() method returns 0 and the * operator
   1906    * returns NULL.
   1907    */
   1908   class V8_EXPORT Value {
   1909    public:
   1910     explicit Value(Handle<v8::Value> obj);
   1911     ~Value();
   1912     uint16_t* operator*() { return str_; }
   1913     const uint16_t* operator*() const { return str_; }
   1914     int length() const { return length_; }
   1915    private:
   1916     uint16_t* str_;
   1917     int length_;
   1918 
   1919     // Disallow copying and assigning.
   1920     Value(const Value&);
   1921     void operator=(const Value&);
   1922   };
   1923 
   1924  private:
   1925   void VerifyExternalStringResourceBase(ExternalStringResourceBase* v,
   1926                                         Encoding encoding) const;
   1927   void VerifyExternalStringResource(ExternalStringResource* val) const;
   1928   static void CheckCast(v8::Value* obj);
   1929 };
   1930 
   1931 
   1932 /**
   1933  * A JavaScript symbol (ECMA-262 edition 6)
   1934  *
   1935  * This is an experimental feature. Use at your own risk.
   1936  */
   1937 class V8_EXPORT Symbol : public Primitive {
   1938  public:
   1939   // Returns the print name string of the symbol, or undefined if none.
   1940   Local<Value> Name() const;
   1941 
   1942   // Create a symbol without a print name.
   1943   static Local<Symbol> New(Isolate* isolate);
   1944 
   1945   // Create a symbol with a print name.
   1946   static Local<Symbol> New(Isolate *isolate, const char* data, int length = -1);
   1947 
   1948   V8_INLINE(static Symbol* Cast(v8::Value* obj));
   1949  private:
   1950   Symbol();
   1951   static void CheckCast(v8::Value* obj);
   1952 };
   1953 
   1954 
   1955 /**
   1956  * A JavaScript number value (ECMA-262, 4.3.20)
   1957  */
   1958 class V8_EXPORT Number : public Primitive {
   1959  public:
   1960   double Value() const;
   1961   static Local<Number> New(double value);
   1962   static Local<Number> New(Isolate* isolate, double value);
   1963   V8_INLINE(static Number* Cast(v8::Value* obj));
   1964  private:
   1965   Number();
   1966   static void CheckCast(v8::Value* obj);
   1967 };
   1968 
   1969 
   1970 /**
   1971  * A JavaScript value representing a signed integer.
   1972  */
   1973 class V8_EXPORT Integer : public Number {
   1974  public:
   1975   static Local<Integer> New(int32_t value);
   1976   static Local<Integer> NewFromUnsigned(uint32_t value);
   1977   static Local<Integer> New(int32_t value, Isolate*);
   1978   static Local<Integer> NewFromUnsigned(uint32_t value, Isolate*);
   1979   int64_t Value() const;
   1980   V8_INLINE(static Integer* Cast(v8::Value* obj));
   1981  private:
   1982   Integer();
   1983   static void CheckCast(v8::Value* obj);
   1984 };
   1985 
   1986 
   1987 /**
   1988  * A JavaScript value representing a 32-bit signed integer.
   1989  */
   1990 class V8_EXPORT Int32 : public Integer {
   1991  public:
   1992   int32_t Value() const;
   1993  private:
   1994   Int32();
   1995 };
   1996 
   1997 
   1998 /**
   1999  * A JavaScript value representing a 32-bit unsigned integer.
   2000  */
   2001 class V8_EXPORT Uint32 : public Integer {
   2002  public:
   2003   uint32_t Value() const;
   2004  private:
   2005   Uint32();
   2006 };
   2007 
   2008 
   2009 enum PropertyAttribute {
   2010   None       = 0,
   2011   ReadOnly   = 1 << 0,
   2012   DontEnum   = 1 << 1,
   2013   DontDelete = 1 << 2
   2014 };
   2015 
   2016 enum ExternalArrayType {
   2017   kExternalByteArray = 1,
   2018   kExternalUnsignedByteArray,
   2019   kExternalShortArray,
   2020   kExternalUnsignedShortArray,
   2021   kExternalIntArray,
   2022   kExternalUnsignedIntArray,
   2023   kExternalFloatArray,
   2024   kExternalDoubleArray,
   2025   kExternalPixelArray
   2026 };
   2027 
   2028 /**
   2029  * Accessor[Getter|Setter] are used as callback functions when
   2030  * setting|getting a particular property. See Object and ObjectTemplate's
   2031  * method SetAccessor.
   2032  */
   2033 typedef Handle<Value> (*AccessorGetter)(Local<String> property,
   2034                                         const AccessorInfo& info);
   2035 typedef void (*AccessorGetterCallback)(
   2036     Local<String> property,
   2037     const PropertyCallbackInfo<Value>& info);
   2038 
   2039 
   2040 typedef void (*AccessorSetter)(Local<String> property,
   2041                                Local<Value> value,
   2042                                const AccessorInfo& info);
   2043 typedef void (*AccessorSetterCallback)(
   2044     Local<String> property,
   2045     Local<Value> value,
   2046     const PropertyCallbackInfo<void>& info);
   2047 
   2048 
   2049 /**
   2050  * Access control specifications.
   2051  *
   2052  * Some accessors should be accessible across contexts.  These
   2053  * accessors have an explicit access control parameter which specifies
   2054  * the kind of cross-context access that should be allowed.
   2055  *
   2056  * Additionally, for security, accessors can prohibit overwriting by
   2057  * accessors defined in JavaScript.  For objects that have such
   2058  * accessors either locally or in their prototype chain it is not
   2059  * possible to overwrite the accessor by using __defineGetter__ or
   2060  * __defineSetter__ from JavaScript code.
   2061  */
   2062 enum AccessControl {
   2063   DEFAULT               = 0,
   2064   ALL_CAN_READ          = 1,
   2065   ALL_CAN_WRITE         = 1 << 1,
   2066   PROHIBITS_OVERWRITING = 1 << 2
   2067 };
   2068 
   2069 
   2070 /**
   2071  * A JavaScript object (ECMA-262, 4.3.3)
   2072  */
   2073 class V8_EXPORT Object : public Value {
   2074  public:
   2075   bool Set(Handle<Value> key,
   2076            Handle<Value> value,
   2077            PropertyAttribute attribs = None);
   2078 
   2079   bool Set(uint32_t index, Handle<Value> value);
   2080 
   2081   // Sets a local property on this object bypassing interceptors and
   2082   // overriding accessors or read-only properties.
   2083   //
   2084   // Note that if the object has an interceptor the property will be set
   2085   // locally, but since the interceptor takes precedence the local property
   2086   // will only be returned if the interceptor doesn't return a value.
   2087   //
   2088   // Note also that this only works for named properties.
   2089   bool ForceSet(Handle<Value> key,
   2090                 Handle<Value> value,
   2091                 PropertyAttribute attribs = None);
   2092 
   2093   Local<Value> Get(Handle<Value> key);
   2094 
   2095   Local<Value> Get(uint32_t index);
   2096 
   2097   /**
   2098    * Gets the property attributes of a property which can be None or
   2099    * any combination of ReadOnly, DontEnum and DontDelete. Returns
   2100    * None when the property doesn't exist.
   2101    */
   2102   PropertyAttribute GetPropertyAttributes(Handle<Value> key);
   2103 
   2104   bool Has(Handle<Value> key);
   2105 
   2106   bool Delete(Handle<Value> key);
   2107 
   2108   // Delete a property on this object bypassing interceptors and
   2109   // ignoring dont-delete attributes.
   2110   bool ForceDelete(Handle<Value> key);
   2111 
   2112   bool Has(uint32_t index);
   2113 
   2114   bool Delete(uint32_t index);
   2115 
   2116   V8_DEPRECATED(bool SetAccessor(Handle<String> name,
   2117                                  AccessorGetter getter,
   2118                                  AccessorSetter setter = 0,
   2119                                  Handle<Value> data = Handle<Value>(),
   2120                                  AccessControl settings = DEFAULT,
   2121                                  PropertyAttribute attribute = None));
   2122   bool SetAccessor(Handle<String> name,
   2123                    AccessorGetterCallback getter,
   2124                    AccessorSetterCallback setter = 0,
   2125                    Handle<Value> data = Handle<Value>(),
   2126                    AccessControl settings = DEFAULT,
   2127                    PropertyAttribute attribute = None);
   2128 
   2129   // This function is not yet stable and should not be used at this time.
   2130   bool SetAccessor(Handle<String> name,
   2131                    Handle<DeclaredAccessorDescriptor> descriptor,
   2132                    AccessControl settings = DEFAULT,
   2133                    PropertyAttribute attribute = None);
   2134 
   2135   /**
   2136    * Returns an array containing the names of the enumerable properties
   2137    * of this object, including properties from prototype objects.  The
   2138    * array returned by this method contains the same values as would
   2139    * be enumerated by a for-in statement over this object.
   2140    */
   2141   Local<Array> GetPropertyNames();
   2142 
   2143   /**
   2144    * This function has the same functionality as GetPropertyNames but
   2145    * the returned array doesn't contain the names of properties from
   2146    * prototype objects.
   2147    */
   2148   Local<Array> GetOwnPropertyNames();
   2149 
   2150   /**
   2151    * Get the prototype object.  This does not skip objects marked to
   2152    * be skipped by __proto__ and it does not consult the security
   2153    * handler.
   2154    */
   2155   Local<Value> GetPrototype();
   2156 
   2157   /**
   2158    * Set the prototype object.  This does not skip objects marked to
   2159    * be skipped by __proto__ and it does not consult the security
   2160    * handler.
   2161    */
   2162   bool SetPrototype(Handle<Value> prototype);
   2163 
   2164   /**
   2165    * Finds an instance of the given function template in the prototype
   2166    * chain.
   2167    */
   2168   Local<Object> FindInstanceInPrototypeChain(Handle<FunctionTemplate> tmpl);
   2169 
   2170   /**
   2171    * Call builtin Object.prototype.toString on this object.
   2172    * This is different from Value::ToString() that may call
   2173    * user-defined toString function. This one does not.
   2174    */
   2175   Local<String> ObjectProtoToString();
   2176 
   2177   /**
   2178    * Returns the function invoked as a constructor for this object.
   2179    * May be the null value.
   2180    */
   2181   Local<Value> GetConstructor();
   2182 
   2183   /**
   2184    * Returns the name of the function invoked as a constructor for this object.
   2185    */
   2186   Local<String> GetConstructorName();
   2187 
   2188   /** Gets the number of internal fields for this Object. */
   2189   int InternalFieldCount();
   2190 
   2191   /** Gets the value from an internal field. */
   2192   V8_INLINE(Local<Value> GetInternalField(int index));
   2193 
   2194   /** Sets the value in an internal field. */
   2195   void SetInternalField(int index, Handle<Value> value);
   2196 
   2197   /**
   2198    * Gets a 2-byte-aligned native pointer from an internal field. This field
   2199    * must have been set by SetAlignedPointerInInternalField, everything else
   2200    * leads to undefined behavior.
   2201    */
   2202   V8_INLINE(void* GetAlignedPointerFromInternalField(int index));
   2203 
   2204   /**
   2205    * Sets a 2-byte-aligned native pointer in an internal field. To retrieve such
   2206    * a field, GetAlignedPointerFromInternalField must be used, everything else
   2207    * leads to undefined behavior.
   2208    */
   2209   void SetAlignedPointerInInternalField(int index, void* value);
   2210 
   2211   // Testers for local properties.
   2212   bool HasOwnProperty(Handle<String> key);
   2213   bool HasRealNamedProperty(Handle<String> key);
   2214   bool HasRealIndexedProperty(uint32_t index);
   2215   bool HasRealNamedCallbackProperty(Handle<String> key);
   2216 
   2217   /**
   2218    * If result.IsEmpty() no real property was located in the prototype chain.
   2219    * This means interceptors in the prototype chain are not called.
   2220    */
   2221   Local<Value> GetRealNamedPropertyInPrototypeChain(Handle<String> key);
   2222 
   2223   /**
   2224    * If result.IsEmpty() no real property was located on the object or
   2225    * in the prototype chain.
   2226    * This means interceptors in the prototype chain are not called.
   2227    */
   2228   Local<Value> GetRealNamedProperty(Handle<String> key);
   2229 
   2230   /** Tests for a named lookup interceptor.*/
   2231   bool HasNamedLookupInterceptor();
   2232 
   2233   /** Tests for an index lookup interceptor.*/
   2234   bool HasIndexedLookupInterceptor();
   2235 
   2236   /**
   2237    * Turns on access check on the object if the object is an instance of
   2238    * a template that has access check callbacks. If an object has no
   2239    * access check info, the object cannot be accessed by anyone.
   2240    */
   2241   void TurnOnAccessCheck();
   2242 
   2243   /**
   2244    * Returns the identity hash for this object. The current implementation
   2245    * uses a hidden property on the object to store the identity hash.
   2246    *
   2247    * The return value will never be 0. Also, it is not guaranteed to be
   2248    * unique.
   2249    */
   2250   int GetIdentityHash();
   2251 
   2252   /**
   2253    * Access hidden properties on JavaScript objects. These properties are
   2254    * hidden from the executing JavaScript and only accessible through the V8
   2255    * C++ API. Hidden properties introduced by V8 internally (for example the
   2256    * identity hash) are prefixed with "v8::".
   2257    */
   2258   bool SetHiddenValue(Handle<String> key, Handle<Value> value);
   2259   Local<Value> GetHiddenValue(Handle<String> key);
   2260   bool DeleteHiddenValue(Handle<String> key);
   2261 
   2262   /**
   2263    * Returns true if this is an instance of an api function (one
   2264    * created from a function created from a function template) and has
   2265    * been modified since it was created.  Note that this method is
   2266    * conservative and may return true for objects that haven't actually
   2267    * been modified.
   2268    */
   2269   bool IsDirty();
   2270 
   2271   /**
   2272    * Clone this object with a fast but shallow copy.  Values will point
   2273    * to the same values as the original object.
   2274    */
   2275   Local<Object> Clone();
   2276 
   2277   /**
   2278    * Returns the context in which the object was created.
   2279    */
   2280   Local<Context> CreationContext();
   2281 
   2282   /**
   2283    * Set the backing store of the indexed properties to be managed by the
   2284    * embedding layer. Access to the indexed properties will follow the rules
   2285    * spelled out in CanvasPixelArray.
   2286    * Note: The embedding program still owns the data and needs to ensure that
   2287    *       the backing store is preserved while V8 has a reference.
   2288    */
   2289   void SetIndexedPropertiesToPixelData(uint8_t* data, int length);
   2290   bool HasIndexedPropertiesInPixelData();
   2291   uint8_t* GetIndexedPropertiesPixelData();
   2292   int GetIndexedPropertiesPixelDataLength();
   2293 
   2294   /**
   2295    * Set the backing store of the indexed properties to be managed by the
   2296    * embedding layer. Access to the indexed properties will follow the rules
   2297    * spelled out for the CanvasArray subtypes in the WebGL specification.
   2298    * Note: The embedding program still owns the data and needs to ensure that
   2299    *       the backing store is preserved while V8 has a reference.
   2300    */
   2301   void SetIndexedPropertiesToExternalArrayData(void* data,
   2302                                                ExternalArrayType array_type,
   2303                                                int number_of_elements);
   2304   bool HasIndexedPropertiesInExternalArrayData();
   2305   void* GetIndexedPropertiesExternalArrayData();
   2306   ExternalArrayType GetIndexedPropertiesExternalArrayDataType();
   2307   int GetIndexedPropertiesExternalArrayDataLength();
   2308 
   2309   /**
   2310    * Checks whether a callback is set by the
   2311    * ObjectTemplate::SetCallAsFunctionHandler method.
   2312    * When an Object is callable this method returns true.
   2313    */
   2314   bool IsCallable();
   2315 
   2316   /**
   2317    * Call an Object as a function if a callback is set by the
   2318    * ObjectTemplate::SetCallAsFunctionHandler method.
   2319    */
   2320   Local<Value> CallAsFunction(Handle<Object> recv,
   2321                               int argc,
   2322                               Handle<Value> argv[]);
   2323 
   2324   /**
   2325    * Call an Object as a constructor if a callback is set by the
   2326    * ObjectTemplate::SetCallAsFunctionHandler method.
   2327    * Note: This method behaves like the Function::NewInstance method.
   2328    */
   2329   Local<Value> CallAsConstructor(int argc, Handle<Value> argv[]);
   2330 
   2331   static Local<Object> New();
   2332   V8_INLINE(static Object* Cast(Value* obj));
   2333 
   2334  private:
   2335   Object();
   2336   static void CheckCast(Value* obj);
   2337   Local<Value> SlowGetInternalField(int index);
   2338   void* SlowGetAlignedPointerFromInternalField(int index);
   2339 };
   2340 
   2341 
   2342 /**
   2343  * An instance of the built-in array constructor (ECMA-262, 15.4.2).
   2344  */
   2345 class V8_EXPORT Array : public Object {
   2346  public:
   2347   uint32_t Length() const;
   2348 
   2349   /**
   2350    * Clones an element at index |index|.  Returns an empty
   2351    * handle if cloning fails (for any reason).
   2352    */
   2353   Local<Object> CloneElementAt(uint32_t index);
   2354 
   2355   /**
   2356    * Creates a JavaScript array with the given length. If the length
   2357    * is negative the returned array will have length 0.
   2358    */
   2359   static Local<Array> New(int length = 0);
   2360 
   2361   V8_INLINE(static Array* Cast(Value* obj));
   2362  private:
   2363   Array();
   2364   static void CheckCast(Value* obj);
   2365 };
   2366 
   2367 
   2368 /**
   2369  * A JavaScript function object (ECMA-262, 15.3).
   2370  */
   2371 class V8_EXPORT Function : public Object {
   2372  public:
   2373   Local<Object> NewInstance() const;
   2374   Local<Object> NewInstance(int argc, Handle<Value> argv[]) const;
   2375   Local<Value> Call(Handle<Object> recv, int argc, Handle<Value> argv[]);
   2376   void SetName(Handle<String> name);
   2377   Handle<Value> GetName() const;
   2378 
   2379   /**
   2380    * Name inferred from variable or property assignment of this function.
   2381    * Used to facilitate debugging and profiling of JavaScript code written
   2382    * in an OO style, where many functions are anonymous but are assigned
   2383    * to object properties.
   2384    */
   2385   Handle<Value> GetInferredName() const;
   2386 
   2387   /**
   2388    * Returns zero based line number of function body and
   2389    * kLineOffsetNotFound if no information available.
   2390    */
   2391   int GetScriptLineNumber() const;
   2392   /**
   2393    * Returns zero based column number of function body and
   2394    * kLineOffsetNotFound if no information available.
   2395    */
   2396   int GetScriptColumnNumber() const;
   2397 
   2398   /**
   2399    * Returns scriptId object.
   2400    * DEPRECATED: use ScriptId() instead.
   2401    */
   2402   Handle<Value> GetScriptId() const;
   2403 
   2404   /**
   2405    * Returns scriptId.
   2406    */
   2407   int ScriptId() const;
   2408 
   2409   ScriptOrigin GetScriptOrigin() const;
   2410   V8_INLINE(static Function* Cast(Value* obj));
   2411   static const int kLineOffsetNotFound;
   2412 
   2413  private:
   2414   Function();
   2415   static void CheckCast(Value* obj);
   2416 };
   2417 
   2418 #ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT
   2419 // The number of required internal fields can be defined by embedder.
   2420 #define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2
   2421 #endif
   2422 
   2423 /**
   2424  * An instance of the built-in ArrayBuffer constructor (ES6 draft 15.13.5).
   2425  * This API is experimental and may change significantly.
   2426  */
   2427 class V8_EXPORT ArrayBuffer : public Object {
   2428  public:
   2429   /**
   2430    * Allocator that V8 uses to allocate |ArrayBuffer|'s memory.
   2431    * The allocator is a global V8 setting. It should be set with
   2432    * V8::SetArrayBufferAllocator prior to creation of a first ArrayBuffer.
   2433    *
   2434    * This API is experimental and may change significantly.
   2435    */
   2436   class V8_EXPORT Allocator { // NOLINT
   2437    public:
   2438     virtual ~Allocator() {}
   2439 
   2440     /**
   2441      * Allocate |length| bytes. Return NULL if allocation is not successful.
   2442      * Memory should be initialized to zeroes.
   2443      */
   2444     virtual void* Allocate(size_t length) = 0;
   2445 
   2446     /**
   2447      * Allocate |length| bytes. Return NULL if allocation is not successful.
   2448      * Memory does not have to be initialized.
   2449      */
   2450     virtual void* AllocateUninitialized(size_t length) {
   2451       // Override with call to |Allocate| for compatibility
   2452       // with legacy version.
   2453       return Allocate(length);
   2454     }
   2455 
   2456     /**
   2457      * Free the memory block of size |length|, pointed to by |data|.
   2458      * That memory is guaranteed to be previously allocated by |Allocate|.
   2459      */
   2460     virtual void Free(void* data, size_t length) {
   2461       // Override with call to |Free(void*)| for compatibility
   2462       // with legacy version.
   2463       Free(data);
   2464     }
   2465 
   2466     /**
   2467      * Deprecated. Never called directly by V8.
   2468      * For compatibility with legacy version of this interface.
   2469      */
   2470     virtual void Free(void* data);
   2471   };
   2472 
   2473   /**
   2474    * The contents of an |ArrayBuffer|. Externalization of |ArrayBuffer|
   2475    * returns an instance of this class, populated, with a pointer to data
   2476    * and byte length.
   2477    *
   2478    * The Data pointer of ArrayBuffer::Contents is always allocated with
   2479    * Allocator::Allocate that is set with V8::SetArrayBufferAllocator.
   2480    *
   2481    * This API is experimental and may change significantly.
   2482    */
   2483   class V8_EXPORT Contents { // NOLINT
   2484    public:
   2485     Contents() : data_(NULL), byte_length_(0) {}
   2486 
   2487     void* Data() const { return data_; }
   2488     size_t ByteLength() const { return byte_length_; }
   2489 
   2490    private:
   2491     void* data_;
   2492     size_t byte_length_;
   2493 
   2494     friend class ArrayBuffer;
   2495   };
   2496 
   2497 
   2498   /**
   2499    * Data length in bytes.
   2500    */
   2501   size_t ByteLength() const;
   2502 
   2503   /**
   2504    * Create a new ArrayBuffer. Allocate |byte_length| bytes.
   2505    * Allocated memory will be owned by a created ArrayBuffer and
   2506    * will be deallocated when it is garbage-collected,
   2507    * unless the object is externalized.
   2508    */
   2509   static Local<ArrayBuffer> New(size_t byte_length);
   2510 
   2511   /**
   2512    * Create a new ArrayBuffer over an existing memory block.
   2513    * The created array buffer is immediately in externalized state.
   2514    * The memory block will not be reclaimed when a created ArrayBuffer
   2515    * is garbage-collected.
   2516    */
   2517   static Local<ArrayBuffer> New(void* data, size_t byte_length);
   2518 
   2519   /**
   2520    * Returns true if ArrayBuffer is extrenalized, that is, does not
   2521    * own its memory block.
   2522    */
   2523   bool IsExternal() const;
   2524 
   2525   /**
   2526    * Neuters this ArrayBuffer and all its views (typed arrays).
   2527    * Neutering sets the byte length of the buffer and all typed arrays to zero,
   2528    * preventing JavaScript from ever accessing underlying backing store.
   2529    * ArrayBuffer should have been externalized.
   2530    */
   2531   void Neuter();
   2532 
   2533   /**
   2534    * Make this ArrayBuffer external. The pointer to underlying memory block
   2535    * and byte length are returned as |Contents| structure. After ArrayBuffer
   2536    * had been etxrenalized, it does no longer owns the memory block. The caller
   2537    * should take steps to free memory when it is no longer needed.
   2538    *
   2539    * The memory block is guaranteed to be allocated with |Allocator::Allocate|
   2540    * that has been set with V8::SetArrayBufferAllocator.
   2541    */
   2542   Contents Externalize();
   2543 
   2544   V8_INLINE(static ArrayBuffer* Cast(Value* obj));
   2545 
   2546   static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
   2547 
   2548  private:
   2549   ArrayBuffer();
   2550   static void CheckCast(Value* obj);
   2551 };
   2552 
   2553 
   2554 #ifndef V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT
   2555 // The number of required internal fields can be defined by embedder.
   2556 #define V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT 2
   2557 #endif
   2558 
   2559 
   2560 /**
   2561  * A base class for an instance of one of "views" over ArrayBuffer,
   2562  * including TypedArrays and DataView (ES6 draft 15.13).
   2563  *
   2564  * This API is experimental and may change significantly.
   2565  */
   2566 class V8_EXPORT ArrayBufferView : public Object {
   2567  public:
   2568   /**
   2569    * Returns underlying ArrayBuffer.
   2570    */
   2571   Local<ArrayBuffer> Buffer();
   2572   /**
   2573    * Byte offset in |Buffer|.
   2574    */
   2575   size_t ByteOffset();
   2576   /**
   2577    * Size of a view in bytes.
   2578    */
   2579   size_t ByteLength();
   2580   /**
   2581    * Base address of a view.
   2582    */
   2583   void* BaseAddress();
   2584 
   2585   V8_INLINE(static ArrayBufferView* Cast(Value* obj));
   2586 
   2587   static const int kInternalFieldCount =
   2588       V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT;
   2589 
   2590  private:
   2591   ArrayBufferView();
   2592   static void CheckCast(Value* obj);
   2593 };
   2594 
   2595 
   2596 /**
   2597  * A base class for an instance of TypedArray series of constructors
   2598  * (ES6 draft 15.13.6).
   2599  * This API is experimental and may change significantly.
   2600  */
   2601 class V8_EXPORT TypedArray : public ArrayBufferView {
   2602  public:
   2603   /**
   2604    * Number of elements in this typed array
   2605    * (e.g. for Int16Array, |ByteLength|/2).
   2606    */
   2607   size_t Length();
   2608 
   2609   V8_INLINE(static TypedArray* Cast(Value* obj));
   2610 
   2611  private:
   2612   TypedArray();
   2613   static void CheckCast(Value* obj);
   2614 };
   2615 
   2616 
   2617 /**
   2618  * An instance of Uint8Array constructor (ES6 draft 15.13.6).
   2619  * This API is experimental and may change significantly.
   2620  */
   2621 class V8_EXPORT Uint8Array : public TypedArray {
   2622  public:
   2623   static Local<Uint8Array> New(Handle<ArrayBuffer> array_buffer,
   2624                                size_t byte_offset, size_t length);
   2625   V8_INLINE(static Uint8Array* Cast(Value* obj));
   2626 
   2627  private:
   2628   Uint8Array();
   2629   static void CheckCast(Value* obj);
   2630 };
   2631 
   2632 
   2633 /**
   2634  * An instance of Uint8ClampedArray constructor (ES6 draft 15.13.6).
   2635  * This API is experimental and may change significantly.
   2636  */
   2637 class V8_EXPORT Uint8ClampedArray : public TypedArray {
   2638  public:
   2639   static Local<Uint8ClampedArray> New(Handle<ArrayBuffer> array_buffer,
   2640                                size_t byte_offset, size_t length);
   2641   V8_INLINE(static Uint8ClampedArray* Cast(Value* obj));
   2642 
   2643  private:
   2644   Uint8ClampedArray();
   2645   static void CheckCast(Value* obj);
   2646 };
   2647 
   2648 /**
   2649  * An instance of Int8Array constructor (ES6 draft 15.13.6).
   2650  * This API is experimental and may change significantly.
   2651  */
   2652 class V8_EXPORT Int8Array : public TypedArray {
   2653  public:
   2654   static Local<Int8Array> New(Handle<ArrayBuffer> array_buffer,
   2655                                size_t byte_offset, size_t length);
   2656   V8_INLINE(static Int8Array* Cast(Value* obj));
   2657 
   2658  private:
   2659   Int8Array();
   2660   static void CheckCast(Value* obj);
   2661 };
   2662 
   2663 
   2664 /**
   2665  * An instance of Uint16Array constructor (ES6 draft 15.13.6).
   2666  * This API is experimental and may change significantly.
   2667  */
   2668 class V8_EXPORT Uint16Array : public TypedArray {
   2669  public:
   2670   static Local<Uint16Array> New(Handle<ArrayBuffer> array_buffer,
   2671                                size_t byte_offset, size_t length);
   2672   V8_INLINE(static Uint16Array* Cast(Value* obj));
   2673 
   2674  private:
   2675   Uint16Array();
   2676   static void CheckCast(Value* obj);
   2677 };
   2678 
   2679 
   2680 /**
   2681  * An instance of Int16Array constructor (ES6 draft 15.13.6).
   2682  * This API is experimental and may change significantly.
   2683  */
   2684 class V8_EXPORT Int16Array : public TypedArray {
   2685  public:
   2686   static Local<Int16Array> New(Handle<ArrayBuffer> array_buffer,
   2687                                size_t byte_offset, size_t length);
   2688   V8_INLINE(static Int16Array* Cast(Value* obj));
   2689 
   2690  private:
   2691   Int16Array();
   2692   static void CheckCast(Value* obj);
   2693 };
   2694 
   2695 
   2696 /**
   2697  * An instance of Uint32Array constructor (ES6 draft 15.13.6).
   2698  * This API is experimental and may change significantly.
   2699  */
   2700 class V8_EXPORT Uint32Array : public TypedArray {
   2701  public:
   2702   static Local<Uint32Array> New(Handle<ArrayBuffer> array_buffer,
   2703                                size_t byte_offset, size_t length);
   2704   V8_INLINE(static Uint32Array* Cast(Value* obj));
   2705 
   2706  private:
   2707   Uint32Array();
   2708   static void CheckCast(Value* obj);
   2709 };
   2710 
   2711 
   2712 /**
   2713  * An instance of Int32Array constructor (ES6 draft 15.13.6).
   2714  * This API is experimental and may change significantly.
   2715  */
   2716 class V8_EXPORT Int32Array : public TypedArray {
   2717  public:
   2718   static Local<Int32Array> New(Handle<ArrayBuffer> array_buffer,
   2719                                size_t byte_offset, size_t length);
   2720   V8_INLINE(static Int32Array* Cast(Value* obj));
   2721 
   2722  private:
   2723   Int32Array();
   2724   static void CheckCast(Value* obj);
   2725 };
   2726 
   2727 
   2728 /**
   2729  * An instance of Float32Array constructor (ES6 draft 15.13.6).
   2730  * This API is experimental and may change significantly.
   2731  */
   2732 class V8_EXPORT Float32Array : public TypedArray {
   2733  public:
   2734   static Local<Float32Array> New(Handle<ArrayBuffer> array_buffer,
   2735                                size_t byte_offset, size_t length);
   2736   V8_INLINE(static Float32Array* Cast(Value* obj));
   2737 
   2738  private:
   2739   Float32Array();
   2740   static void CheckCast(Value* obj);
   2741 };
   2742 
   2743 
   2744 /**
   2745  * An instance of Float64Array constructor (ES6 draft 15.13.6).
   2746  * This API is experimental and may change significantly.
   2747  */
   2748 class V8_EXPORT Float64Array : public TypedArray {
   2749  public:
   2750   static Local<Float64Array> New(Handle<ArrayBuffer> array_buffer,
   2751                                size_t byte_offset, size_t length);
   2752   V8_INLINE(static Float64Array* Cast(Value* obj));
   2753 
   2754  private:
   2755   Float64Array();
   2756   static void CheckCast(Value* obj);
   2757 };
   2758 
   2759 
   2760 /**
   2761  * An instance of DataView constructor (ES6 draft 15.13.7).
   2762  * This API is experimental and may change significantly.
   2763  */
   2764 class V8_EXPORT DataView : public ArrayBufferView {
   2765  public:
   2766   static Local<DataView> New(Handle<ArrayBuffer> array_buffer,
   2767                              size_t byte_offset, size_t length);
   2768   V8_INLINE(static DataView* Cast(Value* obj));
   2769 
   2770  private:
   2771   DataView();
   2772   static void CheckCast(Value* obj);
   2773 };
   2774 
   2775 
   2776 /**
   2777  * An instance of the built-in Date constructor (ECMA-262, 15.9).
   2778  */
   2779 class V8_EXPORT Date : public Object {
   2780  public:
   2781   static Local<Value> New(double time);
   2782 
   2783   // Deprecated, use Date::ValueOf() instead.
   2784   // TODO(svenpanne) Actually deprecate when Chrome is adapted.
   2785   double NumberValue() const { return ValueOf(); }
   2786 
   2787   /**
   2788    * A specialization of Value::NumberValue that is more efficient
   2789    * because we know the structure of this object.
   2790    */
   2791   double ValueOf() const;
   2792 
   2793   V8_INLINE(static Date* Cast(v8::Value* obj));
   2794 
   2795   /**
   2796    * Notification that the embedder has changed the time zone,
   2797    * daylight savings time, or other date / time configuration
   2798    * parameters.  V8 keeps a cache of various values used for
   2799    * date / time computation.  This notification will reset
   2800    * those cached values for the current context so that date /
   2801    * time configuration changes would be reflected in the Date
   2802    * object.
   2803    *
   2804    * This API should not be called more than needed as it will
   2805    * negatively impact the performance of date operations.
   2806    */
   2807   static void DateTimeConfigurationChangeNotification();
   2808 
   2809  private:
   2810   static void CheckCast(v8::Value* obj);
   2811 };
   2812 
   2813 
   2814 /**
   2815  * A Number object (ECMA-262, 4.3.21).
   2816  */
   2817 class V8_EXPORT NumberObject : public Object {
   2818  public:
   2819   static Local<Value> New(double value);
   2820 
   2821   // Deprecated, use NumberObject::ValueOf() instead.
   2822   // TODO(svenpanne) Actually deprecate when Chrome is adapted.
   2823   double NumberValue() const { return ValueOf(); }
   2824 
   2825   /**
   2826    * Returns the Number held by the object.
   2827    */
   2828   double ValueOf() const;
   2829 
   2830   V8_INLINE(static NumberObject* Cast(v8::Value* obj));
   2831 
   2832  private:
   2833   static void CheckCast(v8::Value* obj);
   2834 };
   2835 
   2836 
   2837 /**
   2838  * A Boolean object (ECMA-262, 4.3.15).
   2839  */
   2840 class V8_EXPORT BooleanObject : public Object {
   2841  public:
   2842   static Local<Value> New(bool value);
   2843 
   2844   // Deprecated, use BooleanObject::ValueOf() instead.
   2845   // TODO(svenpanne) Actually deprecate when Chrome is adapted.
   2846   bool BooleanValue() const { return ValueOf(); }
   2847 
   2848   /**
   2849    * Returns the Boolean held by the object.
   2850    */
   2851   bool ValueOf() const;
   2852 
   2853   V8_INLINE(static BooleanObject* Cast(v8::Value* obj));
   2854 
   2855  private:
   2856   static void CheckCast(v8::Value* obj);
   2857 };
   2858 
   2859 
   2860 /**
   2861  * A String object (ECMA-262, 4.3.18).
   2862  */
   2863 class V8_EXPORT StringObject : public Object {
   2864  public:
   2865   static Local<Value> New(Handle<String> value);
   2866 
   2867   // Deprecated, use StringObject::ValueOf() instead.
   2868   // TODO(svenpanne) Actually deprecate when Chrome is adapted.
   2869   Local<String> StringValue() const { return ValueOf(); }
   2870 
   2871   /**
   2872    * Returns the String held by the object.
   2873    */
   2874   Local<String> ValueOf() const;
   2875 
   2876   V8_INLINE(static StringObject* Cast(v8::Value* obj));
   2877 
   2878  private:
   2879   static void CheckCast(v8::Value* obj);
   2880 };
   2881 
   2882 
   2883 /**
   2884  * A Symbol object (ECMA-262 edition 6).
   2885  *
   2886  * This is an experimental feature. Use at your own risk.
   2887  */
   2888 class V8_EXPORT SymbolObject : public Object {
   2889  public:
   2890   static Local<Value> New(Isolate* isolate, Handle<Symbol> value);
   2891 
   2892   // Deprecated, use SymbolObject::ValueOf() instead.
   2893   // TODO(svenpanne) Actually deprecate when Chrome is adapted.
   2894   Local<Symbol> SymbolValue() const { return ValueOf(); }
   2895 
   2896   /**
   2897    * Returns the Symbol held by the object.
   2898    */
   2899   Local<Symbol> ValueOf() const;
   2900 
   2901   V8_INLINE(static SymbolObject* Cast(v8::Value* obj));
   2902 
   2903  private:
   2904   static void CheckCast(v8::Value* obj);
   2905 };
   2906 
   2907 
   2908 /**
   2909  * An instance of the built-in RegExp constructor (ECMA-262, 15.10).
   2910  */
   2911 class V8_EXPORT RegExp : public Object {
   2912  public:
   2913   /**
   2914    * Regular expression flag bits. They can be or'ed to enable a set
   2915    * of flags.
   2916    */
   2917   enum Flags {
   2918     kNone = 0,
   2919     kGlobal = 1,
   2920     kIgnoreCase = 2,
   2921     kMultiline = 4
   2922   };
   2923 
   2924   /**
   2925    * Creates a regular expression from the given pattern string and
   2926    * the flags bit field. May throw a JavaScript exception as
   2927    * described in ECMA-262, 15.10.4.1.
   2928    *
   2929    * For example,
   2930    *   RegExp::New(v8::String::New("foo"),
   2931    *               static_cast<RegExp::Flags>(kGlobal | kMultiline))
   2932    * is equivalent to evaluating "/foo/gm".
   2933    */
   2934   static Local<RegExp> New(Handle<String> pattern, Flags flags);
   2935 
   2936   /**
   2937    * Returns the value of the source property: a string representing
   2938    * the regular expression.
   2939    */
   2940   Local<String> GetSource() const;
   2941 
   2942   /**
   2943    * Returns the flags bit field.
   2944    */
   2945   Flags GetFlags() const;
   2946 
   2947   V8_INLINE(static RegExp* Cast(v8::Value* obj));
   2948 
   2949  private:
   2950   static void CheckCast(v8::Value* obj);
   2951 };
   2952 
   2953 
   2954 /**
   2955  * A JavaScript value that wraps a C++ void*. This type of value is mainly used
   2956  * to associate C++ data structures with JavaScript objects.
   2957  */
   2958 class V8_EXPORT External : public Value {
   2959  public:
   2960   static Local<External> New(void* value);
   2961   V8_INLINE(static External* Cast(Value* obj));
   2962   void* Value() const;
   2963  private:
   2964   static void CheckCast(v8::Value* obj);
   2965 };
   2966 
   2967 
   2968 // --- Templates ---
   2969 
   2970 
   2971 /**
   2972  * The superclass of object and function templates.
   2973  */
   2974 class V8_EXPORT Template : public Data {
   2975  public:
   2976   /** Adds a property to each instance created by this template.*/
   2977   void Set(Handle<String> name, Handle<Data> value,
   2978            PropertyAttribute attributes = None);
   2979   V8_INLINE(void Set(const char* name, Handle<Data> value));
   2980  private:
   2981   Template();
   2982 
   2983   friend class ObjectTemplate;
   2984   friend class FunctionTemplate;
   2985 };
   2986 
   2987 
   2988 template<typename T>
   2989 class ReturnValue {
   2990  public:
   2991   template <class S> V8_INLINE(ReturnValue(const ReturnValue<S>& that))
   2992       : value_(that.value_) {
   2993     TYPE_CHECK(T, S);
   2994   }
   2995   // Handle setters
   2996   template <typename S> V8_INLINE(void Set(const Persistent<S>& handle));
   2997   template <typename S> V8_INLINE(void Set(const Handle<S> handle));
   2998   // Fast primitive setters
   2999   V8_INLINE(void Set(bool value));
   3000   V8_INLINE(void Set(double i));
   3001   V8_INLINE(void Set(int32_t i));
   3002   V8_INLINE(void Set(uint32_t i));
   3003   // Fast JS primitive setters
   3004   V8_INLINE(void SetNull());
   3005   V8_INLINE(void SetUndefined());
   3006   V8_INLINE(void SetEmptyString());
   3007   // Convenience getter for Isolate
   3008   V8_INLINE(Isolate* GetIsolate());
   3009 
   3010  private:
   3011   template<class F> friend class ReturnValue;
   3012   template<class F> friend class FunctionCallbackInfo;
   3013   template<class F> friend class PropertyCallbackInfo;
   3014   V8_INLINE(internal::Object* GetDefaultValue());
   3015   V8_INLINE(explicit ReturnValue(internal::Object** slot));
   3016   internal::Object** value_;
   3017 };
   3018 
   3019 
   3020 /**
   3021  * The argument information given to function call callbacks.  This
   3022  * class provides access to information about the context of the call,
   3023  * including the receiver, the number and values of arguments, and
   3024  * the holder of the function.
   3025  */
   3026 template<typename T>
   3027 class FunctionCallbackInfo {
   3028  public:
   3029   V8_INLINE(int Length() const);
   3030   V8_INLINE(Local<Value> operator[](int i) const);
   3031   V8_INLINE(Local<Function> Callee() const);
   3032   V8_INLINE(Local<Object> This() const);
   3033   V8_INLINE(Local<Object> Holder() const);
   3034   V8_INLINE(bool IsConstructCall() const);
   3035   V8_INLINE(Local<Value> Data() const);
   3036   V8_INLINE(Isolate* GetIsolate() const);
   3037   V8_INLINE(ReturnValue<T> GetReturnValue() const);
   3038   // This shouldn't be public, but the arm compiler needs it.
   3039   static const int kArgsLength = 6;
   3040 
   3041  protected:
   3042   friend class internal::FunctionCallbackArguments;
   3043   friend class internal::CustomArguments<FunctionCallbackInfo>;
   3044   static const int kReturnValueIndex = 0;
   3045   static const int kReturnValueDefaultValueIndex = -1;
   3046   static const int kIsolateIndex = -2;
   3047   static const int kDataIndex = -3;
   3048   static const int kCalleeIndex = -4;
   3049   static const int kHolderIndex = -5;
   3050 
   3051   V8_INLINE(FunctionCallbackInfo(internal::Object** implicit_args,
   3052                    internal::Object** values,
   3053                    int length,
   3054                    bool is_construct_call));
   3055   internal::Object** implicit_args_;
   3056   internal::Object** values_;
   3057   int length_;
   3058   bool is_construct_call_;
   3059 };
   3060 
   3061 
   3062 class V8_EXPORT Arguments : public FunctionCallbackInfo<Value> {
   3063  private:
   3064   friend class internal::FunctionCallbackArguments;
   3065   V8_INLINE(Arguments(internal::Object** implicit_args,
   3066                       internal::Object** values,
   3067                       int length,
   3068                       bool is_construct_call));
   3069 };
   3070 
   3071 /**
   3072  * The information passed to a property callback about the context
   3073  * of the property access.
   3074  */
   3075 template<typename T>
   3076 class PropertyCallbackInfo {
   3077  public:
   3078   V8_INLINE(Isolate* GetIsolate() const);
   3079   V8_INLINE(Local<Value> Data() const);
   3080   V8_INLINE(Local<Object> This() const);
   3081   V8_INLINE(Local<Object> Holder() const);
   3082   V8_INLINE(ReturnValue<T> GetReturnValue() const);
   3083   // This shouldn't be public, but the arm compiler needs it.
   3084   static const int kArgsLength = 6;
   3085 
   3086  protected:
   3087   friend class MacroAssembler;
   3088   friend class internal::PropertyCallbackArguments;
   3089   friend class internal::CustomArguments<PropertyCallbackInfo>;
   3090   static const int kThisIndex = 0;
   3091   static const int kHolderIndex = -1;
   3092   static const int kDataIndex = -2;
   3093   static const int kReturnValueIndex = -3;
   3094   static const int kReturnValueDefaultValueIndex = -4;
   3095   static const int kIsolateIndex = -5;
   3096 
   3097   V8_INLINE(PropertyCallbackInfo(internal::Object** args))
   3098       : args_(args) { }
   3099   internal::Object** args_;
   3100 };
   3101 
   3102 
   3103 class V8_EXPORT AccessorInfo : public PropertyCallbackInfo<Value> {
   3104  private:
   3105   friend class internal::PropertyCallbackArguments;
   3106   V8_INLINE(AccessorInfo(internal::Object** args))
   3107       : PropertyCallbackInfo<Value>(args) { }
   3108 };
   3109 
   3110 
   3111 typedef Handle<Value> (*InvocationCallback)(const Arguments& args);
   3112 typedef void (*FunctionCallback)(const FunctionCallbackInfo<Value>& info);
   3113 
   3114 /**
   3115  * NamedProperty[Getter|Setter] are used as interceptors on object.
   3116  * See ObjectTemplate::SetNamedPropertyHandler.
   3117  */
   3118 typedef Handle<Value> (*NamedPropertyGetter)(Local<String> property,
   3119                                              const AccessorInfo& info);
   3120 typedef void (*NamedPropertyGetterCallback)(
   3121     Local<String> property,
   3122     const PropertyCallbackInfo<Value>& info);
   3123 
   3124 
   3125 /**
   3126  * Returns the value if the setter intercepts the request.
   3127  * Otherwise, returns an empty handle.
   3128  */
   3129 typedef Handle<Value> (*NamedPropertySetter)(Local<String> property,
   3130                                              Local<Value> value,
   3131                                              const AccessorInfo& info);
   3132 typedef void (*NamedPropertySetterCallback)(
   3133     Local<String> property,
   3134     Local<Value> value,
   3135     const PropertyCallbackInfo<Value>& info);
   3136 
   3137 
   3138 /**
   3139  * Returns a non-empty handle if the interceptor intercepts the request.
   3140  * The result is an integer encoding property attributes (like v8::None,
   3141  * v8::DontEnum, etc.)
   3142  */
   3143 typedef Handle<Integer> (*NamedPropertyQuery)(Local<String> property,
   3144                                               const AccessorInfo& info);
   3145 typedef void (*NamedPropertyQueryCallback)(
   3146     Local<String> property,
   3147     const PropertyCallbackInfo<Integer>& info);
   3148 
   3149 
   3150 /**
   3151  * Returns a non-empty handle if the deleter intercepts the request.
   3152  * The return value is true if the property could be deleted and false
   3153  * otherwise.
   3154  */
   3155 typedef Handle<Boolean> (*NamedPropertyDeleter)(Local<String> property,
   3156                                                 const AccessorInfo& info);
   3157 typedef void (*NamedPropertyDeleterCallback)(
   3158     Local<String> property,
   3159     const PropertyCallbackInfo<Boolean>& info);
   3160 
   3161 
   3162 /**
   3163  * Returns an array containing the names of the properties the named
   3164  * property getter intercepts.
   3165  */
   3166 typedef Handle<Array> (*NamedPropertyEnumerator)(const AccessorInfo& info);
   3167 typedef void (*NamedPropertyEnumeratorCallback)(
   3168     const PropertyCallbackInfo<Array>& info);
   3169 
   3170 
   3171 /**
   3172  * Returns the value of the property if the getter intercepts the
   3173  * request.  Otherwise, returns an empty handle.
   3174  */
   3175 typedef Handle<Value> (*IndexedPropertyGetter)(uint32_t index,
   3176                                                const AccessorInfo& info);
   3177 typedef void (*IndexedPropertyGetterCallback)(
   3178     uint32_t index,
   3179     const PropertyCallbackInfo<Value>& info);
   3180 
   3181 
   3182 /**
   3183  * Returns the value if the setter intercepts the request.
   3184  * Otherwise, returns an empty handle.
   3185  */
   3186 typedef Handle<Value> (*IndexedPropertySetter)(uint32_t index,
   3187                                                Local<Value> value,
   3188                                                const AccessorInfo& info);
   3189 typedef void (*IndexedPropertySetterCallback)(
   3190     uint32_t index,
   3191     Local<Value> value,
   3192     const PropertyCallbackInfo<Value>& info);
   3193 
   3194 
   3195 /**
   3196  * Returns a non-empty handle if the interceptor intercepts the request.
   3197  * The result is an integer encoding property attributes.
   3198  */
   3199 typedef Handle<Integer> (*IndexedPropertyQuery)(uint32_t index,
   3200                                                 const AccessorInfo& info);
   3201 typedef void (*IndexedPropertyQueryCallback)(
   3202     uint32_t index,
   3203     const PropertyCallbackInfo<Integer>& info);
   3204 
   3205 
   3206 /**
   3207  * Returns a non-empty handle if the deleter intercepts the request.
   3208  * The return value is true if the property could be deleted and false
   3209  * otherwise.
   3210  */
   3211 typedef Handle<Boolean> (*IndexedPropertyDeleter)(uint32_t index,
   3212                                                   const AccessorInfo& info);
   3213 typedef void (*IndexedPropertyDeleterCallback)(
   3214     uint32_t index,
   3215     const PropertyCallbackInfo<Boolean>& info);
   3216 
   3217 
   3218 /**
   3219  * Returns an array containing the indices of the properties the
   3220  * indexed property getter intercepts.
   3221  */
   3222 typedef Handle<Array> (*IndexedPropertyEnumerator)(const AccessorInfo& info);
   3223 typedef void (*IndexedPropertyEnumeratorCallback)(
   3224     const PropertyCallbackInfo<Array>& info);
   3225 
   3226 
   3227 /**
   3228  * Access type specification.
   3229  */
   3230 enum AccessType {
   3231   ACCESS_GET,
   3232   ACCESS_SET,
   3233   ACCESS_HAS,
   3234   ACCESS_DELETE,
   3235   ACCESS_KEYS
   3236 };
   3237 
   3238 
   3239 /**
   3240  * Returns true if cross-context access should be allowed to the named
   3241  * property with the given key on the host object.
   3242  */
   3243 typedef bool (*NamedSecurityCallback)(Local<Object> host,
   3244                                       Local<Value> key,
   3245                                       AccessType type,
   3246                                       Local<Value> data);
   3247 
   3248 
   3249 /**
   3250  * Returns true if cross-context access should be allowed to the indexed
   3251  * property with the given index on the host object.
   3252  */
   3253 typedef bool (*IndexedSecurityCallback)(Local<Object> host,
   3254                                         uint32_t index,
   3255                                         AccessType type,
   3256                                         Local<Value> data);
   3257 
   3258 
   3259 /**
   3260  * A FunctionTemplate is used to create functions at runtime. There
   3261  * can only be one function created from a FunctionTemplate in a
   3262  * context.  The lifetime of the created function is equal to the
   3263  * lifetime of the context.  So in case the embedder needs to create
   3264  * temporary functions that can be collected using Scripts is
   3265  * preferred.
   3266  *
   3267  * A FunctionTemplate can have properties, these properties are added to the
   3268  * function object when it is created.
   3269  *
   3270  * A FunctionTemplate has a corresponding instance template which is
   3271  * used to create object instances when the function is used as a
   3272  * constructor. Properties added to the instance template are added to
   3273  * each object instance.
   3274  *
   3275  * A FunctionTemplate can have a prototype template. The prototype template
   3276  * is used to create the prototype object of the function.
   3277  *
   3278  * The following example shows how to use a FunctionTemplate:
   3279  *
   3280  * \code
   3281  *    v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New();
   3282  *    t->Set("func_property", v8::Number::New(1));
   3283  *
   3284  *    v8::Local<v8::Template> proto_t = t->PrototypeTemplate();
   3285  *    proto_t->Set("proto_method", v8::FunctionTemplate::New(InvokeCallback));
   3286  *    proto_t->Set("proto_const", v8::Number::New(2));
   3287  *
   3288  *    v8::Local<v8::ObjectTemplate> instance_t = t->InstanceTemplate();
   3289  *    instance_t->SetAccessor("instance_accessor", InstanceAccessorCallback);
   3290  *    instance_t->SetNamedPropertyHandler(PropertyHandlerCallback, ...);
   3291  *    instance_t->Set("instance_property", Number::New(3));
   3292  *
   3293  *    v8::Local<v8::Function> function = t->GetFunction();
   3294  *    v8::Local<v8::Object> instance = function->NewInstance();
   3295  * \endcode
   3296  *
   3297  * Let's use "function" as the JS variable name of the function object
   3298  * and "instance" for the instance object created above.  The function
   3299  * and the instance will have the following properties:
   3300  *
   3301  * \code
   3302  *   func_property in function == true;
   3303  *   function.func_property == 1;
   3304  *
   3305  *   function.prototype.proto_method() invokes 'InvokeCallback'
   3306  *   function.prototype.proto_const == 2;
   3307  *
   3308  *   instance instanceof function == true;
   3309  *   instance.instance_accessor calls 'InstanceAccessorCallback'
   3310  *   instance.instance_property == 3;
   3311  * \endcode
   3312  *
   3313  * A FunctionTemplate can inherit from another one by calling the
   3314  * FunctionTemplate::Inherit method.  The following graph illustrates
   3315  * the semantics of inheritance:
   3316  *
   3317  * \code
   3318  *   FunctionTemplate Parent  -> Parent() . prototype -> { }
   3319  *     ^                                                  ^
   3320  *     | Inherit(Parent)                                  | .__proto__
   3321  *     |                                                  |
   3322  *   FunctionTemplate Child   -> Child()  . prototype -> { }
   3323  * \endcode
   3324  *
   3325  * A FunctionTemplate 'Child' inherits from 'Parent', the prototype
   3326  * object of the Child() function has __proto__ pointing to the
   3327  * Parent() function's prototype object. An instance of the Child
   3328  * function has all properties on Parent's instance templates.
   3329  *
   3330  * Let Parent be the FunctionTemplate initialized in the previous
   3331  * section and create a Child FunctionTemplate by:
   3332  *
   3333  * \code
   3334  *   Local<FunctionTemplate> parent = t;
   3335  *   Local<FunctionTemplate> child = FunctionTemplate::New();
   3336  *   child->Inherit(parent);
   3337  *
   3338  *   Local<Function> child_function = child->GetFunction();
   3339  *   Local<Object> child_instance = child_function->NewInstance();
   3340  * \endcode
   3341  *
   3342  * The Child function and Child instance will have the following
   3343  * properties:
   3344  *
   3345  * \code
   3346  *   child_func.prototype.__proto__ == function.prototype;
   3347  *   child_instance.instance_accessor calls 'InstanceAccessorCallback'
   3348  *   child_instance.instance_property == 3;
   3349  * \endcode
   3350  */
   3351 class V8_EXPORT FunctionTemplate : public Template {
   3352  public:
   3353   /** Creates a function template.*/
   3354   V8_DEPRECATED(static Local<FunctionTemplate> New(
   3355       InvocationCallback callback,
   3356       Handle<Value> data = Handle<Value>(),
   3357       Handle<Signature> signature = Handle<Signature>(),
   3358       int length = 0));
   3359   static Local<FunctionTemplate> New(
   3360       FunctionCallback callback = 0,
   3361       Handle<Value> data = Handle<Value>(),
   3362       Handle<Signature> signature = Handle<Signature>(),
   3363       int length = 0);
   3364 
   3365   /** Returns the unique function instance in the current execution context.*/
   3366   Local<Function> GetFunction();
   3367 
   3368   /**
   3369    * Set the call-handler callback for a FunctionTemplate.  This
   3370    * callback is called whenever the function created from this
   3371    * FunctionTemplate is called.
   3372    */
   3373   V8_DEPRECATED(void SetCallHandler(InvocationCallback callback,
   3374                                     Handle<Value> data = Handle<Value>()));
   3375   void SetCallHandler(FunctionCallback callback,
   3376                       Handle<Value> data = Handle<Value>());
   3377 
   3378   /** Set the predefined length property for the FunctionTemplate. */
   3379   void SetLength(int length);
   3380 
   3381   /** Get the InstanceTemplate. */
   3382   Local<ObjectTemplate> InstanceTemplate();
   3383 
   3384   /** Causes the function template to inherit from a parent function template.*/
   3385   void Inherit(Handle<FunctionTemplate> parent);
   3386 
   3387   /**
   3388    * A PrototypeTemplate is the template used to create the prototype object
   3389    * of the function created by this template.
   3390    */
   3391   Local<ObjectTemplate> PrototypeTemplate();
   3392 
   3393   /**
   3394    * Set the class name of the FunctionTemplate.  This is used for
   3395    * printing objects created with the function created from the
   3396    * FunctionTemplate as its constructor.
   3397    */
   3398   void SetClassName(Handle<String> name);
   3399 
   3400   /**
   3401    * Determines whether the __proto__ accessor ignores instances of
   3402    * the function template.  If instances of the function template are
   3403    * ignored, __proto__ skips all instances and instead returns the
   3404    * next object in the prototype chain.
   3405    *
   3406    * Call with a value of true to make the __proto__ accessor ignore
   3407    * instances of the function template.  Call with a value of false
   3408    * to make the __proto__ accessor not ignore instances of the
   3409    * function template.  By default, instances of a function template
   3410    * are not ignored.
   3411    */
   3412   void SetHiddenPrototype(bool value);
   3413 
   3414   /**
   3415    * Sets the ReadOnly flag in the attributes of the 'prototype' property
   3416    * of functions created from this FunctionTemplate to true.
   3417    */
   3418   void ReadOnlyPrototype();
   3419 
   3420   /**
   3421    * Returns true if the given object is an instance of this function
   3422    * template.
   3423    */
   3424   bool HasInstance(Handle<Value> object);
   3425 
   3426  private:
   3427   FunctionTemplate();
   3428   // TODO(dcarney): Remove with SetCallHandler.
   3429   friend class v8::CallHandlerHelper;
   3430   void SetCallHandlerInternal(InvocationCallback callback, Handle<Value> data);
   3431   friend class Context;
   3432   friend class ObjectTemplate;
   3433 };
   3434 
   3435 
   3436 /**
   3437  * An ObjectTemplate is used to create objects at runtime.
   3438  *
   3439  * Properties added to an ObjectTemplate are added to each object
   3440  * created from the ObjectTemplate.
   3441  */
   3442 class V8_EXPORT ObjectTemplate : public Template {
   3443  public:
   3444   /** Creates an ObjectTemplate. */
   3445   static Local<ObjectTemplate> New();
   3446 
   3447   /** Creates a new instance of this template.*/
   3448   Local<Object> NewInstance();
   3449 
   3450   /**
   3451    * Sets an accessor on the object template.
   3452    *
   3453    * Whenever the property with the given name is accessed on objects
   3454    * created from this ObjectTemplate the getter and setter callbacks
   3455    * are called instead of getting and setting the property directly
   3456    * on the JavaScript object.
   3457    *
   3458    * \param name The name of the property for which an accessor is added.
   3459    * \param getter The callback to invoke when getting the property.
   3460    * \param setter The callback to invoke when setting the property.
   3461    * \param data A piece of data that will be passed to the getter and setter
   3462    *   callbacks whenever they are invoked.
   3463    * \param settings Access control settings for the accessor. This is a bit
   3464    *   field consisting of one of more of
   3465    *   DEFAULT = 0, ALL_CAN_READ = 1, or ALL_CAN_WRITE = 2.
   3466    *   The default is to not allow cross-context access.
   3467    *   ALL_CAN_READ means that all cross-context reads are allowed.
   3468    *   ALL_CAN_WRITE means that all cross-context writes are allowed.
   3469    *   The combination ALL_CAN_READ | ALL_CAN_WRITE can be used to allow all
   3470    *   cross-context access.
   3471    * \param attribute The attributes of the property for which an accessor
   3472    *   is added.
   3473    * \param signature The signature describes valid receivers for the accessor
   3474    *   and is used to perform implicit instance checks against them. If the
   3475    *   receiver is incompatible (i.e. is not an instance of the constructor as
   3476    *   defined by FunctionTemplate::HasInstance()), an implicit TypeError is
   3477    *   thrown and no callback is invoked.
   3478    */
   3479   V8_DEPRECATED(void SetAccessor(Handle<String> name,
   3480                                  AccessorGetter getter,
   3481                                  AccessorSetter setter = 0,
   3482                                  Handle<Value> data = Handle<Value>(),
   3483                                  AccessControl settings = DEFAULT,
   3484                                  PropertyAttribute attribute = None,
   3485                                  Handle<AccessorSignature> signature =
   3486                                      Handle<AccessorSignature>()));
   3487   void SetAccessor(Handle<String> name,
   3488                    AccessorGetterCallback getter,
   3489                    AccessorSetterCallback setter = 0,
   3490                    Handle<Value> data = Handle<Value>(),
   3491                    AccessControl settings = DEFAULT,
   3492                    PropertyAttribute attribute = None,
   3493                    Handle<AccessorSignature> signature =
   3494                        Handle<AccessorSignature>());
   3495 
   3496   // This function is not yet stable and should not be used at this time.
   3497   bool SetAccessor(Handle<String> name,
   3498                    Handle<DeclaredAccessorDescriptor> descriptor,
   3499                    AccessControl settings = DEFAULT,
   3500                    PropertyAttribute attribute = None,
   3501                    Handle<AccessorSignature> signature =
   3502                        Handle<AccessorSignature>());
   3503 
   3504   /**
   3505    * Sets a named property handler on the object template.
   3506    *
   3507    * Whenever a named property is accessed on objects created from
   3508    * this object template, the provided callback is invoked instead of
   3509    * accessing the property directly on the JavaScript object.
   3510    *
   3511    * \param getter The callback to invoke when getting a property.
   3512    * \param setter The callback to invoke when setting a property.
   3513    * \param query The callback to invoke to check if a property is present,
   3514    *   and if present, get its attributes.
   3515    * \param deleter The callback to invoke when deleting a property.
   3516    * \param enumerator The callback to invoke to enumerate all the named
   3517    *   properties of an object.
   3518    * \param data A piece of data that will be passed to the callbacks
   3519    *   whenever they are invoked.
   3520    */
   3521   V8_DEPRECATED(void SetNamedPropertyHandler(
   3522       NamedPropertyGetter getter,
   3523       NamedPropertySetter setter = 0,
   3524       NamedPropertyQuery query = 0,
   3525       NamedPropertyDeleter deleter = 0,
   3526       NamedPropertyEnumerator enumerator = 0,
   3527       Handle<Value> data = Handle<Value>()));
   3528   void SetNamedPropertyHandler(
   3529       NamedPropertyGetterCallback getter,
   3530       NamedPropertySetterCallback setter = 0,
   3531       NamedPropertyQueryCallback query = 0,
   3532       NamedPropertyDeleterCallback deleter = 0,
   3533       NamedPropertyEnumeratorCallback enumerator = 0,
   3534       Handle<Value> data = Handle<Value>());
   3535 
   3536   /**
   3537    * Sets an indexed property handler on the object template.
   3538    *
   3539    * Whenever an indexed property is accessed on objects created from
   3540    * this object template, the provided callback is invoked instead of
   3541    * accessing the property directly on the JavaScript object.
   3542    *
   3543    * \param getter The callback to invoke when getting a property.
   3544    * \param setter The callback to invoke when setting a property.
   3545    * \param query The callback to invoke to check if an object has a property.
   3546    * \param deleter The callback to invoke when deleting a property.
   3547    * \param enumerator The callback to invoke to enumerate all the indexed
   3548    *   properties of an object.
   3549    * \param data A piece of data that will be passed to the callbacks
   3550    *   whenever they are invoked.
   3551    */
   3552   V8_DEPRECATED(void SetIndexedPropertyHandler(
   3553       IndexedPropertyGetter getter,
   3554       IndexedPropertySetter setter = 0,
   3555       IndexedPropertyQuery query = 0,
   3556       IndexedPropertyDeleter deleter = 0,
   3557       IndexedPropertyEnumerator enumerator = 0,
   3558       Handle<Value> data = Handle<Value>()));
   3559   void SetIndexedPropertyHandler(
   3560       IndexedPropertyGetterCallback getter,
   3561       IndexedPropertySetterCallback setter = 0,
   3562       IndexedPropertyQueryCallback query = 0,
   3563       IndexedPropertyDeleterCallback deleter = 0,
   3564       IndexedPropertyEnumeratorCallback enumerator = 0,
   3565       Handle<Value> data = Handle<Value>());
   3566 
   3567   /**
   3568    * Sets the callback to be used when calling instances created from
   3569    * this template as a function.  If no callback is set, instances
   3570    * behave like normal JavaScript objects that cannot be called as a
   3571    * function.
   3572    */
   3573   V8_DEPRECATED(void SetCallAsFunctionHandler(
   3574       InvocationCallback callback,
   3575       Handle<Value> data = Handle<Value>()));
   3576   void SetCallAsFunctionHandler(FunctionCallback callback,
   3577                                 Handle<Value> data = Handle<Value>());
   3578 
   3579   /**
   3580    * Mark object instances of the template as undetectable.
   3581    *
   3582    * In many ways, undetectable objects behave as though they are not
   3583    * there.  They behave like 'undefined' in conditionals and when
   3584    * printed.  However, properties can be accessed and called as on
   3585    * normal objects.
   3586    */
   3587   void MarkAsUndetectable();
   3588 
   3589   /**
   3590    * Sets access check callbacks on the object template.
   3591    *
   3592    * When accessing properties on instances of this object template,
   3593    * the access check callback will be called to determine whether or
   3594    * not to allow cross-context access to the properties.
   3595    * The last parameter specifies whether access checks are turned
   3596    * on by default on instances. If access checks are off by default,
   3597    * they can be turned on on individual instances by calling
   3598    * Object::TurnOnAccessCheck().
   3599    */
   3600   void SetAccessCheckCallbacks(NamedSecurityCallback named_handler,
   3601                                IndexedSecurityCallback indexed_handler,
   3602                                Handle<Value> data = Handle<Value>(),
   3603                                bool turned_on_by_default = true);
   3604 
   3605   /**
   3606    * Gets the number of internal fields for objects generated from
   3607    * this template.
   3608    */
   3609   int InternalFieldCount();
   3610 
   3611   /**
   3612    * Sets the number of internal fields for objects generated from
   3613    * this template.
   3614    */
   3615   void SetInternalFieldCount(int value);
   3616 
   3617  private:
   3618   ObjectTemplate();
   3619   static Local<ObjectTemplate> New(Handle<FunctionTemplate> constructor);
   3620   friend class FunctionTemplate;
   3621 };
   3622 
   3623 
   3624 /**
   3625  * A Signature specifies which receivers and arguments are valid
   3626  * parameters to a function.
   3627  */
   3628 class V8_EXPORT Signature : public Data {
   3629  public:
   3630   static Local<Signature> New(Handle<FunctionTemplate> receiver =
   3631                                   Handle<FunctionTemplate>(),
   3632                               int argc = 0,
   3633                               Handle<FunctionTemplate> argv[] = 0);
   3634  private:
   3635   Signature();
   3636 };
   3637 
   3638 
   3639 /**
   3640  * An AccessorSignature specifies which receivers are valid parameters
   3641  * to an accessor callback.
   3642  */
   3643 class V8_EXPORT AccessorSignature : public Data {
   3644  public:
   3645   static Local<AccessorSignature> New(Handle<FunctionTemplate> receiver =
   3646                                           Handle<FunctionTemplate>());
   3647  private:
   3648   AccessorSignature();
   3649 };
   3650 
   3651 
   3652 class V8_EXPORT DeclaredAccessorDescriptor : public Data {
   3653  private:
   3654   DeclaredAccessorDescriptor();
   3655 };
   3656 
   3657 
   3658 class V8_EXPORT ObjectOperationDescriptor : public Data {
   3659  public:
   3660   // This function is not yet stable and should not be used at this time.
   3661   static Local<RawOperationDescriptor> NewInternalFieldDereference(
   3662       Isolate* isolate,
   3663       int internal_field);
   3664  private:
   3665   ObjectOperationDescriptor();
   3666 };
   3667 
   3668 
   3669 enum DeclaredAccessorDescriptorDataType {
   3670     kDescriptorBoolType,
   3671     kDescriptorInt8Type, kDescriptorUint8Type,
   3672     kDescriptorInt16Type, kDescriptorUint16Type,
   3673     kDescriptorInt32Type, kDescriptorUint32Type,
   3674     kDescriptorFloatType, kDescriptorDoubleType
   3675 };
   3676 
   3677 
   3678 class V8_EXPORT RawOperationDescriptor : public Data {
   3679  public:
   3680   Local<DeclaredAccessorDescriptor> NewHandleDereference(Isolate* isolate);
   3681   Local<RawOperationDescriptor> NewRawDereference(Isolate* isolate);
   3682   Local<RawOperationDescriptor> NewRawShift(Isolate* isolate,
   3683                                             int16_t byte_offset);
   3684   Local<DeclaredAccessorDescriptor> NewPointerCompare(Isolate* isolate,
   3685                                                       void* compare_value);
   3686   Local<DeclaredAccessorDescriptor> NewPrimitiveValue(
   3687       Isolate* isolate,
   3688       DeclaredAccessorDescriptorDataType data_type,
   3689       uint8_t bool_offset = 0);
   3690   Local<DeclaredAccessorDescriptor> NewBitmaskCompare8(Isolate* isolate,
   3691                                                        uint8_t bitmask,
   3692                                                        uint8_t compare_value);
   3693   Local<DeclaredAccessorDescriptor> NewBitmaskCompare16(
   3694       Isolate* isolate,
   3695       uint16_t bitmask,
   3696       uint16_t compare_value);
   3697   Local<DeclaredAccessorDescriptor> NewBitmaskCompare32(
   3698       Isolate* isolate,
   3699       uint32_t bitmask,
   3700       uint32_t compare_value);
   3701 
   3702  private:
   3703   RawOperationDescriptor();
   3704 };
   3705 
   3706 
   3707 /**
   3708  * A utility for determining the type of objects based on the template
   3709  * they were constructed from.
   3710  */
   3711 class V8_EXPORT TypeSwitch : public Data {
   3712  public:
   3713   static Local<TypeSwitch> New(Handle<FunctionTemplate> type);
   3714   static Local<TypeSwitch> New(int argc, Handle<FunctionTemplate> types[]);
   3715   int match(Handle<Value> value);
   3716  private:
   3717   TypeSwitch();
   3718 };
   3719 
   3720 
   3721 // --- Extensions ---
   3722 
   3723 class V8_EXPORT ExternalAsciiStringResourceImpl
   3724     : public String::ExternalAsciiStringResource {
   3725  public:
   3726   ExternalAsciiStringResourceImpl() : data_(0), length_(0) {}
   3727   ExternalAsciiStringResourceImpl(const char* data, size_t length)
   3728       : data_(data), length_(length) {}
   3729   const char* data() const { return data_; }
   3730   size_t length() const { return length_; }
   3731 
   3732  private:
   3733   const char* data_;
   3734   size_t length_;
   3735 };
   3736 
   3737 /**
   3738  * Ignore
   3739  */
   3740 class V8_EXPORT Extension {  // NOLINT
   3741  public:
   3742   // Note that the strings passed into this constructor must live as long
   3743   // as the Extension itself.
   3744   Extension(const char* name,
   3745             const char* source = 0,
   3746             int dep_count = 0,
   3747             const char** deps = 0,
   3748             int source_length = -1);
   3749   virtual ~Extension() { }
   3750   virtual v8::Handle<v8::FunctionTemplate>
   3751       GetNativeFunction(v8::Handle<v8::String> name) {
   3752     return v8::Handle<v8::FunctionTemplate>();
   3753   }
   3754 
   3755   const char* name() const { return name_; }
   3756   size_t source_length() const { return source_length_; }
   3757   const String::ExternalAsciiStringResource* source() const {
   3758     return &source_; }
   3759   int dependency_count() { return dep_count_; }
   3760   const char** dependencies() { return deps_; }
   3761   void set_auto_enable(bool value) { auto_enable_ = value; }
   3762   bool auto_enable() { return auto_enable_; }
   3763 
   3764  private:
   3765   const char* name_;
   3766   size_t source_length_;  // expected to initialize before source_
   3767   ExternalAsciiStringResourceImpl source_;
   3768   int dep_count_;
   3769   const char** deps_;
   3770   bool auto_enable_;
   3771 
   3772   // Disallow copying and assigning.
   3773   Extension(const Extension&);
   3774   void operator=(const Extension&);
   3775 };
   3776 
   3777 
   3778 void V8_EXPORT RegisterExtension(Extension* extension);
   3779 
   3780 
   3781 /**
   3782  * Ignore
   3783  */
   3784 class V8_EXPORT DeclareExtension {
   3785  public:
   3786   V8_INLINE(DeclareExtension(Extension* extension)) {
   3787     RegisterExtension(extension);
   3788   }
   3789 };
   3790 
   3791 
   3792 // --- Statics ---
   3793 
   3794 
   3795 Handle<Primitive> V8_EXPORT Undefined();
   3796 Handle<Primitive> V8_EXPORT Null();
   3797 Handle<Boolean> V8_EXPORT True();
   3798 Handle<Boolean> V8_EXPORT False();
   3799 
   3800 V8_INLINE(Handle<Primitive> Undefined(Isolate* isolate));
   3801 V8_INLINE(Handle<Primitive> Null(Isolate* isolate));
   3802 V8_INLINE(Handle<Boolean> True(Isolate* isolate));
   3803 V8_INLINE(Handle<Boolean> False(Isolate* isolate));
   3804 
   3805 
   3806 /**
   3807  * A set of constraints that specifies the limits of the runtime's memory use.
   3808  * You must set the heap size before initializing the VM - the size cannot be
   3809  * adjusted after the VM is initialized.
   3810  *
   3811  * If you are using threads then you should hold the V8::Locker lock while
   3812  * setting the stack limit and you must set a non-default stack limit separately
   3813  * for each thread.
   3814  */
   3815 class V8_EXPORT ResourceConstraints {
   3816  public:
   3817   ResourceConstraints();
   3818   int max_young_space_size() const { return max_young_space_size_; }
   3819   void set_max_young_space_size(int value) { max_young_space_size_ = value; }
   3820   int max_old_space_size() const { return max_old_space_size_; }
   3821   void set_max_old_space_size(int value) { max_old_space_size_ = value; }
   3822   int max_executable_size() { return max_executable_size_; }
   3823   void set_max_executable_size(int value) { max_executable_size_ = value; }
   3824   uint32_t* stack_limit() const { return stack_limit_; }
   3825   // Sets an address beyond which the VM's stack may not grow.
   3826   void set_stack_limit(uint32_t* value) { stack_limit_ = value; }
   3827  private:
   3828   int max_young_space_size_;
   3829   int max_old_space_size_;
   3830   int max_executable_size_;
   3831   uint32_t* stack_limit_;
   3832 };
   3833 
   3834 
   3835 bool V8_EXPORT SetResourceConstraints(ResourceConstraints* constraints);
   3836 
   3837 
   3838 // --- Exceptions ---
   3839 
   3840 
   3841 typedef void (*FatalErrorCallback)(const char* location, const char* message);
   3842 
   3843 
   3844 typedef void (*MessageCallback)(Handle<Message> message, Handle<Value> error);
   3845 
   3846 
   3847 /**
   3848  * Schedules an exception to be thrown when returning to JavaScript.  When an
   3849  * exception has been scheduled it is illegal to invoke any JavaScript
   3850  * operation; the caller must return immediately and only after the exception
   3851  * has been handled does it become legal to invoke JavaScript operations.
   3852  */
   3853 Handle<Value> V8_EXPORT ThrowException(Handle<Value> exception);
   3854 
   3855 /**
   3856  * Create new error objects by calling the corresponding error object
   3857  * constructor with the message.
   3858  */
   3859 class V8_EXPORT Exception {
   3860  public:
   3861   static Local<Value> RangeError(Handle<String> message);
   3862   static Local<Value> ReferenceError(Handle<String> message);
   3863   static Local<Value> SyntaxError(Handle<String> message);
   3864   static Local<Value> TypeError(Handle<String> message);
   3865   static Local<Value> Error(Handle<String> message);
   3866 };
   3867 
   3868 
   3869 // --- Counters Callbacks ---
   3870 
   3871 typedef int* (*CounterLookupCallback)(const char* name);
   3872 
   3873 typedef void* (*CreateHistogramCallback)(const char* name,
   3874                                          int min,
   3875                                          int max,
   3876                                          size_t buckets);
   3877 
   3878 typedef void (*AddHistogramSampleCallback)(void* histogram, int sample);
   3879 
   3880 // --- Memory Allocation Callback ---
   3881   enum ObjectSpace {
   3882     kObjectSpaceNewSpace = 1 << 0,
   3883     kObjectSpaceOldPointerSpace = 1 << 1,
   3884     kObjectSpaceOldDataSpace = 1 << 2,
   3885     kObjectSpaceCodeSpace = 1 << 3,
   3886     kObjectSpaceMapSpace = 1 << 4,
   3887     kObjectSpaceLoSpace = 1 << 5,
   3888 
   3889     kObjectSpaceAll = kObjectSpaceNewSpace | kObjectSpaceOldPointerSpace |
   3890       kObjectSpaceOldDataSpace | kObjectSpaceCodeSpace | kObjectSpaceMapSpace |
   3891       kObjectSpaceLoSpace
   3892   };
   3893 
   3894   enum AllocationAction {
   3895     kAllocationActionAllocate = 1 << 0,
   3896     kAllocationActionFree = 1 << 1,
   3897     kAllocationActionAll = kAllocationActionAllocate | kAllocationActionFree
   3898   };
   3899 
   3900 typedef void (*MemoryAllocationCallback)(ObjectSpace space,
   3901                                          AllocationAction action,
   3902                                          int size);
   3903 
   3904 // --- Leave Script Callback ---
   3905 typedef void (*CallCompletedCallback)();
   3906 
   3907 // --- Failed Access Check Callback ---
   3908 typedef void (*FailedAccessCheckCallback)(Local<Object> target,
   3909                                           AccessType type,
   3910                                           Local<Value> data);
   3911 
   3912 // --- AllowCodeGenerationFromStrings callbacks ---
   3913 
   3914 /**
   3915  * Callback to check if code generation from strings is allowed. See
   3916  * Context::AllowCodeGenerationFromStrings.
   3917  */
   3918 typedef bool (*AllowCodeGenerationFromStringsCallback)(Local<Context> context);
   3919 
   3920 // --- Garbage Collection Callbacks ---
   3921 
   3922 /**
   3923  * Applications can register callback functions which will be called
   3924  * before and after a garbage collection.  Allocations are not
   3925  * allowed in the callback functions, you therefore cannot manipulate
   3926  * objects (set or delete properties for example) since it is possible
   3927  * such operations will result in the allocation of objects.
   3928  */
   3929 enum GCType {
   3930   kGCTypeScavenge = 1 << 0,
   3931   kGCTypeMarkSweepCompact = 1 << 1,
   3932   kGCTypeAll = kGCTypeScavenge | kGCTypeMarkSweepCompact
   3933 };
   3934 
   3935 enum GCCallbackFlags {
   3936   kNoGCCallbackFlags = 0,
   3937   kGCCallbackFlagCompacted = 1 << 0,
   3938   kGCCallbackFlagConstructRetainedObjectInfos = 1 << 1
   3939 };
   3940 
   3941 typedef void (*GCPrologueCallback)(GCType type, GCCallbackFlags flags);
   3942 typedef void (*GCEpilogueCallback)(GCType type, GCCallbackFlags flags);
   3943 
   3944 typedef void (*GCCallback)();
   3945 
   3946 
   3947 /**
   3948  * Collection of V8 heap information.
   3949  *
   3950  * Instances of this class can be passed to v8::V8::HeapStatistics to
   3951  * get heap statistics from V8.
   3952  */
   3953 class V8_EXPORT HeapStatistics {
   3954  public:
   3955   HeapStatistics();
   3956   size_t total_heap_size() { return total_heap_size_; }
   3957   size_t total_heap_size_executable() { return total_heap_size_executable_; }
   3958   size_t total_physical_size() { return total_physical_size_; }
   3959   size_t used_heap_size() { return used_heap_size_; }
   3960   size_t heap_size_limit() { return heap_size_limit_; }
   3961 
   3962  private:
   3963   size_t total_heap_size_;
   3964   size_t total_heap_size_executable_;
   3965   size_t total_physical_size_;
   3966   size_t used_heap_size_;
   3967   size_t heap_size_limit_;
   3968 
   3969   friend class V8;
   3970   friend class Isolate;
   3971 };
   3972 
   3973 
   3974 class RetainedObjectInfo;
   3975 
   3976 /**
   3977  * Isolate represents an isolated instance of the V8 engine.  V8
   3978  * isolates have completely separate states.  Objects from one isolate
   3979  * must not be used in other isolates.  When V8 is initialized a
   3980  * default isolate is implicitly created and entered.  The embedder
   3981  * can create additional isolates and use them in parallel in multiple
   3982  * threads.  An isolate can be entered by at most one thread at any
   3983  * given time.  The Locker/Unlocker API must be used to synchronize.
   3984  */
   3985 class V8_EXPORT Isolate {
   3986  public:
   3987   /**
   3988    * Stack-allocated class which sets the isolate for all operations
   3989    * executed within a local scope.
   3990    */
   3991   class V8_EXPORT Scope {
   3992    public:
   3993     explicit Scope(Isolate* isolate) : isolate_(isolate) {
   3994       isolate->Enter();
   3995     }
   3996 
   3997     ~Scope() { isolate_->Exit(); }
   3998 
   3999    private:
   4000     Isolate* const isolate_;
   4001 
   4002     // Prevent copying of Scope objects.
   4003     Scope(const Scope&);
   4004     Scope& operator=(const Scope&);
   4005   };
   4006 
   4007   /**
   4008    * Creates a new isolate.  Does not change the currently entered
   4009    * isolate.
   4010    *
   4011    * When an isolate is no longer used its resources should be freed
   4012    * by calling Dispose().  Using the delete operator is not allowed.
   4013    */
   4014   static Isolate* New();
   4015 
   4016   /**
   4017    * Returns the entered isolate for the current thread or NULL in
   4018    * case there is no current isolate.
   4019    */
   4020   static Isolate* GetCurrent();
   4021 
   4022   /**
   4023    * Methods below this point require holding a lock (using Locker) in
   4024    * a multi-threaded environment.
   4025    */
   4026 
   4027   /**
   4028    * Sets this isolate as the entered one for the current thread.
   4029    * Saves the previously entered one (if any), so that it can be
   4030    * restored when exiting.  Re-entering an isolate is allowed.
   4031    */
   4032   void Enter();
   4033 
   4034   /**
   4035    * Exits this isolate by restoring the previously entered one in the
   4036    * current thread.  The isolate may still stay the same, if it was
   4037    * entered more than once.
   4038    *
   4039    * Requires: this == Isolate::GetCurrent().
   4040    */
   4041   void Exit();
   4042 
   4043   /**
   4044    * Disposes the isolate.  The isolate must not be entered by any
   4045    * thread to be disposable.
   4046    */
   4047   void Dispose();
   4048 
   4049   /**
   4050    * Associate embedder-specific data with the isolate
   4051    */
   4052   V8_INLINE(void SetData(void* data));
   4053 
   4054   /**
   4055    * Retrieve embedder-specific data from the isolate.
   4056    * Returns NULL if SetData has never been called.
   4057    */
   4058   V8_INLINE(void* GetData());
   4059 
   4060   /**
   4061    * Get statistics about the heap memory usage.
   4062    */
   4063   void GetHeapStatistics(HeapStatistics* heap_statistics);
   4064 
   4065   /**
   4066    * Adjusts the amount of registered external memory. Used to give V8 an
   4067    * indication of the amount of externally allocated memory that is kept alive
   4068    * by JavaScript objects. V8 uses this to decide when to perform global
   4069    * garbage collections. Registering externally allocated memory will trigger
   4070    * global garbage collections more often than it would otherwise in an attempt
   4071    * to garbage collect the JavaScript objects that keep the externally
   4072    * allocated memory alive.
   4073    *
   4074    * \param change_in_bytes the change in externally allocated memory that is
   4075    *   kept alive by JavaScript objects.
   4076    * \returns the adjusted value.
   4077    */
   4078   intptr_t AdjustAmountOfExternalAllocatedMemory(intptr_t change_in_bytes);
   4079 
   4080   /**
   4081    * Returns heap profiler for this isolate. Will return NULL until the isolate
   4082    * is initialized.
   4083    */
   4084   HeapProfiler* GetHeapProfiler();
   4085 
   4086   /**
   4087    * Returns CPU profiler for this isolate. Will return NULL unless the isolate
   4088    * is initialized. It is the embedder's responsibility to stop all CPU
   4089    * profiling activities if it has started any.
   4090    */
   4091   CpuProfiler* GetCpuProfiler();
   4092 
   4093   /** Returns the context that is on the top of the stack. */
   4094   Local<Context> GetCurrentContext();
   4095 
   4096   /**
   4097    * Allows the host application to group objects together. If one
   4098    * object in the group is alive, all objects in the group are alive.
   4099    * After each garbage collection, object groups are removed. It is
   4100    * intended to be used in the before-garbage-collection callback
   4101    * function, for instance to simulate DOM tree connections among JS
   4102    * wrapper objects. Object groups for all dependent handles need to
   4103    * be provided for kGCTypeMarkSweepCompact collections, for all other
   4104    * garbage collection types it is sufficient to provide object groups
   4105    * for partially dependent handles only.
   4106    */
   4107   void SetObjectGroupId(const Persistent<Value>& object,
   4108                         UniqueId id);
   4109 
   4110   /**
   4111    * Allows the host application to declare implicit references from an object
   4112    * group to an object. If the objects of the object group are alive, the child
   4113    * object is alive too. After each garbage collection, all implicit references
   4114    * are removed. It is intended to be used in the before-garbage-collection
   4115    * callback function.
   4116    */
   4117   void SetReferenceFromGroup(UniqueId id,
   4118                              const Persistent<Value>& child);
   4119 
   4120   /**
   4121    * Allows the host application to declare implicit references from an object
   4122    * to another object. If the parent object is alive, the child object is alive
   4123    * too. After each garbage collection, all implicit references are removed. It
   4124    * is intended to be used in the before-garbage-collection callback function.
   4125    */
   4126   void SetReference(const Persistent<Object>& parent,
   4127                     const Persistent<Value>& child);
   4128 
   4129  private:
   4130   Isolate();
   4131   Isolate(const Isolate&);
   4132   ~Isolate();
   4133   Isolate& operator=(const Isolate&);
   4134   void* operator new(size_t size);
   4135   void operator delete(void*, size_t);
   4136 };
   4137 
   4138 
   4139 class V8_EXPORT StartupData {
   4140  public:
   4141   enum CompressionAlgorithm {
   4142     kUncompressed,
   4143     kBZip2
   4144   };
   4145 
   4146   const char* data;
   4147   int compressed_size;
   4148   int raw_size;
   4149 };
   4150 
   4151 
   4152 /**
   4153  * A helper class for driving V8 startup data decompression.  It is based on
   4154  * "CompressedStartupData" API functions from the V8 class.  It isn't mandatory
   4155  * for an embedder to use this class, instead, API functions can be used
   4156  * directly.
   4157  *
   4158  * For an example of the class usage, see the "shell.cc" sample application.
   4159  */
   4160 class V8_EXPORT StartupDataDecompressor {  // NOLINT
   4161  public:
   4162   StartupDataDecompressor();
   4163   virtual ~StartupDataDecompressor();
   4164   int Decompress();
   4165 
   4166  protected:
   4167   virtual int DecompressData(char* raw_data,
   4168                              int* raw_data_size,
   4169                              const char* compressed_data,
   4170                              int compressed_data_size) = 0;
   4171 
   4172  private:
   4173   char** raw_data;
   4174 };
   4175 
   4176 
   4177 /**
   4178  * EntropySource is used as a callback function when v8 needs a source
   4179  * of entropy.
   4180  */
   4181 typedef bool (*EntropySource)(unsigned char* buffer, size_t length);
   4182 
   4183 
   4184 /**
   4185  * ReturnAddressLocationResolver is used as a callback function when v8 is
   4186  * resolving the location of a return address on the stack. Profilers that
   4187  * change the return address on the stack can use this to resolve the stack
   4188  * location to whereever the profiler stashed the original return address.
   4189  *
   4190  * \param return_addr_location points to a location on stack where a machine
   4191  *    return address resides.
   4192  * \returns either return_addr_location, or else a pointer to the profiler's
   4193  *    copy of the original return address.
   4194  *
   4195  * \note the resolver function must not cause garbage collection.
   4196  */
   4197 typedef uintptr_t (*ReturnAddressLocationResolver)(
   4198     uintptr_t return_addr_location);
   4199 
   4200 
   4201 /**
   4202  * FunctionEntryHook is the type of the profile entry hook called at entry to
   4203  * any generated function when function-level profiling is enabled.
   4204  *
   4205  * \param function the address of the function that's being entered.
   4206  * \param return_addr_location points to a location on stack where the machine
   4207  *    return address resides. This can be used to identify the caller of
   4208  *    \p function, and/or modified to divert execution when \p function exits.
   4209  *
   4210  * \note the entry hook must not cause garbage collection.
   4211  */
   4212 typedef void (*FunctionEntryHook)(uintptr_t function,
   4213                                   uintptr_t return_addr_location);
   4214 
   4215 
   4216 /**
   4217  * A JIT code event is issued each time code is added, moved or removed.
   4218  *
   4219  * \note removal events are not currently issued.
   4220  */
   4221 struct JitCodeEvent {
   4222   enum EventType {
   4223     CODE_ADDED,
   4224     CODE_MOVED,
   4225     CODE_REMOVED,
   4226     CODE_ADD_LINE_POS_INFO,
   4227     CODE_START_LINE_INFO_RECORDING,
   4228     CODE_END_LINE_INFO_RECORDING
   4229   };
   4230   // Definition of the code position type. The "POSITION" type means the place
   4231   // in the source code which are of interest when making stack traces to
   4232   // pin-point the source location of a stack frame as close as possible.
   4233   // The "STATEMENT_POSITION" means the place at the beginning of each
   4234   // statement, and is used to indicate possible break locations.
   4235   enum PositionType {
   4236     POSITION,
   4237     STATEMENT_POSITION
   4238   };
   4239 
   4240   // Type of event.
   4241   EventType type;
   4242   // Start of the instructions.
   4243   void* code_start;
   4244   // Size of the instructions.
   4245   size_t code_len;
   4246   // Script info for CODE_ADDED event.
   4247   Handle<Script> script;
   4248   // User-defined data for *_LINE_INFO_* event. It's used to hold the source
   4249   // code line information which is returned from the
   4250   // CODE_START_LINE_INFO_RECORDING event. And it's passed to subsequent
   4251   // CODE_ADD_LINE_POS_INFO and CODE_END_LINE_INFO_RECORDING events.
   4252   void* user_data;
   4253 
   4254   struct name_t {
   4255     // Name of the object associated with the code, note that the string is not
   4256     // zero-terminated.
   4257     const char* str;
   4258     // Number of chars in str.
   4259     size_t len;
   4260   };
   4261 
   4262   struct line_info_t {
   4263     // PC offset
   4264     size_t offset;
   4265     // Code postion
   4266     size_t pos;
   4267     // The position type.
   4268     PositionType position_type;
   4269   };
   4270 
   4271   union {
   4272     // Only valid for CODE_ADDED.
   4273     struct name_t name;
   4274 
   4275     // Only valid for CODE_ADD_LINE_POS_INFO
   4276     struct line_info_t line_info;
   4277 
   4278     // New location of instructions. Only valid for CODE_MOVED.
   4279     void* new_code_start;
   4280   };
   4281 };
   4282 
   4283 /**
   4284  * Option flags passed to the SetJitCodeEventHandler function.
   4285  */
   4286 enum JitCodeEventOptions {
   4287   kJitCodeEventDefault = 0,
   4288   // Generate callbacks for already existent code.
   4289   kJitCodeEventEnumExisting = 1
   4290 };
   4291 
   4292 
   4293 /**
   4294  * Callback function passed to SetJitCodeEventHandler.
   4295  *
   4296  * \param event code add, move or removal event.
   4297  */
   4298 typedef void (*JitCodeEventHandler)(const JitCodeEvent* event);
   4299 
   4300 
   4301 /**
   4302  * Interface for iterating through all external resources in the heap.
   4303  */
   4304 class V8_EXPORT ExternalResourceVisitor {  // NOLINT
   4305  public:
   4306   virtual ~ExternalResourceVisitor() {}
   4307   virtual void VisitExternalString(Handle<String> string) {}
   4308 };
   4309 
   4310 
   4311 /**
   4312  * Interface for iterating through all the persistent handles in the heap.
   4313  */
   4314 class V8_EXPORT PersistentHandleVisitor {  // NOLINT
   4315  public:
   4316   virtual ~PersistentHandleVisitor() {}
   4317   virtual void VisitPersistentHandle(Persistent<Value>* value,
   4318                                      uint16_t class_id) {}
   4319 };
   4320 
   4321 
   4322 /**
   4323  * Asserts that no action is performed that could cause a handle's value
   4324  * to be modified. Useful when otherwise unsafe handle operations need to
   4325  * be performed.
   4326  */
   4327 class V8_EXPORT AssertNoGCScope {
   4328 #ifndef DEBUG
   4329   // TODO(yangguo): remove isolate argument.
   4330   V8_INLINE(AssertNoGCScope(Isolate* isolate)) { }
   4331 #else
   4332   AssertNoGCScope(Isolate* isolate);
   4333   ~AssertNoGCScope();
   4334  private:
   4335   void* disallow_heap_allocation_;
   4336 #endif
   4337 };
   4338 
   4339 
   4340 /**
   4341  * Container class for static utility functions.
   4342  */
   4343 class V8_EXPORT V8 {
   4344  public:
   4345   /** Set the callback to invoke in case of fatal errors. */
   4346   static void SetFatalErrorHandler(FatalErrorCallback that);
   4347 
   4348   /**
   4349    * Set the callback to invoke to check if code generation from
   4350    * strings should be allowed.
   4351    */
   4352   static void SetAllowCodeGenerationFromStringsCallback(
   4353       AllowCodeGenerationFromStringsCallback that);
   4354 
   4355   /**
   4356    * Set allocator to use for ArrayBuffer memory.
   4357    * The allocator should be set only once. The allocator should be set
   4358    * before any code tha uses ArrayBuffers is executed.
   4359    * This allocator is used in all isolates.
   4360    */
   4361   static void SetArrayBufferAllocator(ArrayBuffer::Allocator* allocator);
   4362 
   4363   /**
   4364    * Ignore out-of-memory exceptions.
   4365    *
   4366    * V8 running out of memory is treated as a fatal error by default.
   4367    * This means that the fatal error handler is called and that V8 is
   4368    * terminated.
   4369    *
   4370    * IgnoreOutOfMemoryException can be used to not treat an
   4371    * out-of-memory situation as a fatal error.  This way, the contexts
   4372    * that did not cause the out of memory problem might be able to
   4373    * continue execution.
   4374    */
   4375   static void IgnoreOutOfMemoryException();
   4376 
   4377   /**
   4378    * Check if V8 is dead and therefore unusable.  This is the case after
   4379    * fatal errors such as out-of-memory situations.
   4380    */
   4381   static bool IsDead();
   4382 
   4383   /**
   4384    * The following 4 functions are to be used when V8 is built with
   4385    * the 'compress_startup_data' flag enabled. In this case, the
   4386    * embedder must decompress startup data prior to initializing V8.
   4387    *
   4388    * This is how interaction with V8 should look like:
   4389    *   int compressed_data_count = v8::V8::GetCompressedStartupDataCount();
   4390    *   v8::StartupData* compressed_data =
   4391    *     new v8::StartupData[compressed_data_count];
   4392    *   v8::V8::GetCompressedStartupData(compressed_data);
   4393    *   ... decompress data (compressed_data can be updated in-place) ...
   4394    *   v8::V8::SetDecompressedStartupData(compressed_data);
   4395    *   ... now V8 can be initialized
   4396    *   ... make sure the decompressed data stays valid until V8 shutdown
   4397    *
   4398    * A helper class StartupDataDecompressor is provided. It implements
   4399    * the protocol of the interaction described above, and can be used in
   4400    * most cases instead of calling these API functions directly.
   4401    */
   4402   static StartupData::CompressionAlgorithm GetCompressedStartupDataAlgorithm();
   4403   static int GetCompressedStartupDataCount();
   4404   static void GetCompressedStartupData(StartupData* compressed_data);
   4405   static void SetDecompressedStartupData(StartupData* decompressed_data);
   4406 
   4407   /**
   4408    * Adds a message listener.
   4409    *
   4410    * The same message listener can be added more than once and in that
   4411    * case it will be called more than once for each message.
   4412    *
   4413    * If data is specified, it will be passed to the callback when it is called.
   4414    * Otherwise, the exception object will be passed to the callback instead.
   4415    */
   4416   static bool AddMessageListener(MessageCallback that,
   4417                                  Handle<Value> data = Handle<Value>());
   4418 
   4419   /**
   4420    * Remove all message listeners from the specified callback function.
   4421    */
   4422   static void RemoveMessageListeners(MessageCallback that);
   4423 
   4424   /**
   4425    * Tells V8 to capture current stack trace when uncaught exception occurs
   4426    * and report it to the message listeners. The option is off by default.
   4427    */
   4428   static void SetCaptureStackTraceForUncaughtExceptions(
   4429       bool capture,
   4430       int frame_limit = 10,
   4431       StackTrace::StackTraceOptions options = StackTrace::kOverview);
   4432 
   4433   /**
   4434    * Sets V8 flags from a string.
   4435    */
   4436   static void SetFlagsFromString(const char* str, int length);
   4437 
   4438   /**
   4439    * Sets V8 flags from the command line.
   4440    */
   4441   static void SetFlagsFromCommandLine(int* argc,
   4442                                       char** argv,
   4443                                       bool remove_flags);
   4444 
   4445   /** Get the version string. */
   4446   static const char* GetVersion();
   4447 
   4448   /**
   4449    * Enables the host application to provide a mechanism for recording
   4450    * statistics counters.
   4451    */
   4452   static void SetCounterFunction(CounterLookupCallback);
   4453 
   4454   /**
   4455    * Enables the host application to provide a mechanism for recording
   4456    * histograms. The CreateHistogram function returns a
   4457    * histogram which will later be passed to the AddHistogramSample
   4458    * function.
   4459    */
   4460   static void SetCreateHistogramFunction(CreateHistogramCallback);
   4461   static void SetAddHistogramSampleFunction(AddHistogramSampleCallback);
   4462 
   4463   /** Callback function for reporting failed access checks.*/
   4464   static void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback);
   4465 
   4466   /**
   4467    * Enables the host application to receive a notification before a
   4468    * garbage collection.  Allocations are not allowed in the
   4469    * callback function, you therefore cannot manipulate objects (set
   4470    * or delete properties for example) since it is possible such
   4471    * operations will result in the allocation of objects. It is possible
   4472    * to specify the GCType filter for your callback. But it is not possible to
   4473    * register the same callback function two times with different
   4474    * GCType filters.
   4475    */
   4476   static void AddGCPrologueCallback(
   4477       GCPrologueCallback callback, GCType gc_type_filter = kGCTypeAll);
   4478 
   4479   /**
   4480    * This function removes callback which was installed by
   4481    * AddGCPrologueCallback function.
   4482    */
   4483   static void RemoveGCPrologueCallback(GCPrologueCallback callback);
   4484 
   4485   /**
   4486    * The function is deprecated. Please use AddGCPrologueCallback instead.
   4487    * Enables the host application to receive a notification before a
   4488    * garbage collection.  Allocations are not allowed in the
   4489    * callback function, you therefore cannot manipulate objects (set
   4490    * or delete properties for example) since it is possible such
   4491    * operations will result in the allocation of objects.
   4492    */
   4493   V8_DEPRECATED(static void SetGlobalGCPrologueCallback(GCCallback));
   4494 
   4495   /**
   4496    * Enables the host application to receive a notification after a
   4497    * garbage collection.  Allocations are not allowed in the
   4498    * callback function, you therefore cannot manipulate objects (set
   4499    * or delete properties for example) since it is possible such
   4500    * operations will result in the allocation of objects. It is possible
   4501    * to specify the GCType filter for your callback. But it is not possible to
   4502    * register the same callback function two times with different
   4503    * GCType filters.
   4504    */
   4505   static void AddGCEpilogueCallback(
   4506       GCEpilogueCallback callback, GCType gc_type_filter = kGCTypeAll);
   4507 
   4508   /**
   4509    * This function removes callback which was installed by
   4510    * AddGCEpilogueCallback function.
   4511    */
   4512   static void RemoveGCEpilogueCallback(GCEpilogueCallback callback);
   4513 
   4514   /**
   4515    * The function is deprecated. Please use AddGCEpilogueCallback instead.
   4516    * Enables the host application to receive a notification after a
   4517    * major garbage collection.  Allocations are not allowed in the
   4518    * callback function, you therefore cannot manipulate objects (set
   4519    * or delete properties for example) since it is possible such
   4520    * operations will result in the allocation of objects.
   4521    */
   4522   V8_DEPRECATED(static void SetGlobalGCEpilogueCallback(GCCallback));
   4523 
   4524   /**
   4525    * Enables the host application to provide a mechanism to be notified
   4526    * and perform custom logging when V8 Allocates Executable Memory.
   4527    */
   4528   static void AddMemoryAllocationCallback(MemoryAllocationCallback callback,
   4529                                           ObjectSpace space,
   4530                                           AllocationAction action);
   4531 
   4532   /**
   4533    * Removes callback that was installed by AddMemoryAllocationCallback.
   4534    */
   4535   static void RemoveMemoryAllocationCallback(MemoryAllocationCallback callback);
   4536 
   4537   /**
   4538    * Adds a callback to notify the host application when a script finished
   4539    * running.  If a script re-enters the runtime during executing, the
   4540    * CallCompletedCallback is only invoked when the outer-most script
   4541    * execution ends.  Executing scripts inside the callback do not trigger
   4542    * further callbacks.
   4543    */
   4544   static void AddCallCompletedCallback(CallCompletedCallback callback);
   4545 
   4546   /**
   4547    * Removes callback that was installed by AddCallCompletedCallback.
   4548    */
   4549   static void RemoveCallCompletedCallback(CallCompletedCallback callback);
   4550 
   4551   /**
   4552    * Initializes from snapshot if possible. Otherwise, attempts to
   4553    * initialize from scratch.  This function is called implicitly if
   4554    * you use the API without calling it first.
   4555    */
   4556   static bool Initialize();
   4557 
   4558   /**
   4559    * Allows the host application to provide a callback which can be used
   4560    * as a source of entropy for random number generators.
   4561    */
   4562   static void SetEntropySource(EntropySource source);
   4563 
   4564   /**
   4565    * Allows the host application to provide a callback that allows v8 to
   4566    * cooperate with a profiler that rewrites return addresses on stack.
   4567    */
   4568   static void SetReturnAddressLocationResolver(
   4569       ReturnAddressLocationResolver return_address_resolver);
   4570 
   4571   /**
   4572    * Deprecated, use the variant with the Isolate parameter below instead.
   4573    */
   4574   V8_DEPRECATED(static bool SetFunctionEntryHook(FunctionEntryHook entry_hook));
   4575 
   4576   /**
   4577    * Allows the host application to provide the address of a function that's
   4578    * invoked on entry to every V8-generated function.
   4579    * Note that \p entry_hook is invoked at the very start of each
   4580    * generated function.
   4581    *
   4582    * \param isolate the isolate to operate on.
   4583    * \param entry_hook a function that will be invoked on entry to every
   4584    *   V8-generated function.
   4585    * \returns true on success on supported platforms, false on failure.
   4586    * \note Setting an entry hook can only be done very early in an isolates
   4587    *   lifetime, and once set, the entry hook cannot be revoked.
   4588    */
   4589   static bool SetFunctionEntryHook(Isolate* isolate,
   4590                                    FunctionEntryHook entry_hook);
   4591 
   4592   /**
   4593    * Allows the host application to provide the address of a function that is
   4594    * notified each time code is added, moved or removed.
   4595    *
   4596    * \param options options for the JIT code event handler.
   4597    * \param event_handler the JIT code event handler, which will be invoked
   4598    *     each time code is added, moved or removed.
   4599    * \note \p event_handler won't get notified of existent code.
   4600    * \note since code removal notifications are not currently issued, the
   4601    *     \p event_handler may get notifications of code that overlaps earlier
   4602    *     code notifications. This happens when code areas are reused, and the
   4603    *     earlier overlapping code areas should therefore be discarded.
   4604    * \note the events passed to \p event_handler and the strings they point to
   4605    *     are not guaranteed to live past each call. The \p event_handler must
   4606    *     copy strings and other parameters it needs to keep around.
   4607    * \note the set of events declared in JitCodeEvent::EventType is expected to
   4608    *     grow over time, and the JitCodeEvent structure is expected to accrue
   4609    *     new members. The \p event_handler function must ignore event codes
   4610    *     it does not recognize to maintain future compatibility.
   4611    */
   4612   static void SetJitCodeEventHandler(JitCodeEventOptions options,
   4613                                      JitCodeEventHandler event_handler);
   4614 
   4615   // TODO(svenpanne) Really deprecate me when Chrome is fixed.
   4616   /** Deprecated. Use Isolate::AdjustAmountOfExternalAllocatedMemory instead. */
   4617   static intptr_t AdjustAmountOfExternalAllocatedMemory(
   4618       intptr_t change_in_bytes);
   4619 
   4620   /**
   4621    * Suspends recording of tick samples in the profiler.
   4622    * When the V8 profiling mode is enabled (usually via command line
   4623    * switches) this function suspends recording of tick samples.
   4624    * Profiling ticks are discarded until ResumeProfiler() is called.
   4625    *
   4626    * See also the --prof and --prof_auto command line switches to
   4627    * enable V8 profiling.
   4628    */
   4629   V8_DEPRECATED(static void PauseProfiler());
   4630 
   4631   /**
   4632    * Resumes recording of tick samples in the profiler.
   4633    * See also PauseProfiler().
   4634    */
   4635   V8_DEPRECATED(static void ResumeProfiler());
   4636 
   4637   /**
   4638    * Return whether profiler is currently paused.
   4639    */
   4640   V8_DEPRECATED(static bool IsProfilerPaused());
   4641 
   4642   /**
   4643    * Retrieve the V8 thread id of the calling thread.
   4644    *
   4645    * The thread id for a thread should only be retrieved after the V8
   4646    * lock has been acquired with a Locker object with that thread.
   4647    */
   4648   static int GetCurrentThreadId();
   4649 
   4650   /**
   4651    * Forcefully terminate execution of a JavaScript thread.  This can
   4652    * be used to terminate long-running scripts.
   4653    *
   4654    * TerminateExecution should only be called when then V8 lock has
   4655    * been acquired with a Locker object.  Therefore, in order to be
   4656    * able to terminate long-running threads, preemption must be
   4657    * enabled to allow the user of TerminateExecution to acquire the
   4658    * lock.
   4659    *
   4660    * The termination is achieved by throwing an exception that is
   4661    * uncatchable by JavaScript exception handlers.  Termination
   4662    * exceptions act as if they were caught by a C++ TryCatch exception
   4663    * handler.  If forceful termination is used, any C++ TryCatch
   4664    * exception handler that catches an exception should check if that
   4665    * exception is a termination exception and immediately return if
   4666    * that is the case.  Returning immediately in that case will
   4667    * continue the propagation of the termination exception if needed.
   4668    *
   4669    * The thread id passed to TerminateExecution must have been
   4670    * obtained by calling GetCurrentThreadId on the thread in question.
   4671    *
   4672    * \param thread_id The thread id of the thread to terminate.
   4673    */
   4674   static void TerminateExecution(int thread_id);
   4675 
   4676   /**
   4677    * Forcefully terminate the current thread of JavaScript execution
   4678    * in the given isolate. If no isolate is provided, the default
   4679    * isolate is used.
   4680    *
   4681    * This method can be used by any thread even if that thread has not
   4682    * acquired the V8 lock with a Locker object.
   4683    *
   4684    * \param isolate The isolate in which to terminate the current JS execution.
   4685    */
   4686   static void TerminateExecution(Isolate* isolate = NULL);
   4687 
   4688   /**
   4689    * Is V8 terminating JavaScript execution.
   4690    *
   4691    * Returns true if JavaScript execution is currently terminating
   4692    * because of a call to TerminateExecution.  In that case there are
   4693    * still JavaScript frames on the stack and the termination
   4694    * exception is still active.
   4695    *
   4696    * \param isolate The isolate in which to check.
   4697    */
   4698   static bool IsExecutionTerminating(Isolate* isolate = NULL);
   4699 
   4700   /**
   4701    * Resume execution capability in the given isolate, whose execution
   4702    * was previously forcefully terminated using TerminateExecution().
   4703    *
   4704    * When execution is forcefully terminated using TerminateExecution(),
   4705    * the isolate can not resume execution until all JavaScript frames
   4706    * have propagated the uncatchable exception which is generated.  This
   4707    * method allows the program embedding the engine to handle the
   4708    * termination event and resume execution capability, even if
   4709    * JavaScript frames remain on the stack.
   4710    *
   4711    * This method can be used by any thread even if that thread has not
   4712    * acquired the V8 lock with a Locker object.
   4713    *
   4714    * \param isolate The isolate in which to resume execution capability.
   4715    */
   4716   static void CancelTerminateExecution(Isolate* isolate);
   4717 
   4718   /**
   4719    * Releases any resources used by v8 and stops any utility threads
   4720    * that may be running.  Note that disposing v8 is permanent, it
   4721    * cannot be reinitialized.
   4722    *
   4723    * It should generally not be necessary to dispose v8 before exiting
   4724    * a process, this should happen automatically.  It is only necessary
   4725    * to use if the process needs the resources taken up by v8.
   4726    */
   4727   static bool Dispose();
   4728 
   4729   /** Deprecated. Use Isolate::GetHeapStatistics instead. */
   4730   V8_DEPRECATED(static void GetHeapStatistics(HeapStatistics* heap_statistics));
   4731 
   4732   /**
   4733    * Iterates through all external resources referenced from current isolate
   4734    * heap.  GC is not invoked prior to iterating, therefore there is no
   4735    * guarantee that visited objects are still alive.
   4736    */
   4737   static void VisitExternalResources(ExternalResourceVisitor* visitor);
   4738 
   4739   /**
   4740    * Iterates through all the persistent handles in the current isolate's heap
   4741    * that have class_ids.
   4742    */
   4743   static void VisitHandlesWithClassIds(PersistentHandleVisitor* visitor);
   4744 
   4745   /**
   4746    * Iterates through all the persistent handles in the current isolate's heap
   4747    * that have class_ids and are candidates to be marked as partially dependent
   4748    * handles. This will visit handles to young objects created since the last
   4749    * garbage collection but is free to visit an arbitrary superset of these
   4750    * objects.
   4751    */
   4752   static void VisitHandlesForPartialDependence(
   4753       Isolate* isolate, PersistentHandleVisitor* visitor);
   4754 
   4755   /**
   4756    * Optional notification that the embedder is idle.
   4757    * V8 uses the notification to reduce memory footprint.
   4758    * This call can be used repeatedly if the embedder remains idle.
   4759    * Returns true if the embedder should stop calling IdleNotification
   4760    * until real work has been done.  This indicates that V8 has done
   4761    * as much cleanup as it will be able to do.
   4762    *
   4763    * The hint argument specifies the amount of work to be done in the function
   4764    * on scale from 1 to 1000. There is no guarantee that the actual work will
   4765    * match the hint.
   4766    */
   4767   static bool IdleNotification(int hint = 1000);
   4768 
   4769   /**
   4770    * Optional notification that the system is running low on memory.
   4771    * V8 uses these notifications to attempt to free memory.
   4772    */
   4773   static void LowMemoryNotification();
   4774 
   4775   /**
   4776    * Optional notification that a context has been disposed. V8 uses
   4777    * these notifications to guide the GC heuristic. Returns the number
   4778    * of context disposals - including this one - since the last time
   4779    * V8 had a chance to clean up.
   4780    */
   4781   static int ContextDisposedNotification();
   4782 
   4783   /**
   4784    * Initialize the ICU library bundled with V8. The embedder should only
   4785    * invoke this method when using the bundled ICU. Returns true on success.
   4786    */
   4787   static bool InitializeICU();
   4788 
   4789  private:
   4790   V8();
   4791 
   4792   static internal::Object** GlobalizeReference(internal::Isolate* isolate,
   4793                                                internal::Object** handle);
   4794   static void DisposeGlobal(internal::Object** global_handle);
   4795   typedef WeakReferenceCallbacks<Value, void>::Revivable RevivableCallback;
   4796   static void MakeWeak(internal::Object** global_handle,
   4797                        void* data,
   4798                        RevivableCallback weak_reference_callback);
   4799   static void ClearWeak(internal::Object** global_handle);
   4800   static int Eternalize(internal::Isolate* isolate,
   4801                         internal::Object** handle);
   4802   static internal::Object** GetEternal(internal::Isolate* isolate, int index);
   4803 
   4804   template <class T> friend class Handle;
   4805   template <class T> friend class Local;
   4806   template <class T> friend class Persistent;
   4807   friend class Context;
   4808 };
   4809 
   4810 
   4811 /**
   4812  * An external exception handler.
   4813  */
   4814 class V8_EXPORT TryCatch {
   4815  public:
   4816   /**
   4817    * Creates a new try/catch block and registers it with v8.  Note that
   4818    * all TryCatch blocks should be stack allocated because the memory
   4819    * location itself is compared against JavaScript try/catch blocks.
   4820    */
   4821   TryCatch();
   4822 
   4823   /**
   4824    * Unregisters and deletes this try/catch block.
   4825    */
   4826   ~TryCatch();
   4827 
   4828   /**
   4829    * Returns true if an exception has been caught by this try/catch block.
   4830    */
   4831   bool HasCaught() const;
   4832 
   4833   /**
   4834    * For certain types of exceptions, it makes no sense to continue execution.
   4835    *
   4836    * If CanContinue returns false, the correct action is to perform any C++
   4837    * cleanup needed and then return.  If CanContinue returns false and
   4838    * HasTerminated returns true, it is possible to call
   4839    * CancelTerminateExecution in order to continue calling into the engine.
   4840    */
   4841   bool CanContinue() const;
   4842 
   4843   /**
   4844    * Returns true if an exception has been caught due to script execution
   4845    * being terminated.
   4846    *
   4847    * There is no JavaScript representation of an execution termination
   4848    * exception.  Such exceptions are thrown when the TerminateExecution
   4849    * methods are called to terminate a long-running script.
   4850    *
   4851    * If such an exception has been thrown, HasTerminated will return true,
   4852    * indicating that it is possible to call CancelTerminateExecution in order
   4853    * to continue calling into the engine.
   4854    */
   4855   bool HasTerminated() const;
   4856 
   4857   /**
   4858    * Throws the exception caught by this TryCatch in a way that avoids
   4859    * it being caught again by this same TryCatch.  As with ThrowException
   4860    * it is illegal to execute any JavaScript operations after calling
   4861    * ReThrow; the caller must return immediately to where the exception
   4862    * is caught.
   4863    */
   4864   Handle<Value> ReThrow();
   4865 
   4866   /**
   4867    * Returns the exception caught by this try/catch block.  If no exception has
   4868    * been caught an empty handle is returned.
   4869    *
   4870    * The returned handle is valid until this TryCatch block has been destroyed.
   4871    */
   4872   Local<Value> Exception() const;
   4873 
   4874   /**
   4875    * Returns the .stack property of the thrown object.  If no .stack
   4876    * property is present an empty handle is returned.
   4877    */
   4878   Local<Value> StackTrace() const;
   4879 
   4880   /**
   4881    * Returns the message associated with this exception.  If there is
   4882    * no message associated an empty handle is returned.
   4883    *
   4884    * The returned handle is valid until this TryCatch block has been
   4885    * destroyed.
   4886    */
   4887   Local<v8::Message> Message() const;
   4888 
   4889   /**
   4890    * Clears any exceptions that may have been caught by this try/catch block.
   4891    * After this method has been called, HasCaught() will return false.
   4892    *
   4893    * It is not necessary to clear a try/catch block before using it again; if
   4894    * another exception is thrown the previously caught exception will just be
   4895    * overwritten.  However, it is often a good idea since it makes it easier
   4896    * to determine which operation threw a given exception.
   4897    */
   4898   void Reset();
   4899 
   4900   /**
   4901    * Set verbosity of the external exception handler.
   4902    *
   4903    * By default, exceptions that are caught by an external exception
   4904    * handler are not reported.  Call SetVerbose with true on an
   4905    * external exception handler to have exceptions caught by the
   4906    * handler reported as if they were not caught.
   4907    */
   4908   void SetVerbose(bool value);
   4909 
   4910   /**
   4911    * Set whether or not this TryCatch should capture a Message object
   4912    * which holds source information about where the exception
   4913    * occurred.  True by default.
   4914    */
   4915   void SetCaptureMessage(bool value);
   4916 
   4917  private:
   4918   // Make it hard to create heap-allocated TryCatch blocks.
   4919   TryCatch(const TryCatch&);
   4920   void operator=(const TryCatch&);
   4921   void* operator new(size_t size);
   4922   void operator delete(void*, size_t);
   4923 
   4924   v8::internal::Isolate* isolate_;
   4925   void* next_;
   4926   void* exception_;
   4927   void* message_obj_;
   4928   void* message_script_;
   4929   int message_start_pos_;
   4930   int message_end_pos_;
   4931   bool is_verbose_ : 1;
   4932   bool can_continue_ : 1;
   4933   bool capture_message_ : 1;
   4934   bool rethrow_ : 1;
   4935   bool has_terminated_ : 1;
   4936 
   4937   friend class v8::internal::Isolate;
   4938 };
   4939 
   4940 
   4941 // --- Context ---
   4942 
   4943 
   4944 /**
   4945  * Ignore
   4946  */
   4947 class V8_EXPORT ExtensionConfiguration {
   4948  public:
   4949   ExtensionConfiguration(int name_count, const char* names[])
   4950       : name_count_(name_count), names_(names) { }
   4951  private:
   4952   friend class ImplementationUtilities;
   4953   int name_count_;
   4954   const char** names_;
   4955 };
   4956 
   4957 
   4958 /**
   4959  * A sandboxed execution context with its own set of built-in objects
   4960  * and functions.
   4961  */
   4962 class V8_EXPORT Context {
   4963  public:
   4964   /**
   4965    * Returns the global proxy object or global object itself for
   4966    * detached contexts.
   4967    *
   4968    * Global proxy object is a thin wrapper whose prototype points to
   4969    * actual context's global object with the properties like Object, etc.
   4970    * This is done that way for security reasons (for more details see
   4971    * https://wiki.mozilla.org/Gecko:SplitWindow).
   4972    *
   4973    * Please note that changes to global proxy object prototype most probably
   4974    * would break VM---v8 expects only global object as a prototype of
   4975    * global proxy object.
   4976    *
   4977    * If DetachGlobal() has been invoked, Global() would return actual global
   4978    * object until global is reattached with ReattachGlobal().
   4979    */
   4980   Local<Object> Global();
   4981 
   4982   /**
   4983    * Detaches the global object from its context before
   4984    * the global object can be reused to create a new context.
   4985    */
   4986   void DetachGlobal();
   4987 
   4988   /**
   4989    * Reattaches a global object to a context.  This can be used to
   4990    * restore the connection between a global object and a context
   4991    * after DetachGlobal has been called.
   4992    *
   4993    * \param global_object The global object to reattach to the
   4994    *   context.  For this to work, the global object must be the global
   4995    *   object that was associated with this context before a call to
   4996    *   DetachGlobal.
   4997    */
   4998   void ReattachGlobal(Handle<Object> global_object);
   4999 
   5000   /**
   5001    * Creates a new context and returns a handle to the newly allocated
   5002    * context.
   5003    *
   5004    * \param isolate The isolate in which to create the context.
   5005    *
   5006    * \param extensions An optional extension configuration containing
   5007    * the extensions to be installed in the newly created context.
   5008    *
   5009    * \param global_template An optional object template from which the
   5010    * global object for the newly created context will be created.
   5011    *
   5012    * \param global_object An optional global object to be reused for
   5013    * the newly created context. This global object must have been
   5014    * created by a previous call to Context::New with the same global
   5015    * template. The state of the global object will be completely reset
   5016    * and only object identify will remain.
   5017    */
   5018   static Local<Context> New(
   5019       Isolate* isolate,
   5020       ExtensionConfiguration* extensions = NULL,
   5021       Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(),
   5022       Handle<Value> global_object = Handle<Value>());
   5023 
   5024   /** Deprecated. Use Isolate version instead. */
   5025   V8_DEPRECATED(static Persistent<Context> New(
   5026       ExtensionConfiguration* extensions = NULL,
   5027       Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(),
   5028       Handle<Value> global_object = Handle<Value>()));
   5029 
   5030   /** Returns the last entered context. */
   5031   static Local<Context> GetEntered();
   5032 
   5033   // TODO(svenpanne) Actually deprecate this.
   5034   /** Deprecated. Use Isolate::GetCurrentContext instead. */
   5035   static Local<Context> GetCurrent();
   5036 
   5037   /**
   5038    * Returns the context of the calling JavaScript code.  That is the
   5039    * context of the top-most JavaScript frame.  If there are no
   5040    * JavaScript frames an empty handle is returned.
   5041    */
   5042   static Local<Context> GetCalling();
   5043 
   5044   /**
   5045    * Sets the security token for the context.  To access an object in
   5046    * another context, the security tokens must match.
   5047    */
   5048   void SetSecurityToken(Handle<Value> token);
   5049 
   5050   /** Restores the security token to the default value. */
   5051   void UseDefaultSecurityToken();
   5052 
   5053   /** Returns the security token of this context.*/
   5054   Handle<Value> GetSecurityToken();
   5055 
   5056   /**
   5057    * Enter this context.  After entering a context, all code compiled
   5058    * and run is compiled and run in this context.  If another context
   5059    * is already entered, this old context is saved so it can be
   5060    * restored when the new context is exited.
   5061    */
   5062   void Enter();
   5063 
   5064   /**
   5065    * Exit this context.  Exiting the current context restores the
   5066    * context that was in place when entering the current context.
   5067    */
   5068   void Exit();
   5069 
   5070   /** Returns true if the context has experienced an out of memory situation. */
   5071   bool HasOutOfMemoryException();
   5072 
   5073   /** Returns true if V8 has a current context. */
   5074   static bool InContext();
   5075 
   5076   /** Returns an isolate associated with a current context. */
   5077   v8::Isolate* GetIsolate();
   5078 
   5079   /**
   5080    * Gets the embedder data with the given index, which must have been set by a
   5081    * previous call to SetEmbedderData with the same index. Note that index 0
   5082    * currently has a special meaning for Chrome's debugger.
   5083    */
   5084   V8_INLINE(Local<Value> GetEmbedderData(int index));
   5085 
   5086   /**
   5087    * Sets the embedder data with the given index, growing the data as
   5088    * needed. Note that index 0 currently has a special meaning for Chrome's
   5089    * debugger.
   5090    */
   5091   void SetEmbedderData(int index, Handle<Value> value);
   5092 
   5093   /**
   5094    * Gets a 2-byte-aligned native pointer from the embedder data with the given
   5095    * index, which must have bees set by a previous call to
   5096    * SetAlignedPointerInEmbedderData with the same index. Note that index 0
   5097    * currently has a special meaning for Chrome's debugger.
   5098    */
   5099   V8_INLINE(void* GetAlignedPointerFromEmbedderData(int index));
   5100 
   5101   /**
   5102    * Sets a 2-byte-aligned native pointer in the embedder data with the given
   5103    * index, growing the data as needed. Note that index 0 currently has a
   5104    * special meaning for Chrome's debugger.
   5105    */
   5106   void SetAlignedPointerInEmbedderData(int index, void* value);
   5107 
   5108   /**
   5109    * Control whether code generation from strings is allowed. Calling
   5110    * this method with false will disable 'eval' and the 'Function'
   5111    * constructor for code running in this context. If 'eval' or the
   5112    * 'Function' constructor are used an exception will be thrown.
   5113    *
   5114    * If code generation from strings is not allowed the
   5115    * V8::AllowCodeGenerationFromStrings callback will be invoked if
   5116    * set before blocking the call to 'eval' or the 'Function'
   5117    * constructor. If that callback returns true, the call will be
   5118    * allowed, otherwise an exception will be thrown. If no callback is
   5119    * set an exception will be thrown.
   5120    */
   5121   void AllowCodeGenerationFromStrings(bool allow);
   5122 
   5123   /**
   5124    * Returns true if code generation from strings is allowed for the context.
   5125    * For more details see AllowCodeGenerationFromStrings(bool) documentation.
   5126    */
   5127   bool IsCodeGenerationFromStringsAllowed();
   5128 
   5129   /**
   5130    * Sets the error description for the exception that is thrown when
   5131    * code generation from strings is not allowed and 'eval' or the 'Function'
   5132    * constructor are called.
   5133    */
   5134   void SetErrorMessageForCodeGenerationFromStrings(Handle<String> message);
   5135 
   5136   /**
   5137    * Stack-allocated class which sets the execution context for all
   5138    * operations executed within a local scope.
   5139    */
   5140   class Scope {
   5141    public:
   5142     explicit V8_INLINE(Scope(Handle<Context> context)) : context_(context) {
   5143       context_->Enter();
   5144     }
   5145     // TODO(dcarney): deprecate
   5146     V8_INLINE(Scope(Isolate* isolate, Persistent<Context>& context)) // NOLINT
   5147 #ifndef V8_USE_UNSAFE_HANDLES
   5148     : context_(Handle<Context>::New(isolate, context)) {
   5149 #else
   5150     : context_(Local<Context>::New(isolate, context)) {
   5151 #endif
   5152       context_->Enter();
   5153     }
   5154     V8_INLINE(~Scope()) { context_->Exit(); }
   5155 
   5156    private:
   5157     Handle<Context> context_;
   5158   };
   5159 
   5160  private:
   5161   friend class Value;
   5162   friend class Script;
   5163   friend class Object;
   5164   friend class Function;
   5165 
   5166   Local<Value> SlowGetEmbedderData(int index);
   5167   void* SlowGetAlignedPointerFromEmbedderData(int index);
   5168 };
   5169 
   5170 
   5171 /**
   5172  * Multiple threads in V8 are allowed, but only one thread at a time is allowed
   5173  * to use any given V8 isolate, see the comments in the Isolate class. The
   5174  * definition of 'using a V8 isolate' includes accessing handles or holding onto
   5175  * object pointers obtained from V8 handles while in the particular V8 isolate.
   5176  * It is up to the user of V8 to ensure, perhaps with locking, that this
   5177  * constraint is not violated. In addition to any other synchronization
   5178  * mechanism that may be used, the v8::Locker and v8::Unlocker classes must be
   5179  * used to signal thead switches to V8.
   5180  *
   5181  * v8::Locker is a scoped lock object. While it's active, i.e. between its
   5182  * construction and destruction, the current thread is allowed to use the locked
   5183  * isolate. V8 guarantees that an isolate can be locked by at most one thread at
   5184  * any time. In other words, the scope of a v8::Locker is a critical section.
   5185  *
   5186  * Sample usage:
   5187 * \code
   5188  * ...
   5189  * {
   5190  *   v8::Locker locker(isolate);
   5191  *   v8::Isolate::Scope isolate_scope(isolate);
   5192  *   ...
   5193  *   // Code using V8 and isolate goes here.
   5194  *   ...
   5195  * } // Destructor called here
   5196  * \endcode
   5197  *
   5198  * If you wish to stop using V8 in a thread A you can do this either by
   5199  * destroying the v8::Locker object as above or by constructing a v8::Unlocker
   5200  * object:
   5201  *
   5202  * \code
   5203  * {
   5204  *   isolate->Exit();
   5205  *   v8::Unlocker unlocker(isolate);
   5206  *   ...
   5207  *   // Code not using V8 goes here while V8 can run in another thread.
   5208  *   ...
   5209  * } // Destructor called here.
   5210  * isolate->Enter();
   5211  * \endcode
   5212  *
   5213  * The Unlocker object is intended for use in a long-running callback from V8,
   5214  * where you want to release the V8 lock for other threads to use.
   5215  *
   5216  * The v8::Locker is a recursive lock, i.e. you can lock more than once in a
   5217  * given thread. This can be useful if you have code that can be called either
   5218  * from code that holds the lock or from code that does not. The Unlocker is
   5219  * not recursive so you can not have several Unlockers on the stack at once, and
   5220  * you can not use an Unlocker in a thread that is not inside a Locker's scope.
   5221  *
   5222  * An unlocker will unlock several lockers if it has to and reinstate the
   5223  * correct depth of locking on its destruction, e.g.:
   5224  *
   5225  * \code
   5226  * // V8 not locked.
   5227  * {
   5228  *   v8::Locker locker(isolate);
   5229  *   Isolate::Scope isolate_scope(isolate);
   5230  *   // V8 locked.
   5231  *   {
   5232  *     v8::Locker another_locker(isolate);
   5233  *     // V8 still locked (2 levels).
   5234  *     {
   5235  *       isolate->Exit();
   5236  *       v8::Unlocker unlocker(isolate);
   5237  *       // V8 not locked.
   5238  *     }
   5239  *     isolate->Enter();
   5240  *     // V8 locked again (2 levels).
   5241  *   }
   5242  *   // V8 still locked (1 level).
   5243  * }
   5244  * // V8 Now no longer locked.
   5245  * \endcode
   5246  */
   5247 class V8_EXPORT Unlocker {
   5248  public:
   5249   /**
   5250    * Initialize Unlocker for a given Isolate.
   5251    */
   5252   V8_INLINE(explicit Unlocker(Isolate* isolate)) { Initialize(isolate); }
   5253 
   5254   /** Deprecated. Use Isolate version instead. */
   5255   V8_DEPRECATED(Unlocker());
   5256 
   5257   ~Unlocker();
   5258  private:
   5259   void Initialize(Isolate* isolate);
   5260 
   5261   internal::Isolate* isolate_;
   5262 };
   5263 
   5264 
   5265 class V8_EXPORT Locker {
   5266  public:
   5267   /**
   5268    * Initialize Locker for a given Isolate.
   5269    */
   5270   V8_INLINE(explicit Locker(Isolate* isolate)) { Initialize(isolate); }
   5271 
   5272   /** Deprecated. Use Isolate version instead. */
   5273   V8_DEPRECATED(Locker());
   5274 
   5275   ~Locker();
   5276 
   5277   /**
   5278    * Start preemption.
   5279    *
   5280    * When preemption is started, a timer is fired every n milliseconds
   5281    * that will switch between multiple threads that are in contention
   5282    * for the V8 lock.
   5283    */
   5284   static void StartPreemption(int every_n_ms);
   5285 
   5286   /**
   5287    * Stop preemption.
   5288    */
   5289   static void StopPreemption();
   5290 
   5291   /**
   5292    * Returns whether or not the locker for a given isolate, is locked by the
   5293    * current thread.
   5294    */
   5295   static bool IsLocked(Isolate* isolate);
   5296 
   5297   /**
   5298    * Returns whether v8::Locker is being used by this V8 instance.
   5299    */
   5300   static bool IsActive();
   5301 
   5302  private:
   5303   void Initialize(Isolate* isolate);
   5304 
   5305   bool has_lock_;
   5306   bool top_level_;
   5307   internal::Isolate* isolate_;
   5308 
   5309   static bool active_;
   5310 
   5311   // Disallow copying and assigning.
   5312   Locker(const Locker&);
   5313   void operator=(const Locker&);
   5314 };
   5315 
   5316 
   5317 /**
   5318  * A struct for exporting HeapStats data from V8, using "push" model.
   5319  */
   5320 struct HeapStatsUpdate;
   5321 
   5322 
   5323 /**
   5324  * An interface for exporting data from V8, using "push" model.
   5325  */
   5326 class V8_EXPORT OutputStream {  // NOLINT
   5327  public:
   5328   enum OutputEncoding {
   5329     kAscii = 0  // 7-bit ASCII.
   5330   };
   5331   enum WriteResult {
   5332     kContinue = 0,
   5333     kAbort = 1
   5334   };
   5335   virtual ~OutputStream() {}
   5336   /** Notify about the end of stream. */
   5337   virtual void EndOfStream() = 0;
   5338   /** Get preferred output chunk size. Called only once. */
   5339   virtual int GetChunkSize() { return 1024; }
   5340   /** Get preferred output encoding. Called only once. */
   5341   virtual OutputEncoding GetOutputEncoding() { return kAscii; }
   5342   /**
   5343    * Writes the next chunk of snapshot data into the stream. Writing
   5344    * can be stopped by returning kAbort as function result. EndOfStream
   5345    * will not be called in case writing was aborted.
   5346    */
   5347   virtual WriteResult WriteAsciiChunk(char* data, int size) = 0;
   5348   /**
   5349    * Writes the next chunk of heap stats data into the stream. Writing
   5350    * can be stopped by returning kAbort as function result. EndOfStream
   5351    * will not be called in case writing was aborted.
   5352    */
   5353   virtual WriteResult WriteHeapStatsChunk(HeapStatsUpdate* data, int count) {
   5354     return kAbort;
   5355   };
   5356 };
   5357 
   5358 
   5359 /**
   5360  * An interface for reporting progress and controlling long-running
   5361  * activities.
   5362  */
   5363 class V8_EXPORT ActivityControl {  // NOLINT
   5364  public:
   5365   enum ControlOption {
   5366     kContinue = 0,
   5367     kAbort = 1
   5368   };
   5369   virtual ~ActivityControl() {}
   5370   /**
   5371    * Notify about current progress. The activity can be stopped by
   5372    * returning kAbort as the callback result.
   5373    */
   5374   virtual ControlOption ReportProgressValue(int done, int total) = 0;
   5375 };
   5376 
   5377 
   5378 // --- Implementation ---
   5379 
   5380 
   5381 namespace internal {
   5382 
   5383 const int kApiPointerSize = sizeof(void*);  // NOLINT
   5384 const int kApiIntSize = sizeof(int);  // NOLINT
   5385 
   5386 // Tag information for HeapObject.
   5387 const int kHeapObjectTag = 1;
   5388 const int kHeapObjectTagSize = 2;
   5389 const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1;
   5390 
   5391 // Tag information for Smi.
   5392 const int kSmiTag = 0;
   5393 const int kSmiTagSize = 1;
   5394 const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1;
   5395 
   5396 template <size_t ptr_size> struct SmiTagging;
   5397 
   5398 template<int kSmiShiftSize>
   5399 V8_INLINE(internal::Object* IntToSmi(int value)) {
   5400   int smi_shift_bits = kSmiTagSize + kSmiShiftSize;
   5401   intptr_t tagged_value =
   5402       (static_cast<intptr_t>(value) << smi_shift_bits) | kSmiTag;
   5403   return reinterpret_cast<internal::Object*>(tagged_value);
   5404 }
   5405 
   5406 // Smi constants for 32-bit systems.
   5407 template <> struct SmiTagging<4> {
   5408   static const int kSmiShiftSize = 0;
   5409   static const int kSmiValueSize = 31;
   5410   V8_INLINE(static int SmiToInt(internal::Object* value)) {
   5411     int shift_bits = kSmiTagSize + kSmiShiftSize;
   5412     // Throw away top 32 bits and shift down (requires >> to be sign extending).
   5413     return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits;
   5414   }
   5415   V8_INLINE(static internal::Object* IntToSmi(int value)) {
   5416     return internal::IntToSmi<kSmiShiftSize>(value);
   5417   }
   5418   V8_INLINE(static bool IsValidSmi(intptr_t value)) {
   5419     // To be representable as an tagged small integer, the two
   5420     // most-significant bits of 'value' must be either 00 or 11 due to
   5421     // sign-extension. To check this we add 01 to the two
   5422     // most-significant bits, and check if the most-significant bit is 0
   5423     //
   5424     // CAUTION: The original code below:
   5425     // bool result = ((value + 0x40000000) & 0x80000000) == 0;
   5426     // may lead to incorrect results according to the C language spec, and
   5427     // in fact doesn't work correctly with gcc4.1.1 in some cases: The
   5428     // compiler may produce undefined results in case of signed integer
   5429     // overflow. The computation must be done w/ unsigned ints.
   5430     return static_cast<uintptr_t>(value + 0x40000000U) < 0x80000000U;
   5431   }
   5432 };
   5433 
   5434 // Smi constants for 64-bit systems.
   5435 template <> struct SmiTagging<8> {
   5436   static const int kSmiShiftSize = 31;
   5437   static const int kSmiValueSize = 32;
   5438   V8_INLINE(static int SmiToInt(internal::Object* value)) {
   5439     int shift_bits = kSmiTagSize + kSmiShiftSize;
   5440     // Shift down and throw away top 32 bits.
   5441     return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits);
   5442   }
   5443   V8_INLINE(static internal::Object* IntToSmi(int value)) {
   5444     return internal::IntToSmi<kSmiShiftSize>(value);
   5445   }
   5446   V8_INLINE(static bool IsValidSmi(intptr_t value)) {
   5447     // To be representable as a long smi, the value must be a 32-bit integer.
   5448     return (value == static_cast<int32_t>(value));
   5449   }
   5450 };
   5451 
   5452 typedef SmiTagging<kApiPointerSize> PlatformSmiTagging;
   5453 const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize;
   5454 const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize;
   5455 
   5456 /**
   5457  * This class exports constants and functionality from within v8 that
   5458  * is necessary to implement inline functions in the v8 api.  Don't
   5459  * depend on functions and constants defined here.
   5460  */
   5461 class Internals {
   5462  public:
   5463   // These values match non-compiler-dependent values defined within
   5464   // the implementation of v8.
   5465   static const int kHeapObjectMapOffset = 0;
   5466   static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize;
   5467   static const int kStringResourceOffset = 3 * kApiPointerSize;
   5468 
   5469   static const int kOddballKindOffset = 3 * kApiPointerSize;
   5470   static const int kForeignAddressOffset = kApiPointerSize;
   5471   static const int kJSObjectHeaderSize = 3 * kApiPointerSize;
   5472   static const int kFixedArrayHeaderSize = 2 * kApiPointerSize;
   5473   static const int kContextHeaderSize = 2 * kApiPointerSize;
   5474   static const int kContextEmbedderDataIndex = 65;
   5475   static const int kFullStringRepresentationMask = 0x07;
   5476   static const int kStringEncodingMask = 0x4;
   5477   static const int kExternalTwoByteRepresentationTag = 0x02;
   5478   static const int kExternalAsciiRepresentationTag = 0x06;
   5479 
   5480   static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize;
   5481   static const int kIsolateRootsOffset = 3 * kApiPointerSize;
   5482   static const int kUndefinedValueRootIndex = 5;
   5483   static const int kNullValueRootIndex = 7;
   5484   static const int kTrueValueRootIndex = 8;
   5485   static const int kFalseValueRootIndex = 9;
   5486   static const int kEmptyStringRootIndex = 133;
   5487 
   5488   static const int kNodeClassIdOffset = 1 * kApiPointerSize;
   5489   static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3;
   5490   static const int kNodeStateMask = 0xf;
   5491   static const int kNodeStateIsWeakValue = 2;
   5492   static const int kNodeStateIsPendingValue = 3;
   5493   static const int kNodeStateIsNearDeathValue = 4;
   5494   static const int kNodeIsIndependentShift = 4;
   5495   static const int kNodeIsPartiallyDependentShift = 5;
   5496 
   5497   static const int kJSObjectType = 0xb1;
   5498   static const int kFirstNonstringType = 0x80;
   5499   static const int kOddballType = 0x83;
   5500   static const int kForeignType = 0x87;
   5501 
   5502   static const int kUndefinedOddballKind = 5;
   5503   static const int kNullOddballKind = 3;
   5504 
   5505   static void CheckInitializedImpl(v8::Isolate* isolate);
   5506   V8_INLINE(static void CheckInitialized(v8::Isolate* isolate)) {
   5507 #ifdef V8_ENABLE_CHECKS
   5508     CheckInitializedImpl(isolate);
   5509 #endif
   5510   }
   5511 
   5512   V8_INLINE(static bool HasHeapObjectTag(internal::Object* value)) {
   5513     return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) ==
   5514             kHeapObjectTag);
   5515   }
   5516 
   5517   V8_INLINE(static int SmiValue(internal::Object* value)) {
   5518     return PlatformSmiTagging::SmiToInt(value);
   5519   }
   5520 
   5521   V8_INLINE(static internal::Object* IntToSmi(int value)) {
   5522     return PlatformSmiTagging::IntToSmi(value);
   5523   }
   5524 
   5525   V8_INLINE(static bool IsValidSmi(intptr_t value)) {
   5526     return PlatformSmiTagging::IsValidSmi(value);
   5527   }
   5528 
   5529   V8_INLINE(static int GetInstanceType(internal::Object* obj)) {
   5530     typedef internal::Object O;
   5531     O* map = ReadField<O*>(obj, kHeapObjectMapOffset);
   5532     return ReadField<uint8_t>(map, kMapInstanceTypeOffset);
   5533   }
   5534 
   5535   V8_INLINE(static int GetOddballKind(internal::Object* obj)) {
   5536     typedef internal::Object O;
   5537     return SmiValue(ReadField<O*>(obj, kOddballKindOffset));
   5538   }
   5539 
   5540   V8_INLINE(static bool IsExternalTwoByteString(int instance_type)) {
   5541     int representation = (instance_type & kFullStringRepresentationMask);
   5542     return representation == kExternalTwoByteRepresentationTag;
   5543   }
   5544 
   5545   V8_INLINE(static uint8_t GetNodeFlag(internal::Object** obj, int shift)) {
   5546       uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
   5547       return *addr & static_cast<uint8_t>(1U << shift);
   5548   }
   5549 
   5550   V8_INLINE(static void UpdateNodeFlag(internal::Object** obj,
   5551                                        bool value, int shift)) {
   5552       uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
   5553       uint8_t mask = static_cast<uint8_t>(1 << shift);
   5554       *addr = static_cast<uint8_t>((*addr & ~mask) | (value << shift));
   5555   }
   5556 
   5557   V8_INLINE(static uint8_t GetNodeState(internal::Object** obj)) {
   5558     uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
   5559     return *addr & kNodeStateMask;
   5560   }
   5561 
   5562   V8_INLINE(static void UpdateNodeState(internal::Object** obj,
   5563                                         uint8_t value)) {
   5564     uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
   5565     *addr = static_cast<uint8_t>((*addr & ~kNodeStateMask) | value);
   5566   }
   5567 
   5568   V8_INLINE(static void SetEmbedderData(v8::Isolate* isolate, void* data)) {
   5569     uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) +
   5570         kIsolateEmbedderDataOffset;
   5571     *reinterpret_cast<void**>(addr) = data;
   5572   }
   5573 
   5574   V8_INLINE(static void* GetEmbedderData(v8::Isolate* isolate)) {
   5575     uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) +
   5576         kIsolateEmbedderDataOffset;
   5577     return *reinterpret_cast<void**>(addr);
   5578   }
   5579 
   5580   V8_INLINE(static internal::Object** GetRoot(v8::Isolate* isolate,
   5581                                               int index)) {
   5582     uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset;
   5583     return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize);
   5584   }
   5585 
   5586   template <typename T>
   5587   V8_INLINE(static T ReadField(Object* ptr, int offset)) {
   5588     uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag;
   5589     return *reinterpret_cast<T*>(addr);
   5590   }
   5591 
   5592   template <typename T>
   5593   V8_INLINE(static T ReadEmbedderData(Context* context, int index)) {
   5594     typedef internal::Object O;
   5595     typedef internal::Internals I;
   5596     O* ctx = *reinterpret_cast<O**>(context);
   5597     int embedder_data_offset = I::kContextHeaderSize +
   5598         (internal::kApiPointerSize * I::kContextEmbedderDataIndex);
   5599     O* embedder_data = I::ReadField<O*>(ctx, embedder_data_offset);
   5600     int value_offset =
   5601         I::kFixedArrayHeaderSize + (internal::kApiPointerSize * index);
   5602     return I::ReadField<T>(embedder_data, value_offset);
   5603   }
   5604 
   5605   V8_INLINE(static bool CanCastToHeapObject(void* o)) { return false; }
   5606   V8_INLINE(static bool CanCastToHeapObject(Context* o)) { return true; }
   5607   V8_INLINE(static bool CanCastToHeapObject(String* o)) { return true; }
   5608   V8_INLINE(static bool CanCastToHeapObject(Object* o)) { return true; }
   5609   V8_INLINE(static bool CanCastToHeapObject(Message* o)) { return true; }
   5610   V8_INLINE(static bool CanCastToHeapObject(StackTrace* o)) { return true; }
   5611   V8_INLINE(static bool CanCastToHeapObject(StackFrame* o)) { return true; }
   5612 };
   5613 
   5614 }  // namespace internal
   5615 
   5616 
   5617 template <class T>
   5618 Local<T>::Local() : Handle<T>() { }
   5619 
   5620 
   5621 template <class T>
   5622 Local<T> Local<T>::New(Handle<T> that) {
   5623   if (that.IsEmpty()) return Local<T>();
   5624   T* that_ptr = *that;
   5625   internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr);
   5626   if (internal::Internals::CanCastToHeapObject(that_ptr)) {
   5627     return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(
   5628         reinterpret_cast<internal::HeapObject*>(*p))));
   5629   }
   5630   return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p)));
   5631 }
   5632 
   5633 
   5634 template <class T>
   5635 Local<T> Local<T>::New(Isolate* isolate, Handle<T> that) {
   5636   return New(isolate, that.val_);
   5637 }
   5638 
   5639 #ifndef V8_USE_UNSAFE_HANDLES
   5640 template <class T>
   5641 Local<T> Local<T>::New(Isolate* isolate, const Persistent<T>& that) {
   5642   return New(isolate, that.val_);
   5643 }
   5644 
   5645 template <class T>
   5646 Handle<T> Handle<T>::New(Isolate* isolate, T* that) {
   5647   if (that == NULL) return Handle<T>();
   5648   T* that_ptr = that;
   5649   internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr);
   5650   return Handle<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(
   5651       reinterpret_cast<internal::Isolate*>(isolate), *p)));
   5652 }
   5653 #endif
   5654 
   5655 
   5656 template <class T>
   5657 Local<T> Local<T>::New(Isolate* isolate, T* that) {
   5658   if (that == NULL) return Local<T>();
   5659   T* that_ptr = that;
   5660   internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr);
   5661   return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(
   5662       reinterpret_cast<internal::Isolate*>(isolate), *p)));
   5663 }
   5664 
   5665 
   5666 template<class T>
   5667 int Local<T>::Eternalize(Isolate* isolate) {
   5668   return V8::Eternalize(reinterpret_cast<internal::Isolate*>(isolate),
   5669                         reinterpret_cast<internal::Object**>(this->val_));
   5670 }
   5671 
   5672 
   5673 template<class T>
   5674 Local<T> Local<T>::GetEternal(Isolate* isolate, int index) {
   5675   internal::Object** handle =
   5676       V8::GetEternal(reinterpret_cast<internal::Isolate*>(isolate), index);
   5677   return Local<T>(T::Cast(reinterpret_cast<Value*>(handle)));
   5678 }
   5679 
   5680 
   5681 #ifdef V8_USE_UNSAFE_HANDLES
   5682 template <class T>
   5683 Persistent<T> Persistent<T>::New(Handle<T> that) {
   5684   return New(Isolate::GetCurrent(), that.val_);
   5685 }
   5686 
   5687 
   5688 template <class T>
   5689 Persistent<T> Persistent<T>::New(Isolate* isolate, Handle<T> that) {
   5690   return New(Isolate::GetCurrent(), that.val_);
   5691 }
   5692 
   5693 template <class T>
   5694 Persistent<T> Persistent<T>::New(Isolate* isolate, Persistent<T> that) {
   5695   return New(Isolate::GetCurrent(), that.val_);
   5696 }
   5697 #endif
   5698 
   5699 
   5700 template <class T>
   5701 T* Persistent<T>::New(Isolate* isolate, T* that) {
   5702   if (that == NULL) return NULL;
   5703   internal::Object** p = reinterpret_cast<internal::Object**>(that);
   5704   return reinterpret_cast<T*>(
   5705       V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate),
   5706                              p));
   5707 }
   5708 
   5709 
   5710 template <class T>
   5711 bool Persistent<T>::IsIndependent() const {
   5712   typedef internal::Internals I;
   5713   if (this->IsEmpty()) return false;
   5714   return I::GetNodeFlag(reinterpret_cast<internal::Object**>(this->val_),
   5715                         I::kNodeIsIndependentShift);
   5716 }
   5717 
   5718 
   5719 template <class T>
   5720 bool Persistent<T>::IsNearDeath() const {
   5721   typedef internal::Internals I;
   5722   if (this->IsEmpty()) return false;
   5723   uint8_t node_state =
   5724       I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_));
   5725   return node_state == I::kNodeStateIsNearDeathValue ||
   5726       node_state == I::kNodeStateIsPendingValue;
   5727 }
   5728 
   5729 
   5730 template <class T>
   5731 bool Persistent<T>::IsWeak() const {
   5732   typedef internal::Internals I;
   5733   if (this->IsEmpty()) return false;
   5734   return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) ==
   5735       I::kNodeStateIsWeakValue;
   5736 }
   5737 
   5738 
   5739 template <class T>
   5740 void Persistent<T>::Dispose() {
   5741   if (this->IsEmpty()) return;
   5742   V8::DisposeGlobal(reinterpret_cast<internal::Object**>(this->val_));
   5743 #ifndef V8_USE_UNSAFE_HANDLES
   5744   val_ = 0;
   5745 #endif
   5746 }
   5747 
   5748 
   5749 template <class T>
   5750 template <typename S, typename P>
   5751 void Persistent<T>::MakeWeak(
   5752     P* parameters,
   5753     typename WeakReferenceCallbacks<S, P>::Revivable callback) {
   5754   TYPE_CHECK(S, T);
   5755   typedef typename WeakReferenceCallbacks<Value, void>::Revivable Revivable;
   5756   V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_),
   5757                parameters,
   5758                reinterpret_cast<Revivable>(callback));
   5759 }
   5760 
   5761 
   5762 template <class T>
   5763 template <typename P>
   5764 void Persistent<T>::MakeWeak(
   5765     P* parameters,
   5766     typename WeakReferenceCallbacks<T, P>::Revivable callback) {
   5767   MakeWeak<T, P>(parameters, callback);
   5768 }
   5769 
   5770 
   5771 template <class T>
   5772 template <typename S, typename P>
   5773 void Persistent<T>::MakeWeak(
   5774     Isolate* isolate,
   5775     P* parameters,
   5776     typename WeakReferenceCallbacks<S, P>::Revivable callback) {
   5777   MakeWeak<S, P>(parameters, callback);
   5778 }
   5779 
   5780 
   5781 template <class T>
   5782 template<typename P>
   5783 void Persistent<T>::MakeWeak(
   5784     Isolate* isolate,
   5785     P* parameters,
   5786     typename WeakReferenceCallbacks<T, P>::Revivable callback) {
   5787   MakeWeak<P>(parameters, callback);
   5788 }
   5789 
   5790 
   5791 template <class T>
   5792 void Persistent<T>::ClearWeak() {
   5793   V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_));
   5794 }
   5795 
   5796 
   5797 template <class T>
   5798 void Persistent<T>::MarkIndependent() {
   5799   typedef internal::Internals I;
   5800   if (this->IsEmpty()) return;
   5801   I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_),
   5802                     true,
   5803                     I::kNodeIsIndependentShift);
   5804 }
   5805 
   5806 
   5807 template <class T>
   5808 void Persistent<T>::MarkPartiallyDependent() {
   5809   typedef internal::Internals I;
   5810   if (this->IsEmpty()) return;
   5811   I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_),
   5812                     true,
   5813                     I::kNodeIsPartiallyDependentShift);
   5814 }
   5815 
   5816 
   5817 template <class T>
   5818 void Persistent<T>::Reset(Isolate* isolate, const Handle<T>& other) {
   5819   Dispose(isolate);
   5820 #ifdef V8_USE_UNSAFE_HANDLES
   5821   *this = *New(isolate, other);
   5822 #else
   5823   if (other.IsEmpty()) {
   5824     this->val_ = NULL;
   5825     return;
   5826   }
   5827   internal::Object** p = reinterpret_cast<internal::Object**>(other.val_);
   5828   this->val_ = reinterpret_cast<T*>(
   5829       V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), p));
   5830 #endif
   5831 }
   5832 
   5833 
   5834 #ifndef V8_USE_UNSAFE_HANDLES
   5835 template <class T>
   5836 void Persistent<T>::Reset(Isolate* isolate, const Persistent<T>& other) {
   5837   Dispose(isolate);
   5838   if (other.IsEmpty()) {
   5839     this->val_ = NULL;
   5840     return;
   5841   }
   5842   internal::Object** p = reinterpret_cast<internal::Object**>(other.val_);
   5843   this->val_ = reinterpret_cast<T*>(
   5844       V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), p));
   5845 }
   5846 #endif
   5847 
   5848 
   5849 template <class T>
   5850 T* Persistent<T>::ClearAndLeak() {
   5851   T* old;
   5852 #ifdef V8_USE_UNSAFE_HANDLES
   5853   old = **this;
   5854   *this = Persistent<T>();
   5855 #else
   5856   old = val_;
   5857   val_ = NULL;
   5858 #endif
   5859   return old;
   5860 }
   5861 
   5862 
   5863 template <class T>
   5864 void Persistent<T>::SetWrapperClassId(uint16_t class_id) {
   5865   typedef internal::Internals I;
   5866   if (this->IsEmpty()) return;
   5867   internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_);
   5868   uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset;
   5869   *reinterpret_cast<uint16_t*>(addr) = class_id;
   5870 }
   5871 
   5872 
   5873 template <class T>
   5874 uint16_t Persistent<T>::WrapperClassId() const {
   5875   typedef internal::Internals I;
   5876   if (this->IsEmpty()) return 0;
   5877   internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_);
   5878   uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset;
   5879   return *reinterpret_cast<uint16_t*>(addr);
   5880 }
   5881 
   5882 
   5883 template<typename T>
   5884 ReturnValue<T>::ReturnValue(internal::Object** slot) : value_(slot) {}
   5885 
   5886 template<typename T>
   5887 template<typename S>
   5888 void ReturnValue<T>::Set(const Persistent<S>& handle) {
   5889   TYPE_CHECK(T, S);
   5890   if (V8_UNLIKELY(handle.IsEmpty())) {
   5891     *value_ = GetDefaultValue();
   5892   } else {
   5893     *value_ = *reinterpret_cast<internal::Object**>(*handle);
   5894   }
   5895 }
   5896 
   5897 template<typename T>
   5898 template<typename S>
   5899 void ReturnValue<T>::Set(const Handle<S> handle) {
   5900   TYPE_CHECK(T, S);
   5901   if (V8_UNLIKELY(handle.IsEmpty())) {
   5902     *value_ = GetDefaultValue();
   5903   } else {
   5904     *value_ = *reinterpret_cast<internal::Object**>(*handle);
   5905   }
   5906 }
   5907 
   5908 template<typename T>
   5909 void ReturnValue<T>::Set(double i) {
   5910   TYPE_CHECK(T, Number);
   5911   Set(Number::New(GetIsolate(), i));
   5912 }
   5913 
   5914 template<typename T>
   5915 void ReturnValue<T>::Set(int32_t i) {
   5916   TYPE_CHECK(T, Integer);
   5917   typedef internal::Internals I;
   5918   if (V8_LIKELY(I::IsValidSmi(i))) {
   5919     *value_ = I::IntToSmi(i);
   5920     return;
   5921   }
   5922   Set(Integer::New(i, GetIsolate()));
   5923 }
   5924 
   5925 template<typename T>
   5926 void ReturnValue<T>::Set(uint32_t i) {
   5927   TYPE_CHECK(T, Integer);
   5928   typedef internal::Internals I;
   5929   // Can't simply use INT32_MAX here for whatever reason.
   5930   bool fits_into_int32_t = (i & (1U << 31)) == 0;
   5931   if (V8_LIKELY(fits_into_int32_t)) {
   5932     Set(static_cast<int32_t>(i));
   5933     return;
   5934   }
   5935   Set(Integer::NewFromUnsigned(i, GetIsolate()));
   5936 }
   5937 
   5938 template<typename T>
   5939 void ReturnValue<T>::Set(bool value) {
   5940   TYPE_CHECK(T, Boolean);
   5941   typedef internal::Internals I;
   5942   int root_index;
   5943   if (value) {
   5944     root_index = I::kTrueValueRootIndex;
   5945   } else {
   5946     root_index = I::kFalseValueRootIndex;
   5947   }
   5948   *value_ = *I::GetRoot(GetIsolate(), root_index);
   5949 }
   5950 
   5951 template<typename T>
   5952 void ReturnValue<T>::SetNull() {
   5953   TYPE_CHECK(T, Primitive);
   5954   typedef internal::Internals I;
   5955   *value_ = *I::GetRoot(GetIsolate(), I::kNullValueRootIndex);
   5956 }
   5957 
   5958 template<typename T>
   5959 void ReturnValue<T>::SetUndefined() {
   5960   TYPE_CHECK(T, Primitive);
   5961   typedef internal::Internals I;
   5962   *value_ = *I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex);
   5963 }
   5964 
   5965 template<typename T>
   5966 void ReturnValue<T>::SetEmptyString() {
   5967   TYPE_CHECK(T, String);
   5968   typedef internal::Internals I;
   5969   *value_ = *I::GetRoot(GetIsolate(), I::kEmptyStringRootIndex);
   5970 }
   5971 
   5972 template<typename T>
   5973 Isolate* ReturnValue<T>::GetIsolate() {
   5974   // Isolate is always the pointer below the default value on the stack.
   5975   return *reinterpret_cast<Isolate**>(&value_[-2]);
   5976 }
   5977 
   5978 template<typename T>
   5979 internal::Object* ReturnValue<T>::GetDefaultValue() {
   5980   // Default value is always the pointer below value_ on the stack.
   5981   return value_[-1];
   5982 }
   5983 
   5984 
   5985 template<typename T>
   5986 FunctionCallbackInfo<T>::FunctionCallbackInfo(internal::Object** implicit_args,
   5987                                               internal::Object** values,
   5988                                               int length,
   5989                                               bool is_construct_call)
   5990     : implicit_args_(implicit_args),
   5991       values_(values),
   5992       length_(length),
   5993       is_construct_call_(is_construct_call) { }
   5994 
   5995 
   5996 Arguments::Arguments(internal::Object** args,
   5997                      internal::Object** values,
   5998                      int length,
   5999                      bool is_construct_call)
   6000     : FunctionCallbackInfo<Value>(args, values, length, is_construct_call) { }
   6001 
   6002 
   6003 template<typename T>
   6004 Local<Value> FunctionCallbackInfo<T>::operator[](int i) const {
   6005   if (i < 0 || length_ <= i) return Local<Value>(*Undefined());
   6006   return Local<Value>(reinterpret_cast<Value*>(values_ - i));
   6007 }
   6008 
   6009 
   6010 template<typename T>
   6011 Local<Function> FunctionCallbackInfo<T>::Callee() const {
   6012   return Local<Function>(reinterpret_cast<Function*>(
   6013       &implicit_args_[kCalleeIndex]));
   6014 }
   6015 
   6016 
   6017 template<typename T>
   6018 Local<Object> FunctionCallbackInfo<T>::This() const {
   6019   return Local<Object>(reinterpret_cast<Object*>(values_ + 1));
   6020 }
   6021 
   6022 
   6023 template<typename T>
   6024 Local<Object> FunctionCallbackInfo<T>::Holder() const {
   6025   return Local<Object>(reinterpret_cast<Object*>(
   6026       &implicit_args_[kHolderIndex]));
   6027 }
   6028 
   6029 
   6030 template<typename T>
   6031 Local<Value> FunctionCallbackInfo<T>::Data() const {
   6032   return Local<Value>(reinterpret_cast<Value*>(&implicit_args_[kDataIndex]));
   6033 }
   6034 
   6035 
   6036 template<typename T>
   6037 Isolate* FunctionCallbackInfo<T>::GetIsolate() const {
   6038   return *reinterpret_cast<Isolate**>(&implicit_args_[kIsolateIndex]);
   6039 }
   6040 
   6041 
   6042 template<typename T>
   6043 ReturnValue<T> FunctionCallbackInfo<T>::GetReturnValue() const {
   6044   return ReturnValue<T>(&implicit_args_[kReturnValueIndex]);
   6045 }
   6046 
   6047 
   6048 template<typename T>
   6049 bool FunctionCallbackInfo<T>::IsConstructCall() const {
   6050   return is_construct_call_;
   6051 }
   6052 
   6053 
   6054 template<typename T>
   6055 int FunctionCallbackInfo<T>::Length() const {
   6056   return length_;
   6057 }
   6058 
   6059 
   6060 template <class T>
   6061 Local<T> HandleScope::Close(Handle<T> value) {
   6062   internal::Object** before = reinterpret_cast<internal::Object**>(*value);
   6063   internal::Object** after = RawClose(before);
   6064   return Local<T>(reinterpret_cast<T*>(after));
   6065 }
   6066 
   6067 Handle<Value> ScriptOrigin::ResourceName() const {
   6068   return resource_name_;
   6069 }
   6070 
   6071 
   6072 Handle<Integer> ScriptOrigin::ResourceLineOffset() const {
   6073   return resource_line_offset_;
   6074 }
   6075 
   6076 
   6077 Handle<Integer> ScriptOrigin::ResourceColumnOffset() const {
   6078   return resource_column_offset_;
   6079 }
   6080 
   6081 Handle<Boolean> ScriptOrigin::ResourceIsSharedCrossOrigin() const {
   6082   return resource_is_shared_cross_origin_;
   6083 }
   6084 
   6085 
   6086 Handle<Boolean> Boolean::New(bool value) {
   6087   return value ? True() : False();
   6088 }
   6089 
   6090 
   6091 void Template::Set(const char* name, v8::Handle<Data> value) {
   6092   Set(v8::String::New(name), value);
   6093 }
   6094 
   6095 
   6096 Local<Value> Object::GetInternalField(int index) {
   6097 #ifndef V8_ENABLE_CHECKS
   6098   typedef internal::Object O;
   6099   typedef internal::Internals I;
   6100   O* obj = *reinterpret_cast<O**>(this);
   6101   // Fast path: If the object is a plain JSObject, which is the common case, we
   6102   // know where to find the internal fields and can return the value directly.
   6103   if (I::GetInstanceType(obj) == I::kJSObjectType) {
   6104     int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
   6105     O* value = I::ReadField<O*>(obj, offset);
   6106     O** result = HandleScope::CreateHandle(value);
   6107     return Local<Value>(reinterpret_cast<Value*>(result));
   6108   }
   6109 #endif
   6110   return SlowGetInternalField(index);
   6111 }
   6112 
   6113 
   6114 void* Object::GetAlignedPointerFromInternalField(int index) {
   6115 #ifndef V8_ENABLE_CHECKS
   6116   typedef internal::Object O;
   6117   typedef internal::Internals I;
   6118   O* obj = *reinterpret_cast<O**>(this);
   6119   // Fast path: If the object is a plain JSObject, which is the common case, we
   6120   // know where to find the internal fields and can return the value directly.
   6121   if (V8_LIKELY(I::GetInstanceType(obj) == I::kJSObjectType)) {
   6122     int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
   6123     return I::ReadField<void*>(obj, offset);
   6124   }
   6125 #endif
   6126   return SlowGetAlignedPointerFromInternalField(index);
   6127 }
   6128 
   6129 
   6130 String* String::Cast(v8::Value* value) {
   6131 #ifdef V8_ENABLE_CHECKS
   6132   CheckCast(value);
   6133 #endif
   6134   return static_cast<String*>(value);
   6135 }
   6136 
   6137 
   6138 Local<String> String::Empty(Isolate* isolate) {
   6139   typedef internal::Object* S;
   6140   typedef internal::Internals I;
   6141   I::CheckInitialized(isolate);
   6142   S* slot = I::GetRoot(isolate, I::kEmptyStringRootIndex);
   6143   return Local<String>(reinterpret_cast<String*>(slot));
   6144 }
   6145 
   6146 
   6147 Local<String> String::New(const char* data, int length) {
   6148   return NewFromUtf8(Isolate::GetCurrent(), data, kNormalString, length);
   6149 }
   6150 
   6151 
   6152 Local<String> String::New(const uint16_t* data, int length) {
   6153   return NewFromTwoByte(Isolate::GetCurrent(), data, kNormalString, length);
   6154 }
   6155 
   6156 
   6157 Local<String> String::NewSymbol(const char* data, int length) {
   6158   return NewFromUtf8(Isolate::GetCurrent(), data, kInternalizedString, length);
   6159 }
   6160 
   6161 
   6162 Local<String> String::NewUndetectable(const char* data, int length) {
   6163   return NewFromUtf8(Isolate::GetCurrent(), data, kUndetectableString, length);
   6164 }
   6165 
   6166 
   6167 Local<String> String::NewUndetectable(const uint16_t* data, int length) {
   6168   return NewFromTwoByte(
   6169       Isolate::GetCurrent(), data, kUndetectableString, length);
   6170 }
   6171 
   6172 
   6173 String::ExternalStringResource* String::GetExternalStringResource() const {
   6174   typedef internal::Object O;
   6175   typedef internal::Internals I;
   6176   O* obj = *reinterpret_cast<O**>(const_cast<String*>(this));
   6177   String::ExternalStringResource* result;
   6178   if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) {
   6179     void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
   6180     result = reinterpret_cast<String::ExternalStringResource*>(value);
   6181   } else {
   6182     result = NULL;
   6183   }
   6184 #ifdef V8_ENABLE_CHECKS
   6185   VerifyExternalStringResource(result);
   6186 #endif
   6187   return result;
   6188 }
   6189 
   6190 
   6191 String::ExternalStringResourceBase* String::GetExternalStringResourceBase(
   6192     String::Encoding* encoding_out) const {
   6193   typedef internal::Object O;
   6194   typedef internal::Internals I;
   6195   O* obj = *reinterpret_cast<O**>(const_cast<String*>(this));
   6196   int type = I::GetInstanceType(obj) & I::kFullStringRepresentationMask;
   6197   *encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask);
   6198   ExternalStringResourceBase* resource = NULL;
   6199   if (type == I::kExternalAsciiRepresentationTag ||
   6200       type == I::kExternalTwoByteRepresentationTag) {
   6201     void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
   6202     resource = static_cast<ExternalStringResourceBase*>(value);
   6203   }
   6204 #ifdef V8_ENABLE_CHECKS
   6205     VerifyExternalStringResourceBase(resource, *encoding_out);
   6206 #endif
   6207   return resource;
   6208 }
   6209 
   6210 
   6211 bool Value::IsUndefined() const {
   6212 #ifdef V8_ENABLE_CHECKS
   6213   return FullIsUndefined();
   6214 #else
   6215   return QuickIsUndefined();
   6216 #endif
   6217 }
   6218 
   6219 bool Value::QuickIsUndefined() const {
   6220   typedef internal::Object O;
   6221   typedef internal::Internals I;
   6222   O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this));
   6223   if (!I::HasHeapObjectTag(obj)) return false;
   6224   if (I::GetInstanceType(obj) != I::kOddballType) return false;
   6225   return (I::GetOddballKind(obj) == I::kUndefinedOddballKind);
   6226 }
   6227 
   6228 
   6229 bool Value::IsNull() const {
   6230 #ifdef V8_ENABLE_CHECKS
   6231   return FullIsNull();
   6232 #else
   6233   return QuickIsNull();
   6234 #endif
   6235 }
   6236 
   6237 bool Value::QuickIsNull() const {
   6238   typedef internal::Object O;
   6239   typedef internal::Internals I;
   6240   O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this));
   6241   if (!I::HasHeapObjectTag(obj)) return false;
   6242   if (I::GetInstanceType(obj) != I::kOddballType) return false;
   6243   return (I::GetOddballKind(obj) == I::kNullOddballKind);
   6244 }
   6245 
   6246 
   6247 bool Value::IsString() const {
   6248 #ifdef V8_ENABLE_CHECKS
   6249   return FullIsString();
   6250 #else
   6251   return QuickIsString();
   6252 #endif
   6253 }
   6254 
   6255 bool Value::QuickIsString() const {
   6256   typedef internal::Object O;
   6257   typedef internal::Internals I;
   6258   O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this));
   6259   if (!I::HasHeapObjectTag(obj)) return false;
   6260   return (I::GetInstanceType(obj) < I::kFirstNonstringType);
   6261 }
   6262 
   6263 
   6264 template <class T> Value* Value::Cast(T* value) {
   6265   return static_cast<Value*>(value);
   6266 }
   6267 
   6268 
   6269 Symbol* Symbol::Cast(v8::Value* value) {
   6270 #ifdef V8_ENABLE_CHECKS
   6271   CheckCast(value);
   6272 #endif
   6273   return static_cast<Symbol*>(value);
   6274 }
   6275 
   6276 
   6277 Number* Number::Cast(v8::Value* value) {
   6278 #ifdef V8_ENABLE_CHECKS
   6279   CheckCast(value);
   6280 #endif
   6281   return static_cast<Number*>(value);
   6282 }
   6283 
   6284 
   6285 Integer* Integer::Cast(v8::Value* value) {
   6286 #ifdef V8_ENABLE_CHECKS
   6287   CheckCast(value);
   6288 #endif
   6289   return static_cast<Integer*>(value);
   6290 }
   6291 
   6292 
   6293 Date* Date::Cast(v8::Value* value) {
   6294 #ifdef V8_ENABLE_CHECKS
   6295   CheckCast(value);
   6296 #endif
   6297   return static_cast<Date*>(value);
   6298 }
   6299 
   6300 
   6301 StringObject* StringObject::Cast(v8::Value* value) {
   6302 #ifdef V8_ENABLE_CHECKS
   6303   CheckCast(value);
   6304 #endif
   6305   return static_cast<StringObject*>(value);
   6306 }
   6307 
   6308 
   6309 SymbolObject* SymbolObject::Cast(v8::Value* value) {
   6310 #ifdef V8_ENABLE_CHECKS
   6311   CheckCast(value);
   6312 #endif
   6313   return static_cast<SymbolObject*>(value);
   6314 }
   6315 
   6316 
   6317 NumberObject* NumberObject::Cast(v8::Value* value) {
   6318 #ifdef V8_ENABLE_CHECKS
   6319   CheckCast(value);
   6320 #endif
   6321   return static_cast<NumberObject*>(value);
   6322 }
   6323 
   6324 
   6325 BooleanObject* BooleanObject::Cast(v8::Value* value) {
   6326 #ifdef V8_ENABLE_CHECKS
   6327   CheckCast(value);
   6328 #endif
   6329   return static_cast<BooleanObject*>(value);
   6330 }
   6331 
   6332 
   6333 RegExp* RegExp::Cast(v8::Value* value) {
   6334 #ifdef V8_ENABLE_CHECKS
   6335   CheckCast(value);
   6336 #endif
   6337   return static_cast<RegExp*>(value);
   6338 }
   6339 
   6340 
   6341 Object* Object::Cast(v8::Value* value) {
   6342 #ifdef V8_ENABLE_CHECKS
   6343   CheckCast(value);
   6344 #endif
   6345   return static_cast<Object*>(value);
   6346 }
   6347 
   6348 
   6349 Array* Array::Cast(v8::Value* value) {
   6350 #ifdef V8_ENABLE_CHECKS
   6351   CheckCast(value);
   6352 #endif
   6353   return static_cast<Array*>(value);
   6354 }
   6355 
   6356 
   6357 ArrayBuffer* ArrayBuffer::Cast(v8::Value* value) {
   6358 #ifdef V8_ENABLE_CHECKS
   6359   CheckCast(value);
   6360 #endif
   6361   return static_cast<ArrayBuffer*>(value);
   6362 }
   6363 
   6364 
   6365 ArrayBufferView* ArrayBufferView::Cast(v8::Value* value) {
   6366 #ifdef V8_ENABLE_CHECKS
   6367   CheckCast(value);
   6368 #endif
   6369   return static_cast<ArrayBufferView*>(value);
   6370 }
   6371 
   6372 
   6373 TypedArray* TypedArray::Cast(v8::Value* value) {
   6374 #ifdef V8_ENABLE_CHECKS
   6375   CheckCast(value);
   6376 #endif
   6377   return static_cast<TypedArray*>(value);
   6378 }
   6379 
   6380 
   6381 Uint8Array* Uint8Array::Cast(v8::Value* value) {
   6382 #ifdef V8_ENABLE_CHECKS
   6383   CheckCast(value);
   6384 #endif
   6385   return static_cast<Uint8Array*>(value);
   6386 }
   6387 
   6388 
   6389 Int8Array* Int8Array::Cast(v8::Value* value) {
   6390 #ifdef V8_ENABLE_CHECKS
   6391   CheckCast(value);
   6392 #endif
   6393   return static_cast<Int8Array*>(value);
   6394 }
   6395 
   6396 
   6397 Uint16Array* Uint16Array::Cast(v8::Value* value) {
   6398 #ifdef V8_ENABLE_CHECKS
   6399   CheckCast(value);
   6400 #endif
   6401   return static_cast<Uint16Array*>(value);
   6402 }
   6403 
   6404 
   6405 Int16Array* Int16Array::Cast(v8::Value* value) {
   6406 #ifdef V8_ENABLE_CHECKS
   6407   CheckCast(value);
   6408 #endif
   6409   return static_cast<Int16Array*>(value);
   6410 }
   6411 
   6412 
   6413 Uint32Array* Uint32Array::Cast(v8::Value* value) {
   6414 #ifdef V8_ENABLE_CHECKS
   6415   CheckCast(value);
   6416 #endif
   6417   return static_cast<Uint32Array*>(value);
   6418 }
   6419 
   6420 
   6421 Int32Array* Int32Array::Cast(v8::Value* value) {
   6422 #ifdef V8_ENABLE_CHECKS
   6423   CheckCast(value);
   6424 #endif
   6425   return static_cast<Int32Array*>(value);
   6426 }
   6427 
   6428 
   6429 Float32Array* Float32Array::Cast(v8::Value* value) {
   6430 #ifdef V8_ENABLE_CHECKS
   6431   CheckCast(value);
   6432 #endif
   6433   return static_cast<Float32Array*>(value);
   6434 }
   6435 
   6436 
   6437 Float64Array* Float64Array::Cast(v8::Value* value) {
   6438 #ifdef V8_ENABLE_CHECKS
   6439   CheckCast(value);
   6440 #endif
   6441   return static_cast<Float64Array*>(value);
   6442 }
   6443 
   6444 
   6445 Uint8ClampedArray* Uint8ClampedArray::Cast(v8::Value* value) {
   6446 #ifdef V8_ENABLE_CHECKS
   6447   CheckCast(value);
   6448 #endif
   6449   return static_cast<Uint8ClampedArray*>(value);
   6450 }
   6451 
   6452 
   6453 DataView* DataView::Cast(v8::Value* value) {
   6454 #ifdef V8_ENABLE_CHECKS
   6455   CheckCast(value);
   6456 #endif
   6457   return static_cast<DataView*>(value);
   6458 }
   6459 
   6460 
   6461 Function* Function::Cast(v8::Value* value) {
   6462 #ifdef V8_ENABLE_CHECKS
   6463   CheckCast(value);
   6464 #endif
   6465   return static_cast<Function*>(value);
   6466 }
   6467 
   6468 
   6469 External* External::Cast(v8::Value* value) {
   6470 #ifdef V8_ENABLE_CHECKS
   6471   CheckCast(value);
   6472 #endif
   6473   return static_cast<External*>(value);
   6474 }
   6475 
   6476 
   6477 template<typename T>
   6478 Isolate* PropertyCallbackInfo<T>::GetIsolate() const {
   6479   return *reinterpret_cast<Isolate**>(&args_[kIsolateIndex]);
   6480 }
   6481 
   6482 
   6483 template<typename T>
   6484 Local<Value> PropertyCallbackInfo<T>::Data() const {
   6485   return Local<Value>(reinterpret_cast<Value*>(&args_[kDataIndex]));
   6486 }
   6487 
   6488 
   6489 template<typename T>
   6490 Local<Object> PropertyCallbackInfo<T>::This() const {
   6491   return Local<Object>(reinterpret_cast<Object*>(&args_[kThisIndex]));
   6492 }
   6493 
   6494 
   6495 template<typename T>
   6496 Local<Object> PropertyCallbackInfo<T>::Holder() const {
   6497   return Local<Object>(reinterpret_cast<Object*>(&args_[kHolderIndex]));
   6498 }
   6499 
   6500 
   6501 template<typename T>
   6502 ReturnValue<T> PropertyCallbackInfo<T>::GetReturnValue() const {
   6503   return ReturnValue<T>(&args_[kReturnValueIndex]);
   6504 }
   6505 
   6506 
   6507 Handle<Primitive> Undefined(Isolate* isolate) {
   6508   typedef internal::Object* S;
   6509   typedef internal::Internals I;
   6510   I::CheckInitialized(isolate);
   6511   S* slot = I::GetRoot(isolate, I::kUndefinedValueRootIndex);
   6512   return Handle<Primitive>(reinterpret_cast<Primitive*>(slot));
   6513 }
   6514 
   6515 
   6516 Handle<Primitive> Null(Isolate* isolate) {
   6517   typedef internal::Object* S;
   6518   typedef internal::Internals I;
   6519   I::CheckInitialized(isolate);
   6520   S* slot = I::GetRoot(isolate, I::kNullValueRootIndex);
   6521   return Handle<Primitive>(reinterpret_cast<Primitive*>(slot));
   6522 }
   6523 
   6524 
   6525 Handle<Boolean> True(Isolate* isolate) {
   6526   typedef internal::Object* S;
   6527   typedef internal::Internals I;
   6528   I::CheckInitialized(isolate);
   6529   S* slot = I::GetRoot(isolate, I::kTrueValueRootIndex);
   6530   return Handle<Boolean>(reinterpret_cast<Boolean*>(slot));
   6531 }
   6532 
   6533 
   6534 Handle<Boolean> False(Isolate* isolate) {
   6535   typedef internal::Object* S;
   6536   typedef internal::Internals I;
   6537   I::CheckInitialized(isolate);
   6538   S* slot = I::GetRoot(isolate, I::kFalseValueRootIndex);
   6539   return Handle<Boolean>(reinterpret_cast<Boolean*>(slot));
   6540 }
   6541 
   6542 
   6543 void Isolate::SetData(void* data) {
   6544   typedef internal::Internals I;
   6545   I::SetEmbedderData(this, data);
   6546 }
   6547 
   6548 
   6549 void* Isolate::GetData() {
   6550   typedef internal::Internals I;
   6551   return I::GetEmbedderData(this);
   6552 }
   6553 
   6554 
   6555 Local<Value> Context::GetEmbedderData(int index) {
   6556 #ifndef V8_ENABLE_CHECKS
   6557   typedef internal::Object O;
   6558   typedef internal::Internals I;
   6559   O** result = HandleScope::CreateHandle(I::ReadEmbedderData<O*>(this, index));
   6560   return Local<Value>(reinterpret_cast<Value*>(result));
   6561 #else
   6562   return SlowGetEmbedderData(index);
   6563 #endif
   6564 }
   6565 
   6566 
   6567 void* Context::GetAlignedPointerFromEmbedderData(int index) {
   6568 #ifndef V8_ENABLE_CHECKS
   6569   typedef internal::Internals I;
   6570   return I::ReadEmbedderData<void*>(this, index);
   6571 #else
   6572   return SlowGetAlignedPointerFromEmbedderData(index);
   6573 #endif
   6574 }
   6575 
   6576 
   6577 /**
   6578  * \example shell.cc
   6579  * A simple shell that takes a list of expressions on the
   6580  * command-line and executes them.
   6581  */
   6582 
   6583 
   6584 /**
   6585  * \example process.cc
   6586  */
   6587 
   6588 
   6589 }  // namespace v8
   6590 
   6591 
   6592 #undef TYPE_CHECK
   6593 
   6594 
   6595 #endif  // V8_H_
   6596