diff options
Diffstat (limited to 'chromium/v8/include/v8.h')
-rw-r--r-- | chromium/v8/include/v8.h | 1238 |
1 files changed, 775 insertions, 463 deletions
diff --git a/chromium/v8/include/v8.h b/chromium/v8/include/v8.h index de2733838ff..9bf96081d5a 100644 --- a/chromium/v8/include/v8.h +++ b/chromium/v8/include/v8.h @@ -105,6 +105,7 @@ class NumberObject; class Object; class ObjectOperationDescriptor; class ObjectTemplate; +class Platform; class Primitive; class RawOperationDescriptor; class Signature; @@ -114,6 +115,7 @@ class String; class StringObject; class Symbol; class SymbolObject; +class Private; class Uint32; class Utils; class Value; @@ -121,8 +123,10 @@ template <class T> class Handle; template <class T> class Local; template <class T> class Eternal; template<class T> class NonCopyablePersistentTraits; +template<class T> class PersistentBase; template<class T, class M = NonCopyablePersistentTraits<T> > class Persistent; +template<class T> class UniquePersistent; template<class T, class P> class WeakCallbackObject; class FunctionTemplate; class ObjectTemplate; @@ -135,6 +139,7 @@ class DeclaredAccessorDescriptor; class ObjectOperationDescriptor; class RawOperationDescriptor; class CallHandlerHelper; +class EscapableHandleScope; namespace internal { class Arguments; @@ -254,17 +259,17 @@ template <class T> class Handle { * The handles' references are not checked. */ template <class S> V8_INLINE bool operator==(const Handle<S>& that) const { - internal::Object** a = reinterpret_cast<internal::Object**>(**this); - internal::Object** b = reinterpret_cast<internal::Object**>(*that); + internal::Object** a = reinterpret_cast<internal::Object**>(this->val_); + internal::Object** b = reinterpret_cast<internal::Object**>(that.val_); if (a == 0) return b == 0; if (b == 0) return false; return *a == *b; } template <class S> V8_INLINE bool operator==( - const Persistent<S>& that) const { - internal::Object** a = reinterpret_cast<internal::Object**>(**this); - internal::Object** b = reinterpret_cast<internal::Object**>(*that); + const PersistentBase<S>& that) const { + internal::Object** a = reinterpret_cast<internal::Object**>(this->val_); + internal::Object** b = reinterpret_cast<internal::Object**>(that.val_); if (a == 0) return b == 0; if (b == 0) return false; return *a == *b; @@ -301,7 +306,8 @@ template <class T> class Handle { V8_INLINE static Handle<T> New(Isolate* isolate, Handle<T> that) { return New(isolate, that.val_); } - V8_INLINE static Handle<T> New(Isolate* isolate, const Persistent<T>& that) { + V8_INLINE static Handle<T> New(Isolate* isolate, + const PersistentBase<T>& that) { return New(isolate, that.val_); } @@ -317,6 +323,8 @@ template <class T> class Handle { private: friend class Utils; template<class F, class M> friend class Persistent; + template<class F> friend class PersistentBase; + template<class F> friend class Handle; template<class F> friend class Local; template<class F> friend class FunctionCallbackInfo; template<class F> friend class PropertyCallbackInfo; @@ -327,6 +335,8 @@ template <class T> class Handle { friend Handle<Boolean> False(Isolate* isolate); friend class Context; friend class HandleScope; + friend class Object; + friend class Private; V8_INLINE static Handle<T> New(Isolate* isolate, T* that); @@ -377,11 +387,9 @@ template <class T> class Local : public Handle<T> { * The referee is kept alive by the local handle even when * the original handle is destroyed/disposed. */ - V8_INLINE static Local<T> New(Handle<T> that); V8_INLINE static Local<T> New(Isolate* isolate, Handle<T> that); - template<class M> V8_INLINE static Local<T> New(Isolate* isolate, - const Persistent<T, M>& that); + const PersistentBase<T>& that); #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR @@ -392,8 +400,10 @@ template <class T> class Local : public Handle<T> { private: friend class Utils; template<class F> friend class Eternal; + template<class F> friend class PersistentBase; template<class F, class M> friend class Persistent; template<class F> friend class Handle; + template<class F> friend class Local; template<class F> friend class FunctionCallbackInfo; template<class F> friend class PropertyCallbackInfo; friend class String; @@ -401,6 +411,7 @@ template <class T> class Local : public Handle<T> { friend class Context; template<class F> friend class internal::CustomArguments; friend class HandleScope; + friend class EscapableHandleScope; V8_INLINE static Local<T> New(Isolate* isolate, T* that); }; @@ -457,100 +468,21 @@ class WeakReferenceCallbacks { /** - * Default traits for Persistent. This class does not allow - * use of the copy constructor or assignment operator. - * At present kResetInDestructor is not set, but that will change in a future - * version. - */ -template<class T> -class NonCopyablePersistentTraits { - public: - typedef Persistent<T, NonCopyablePersistentTraits<T> > NonCopyablePersistent; - static const bool kResetInDestructor = false; - template<class S, class M> - V8_INLINE static void Copy(const Persistent<S, M>& source, - NonCopyablePersistent* dest) { - Uncompilable<Object>(); - } - // TODO(dcarney): come up with a good compile error here. - template<class O> V8_INLINE static void Uncompilable() { - TYPE_CHECK(O, Primitive); - } -}; - - -/** * An object reference that is independent of any handle scope. Where * a Local handle only lives as long as the HandleScope in which it was - * allocated, a Persistent handle remains valid until it is explicitly + * allocated, a PersistentBase handle remains valid until it is explicitly * disposed. * * A persistent handle contains a reference to a storage cell within * the v8 engine which holds an object value and which is updated by * the garbage collector whenever the object is moved. A new storage - * cell can be created using the constructor or Persistent::Reset and - * existing handles can be disposed using Persistent::Reset. + * cell can be created using the constructor or PersistentBase::Reset and + * existing handles can be disposed using PersistentBase::Reset. * - * Copy, assignment and destructor bevavior is controlled by the traits - * class M. */ -template <class T, class M> class Persistent { +template <class T> class PersistentBase { public: /** - * A Persistent with no storage cell. - */ - V8_INLINE Persistent() : val_(0) { } - /** - * Construct a Persistent from a Handle. - * When the Handle is non-empty, a new storage cell is created - * pointing to the same object, and no flags are set. - */ - template <class S> V8_INLINE Persistent(Isolate* isolate, Handle<S> that) - : val_(New(isolate, *that)) { - TYPE_CHECK(T, S); - } - /** - * Construct a Persistent from a Persistent. - * When the Persistent is non-empty, a new storage cell is created - * pointing to the same object, and no flags are set. - */ - template <class S, class M2> - V8_INLINE Persistent(Isolate* isolate, const Persistent<S, M2>& that) - : val_(New(isolate, *that)) { - TYPE_CHECK(T, S); - } - /** - * The copy constructors and assignment operator create a Persistent - * exactly as the Persistent constructor, but the Copy function from the - * traits class is called, allowing the setting of flags based on the - * copied Persistent. - */ - V8_INLINE Persistent(const Persistent& that) : val_(0) { - Copy(that); - } - template <class S, class M2> - V8_INLINE Persistent(const Persistent<S, M2>& that) : val_(0) { - Copy(that); - } - V8_INLINE Persistent& operator=(const Persistent& that) { // NOLINT - Copy(that); - return *this; - } - template <class S, class M2> - V8_INLINE Persistent& operator=(const Persistent<S, M2>& that) { // NOLINT - Copy(that); - return *this; - } - /** - * The destructor will dispose the Persistent based on the - * kResetInDestructor flags in the traits class. Since not calling dispose - * can result in a memory leak, it is recommended to always set this flag. - */ - V8_INLINE ~Persistent() { - if (M::kResetInDestructor) Reset(); - } - - /** * If non-empty, destroy the underlying storage cell * IsEmpty() will return true after this call. */ @@ -561,53 +493,35 @@ template <class T, class M> class Persistent { */ template <class S> V8_INLINE void Reset(Isolate* isolate, const Handle<S>& other); + /** * If non-empty, destroy the underlying storage cell * and create a new one with the contents of other if other is non empty */ - template <class S, class M2> - V8_INLINE void Reset(Isolate* isolate, const Persistent<S, M2>& other); - // TODO(dcarney): deprecate - V8_INLINE void Dispose() { Reset(); } - V8_DEPRECATED(V8_INLINE void Dispose(Isolate* isolate)) { Reset(); } + template <class S> + V8_INLINE void Reset(Isolate* isolate, const PersistentBase<S>& other); V8_INLINE bool IsEmpty() const { return val_ == 0; } - // TODO(dcarney): this is pretty useless, fix or remove template <class S> - V8_INLINE static Persistent<T>& Cast(Persistent<S>& that) { // NOLINT -#ifdef V8_ENABLE_CHECKS - // If we're going to perform the type check then we have to check - // that the handle isn't empty before doing the checked cast. - if (!that.IsEmpty()) T::Cast(*that); -#endif - return reinterpret_cast<Persistent<T>&>(that); - } - - // TODO(dcarney): this is pretty useless, fix or remove - template <class S> V8_INLINE Persistent<S>& As() { // NOLINT - return Persistent<S>::Cast(*this); - } - - template <class S, class M2> - V8_INLINE bool operator==(const Persistent<S, M2>& that) const { - internal::Object** a = reinterpret_cast<internal::Object**>(**this); - internal::Object** b = reinterpret_cast<internal::Object**>(*that); + V8_INLINE bool operator==(const PersistentBase<S>& that) const { + internal::Object** a = reinterpret_cast<internal::Object**>(this->val_); + internal::Object** b = reinterpret_cast<internal::Object**>(that.val_); if (a == 0) return b == 0; if (b == 0) return false; return *a == *b; } template <class S> V8_INLINE bool operator==(const Handle<S>& that) const { - internal::Object** a = reinterpret_cast<internal::Object**>(**this); - internal::Object** b = reinterpret_cast<internal::Object**>(*that); + internal::Object** a = reinterpret_cast<internal::Object**>(this->val_); + internal::Object** b = reinterpret_cast<internal::Object**>(that.val_); if (a == 0) return b == 0; if (b == 0) return false; return *a == *b; } - template <class S, class M2> - V8_INLINE bool operator!=(const Persistent<S, M2>& that) const { + template <class S> + V8_INLINE bool operator!=(const PersistentBase<S>& that) const { return !operator==(that); } @@ -625,22 +539,8 @@ template <class T, class M> class Persistent { P* parameter, typename WeakCallbackData<S, P>::Callback callback); - // TODO(dcarney): deprecate - template<typename S, typename P> - V8_INLINE void MakeWeak( - P* parameter, - typename WeakReferenceCallbacks<S, P>::Revivable callback); - - // TODO(dcarney): deprecate - template<typename P> - V8_INLINE void MakeWeak( - P* parameter, - typename WeakReferenceCallbacks<T, P>::Revivable callback); - V8_INLINE void ClearWeak(); - V8_DEPRECATED(V8_INLINE void ClearWeak(Isolate* isolate)) { ClearWeak(); } - /** * Marks the reference to this object independent. Garbage collector is free * to ignore any object groups containing this object. Weak callback for an @@ -649,10 +549,6 @@ template <class T, class M> class Persistent { */ V8_INLINE void MarkIndependent(); - V8_DEPRECATED(V8_INLINE void MarkIndependent(Isolate* isolate)) { - MarkIndependent(); - } - /** * Marks the reference to this object partially dependent. Partially dependent * handles only depend on other partially dependent handles and these @@ -663,80 +559,279 @@ template <class T, class M> class Persistent { */ V8_INLINE void MarkPartiallyDependent(); - V8_DEPRECATED(V8_INLINE void MarkPartiallyDependent(Isolate* isolate)) { - MarkPartiallyDependent(); - } - V8_INLINE bool IsIndependent() const; - V8_DEPRECATED(V8_INLINE bool IsIndependent(Isolate* isolate) const) { - return IsIndependent(); - } - /** Checks if the handle holds the only reference to an object. */ V8_INLINE bool IsNearDeath() const; - V8_DEPRECATED(V8_INLINE bool IsNearDeath(Isolate* isolate) const) { - return IsNearDeath(); - } - /** Returns true if the handle's reference is weak. */ V8_INLINE bool IsWeak() const; - V8_DEPRECATED(V8_INLINE bool IsWeak(Isolate* isolate) const) { - return IsWeak(); - } - /** * Assigns a wrapper class ID to the handle. See RetainedObjectInfo interface * description in v8-profiler.h for details. */ V8_INLINE void SetWrapperClassId(uint16_t class_id); - V8_DEPRECATED( - V8_INLINE void SetWrapperClassId(Isolate * isolate, uint16_t class_id)) { - SetWrapperClassId(class_id); - } - /** * Returns the class ID previously assigned to this handle or 0 if no class ID * was previously assigned. */ V8_INLINE uint16_t WrapperClassId() const; - V8_DEPRECATED(V8_INLINE uint16_t WrapperClassId(Isolate* isolate) const) { - return WrapperClassId(); + private: + friend class Isolate; + friend class Utils; + template<class F> friend class Handle; + template<class F> friend class Local; + template<class F1, class F2> friend class Persistent; + template<class F> friend class UniquePersistent; + template<class F> friend class PersistentBase; + template<class F> friend class ReturnValue; + + explicit V8_INLINE PersistentBase(T* val) : val_(val) {} + PersistentBase(PersistentBase& other); // NOLINT + void operator=(PersistentBase&); + V8_INLINE static T* New(Isolate* isolate, T* that); + + T* val_; +}; + + +/** + * Default traits for Persistent. This class does not allow + * use of the copy constructor or assignment operator. + * At present kResetInDestructor is not set, but that will change in a future + * version. + */ +template<class T> +class NonCopyablePersistentTraits { + public: + typedef Persistent<T, NonCopyablePersistentTraits<T> > NonCopyablePersistent; + static const bool kResetInDestructor = false; + template<class S, class M> + V8_INLINE static void Copy(const Persistent<S, M>& source, + NonCopyablePersistent* dest) { + Uncompilable<Object>(); + } + // TODO(dcarney): come up with a good compile error here. + template<class O> V8_INLINE static void Uncompilable() { + TYPE_CHECK(O, Primitive); + } +}; + + +/** + * Helper class traits to allow copying and assignment of Persistent. + * This will clone the contents of storage cell, but not any of the flags, etc. + */ +template<class T> +struct CopyablePersistentTraits { + typedef Persistent<T, CopyablePersistentTraits<T> > CopyablePersistent; + static const bool kResetInDestructor = true; + template<class S, class M> + static V8_INLINE void Copy(const Persistent<S, M>& source, + CopyablePersistent* dest) { + // do nothing, just allow copy } +}; - // TODO(dcarney): remove + +/** + * A PersistentBase which allows copy and assignment. + * + * Copy, assignment and destructor bevavior is controlled by the traits + * class M. + * + * Note: Persistent class hierarchy is subject to future changes. + */ +template <class T, class M> class Persistent : public PersistentBase<T> { + public: + /** + * A Persistent with no storage cell. + */ + V8_INLINE Persistent() : PersistentBase<T>(0) { } + /** + * Construct a Persistent from a Handle. + * When the Handle is non-empty, a new storage cell is created + * pointing to the same object, and no flags are set. + */ + template <class S> V8_INLINE Persistent(Isolate* isolate, Handle<S> that) + : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) { + TYPE_CHECK(T, S); + } + /** + * Construct a Persistent from a Persistent. + * When the Persistent is non-empty, a new storage cell is created + * pointing to the same object, and no flags are set. + */ + template <class S, class M2> + V8_INLINE Persistent(Isolate* isolate, const Persistent<S, M2>& that) + : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) { + TYPE_CHECK(T, S); + } + /** + * The copy constructors and assignment operator create a Persistent + * exactly as the Persistent constructor, but the Copy function from the + * traits class is called, allowing the setting of flags based on the + * copied Persistent. + */ + V8_INLINE Persistent(const Persistent& that) : PersistentBase<T>(0) { + Copy(that); + } + template <class S, class M2> + V8_INLINE Persistent(const Persistent<S, M2>& that) : PersistentBase<T>(0) { + Copy(that); + } + V8_INLINE Persistent& operator=(const Persistent& that) { // NOLINT + Copy(that); + return *this; + } + template <class S, class M2> + V8_INLINE Persistent& operator=(const Persistent<S, M2>& that) { // NOLINT + Copy(that); + return *this; + } + /** + * The destructor will dispose the Persistent based on the + * kResetInDestructor flags in the traits class. Since not calling dispose + * can result in a memory leak, it is recommended to always set this flag. + */ + V8_INLINE ~Persistent() { + if (M::kResetInDestructor) this->Reset(); + } + + V8_DEPRECATED("Use Reset instead", + V8_INLINE void Dispose()) { this->Reset(); } + + // TODO(dcarney): this is pretty useless, fix or remove + template <class S> + V8_INLINE static Persistent<T>& Cast(Persistent<S>& that) { // NOLINT +#ifdef V8_ENABLE_CHECKS + // If we're going to perform the type check then we have to check + // that the handle isn't empty before doing the checked cast. + if (!that.IsEmpty()) T::Cast(*that); +#endif + return reinterpret_cast<Persistent<T>&>(that); + } + + // TODO(dcarney): this is pretty useless, fix or remove + template <class S> V8_INLINE Persistent<S>& As() { // NOLINT + return Persistent<S>::Cast(*this); + } + + template<typename S, typename P> + V8_DEPRECATED( + "Use SetWeak instead", + V8_INLINE void MakeWeak( + P* parameter, + typename WeakReferenceCallbacks<S, P>::Revivable callback)); + + template<typename P> + V8_DEPRECATED( + "Use SetWeak instead", + V8_INLINE void MakeWeak( + P* parameter, + typename WeakReferenceCallbacks<T, P>::Revivable callback)); + + // This will be removed. V8_INLINE T* ClearAndLeak(); - // TODO(dcarney): remove - V8_INLINE void Clear() { val_ = 0; } + V8_DEPRECATED("This will be removed", + V8_INLINE void Clear()) { this->val_ = 0; } // TODO(dcarney): remove #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR private: #endif - template <class S> V8_INLINE Persistent(S* that) : val_(that) { } + template <class S> V8_INLINE Persistent(S* that) : PersistentBase<T>(that) { } - V8_INLINE T* operator*() const { return val_; } + V8_INLINE T* operator*() const { return this->val_; } private: + friend class Isolate; friend class Utils; template<class F> friend class Handle; template<class F> friend class Local; template<class F1, class F2> friend class Persistent; template<class F> friend class ReturnValue; - V8_INLINE static T* New(Isolate* isolate, T* that); template<class S, class M2> V8_INLINE void Copy(const Persistent<S, M2>& that); +}; - T* val_; + +/** + * A PersistentBase which has move semantics. + * + * Note: Persistent class hierarchy is subject to future changes. + */ +template<class T> +class UniquePersistent : public PersistentBase<T> { + struct RValue { + V8_INLINE explicit RValue(UniquePersistent* object) : object(object) {} + UniquePersistent* object; + }; + + public: + /** + * A UniquePersistent with no storage cell. + */ + V8_INLINE UniquePersistent() : PersistentBase<T>(0) { } + /** + * Construct a UniquePersistent from a Handle. + * When the Handle is non-empty, a new storage cell is created + * pointing to the same object, and no flags are set. + */ + template <class S> + V8_INLINE UniquePersistent(Isolate* isolate, Handle<S> that) + : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) { + TYPE_CHECK(T, S); + } + /** + * Construct a UniquePersistent from a PersistentBase. + * When the Persistent is non-empty, a new storage cell is created + * pointing to the same object, and no flags are set. + */ + template <class S> + V8_INLINE UniquePersistent(Isolate* isolate, const PersistentBase<S>& that) + : PersistentBase<T>(PersistentBase<T>::New(isolate, that.val_)) { + TYPE_CHECK(T, S); + } + /** + * Move constructor. + */ + V8_INLINE UniquePersistent(RValue rvalue) + : PersistentBase<T>(rvalue.object->val_) { + rvalue.object->val_ = 0; + } + V8_INLINE ~UniquePersistent() { this->Reset(); } + /** + * Move via assignment. + */ + template<class S> + V8_INLINE UniquePersistent& operator=(UniquePersistent<S> rhs) { + TYPE_CHECK(T, S); + this->val_ = rhs.val_; + rhs.val_ = 0; + return *this; + } + /** + * Cast operator for moves. + */ + V8_INLINE operator RValue() { return RValue(this); } + /** + * Pass allows returning uniques from functions, etc. + */ + V8_INLINE UniquePersistent Pass() { return UniquePersistent(RValue(this)); } + + private: + UniquePersistent(UniquePersistent&); + void operator=(UniquePersistent&); }; + /** * A stack-allocated class that governs a number of local handles. * After a handle scope has been created, all local handles will be @@ -757,27 +852,28 @@ class V8_EXPORT HandleScope { ~HandleScope(); - /** - * Closes the handle scope and returns the value as a handle in the - * previous scope, which is the new current scope after the call. - */ - template <class T> Local<T> Close(Handle<T> value); + template <class T> + V8_DEPRECATED("Use EscapableHandleScope::Escape instead", + Local<T> Close(Handle<T> value)); /** * Counts the number of allocated handles. */ static int NumberOfHandles(); + private: /** * Creates a new handle with the given value. */ - static internal::Object** CreateHandle(internal::Object* value); static internal::Object** CreateHandle(internal::Isolate* isolate, internal::Object* value); - // Faster version, uses HeapObject to obtain the current Isolate. - static internal::Object** CreateHandle(internal::HeapObject* value); + // Uses HeapObject to obtain the current Isolate. + static internal::Object** CreateHandle(internal::HeapObject* heap_object, + internal::Object* value); + + V8_INLINE HandleScope() {} + void Initialize(Isolate* isolate); - private: // Make it hard to create heap-allocated or illegal handle scopes by // disallowing certain operations. HandleScope(const HandleScope&); @@ -798,19 +894,58 @@ class V8_EXPORT HandleScope { } }; - void Initialize(Isolate* isolate); void Leave(); internal::Isolate* isolate_; internal::Object** prev_next_; internal::Object** prev_limit_; + // TODO(dcarney): remove this field // Allow for the active closing of HandleScopes which allows to pass a handle // from the HandleScope being closed to the next top most HandleScope. bool is_closed_; internal::Object** RawClose(internal::Object** value); friend class ImplementationUtilities; + friend class EscapableHandleScope; + template<class F> friend class Handle; + template<class F> friend class Local; + friend class Object; + friend class Context; +}; + + +/** + * A HandleScope which first allocates a handle in the current scope + * which will be later filled with the escape value. + */ +class V8_EXPORT EscapableHandleScope : public HandleScope { + public: + EscapableHandleScope(Isolate* isolate); + V8_INLINE ~EscapableHandleScope() {} + + /** + * Pushes the value into the previous scope and returns a handle to it. + * Cannot be called twice. + */ + template <class T> + V8_INLINE Local<T> Escape(Local<T> value) { + internal::Object** slot = + Escape(reinterpret_cast<internal::Object**>(*value)); + return Local<T>(reinterpret_cast<T*>(slot)); + } + + private: + internal::Object** Escape(internal::Object** escape_value); + + // Make it hard to create heap-allocated or illegal handle scopes by + // disallowing certain operations. + EscapableHandleScope(const EscapableHandleScope&); + void operator=(const EscapableHandleScope&); + void* operator new(size_t size); + void operator delete(void*, size_t); + + internal::Object** escape_slot_; }; @@ -857,7 +992,9 @@ class V8_EXPORT ScriptData { // NOLINT * \param input Pointer to UTF-8 script source code. * \param length Length of UTF-8 script source code. */ - static ScriptData* PreCompile(const char* input, int length); + static ScriptData* PreCompile(Isolate* isolate, + const char* input, + int length); /** * Pre-compiles the specified script (context-independent). @@ -1009,9 +1146,8 @@ class V8_EXPORT Script { /** * Returns the script id value. - * DEPRECATED: Please use GetId(). */ - Local<Value> Id(); + V8_DEPRECATED("Use GetId instead", Local<Value> Id()); /** * Returns the script id. @@ -1103,7 +1239,9 @@ class V8_EXPORT Message { bool IsSharedCrossOrigin() const; // TODO(1245381): Print to a string instead of on a FILE. - static void PrintCurrentStackTrace(FILE* out); + static void PrintCurrentStackTrace(Isolate* isolate, FILE* out); + V8_DEPRECATED("Will be removed", + static void PrintCurrentStackTrace(FILE* out)); static const int kNoLineNumberInfo = 0; static const int kNoColumnInfo = 0; @@ -1158,8 +1296,12 @@ class V8_EXPORT StackTrace { * StackFrame. */ static Local<StackTrace> CurrentStackTrace( + Isolate* isolate, int frame_limit, StackTraceOptions options = kOverview); + V8_DEPRECATED("Will be removed", + static Local<StackTrace> CurrentStackTrace( + int frame_limit, StackTraceOptions options = kOverview)); }; @@ -1463,6 +1605,7 @@ class V8_EXPORT Value : public Data { /** JS == */ bool Equals(Handle<Value> that) const; bool StrictEquals(Handle<Value> that) const; + bool SameValue(Handle<Value> that) const; template <class T> V8_INLINE static Value* Cast(T* value); @@ -1489,7 +1632,9 @@ class V8_EXPORT Primitive : public Value { }; class V8_EXPORT Boolean : public Primitive { public: bool Value() const; - V8_INLINE static Handle<Boolean> New(bool value); + V8_INLINE static Handle<Boolean> New(Isolate* isolate, bool value); + V8_DEPRECATED("Will be removed", + V8_INLINE static Handle<Boolean> New(bool value)); }; @@ -1516,11 +1661,6 @@ class V8_EXPORT String : public Primitive { int Utf8Length() const; /** - * This function is no longer useful. - */ - V8_DEPRECATED(V8_INLINE bool MayContainNonAscii() const) { return true; } - - /** * Returns whether this string is known to contain only one byte data. * Does not read the string. * False negatives are possible. @@ -1570,11 +1710,6 @@ class V8_EXPORT String : public Primitive { int start = 0, int length = -1, int options = NO_OPTIONS) const; - // ASCII characters. - V8_DEPRECATED(int WriteAscii(char* buffer, - int start = 0, - int length = -1, - int options = NO_OPTIONS) const); // One byte characters. int WriteOneByte(uint8_t* buffer, int start = 0, @@ -1705,24 +1840,29 @@ class V8_EXPORT String : public Primitive { V8_INLINE static String* Cast(v8::Value* obj); - // TODO(dcarney): deprecate /** * Allocates a new string from either UTF-8 encoded or ASCII data. * The second parameter 'length' gives the buffer length. If omitted, * the function calls 'strlen' to determine the buffer length. */ - V8_INLINE static Local<String> New(const char* data, int length = -1); + V8_DEPRECATED( + "Use NewFromUtf8 instead", + V8_INLINE static Local<String> New(const char* data, int length = -1)); - // TODO(dcarney): deprecate /** Allocates a new string from 16-bit character codes.*/ - V8_INLINE static Local<String> New(const uint16_t* data, int length = -1); + V8_DEPRECATED( + "Use NewFromTwoByte instead", + V8_INLINE static Local<String> New( + const uint16_t* data, int length = -1)); - // TODO(dcarney): deprecate /** * Creates an internalized string (historically called a "symbol", * not to be confused with ES6 symbols). Returns one if it exists already. */ - V8_INLINE static Local<String> NewSymbol(const char* data, int length = -1); + V8_DEPRECATED( + "Use NewFromUtf8 instead", + V8_INLINE static Local<String> NewSymbol( + const char* data, int length = -1)); enum NewStringType { kNormalString, kInternalizedString, kUndetectableString @@ -1762,7 +1902,10 @@ class V8_EXPORT String : public Primitive { * should the underlying buffer be deallocated or modified except through the * destructor of the external string resource. */ - static Local<String> NewExternal(ExternalStringResource* resource); + static Local<String> NewExternal(Isolate* isolate, + ExternalStringResource* resource); + V8_DEPRECATED("Will be removed", static Local<String> NewExternal( + ExternalStringResource* resource)); /** * Associate an external string resource with this string by transforming it @@ -1783,7 +1926,10 @@ class V8_EXPORT String : public Primitive { * should the underlying buffer be deallocated or modified except through the * destructor of the external string resource. */ - static Local<String> NewExternal(ExternalAsciiStringResource* resource); + static Local<String> NewExternal(Isolate* isolate, + ExternalAsciiStringResource* resource); + V8_DEPRECATED("Will be removed", static Local<String> NewExternal( + ExternalAsciiStringResource* resource)); /** * Associate an external string resource with this string by transforming it @@ -1801,15 +1947,17 @@ class V8_EXPORT String : public Primitive { */ bool CanMakeExternal(); - // TODO(dcarney): deprecate /** Creates an undetectable string from the supplied ASCII or UTF-8 data.*/ - V8_INLINE static Local<String> NewUndetectable(const char* data, - int length = -1); + V8_DEPRECATED( + "Use NewFromUtf8 instead", + V8_INLINE static Local<String> NewUndetectable(const char* data, + int length = -1)); - // TODO(dcarney): deprecate /** Creates an undetectable string from the supplied 16-bit character codes.*/ - V8_INLINE static Local<String> NewUndetectable(const uint16_t* data, - int length = -1); + V8_DEPRECATED( + "Use NewFromTwoByte instead", + V8_INLINE static Local<String> NewUndetectable(const uint16_t* data, + int length = -1)); /** * Converts an object to a UTF-8-encoded character array. Useful if @@ -1843,8 +1991,8 @@ class V8_EXPORT String : public Primitive { */ class V8_EXPORT AsciiValue { public: - // TODO(dcarney): deprecate - explicit AsciiValue(Handle<v8::Value> obj); + V8_DEPRECATED("Use Utf8Value instead", + explicit AsciiValue(Handle<v8::Value> obj)); ~AsciiValue(); char* operator*() { return str_; } const char* operator*() const { return str_; } @@ -1898,11 +2046,9 @@ class V8_EXPORT Symbol : public Primitive { // Returns the print name string of the symbol, or undefined if none. Local<Value> Name() const; - // Create a symbol without a print name. - static Local<Symbol> New(Isolate* isolate); - - // Create a symbol with a print name. - static Local<Symbol> New(Isolate *isolate, const char* data, int length = -1); + // Create a symbol. If data is not NULL, it will be used as a print name. + static Local<Symbol> New( + Isolate *isolate, const char* data = NULL, int length = -1); V8_INLINE static Symbol* Cast(v8::Value* obj); private: @@ -1912,13 +2058,33 @@ class V8_EXPORT Symbol : public Primitive { /** + * A private symbol + * + * This is an experimental feature. Use at your own risk. + */ +class V8_EXPORT Private : public Data { + public: + // Returns the print name string of the private symbol, or undefined if none. + Local<Value> Name() const; + + // Create a private symbol. If data is not NULL, it will be the print name. + static Local<Private> New( + Isolate *isolate, const char* data = NULL, int length = -1); + + private: + Private(); +}; + + +/** * A JavaScript number value (ECMA-262, 4.3.20) */ class V8_EXPORT Number : public Primitive { public: double Value() const; - static Local<Number> New(double value); static Local<Number> New(Isolate* isolate, double value); + // Will be deprecated soon. + static Local<Number> New(double value); V8_INLINE static Number* Cast(v8::Value* obj); private: Number(); @@ -1931,10 +2097,13 @@ class V8_EXPORT Number : public Primitive { */ class V8_EXPORT Integer : public Number { public: - static Local<Integer> New(int32_t value); - static Local<Integer> NewFromUnsigned(uint32_t value); + static Local<Integer> New(Isolate* isolate, int32_t value); + static Local<Integer> NewFromUnsigned(Isolate* isolate, uint32_t value); + // Will be deprecated soon. static Local<Integer> New(int32_t value, Isolate*); static Local<Integer> NewFromUnsigned(uint32_t value, Isolate*); + static Local<Integer> New(int32_t value); + static Local<Integer> NewFromUnsigned(uint32_t value); int64_t Value() const; V8_INLINE static Integer* Cast(v8::Value* obj); private: @@ -2081,6 +2250,17 @@ class V8_EXPORT Object : public Value { AccessControl settings = DEFAULT); /** + * Functionality for private properties. + * This is an experimental feature, use at your own risk. + * Note: Private properties are inherited. Do not rely on this, since it may + * change. + */ + bool HasPrivate(Handle<Private> key); + bool SetPrivate(Handle<Private> key, Handle<Value> value); + bool DeletePrivate(Handle<Private> key); + Local<Value> GetPrivate(Handle<Private> key); + + /** * Returns an array containing the names of the enumerable properties * of this object, including properties from prototype objects. The * array returned by this method contains the same values as would @@ -2265,7 +2445,7 @@ class V8_EXPORT Object : public Value { * Call an Object as a function if a callback is set by the * ObjectTemplate::SetCallAsFunctionHandler method. */ - Local<Value> CallAsFunction(Handle<Object> recv, + Local<Value> CallAsFunction(Handle<Value> recv, int argc, Handle<Value> argv[]); @@ -2276,6 +2456,8 @@ class V8_EXPORT Object : public Value { */ Local<Value> CallAsConstructor(int argc, Handle<Value> argv[]); + static Local<Object> New(Isolate* isolate); + // Will be deprecated soon. static Local<Object> New(); V8_INLINE static Object* Cast(Value* obj); @@ -2304,7 +2486,8 @@ class V8_EXPORT Array : public Object { * Creates a JavaScript array with the given length. If the length * is negative the returned array will have length 0. */ - static Local<Array> New(int length = 0); + static Local<Array> New(Isolate* isolate, int length = 0); + V8_DEPRECATED("Will be removed", static Local<Array> New(int length = 0)); V8_INLINE static Array* Cast(Value* obj); private: @@ -2364,17 +2547,18 @@ class FunctionCallbackInfo { V8_INLINE Isolate* GetIsolate() const; V8_INLINE ReturnValue<T> GetReturnValue() const; // This shouldn't be public, but the arm compiler needs it. - static const int kArgsLength = 6; + static const int kArgsLength = 7; protected: friend class internal::FunctionCallbackArguments; friend class internal::CustomArguments<FunctionCallbackInfo>; - static const int kReturnValueIndex = 0; - static const int kReturnValueDefaultValueIndex = -1; - static const int kIsolateIndex = -2; - static const int kDataIndex = -3; - static const int kCalleeIndex = -4; - static const int kHolderIndex = -5; + static const int kHolderIndex = 0; + static const int kIsolateIndex = 1; + static const int kReturnValueDefaultValueIndex = 2; + static const int kReturnValueIndex = 3; + static const int kDataIndex = 4; + static const int kCalleeIndex = 5; + static const int kContextSaveIndex = 6; V8_INLINE FunctionCallbackInfo(internal::Object** implicit_args, internal::Object** values, @@ -2406,12 +2590,12 @@ class PropertyCallbackInfo { friend class MacroAssembler; friend class internal::PropertyCallbackArguments; friend class internal::CustomArguments<PropertyCallbackInfo>; - static const int kThisIndex = 0; - static const int kDataIndex = -1; - static const int kReturnValueIndex = -2; - static const int kReturnValueDefaultValueIndex = -3; - static const int kIsolateIndex = -4; - static const int kHolderIndex = -5; + static const int kHolderIndex = 0; + static const int kIsolateIndex = 1; + static const int kReturnValueDefaultValueIndex = 2; + static const int kReturnValueIndex = 3; + static const int kDataIndex = 4; + static const int kThisIndex = 5; V8_INLINE PropertyCallbackInfo(internal::Object** args) : args_(args) {} internal::Object** args_; @@ -2437,7 +2621,7 @@ class V8_EXPORT Function : public Object { Local<Object> NewInstance() const; Local<Object> NewInstance(int argc, Handle<Value> argv[]) const; - Local<Value> Call(Handle<Object> recv, int argc, Handle<Value> argv[]); + Local<Value> Call(Handle<Value> recv, int argc, Handle<Value> argv[]); void SetName(Handle<String> name); Handle<Value> GetName() const; @@ -2450,6 +2634,12 @@ class V8_EXPORT Function : public Object { Handle<Value> GetInferredName() const; /** + * User-defined name assigned to the "displayName" property of this function. + * Used to facilitate debugging and profiling of JavaScript code. + */ + Handle<Value> GetDisplayName() const; + + /** * Returns zero based line number of function body and * kLineOffsetNotFound if no information available. */ @@ -2461,10 +2651,14 @@ class V8_EXPORT Function : public Object { int GetScriptColumnNumber() const; /** + * Tells whether this function is builtin. + */ + bool IsBuiltin() const; + + /** * Returns scriptId object. - * DEPRECATED: use ScriptId() instead. */ - Handle<Value> GetScriptId() const; + V8_DEPRECATED("Use ScriptId instead", Handle<Value> GetScriptId() const); /** * Returns scriptId. @@ -2556,7 +2750,9 @@ class V8_EXPORT ArrayBuffer : public Object { * will be deallocated when it is garbage-collected, * unless the object is externalized. */ - static Local<ArrayBuffer> New(size_t byte_length); + static Local<ArrayBuffer> New(Isolate* isolate, size_t byte_length); + V8_DEPRECATED("Will be removed", + static Local<ArrayBuffer> New(size_t byte_length)); /** * Create a new ArrayBuffer over an existing memory block. @@ -2564,7 +2760,10 @@ class V8_EXPORT ArrayBuffer : public Object { * The memory block will not be reclaimed when a created ArrayBuffer * is garbage-collected. */ - static Local<ArrayBuffer> New(void* data, size_t byte_length); + static Local<ArrayBuffer> New(Isolate* isolate, void* data, + size_t byte_length); + V8_DEPRECATED("Will be removed", + static Local<ArrayBuffer> New(void* data, size_t byte_length)); /** * Returns true if ArrayBuffer is extrenalized, that is, does not @@ -2627,10 +2826,6 @@ class V8_EXPORT ArrayBufferView : public Object { * Size of a view in bytes. */ size_t ByteLength(); - /** - * Base address of a view. - */ - void* BaseAddress(); V8_INLINE static ArrayBufferView* Cast(Value* obj); @@ -2828,11 +3023,12 @@ class V8_EXPORT DataView : public ArrayBufferView { */ class V8_EXPORT Date : public Object { public: - static Local<Value> New(double time); + static Local<Value> New(Isolate* isolate, double time); + V8_DEPRECATED("Will be removed", static Local<Value> New(double time)); - // Deprecated, use Date::ValueOf() instead. - // TODO(svenpanne) Actually deprecate when Chrome is adapted. - double NumberValue() const { return ValueOf(); } + V8_DEPRECATED( + "Use ValueOf instead", + double NumberValue() const) { return ValueOf(); } /** * A specialization of Value::NumberValue that is more efficient @@ -2854,7 +3050,9 @@ class V8_EXPORT Date : public Object { * This API should not be called more than needed as it will * negatively impact the performance of date operations. */ - static void DateTimeConfigurationChangeNotification(); + static void DateTimeConfigurationChangeNotification(Isolate* isolate); + V8_DEPRECATED("Will be removed", + static void DateTimeConfigurationChangeNotification()); private: static void CheckCast(v8::Value* obj); @@ -2866,11 +3064,12 @@ class V8_EXPORT Date : public Object { */ class V8_EXPORT NumberObject : public Object { public: - static Local<Value> New(double value); + static Local<Value> New(Isolate* isolate, double value); + V8_DEPRECATED("Will be removed", static Local<Value> New(double value)); - // Deprecated, use NumberObject::ValueOf() instead. - // TODO(svenpanne) Actually deprecate when Chrome is adapted. - double NumberValue() const { return ValueOf(); } + V8_DEPRECATED( + "Use ValueOf instead", + double NumberValue() const) { return ValueOf(); } /** * Returns the Number held by the object. @@ -2891,9 +3090,9 @@ class V8_EXPORT BooleanObject : public Object { public: static Local<Value> New(bool value); - // Deprecated, use BooleanObject::ValueOf() instead. - // TODO(svenpanne) Actually deprecate when Chrome is adapted. - bool BooleanValue() const { return ValueOf(); } + V8_DEPRECATED( + "Use ValueOf instead", + bool BooleanValue() const) { return ValueOf(); } /** * Returns the Boolean held by the object. @@ -2914,9 +3113,9 @@ class V8_EXPORT StringObject : public Object { public: static Local<Value> New(Handle<String> value); - // Deprecated, use StringObject::ValueOf() instead. - // TODO(svenpanne) Actually deprecate when Chrome is adapted. - Local<String> StringValue() const { return ValueOf(); } + V8_DEPRECATED( + "Use ValueOf instead", + Local<String> StringValue() const) { return ValueOf(); } /** * Returns the String held by the object. @@ -2939,9 +3138,9 @@ class V8_EXPORT SymbolObject : public Object { public: static Local<Value> New(Isolate* isolate, Handle<Symbol> value); - // Deprecated, use SymbolObject::ValueOf() instead. - // TODO(svenpanne) Actually deprecate when Chrome is adapted. - Local<Symbol> SymbolValue() const { return ValueOf(); } + V8_DEPRECATED( + "Use ValueOf instead", + Local<Symbol> SymbolValue() const) { return ValueOf(); } /** * Returns the Symbol held by the object. @@ -3007,7 +3206,8 @@ class V8_EXPORT RegExp : public Object { */ class V8_EXPORT External : public Value { public: - static Local<External> New(void* value); + static Local<External> New(Isolate* isolate, void* value); + V8_DEPRECATED("Will be removed", static Local<External> New(void *value)); V8_INLINE static External* Cast(Value* obj); void* Value() const; private: @@ -3026,7 +3226,9 @@ class V8_EXPORT Template : public Data { /** Adds a property to each instance created by this template.*/ void Set(Handle<String> name, Handle<Data> value, PropertyAttribute attributes = None); - V8_INLINE void Set(const char* name, Handle<Data> value); + V8_INLINE void Set(Isolate* isolate, const char* name, Handle<Data> value); + V8_DEPRECATED("Will be removed", + V8_INLINE void Set(const char* name, Handle<Data> value)); void SetAccessorProperty( Local<String> name, @@ -3309,6 +3511,13 @@ class V8_EXPORT FunctionTemplate : public Template { public: /** Creates a function template.*/ static Local<FunctionTemplate> New( + Isolate* isolate, + FunctionCallback callback = 0, + Handle<Value> data = Handle<Value>(), + Handle<Signature> signature = Handle<Signature>(), + int length = 0); + // Will be deprecated soon. + static Local<FunctionTemplate> New( FunctionCallback callback = 0, Handle<Value> data = Handle<Value>(), Handle<Signature> signature = Handle<Signature>(), @@ -3395,6 +3604,8 @@ class V8_EXPORT FunctionTemplate : public Template { class V8_EXPORT ObjectTemplate : public Template { public: /** Creates an ObjectTemplate. */ + static Local<ObjectTemplate> New(Isolate* isolate); + // Will be deprecated soon. static Local<ObjectTemplate> New(); /** Creates a new instance of this template.*/ @@ -3536,7 +3747,8 @@ class V8_EXPORT ObjectTemplate : public Template { private: ObjectTemplate(); - static Local<ObjectTemplate> New(Handle<FunctionTemplate> constructor); + static Local<ObjectTemplate> New(internal::Isolate* isolate, + Handle<FunctionTemplate> constructor); friend class FunctionTemplate; }; @@ -3547,10 +3759,18 @@ class V8_EXPORT ObjectTemplate : public Template { */ class V8_EXPORT Signature : public Data { public: - static Local<Signature> New(Handle<FunctionTemplate> receiver = + static Local<Signature> New(Isolate* isolate, + Handle<FunctionTemplate> receiver = Handle<FunctionTemplate>(), int argc = 0, Handle<FunctionTemplate> argv[] = 0); + V8_DEPRECATED("Will be removed", + static Local<Signature> New(Handle<FunctionTemplate> receiver = + Handle<FunctionTemplate>(), + int argc = 0, + Handle<FunctionTemplate> argv[] = + 0)); + private: Signature(); }; @@ -3562,8 +3782,13 @@ class V8_EXPORT Signature : public Data { */ class V8_EXPORT AccessorSignature : public Data { public: - static Local<AccessorSignature> New(Handle<FunctionTemplate> receiver = + static Local<AccessorSignature> New(Isolate* isolate, + Handle<FunctionTemplate> receiver = Handle<FunctionTemplate>()); + V8_DEPRECATED("Will be removed", static Local<AccessorSignature> New( + Handle<FunctionTemplate> receiver = + Handle<FunctionTemplate>())); + private: AccessorSignature(); }; @@ -3667,8 +3892,18 @@ class V8_EXPORT Extension { // NOLINT const char** deps = 0, int source_length = -1); virtual ~Extension() { } - virtual v8::Handle<v8::FunctionTemplate> - GetNativeFunction(v8::Handle<v8::String> name) { + virtual v8::Handle<v8::FunctionTemplate> GetNativeFunctionTemplate( + v8::Isolate* isolate, v8::Handle<v8::String> name) { +#if defined(V8_DEPRECATION_WARNINGS) + return v8::Handle<v8::FunctionTemplate>(); +#else + return GetNativeFunction(name); +#endif + } + + V8_DEPRECATED("Will be removed", + virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( + v8::Handle<v8::String> name)) { return v8::Handle<v8::FunctionTemplate>(); } @@ -3711,17 +3946,16 @@ class V8_EXPORT DeclareExtension { // --- Statics --- - -Handle<Primitive> V8_EXPORT Undefined(); -Handle<Primitive> V8_EXPORT Null(); -Handle<Boolean> V8_EXPORT True(); -Handle<Boolean> V8_EXPORT False(); - V8_INLINE Handle<Primitive> Undefined(Isolate* isolate); V8_INLINE Handle<Primitive> Null(Isolate* isolate); V8_INLINE Handle<Boolean> True(Isolate* isolate); V8_INLINE Handle<Boolean> False(Isolate* isolate); +V8_DEPRECATED("Will be removed", Handle<Primitive> V8_EXPORT Undefined()); +V8_DEPRECATED("Will be removed", Handle<Primitive> V8_EXPORT Null()); +V8_DEPRECATED("Will be removed", Handle<Boolean> V8_EXPORT True()); +V8_DEPRECATED("Will be removed", Handle<Boolean> V8_EXPORT False()); + /** * A set of constraints that specifies the limits of the runtime's memory use. @@ -3735,21 +3969,34 @@ V8_INLINE Handle<Boolean> False(Isolate* isolate); class V8_EXPORT ResourceConstraints { public: ResourceConstraints(); + + /** + * Configures the constraints with reasonable default values based on the + * capabilities of the current device the VM is running on. + * + * \param physical_memory The total amount of physical memory on the current + * device, in bytes. + * \param number_of_processors The number of CPUs available on the current + * device. + */ + void ConfigureDefaults(uint64_t physical_memory, + uint32_t number_of_processors); + V8_DEPRECATED("Will be removed", + void ConfigureDefaults(uint64_t physical_memory)); + int max_young_space_size() const { return max_young_space_size_; } void set_max_young_space_size(int value) { max_young_space_size_ = value; } int max_old_space_size() const { return max_old_space_size_; } void set_max_old_space_size(int value) { max_old_space_size_ = value; } - int max_executable_size() { return max_executable_size_; } + int max_executable_size() const { return max_executable_size_; } void set_max_executable_size(int value) { max_executable_size_ = value; } uint32_t* stack_limit() const { return stack_limit_; } // Sets an address beyond which the VM's stack may not grow. void set_stack_limit(uint32_t* value) { stack_limit_ = value; } - Maybe<bool> is_memory_constrained() const { return is_memory_constrained_; } - // If set to true, V8 will limit it's memory usage, at the potential cost of - // lower performance. Note, this option is a tentative addition to the API - // and may be removed or modified without warning. - void set_memory_constrained(bool value) { - is_memory_constrained_ = Maybe<bool>(value); + int max_available_threads() const { return max_available_threads_; } + // Set the number of threads available to V8, assuming at least 1. + void set_max_available_threads(int value) { + max_available_threads_ = value; } private: @@ -3757,11 +4004,15 @@ class V8_EXPORT ResourceConstraints { int max_old_space_size_; int max_executable_size_; uint32_t* stack_limit_; - Maybe<bool> is_memory_constrained_; + int max_available_threads_; }; -bool V8_EXPORT SetResourceConstraints(ResourceConstraints* constraints); +/** + * Sets the given ResourceConstraints on the given Isolate. + */ +bool V8_EXPORT SetResourceConstraints(Isolate* isolate, + ResourceConstraints* constraints); // --- Exceptions --- @@ -3773,13 +4024,9 @@ typedef void (*FatalErrorCallback)(const char* location, const char* message); typedef void (*MessageCallback)(Handle<Message> message, Handle<Value> error); -/** - * Schedules an exception to be thrown when returning to JavaScript. When an - * exception has been scheduled it is illegal to invoke any JavaScript - * operation; the caller must return immediately and only after the exception - * has been handled does it become legal to invoke JavaScript operations. - */ -Handle<Value> V8_EXPORT ThrowException(Handle<Value> exception); +V8_DEPRECATED( + "Use Isolate::ThrowException instead", + Handle<Value> V8_EXPORT ThrowException(Handle<Value> exception)); /** * Create new error objects by calling the corresponding error object @@ -3870,8 +4117,6 @@ enum GCCallbackFlags { typedef void (*GCPrologueCallback)(GCType type, GCCallbackFlags flags); typedef void (*GCEpilogueCallback)(GCType type, GCCallbackFlags flags); -typedef void (*GCCallback)(); - /** * Collection of V8 heap information. @@ -3975,16 +4220,27 @@ class V8_EXPORT Isolate { */ void Dispose(); + V8_DEPRECATED("Use SetData(0, data) instead.", + V8_INLINE void SetData(void* data)); + V8_DEPRECATED("Use GetData(0) instead.", V8_INLINE void* GetData()); + /** - * Associate embedder-specific data with the isolate + * Associate embedder-specific data with the isolate. |slot| has to be + * between 0 and GetNumberOfDataSlots() - 1. */ - V8_INLINE void SetData(void* data); + V8_INLINE void SetData(uint32_t slot, void* data); /** * Retrieve embedder-specific data from the isolate. - * Returns NULL if SetData has never been called. + * Returns NULL if SetData has never been called for the given |slot|. + */ + V8_INLINE void* GetData(uint32_t slot); + + /** + * Returns the maximum number of available embedder data slots. Valid slots + * are in the range of 0 - GetNumberOfDataSlots() - 1. */ - V8_INLINE void* GetData(); + V8_INLINE static uint32_t GetNumberOfDataSlots(); /** * Get statistics about the heap memory usage. @@ -4004,7 +4260,7 @@ class V8_EXPORT Isolate { * kept alive by JavaScript objects. * \returns the adjusted value. */ - intptr_t AdjustAmountOfExternalAllocatedMemory(intptr_t change_in_bytes); + int64_t AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes); /** * Returns heap profiler for this isolate. Will return NULL until the isolate @@ -4019,10 +4275,31 @@ class V8_EXPORT Isolate { */ CpuProfiler* GetCpuProfiler(); + /** Returns true if this isolate has a current context. */ + bool InContext(); + /** Returns the context that is on the top of the stack. */ Local<Context> GetCurrentContext(); /** + * Returns the context of the calling JavaScript code. That is the + * context of the top-most JavaScript frame. If there are no + * JavaScript frames an empty handle is returned. + */ + Local<Context> GetCallingContext(); + + /** Returns the last entered context. */ + Local<Context> GetEnteredContext(); + + /** + * Schedules an exception to be thrown when returning to JavaScript. When an + * exception has been scheduled it is illegal to invoke any JavaScript + * operation; the caller must return immediately and only after the exception + * has been handled does it become legal to invoke JavaScript operations. + */ + Local<Value> ThrowException(Local<Value> exception); + + /** * Allows the host application to group objects together. If one * object in the group is alive, all objects in the group are alive. * After each garbage collection, object groups are removed. It is @@ -4033,8 +4310,8 @@ class V8_EXPORT Isolate { * garbage collection types it is sufficient to provide object groups * for partially dependent handles only. */ - void SetObjectGroupId(const Persistent<Value>& object, - UniqueId id); + template<typename T> void SetObjectGroupId(const Persistent<T>& object, + UniqueId id); /** * Allows the host application to declare implicit references from an object @@ -4043,8 +4320,8 @@ class V8_EXPORT Isolate { * are removed. It is intended to be used in the before-garbage-collection * callback function. */ - void SetReferenceFromGroup(UniqueId id, - const Persistent<Value>& child); + template<typename T> void SetReferenceFromGroup(UniqueId id, + const Persistent<T>& child); /** * Allows the host application to declare implicit references from an object @@ -4052,8 +4329,53 @@ class V8_EXPORT Isolate { * too. After each garbage collection, all implicit references are removed. It * is intended to be used in the before-garbage-collection callback function. */ - void SetReference(const Persistent<Object>& parent, - const Persistent<Value>& child); + template<typename T, typename S> + void SetReference(const Persistent<T>& parent, const Persistent<S>& child); + + typedef void (*GCPrologueCallback)(Isolate* isolate, + GCType type, + GCCallbackFlags flags); + typedef void (*GCEpilogueCallback)(Isolate* isolate, + GCType type, + GCCallbackFlags flags); + + /** + * Enables the host application to receive a notification before a + * garbage collection. Allocations are not allowed in the + * callback function, you therefore cannot manipulate objects (set + * or delete properties for example) since it is possible such + * operations will result in the allocation of objects. It is possible + * to specify the GCType filter for your callback. But it is not possible to + * register the same callback function two times with different + * GCType filters. + */ + void AddGCPrologueCallback( + GCPrologueCallback callback, GCType gc_type_filter = kGCTypeAll); + + /** + * This function removes callback which was installed by + * AddGCPrologueCallback function. + */ + void RemoveGCPrologueCallback(GCPrologueCallback callback); + + /** + * Enables the host application to receive a notification after a + * garbage collection. Allocations are not allowed in the + * callback function, you therefore cannot manipulate objects (set + * or delete properties for example) since it is possible such + * operations will result in the allocation of objects. It is possible + * to specify the GCType filter for your callback. But it is not possible to + * register the same callback function two times with different + * GCType filters. + */ + void AddGCEpilogueCallback( + GCEpilogueCallback callback, GCType gc_type_filter = kGCTypeAll); + + /** + * This function removes callback which was installed by + * AddGCEpilogueCallback function. + */ + void RemoveGCEpilogueCallback(GCEpilogueCallback callback); private: Isolate(); @@ -4062,8 +4384,11 @@ class V8_EXPORT Isolate { Isolate& operator=(const Isolate&); void* operator new(size_t size); void operator delete(void*, size_t); -}; + void SetObjectGroupId(internal::Object** object, UniqueId id); + void SetReferenceFromGroup(UniqueId id, internal::Object** object); + void SetReference(internal::Object** parent, internal::Object** child); +}; class V8_EXPORT StartupData { public: @@ -4412,16 +4737,6 @@ class V8_EXPORT V8 { static void RemoveGCPrologueCallback(GCPrologueCallback callback); /** - * The function is deprecated. Please use AddGCPrologueCallback instead. - * Enables the host application to receive a notification before a - * garbage collection. Allocations are not allowed in the - * callback function, you therefore cannot manipulate objects (set - * or delete properties for example) since it is possible such - * operations will result in the allocation of objects. - */ - V8_DEPRECATED(static void SetGlobalGCPrologueCallback(GCCallback)); - - /** * Enables the host application to receive a notification after a * garbage collection. Allocations are not allowed in the * callback function, you therefore cannot manipulate objects (set @@ -4441,16 +4756,6 @@ class V8_EXPORT V8 { static void RemoveGCEpilogueCallback(GCEpilogueCallback callback); /** - * The function is deprecated. Please use AddGCEpilogueCallback instead. - * Enables the host application to receive a notification after a - * major garbage collection. Allocations are not allowed in the - * callback function, you therefore cannot manipulate objects (set - * or delete properties for example) since it is possible such - * operations will result in the allocation of objects. - */ - V8_DEPRECATED(static void SetGlobalGCEpilogueCallback(GCCallback)); - - /** * Enables the host application to provide a mechanism to be notified * and perform custom logging when V8 Allocates Executable Memory. */ @@ -4498,11 +4803,6 @@ class V8_EXPORT V8 { ReturnAddressLocationResolver return_address_resolver); /** - * Deprecated, use the variant with the Isolate parameter below instead. - */ - V8_DEPRECATED(static bool SetFunctionEntryHook(FunctionEntryHook entry_hook)); - - /** * Allows the host application to provide the address of a function that's * invoked on entry to every V8-generated function. * Note that \p entry_hook is invoked at the very start of each @@ -4541,10 +4841,10 @@ class V8_EXPORT V8 { static void SetJitCodeEventHandler(JitCodeEventOptions options, JitCodeEventHandler event_handler); - // TODO(svenpanne) Really deprecate me when Chrome is fixed. - /** Deprecated. Use Isolate::AdjustAmountOfExternalAllocatedMemory instead. */ - static intptr_t AdjustAmountOfExternalAllocatedMemory( - intptr_t change_in_bytes); + V8_DEPRECATED( + "Use Isolate::AdjustAmountOfExternalAllocatedMemory instead", + static int64_t AdjustAmountOfExternalAllocatedMemory( + int64_t change_in_bytes)); /** * Forcefully terminate the current thread of JavaScript execution @@ -4599,9 +4899,6 @@ class V8_EXPORT V8 { */ static bool Dispose(); - /** Deprecated. Use Isolate::GetHeapStatistics instead. */ - V8_DEPRECATED(static void GetHeapStatistics(HeapStatistics* heap_statistics)); - /** * Iterates through all external resources referenced from current isolate * heap. GC is not invoked prior to iterating, therefore there is no @@ -4659,6 +4956,18 @@ class V8_EXPORT V8 { */ static bool InitializeICU(); + /** + * Sets the v8::Platform to use. This should be invoked before V8 is + * initialized. + */ + static void InitializePlatform(Platform* platform); + + /** + * Clears all references to the v8::Platform. This should be invoked after + * V8 was disposed. + */ + static void ShutdownPlatform(); + private: V8(); @@ -4681,6 +4990,7 @@ class V8_EXPORT V8 { template <class T> friend class Handle; template <class T> friend class Local; template <class T> friend class Eternal; + template <class T> friend class PersistentBase; template <class T, class M> friend class Persistent; friend class Context; }; @@ -4840,20 +5150,16 @@ class V8_EXPORT ExtensionConfiguration { class V8_EXPORT Context { public: /** - * Returns the global proxy object or global object itself for - * detached contexts. + * Returns the global proxy object. * - * Global proxy object is a thin wrapper whose prototype points to - * actual context's global object with the properties like Object, etc. - * This is done that way for security reasons (for more details see + * Global proxy object is a thin wrapper whose prototype points to actual + * context's global object with the properties like Object, etc. This is done + * that way for security reasons (for more details see * https://wiki.mozilla.org/Gecko:SplitWindow). * * Please note that changes to global proxy object prototype most probably - * would break VM---v8 expects only global object as a prototype of - * global proxy object. - * - * If DetachGlobal() has been invoked, Global() would return actual global - * object until global is reattached with ReattachGlobal(). + * would break VM---v8 expects only global object as a prototype of global + * proxy object. */ Local<Object> Global(); @@ -4864,18 +5170,6 @@ class V8_EXPORT Context { void DetachGlobal(); /** - * Reattaches a global object to a context. This can be used to - * restore the connection between a global object and a context - * after DetachGlobal has been called. - * - * \param global_object The global object to reattach to the - * context. For this to work, the global object must be the global - * object that was associated with this context before a call to - * DetachGlobal. - */ - void ReattachGlobal(Handle<Object> global_object); - - /** * Creates a new context and returns a handle to the newly allocated * context. * @@ -4899,25 +5193,14 @@ class V8_EXPORT Context { Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(), Handle<Value> global_object = Handle<Value>()); - /** Deprecated. Use Isolate version instead. */ - V8_DEPRECATED(static Persistent<Context> New( - ExtensionConfiguration* extensions = NULL, - Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(), - Handle<Value> global_object = Handle<Value>())); + V8_DEPRECATED("Use Isolate::GetEnteredContext instead", + static Local<Context> GetEntered()); - /** Returns the last entered context. */ - static Local<Context> GetEntered(); + V8_DEPRECATED("Use Isolate::GetCurrentContext instead", + static Local<Context> GetCurrent()); - // TODO(svenpanne) Actually deprecate this. - /** Deprecated. Use Isolate::GetCurrentContext instead. */ - static Local<Context> GetCurrent(); - - /** - * Returns the context of the calling JavaScript code. That is the - * context of the top-most JavaScript frame. If there are no - * JavaScript frames an empty handle is returned. - */ - static Local<Context> GetCalling(); + V8_DEPRECATED("Use Isolate::GetCallingContext instead", + static Local<Context> GetCalling()); /** * Sets the security token for the context. To access an object in @@ -4948,8 +5231,8 @@ class V8_EXPORT Context { /** Returns true if the context has experienced an out of memory situation. */ bool HasOutOfMemoryException(); - /** Returns true if V8 has a current context. */ - static bool InContext(); + V8_DEPRECATED("Use Isolate::InContext instead", + static bool InContext()); /** Returns an isolate associated with a current context. */ v8::Isolate* GetIsolate(); @@ -5020,8 +5303,9 @@ class V8_EXPORT Context { explicit V8_INLINE Scope(Handle<Context> context) : context_(context) { context_->Enter(); } - // TODO(dcarney): deprecate - V8_INLINE Scope(Isolate* isolate, Persistent<Context>& context) // NOLINT + V8_DEPRECATED( + "Use Handle version instead", + V8_INLINE Scope(Isolate* isolate, Persistent<Context>& context)) // NOLINT : context_(Handle<Context>::New(isolate, context)) { context_->Enter(); } @@ -5125,9 +5409,6 @@ class V8_EXPORT Unlocker { */ V8_INLINE explicit Unlocker(Isolate* isolate) { Initialize(isolate); } - /** Deprecated. Use Isolate version instead. */ - V8_DEPRECATED(Unlocker()); - ~Unlocker(); private: void Initialize(Isolate* isolate); @@ -5143,26 +5424,9 @@ class V8_EXPORT Locker { */ V8_INLINE explicit Locker(Isolate* isolate) { Initialize(isolate); } - /** Deprecated. Use Isolate version instead. */ - V8_DEPRECATED(Locker()); - ~Locker(); /** - * Start preemption. - * - * When preemption is started, a timer is fired every n milliseconds - * that will switch between multiple threads that are in contention - * for the V8 lock. - */ - static void StartPreemption(int every_n_ms); - - /** - * Stop preemption. - */ - static void StopPreemption(); - - /** * Returns whether or not the locker for a given isolate, is locked by the * current thread. */ @@ -5353,13 +5617,13 @@ class Internals { static const int kExternalTwoByteRepresentationTag = 0x02; static const int kExternalAsciiRepresentationTag = 0x06; - static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; - static const int kIsolateRootsOffset = 3 * kApiPointerSize; + static const int kIsolateEmbedderDataOffset = 0 * kApiPointerSize; + static const int kIsolateRootsOffset = 5 * kApiPointerSize; static const int kUndefinedValueRootIndex = 5; static const int kNullValueRootIndex = 7; static const int kTrueValueRootIndex = 8; static const int kFalseValueRootIndex = 9; - static const int kEmptyStringRootIndex = 131; + static const int kEmptyStringRootIndex = 134; static const int kNodeClassIdOffset = 1 * kApiPointerSize; static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3; @@ -5370,7 +5634,7 @@ class Internals { static const int kNodeIsIndependentShift = 4; static const int kNodeIsPartiallyDependentShift = 5; - static const int kJSObjectType = 0xb1; + static const int kJSObjectType = 0xb2; static const int kFirstNonstringType = 0x80; static const int kOddballType = 0x83; static const int kForeignType = 0x87; @@ -5378,7 +5642,9 @@ class Internals { static const int kUndefinedOddballKind = 5; static const int kNullOddballKind = 3; - static void CheckInitializedImpl(v8::Isolate* isolate); + static const uint32_t kNumIsolateDataSlots = 4; + + V8_EXPORT static void CheckInitializedImpl(v8::Isolate* isolate); V8_INLINE static void CheckInitialized(v8::Isolate* isolate) { #ifdef V8_ENABLE_CHECKS CheckInitializedImpl(isolate); @@ -5441,15 +5707,17 @@ class Internals { *addr = static_cast<uint8_t>((*addr & ~kNodeStateMask) | value); } - V8_INLINE static void SetEmbedderData(v8::Isolate* isolate, void* data) { - uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + - kIsolateEmbedderDataOffset; + V8_INLINE static void SetEmbedderData(v8::Isolate *isolate, + uint32_t slot, + void *data) { + uint8_t *addr = reinterpret_cast<uint8_t *>(isolate) + + kIsolateEmbedderDataOffset + slot * kApiPointerSize; *reinterpret_cast<void**>(addr) = data; } - V8_INLINE static void* GetEmbedderData(v8::Isolate* isolate) { + V8_INLINE static void* GetEmbedderData(v8::Isolate* isolate, uint32_t slot) { uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + - kIsolateEmbedderDataOffset; + kIsolateEmbedderDataOffset + slot * kApiPointerSize; return *reinterpret_cast<void**>(addr); } @@ -5494,26 +5762,12 @@ Local<T>::Local() : Handle<T>() { } template <class T> -Local<T> Local<T>::New(Handle<T> that) { - if (that.IsEmpty()) return Local<T>(); - T* that_ptr = *that; - internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); - if (internal::Internals::CanCastToHeapObject(that_ptr)) { - return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( - reinterpret_cast<internal::HeapObject*>(*p)))); - } - return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p))); -} - - -template <class T> Local<T> Local<T>::New(Isolate* isolate, Handle<T> that) { return New(isolate, that.val_); } template <class T> -template <class M> -Local<T> Local<T>::New(Isolate* isolate, const Persistent<T, M>& that) { +Local<T> Local<T>::New(Isolate* isolate, const PersistentBase<T>& that) { return New(isolate, that.val_); } @@ -5551,8 +5805,8 @@ Local<T> Eternal<T>::Get(Isolate* isolate) { } -template <class T, class M> -T* Persistent<T, M>::New(Isolate* isolate, T* that) { +template <class T> +T* PersistentBase<T>::New(Isolate* isolate, T* that) { if (that == NULL) return NULL; internal::Object** p = reinterpret_cast<internal::Object**>(that); return reinterpret_cast<T*>( @@ -5565,7 +5819,7 @@ template <class T, class M> template <class S, class M2> void Persistent<T, M>::Copy(const Persistent<S, M2>& that) { TYPE_CHECK(T, S); - Reset(); + this->Reset(); if (that.IsEmpty()) return; internal::Object** p = reinterpret_cast<internal::Object**>(that.val_); this->val_ = reinterpret_cast<T*>(V8::CopyPersistent(p)); @@ -5573,8 +5827,8 @@ void Persistent<T, M>::Copy(const Persistent<S, M2>& that) { } -template <class T, class M> -bool Persistent<T, M>::IsIndependent() const { +template <class T> +bool PersistentBase<T>::IsIndependent() const { typedef internal::Internals I; if (this->IsEmpty()) return false; return I::GetNodeFlag(reinterpret_cast<internal::Object**>(this->val_), @@ -5582,8 +5836,8 @@ bool Persistent<T, M>::IsIndependent() const { } -template <class T, class M> -bool Persistent<T, M>::IsNearDeath() const { +template <class T> +bool PersistentBase<T>::IsNearDeath() const { typedef internal::Internals I; if (this->IsEmpty()) return false; uint8_t node_state = @@ -5593,8 +5847,8 @@ bool Persistent<T, M>::IsNearDeath() const { } -template <class T, class M> -bool Persistent<T, M>::IsWeak() const { +template <class T> +bool PersistentBase<T>::IsWeak() const { typedef internal::Internals I; if (this->IsEmpty()) return false; return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) == @@ -5602,17 +5856,17 @@ bool Persistent<T, M>::IsWeak() const { } -template <class T, class M> -void Persistent<T, M>::Reset() { +template <class T> +void PersistentBase<T>::Reset() { if (this->IsEmpty()) return; V8::DisposeGlobal(reinterpret_cast<internal::Object**>(this->val_)); val_ = 0; } -template <class T, class M> +template <class T> template <class S> -void Persistent<T, M>::Reset(Isolate* isolate, const Handle<S>& other) { +void PersistentBase<T>::Reset(Isolate* isolate, const Handle<S>& other) { TYPE_CHECK(T, S); Reset(); if (other.IsEmpty()) return; @@ -5620,10 +5874,10 @@ void Persistent<T, M>::Reset(Isolate* isolate, const Handle<S>& other) { } -template <class T, class M> -template <class S, class M2> -void Persistent<T, M>::Reset(Isolate* isolate, - const Persistent<S, M2>& other) { +template <class T> +template <class S> +void PersistentBase<T>::Reset(Isolate* isolate, + const PersistentBase<S>& other) { TYPE_CHECK(T, S); Reset(); if (other.IsEmpty()) return; @@ -5631,9 +5885,9 @@ void Persistent<T, M>::Reset(Isolate* isolate, } -template <class T, class M> +template <class T> template <typename S, typename P> -void Persistent<T, M>::SetWeak( +void PersistentBase<T>::SetWeak( P* parameter, typename WeakCallbackData<S, P>::Callback callback) { TYPE_CHECK(S, T); @@ -5645,9 +5899,9 @@ void Persistent<T, M>::SetWeak( } -template <class T, class M> +template <class T> template <typename P> -void Persistent<T, M>::SetWeak( +void PersistentBase<T>::SetWeak( P* parameter, typename WeakCallbackData<T, P>::Callback callback) { SetWeak<T, P>(parameter, callback); @@ -5677,14 +5931,14 @@ void Persistent<T, M>::MakeWeak( } -template <class T, class M> -void Persistent<T, M>::ClearWeak() { +template <class T> +void PersistentBase<T>::ClearWeak() { V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_)); } -template <class T, class M> -void Persistent<T, M>::MarkIndependent() { +template <class T> +void PersistentBase<T>::MarkIndependent() { typedef internal::Internals I; if (this->IsEmpty()) return; I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), @@ -5693,8 +5947,8 @@ void Persistent<T, M>::MarkIndependent() { } -template <class T, class M> -void Persistent<T, M>::MarkPartiallyDependent() { +template <class T> +void PersistentBase<T>::MarkPartiallyDependent() { typedef internal::Internals I; if (this->IsEmpty()) return; I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), @@ -5706,14 +5960,14 @@ void Persistent<T, M>::MarkPartiallyDependent() { template <class T, class M> T* Persistent<T, M>::ClearAndLeak() { T* old; - old = val_; - val_ = NULL; + old = this->val_; + this->val_ = NULL; return old; } -template <class T, class M> -void Persistent<T, M>::SetWrapperClassId(uint16_t class_id) { +template <class T> +void PersistentBase<T>::SetWrapperClassId(uint16_t class_id) { typedef internal::Internals I; if (this->IsEmpty()) return; internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_); @@ -5722,8 +5976,8 @@ void Persistent<T, M>::SetWrapperClassId(uint16_t class_id) { } -template <class T, class M> -uint16_t Persistent<T, M>::WrapperClassId() const { +template <class T> +uint16_t PersistentBase<T>::WrapperClassId() const { typedef internal::Internals I; if (this->IsEmpty()) return 0; internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_); @@ -5777,7 +6031,6 @@ void ReturnValue<T>::Set(int32_t i) { template<typename T> void ReturnValue<T>::Set(uint32_t i) { TYPE_CHECK(T, Integer); - typedef internal::Internals I; // Can't simply use INT32_MAX here for whatever reason. bool fits_into_int32_t = (i & (1U << 31)) == 0; if (V8_LIKELY(fits_into_int32_t)) { @@ -5847,7 +6100,7 @@ FunctionCallbackInfo<T>::FunctionCallbackInfo(internal::Object** implicit_args, template<typename T> Local<Value> FunctionCallbackInfo<T>::operator[](int i) const { - if (i < 0 || length_ <= i) return Local<Value>(*Undefined()); + if (i < 0 || length_ <= i) return Local<Value>(*Undefined(GetIsolate())); return Local<Value>(reinterpret_cast<Value*>(values_ - i)); } @@ -5928,19 +6181,30 @@ Handle<Boolean> ScriptOrigin::ResourceIsSharedCrossOrigin() const { } +Handle<Boolean> Boolean::New(Isolate* isolate, bool value) { + return value ? True(isolate) : False(isolate); +} + + Handle<Boolean> Boolean::New(bool value) { - return value ? True() : False(); + return Boolean::New(Isolate::GetCurrent(), value); +} + + +void Template::Set(Isolate* isolate, const char* name, v8::Handle<Data> value) { + Set(v8::String::NewFromUtf8(isolate, name), value); } void Template::Set(const char* name, v8::Handle<Data> value) { - Set(v8::String::New(name), value); + Set(Isolate::GetCurrent(), name, value); } Local<Value> Object::GetInternalField(int index) { #ifndef V8_ENABLE_CHECKS typedef internal::Object O; + typedef internal::HeapObject HO; typedef internal::Internals I; O* obj = *reinterpret_cast<O**>(this); // Fast path: If the object is a plain JSObject, which is the common case, we @@ -5948,7 +6212,7 @@ Local<Value> Object::GetInternalField(int index) { if (I::GetInstanceType(obj) == I::kJSObjectType) { int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); O* value = I::ReadField<O*>(obj, offset); - O** result = HandleScope::CreateHandle(value); + O** result = HandleScope::CreateHandle(reinterpret_cast<HO*>(obj), value); return Local<Value>(reinterpret_cast<Value*>(result)); } #endif @@ -6387,21 +6651,69 @@ Handle<Boolean> False(Isolate* isolate) { void Isolate::SetData(void* data) { typedef internal::Internals I; - I::SetEmbedderData(this, data); + I::SetEmbedderData(this, 0, data); } void* Isolate::GetData() { typedef internal::Internals I; - return I::GetEmbedderData(this); + return I::GetEmbedderData(this, 0); +} + + +void Isolate::SetData(uint32_t slot, void* data) { + typedef internal::Internals I; + I::SetEmbedderData(this, slot, data); +} + + +void* Isolate::GetData(uint32_t slot) { + typedef internal::Internals I; + return I::GetEmbedderData(this, slot); +} + + +uint32_t Isolate::GetNumberOfDataSlots() { + typedef internal::Internals I; + return I::kNumIsolateDataSlots; +} + + +template<typename T> +void Isolate::SetObjectGroupId(const Persistent<T>& object, + UniqueId id) { + TYPE_CHECK(Value, T); + SetObjectGroupId(reinterpret_cast<v8::internal::Object**>(object.val_), id); +} + + +template<typename T> +void Isolate::SetReferenceFromGroup(UniqueId id, + const Persistent<T>& object) { + TYPE_CHECK(Value, T); + SetReferenceFromGroup(id, + reinterpret_cast<v8::internal::Object**>(object.val_)); +} + + +template<typename T, typename S> +void Isolate::SetReference(const Persistent<T>& parent, + const Persistent<S>& child) { + TYPE_CHECK(Object, T); + TYPE_CHECK(Value, S); + SetReference(reinterpret_cast<v8::internal::Object**>(parent.val_), + reinterpret_cast<v8::internal::Object**>(child.val_)); } Local<Value> Context::GetEmbedderData(int index) { #ifndef V8_ENABLE_CHECKS typedef internal::Object O; + typedef internal::HeapObject HO; typedef internal::Internals I; - O** result = HandleScope::CreateHandle(I::ReadEmbedderData<O*>(this, index)); + HO* context = *reinterpret_cast<HO**>(this); + O** result = + HandleScope::CreateHandle(context, I::ReadEmbedderData<O*>(this, index)); return Local<Value>(reinterpret_cast<Value*>(result)); #else return SlowGetEmbedderData(index); |