v8.h | v8.h | |||
---|---|---|---|---|
skipping to change at line 227 | skipping to change at line 227 | |||
void* parameter); | void* parameter); | |||
// --- Handles --- | // --- Handles --- | |||
#define TYPE_CHECK(T, S) \ | #define TYPE_CHECK(T, S) \ | |||
while (false) { \ | while (false) { \ | |||
*(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \ | *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \ | |||
} | } | |||
#define V8_USE_UNSAFE_HANDLES | #define V8_USE_UNSAFE_HANDLES | |||
#define V8_USE_OLD_STYLE_PERSISTENT_HANDLE_VISITORS | ||||
/** | /** | |||
* An object reference managed by the v8 garbage collector. | * An object reference managed by the v8 garbage collector. | |||
* | * | |||
* All objects returned from v8 have to be tracked by the garbage | * All objects returned from v8 have to be tracked by the garbage | |||
* collector so that it knows that the objects are still alive. Also, | * collector so that it knows that the objects are still alive. Also, | |||
* because the garbage collector may move objects, it is unsafe to | * because the garbage collector may move objects, it is unsafe to | |||
* point directly to an object. Instead, all objects are stored in | * point directly to an object. Instead, all objects are stored in | |||
* handles which are known by the garbage collector and updated | * handles which are known by the garbage collector and updated | |||
* whenever an object moves. Handles should always be passed by value | * whenever an object moves. Handles should always be passed by value | |||
skipping to change at line 369 | skipping to change at line 370 | |||
private: | private: | |||
#endif | #endif | |||
/** | /** | |||
* Creates a new handle for the specified value. | * Creates a new handle for the specified value. | |||
*/ | */ | |||
V8_INLINE(explicit Handle(T* val)) : val_(val) {} | V8_INLINE(explicit Handle(T* val)) : val_(val) {} | |||
#endif | #endif | |||
private: | private: | |||
template<class F> | template<class F> friend class Persistent; | |||
friend class Persistent; | template<class F> friend class Local; | |||
template<class F> | ||||
friend class Local; | ||||
friend class Arguments; | friend class Arguments; | |||
template<class F> friend class FunctionCallbackInfo; | ||||
template<class F> friend class PropertyCallbackInfo; | ||||
friend class String; | friend class String; | |||
friend class Object; | friend class Object; | |||
friend class AccessorInfo; | friend class AccessorInfo; | |||
friend Handle<Primitive> Undefined(Isolate* isolate); | friend Handle<Primitive> Undefined(Isolate* isolate); | |||
friend Handle<Primitive> Null(Isolate* isolate); | friend Handle<Primitive> Null(Isolate* isolate); | |||
friend Handle<Boolean> True(Isolate* isolate); | friend Handle<Boolean> True(Isolate* isolate); | |||
friend Handle<Boolean> False(Isolate* isolate); | friend Handle<Boolean> False(Isolate* isolate); | |||
friend class Context; | friend class Context; | |||
friend class InternalHandleHelper; | friend class InternalHandleHelper; | |||
friend class LocalContext; | friend class LocalContext; | |||
friend class HandleScope; | ||||
#ifndef V8_USE_UNSAFE_HANDLES | #ifndef V8_USE_UNSAFE_HANDLES | |||
V8_INLINE(static Handle<T> New(Isolate* isolate, T* that)); | V8_INLINE(static Handle<T> New(Isolate* isolate, T* that)); | |||
#endif | #endif | |||
T* val_; | T* val_; | |||
}; | }; | |||
/** | /** | |||
* A light-weight stack-allocated object handle. All operations | * A light-weight stack-allocated object handle. All operations | |||
skipping to change at line 455 | skipping to change at line 457 | |||
V8_INLINE(static Local<T> New(Isolate* isolate, const Persistent<T>& that )); | V8_INLINE(static Local<T> New(Isolate* isolate, const Persistent<T>& that )); | |||
#ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR | #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR | |||
private: | private: | |||
#endif | #endif | |||
template <class S> V8_INLINE(Local(S* that) : Handle<T>(that)) { } | template <class S> V8_INLINE(Local(S* that) : Handle<T>(that)) { } | |||
#endif | #endif | |||
private: | private: | |||
template<class F> | template<class F> friend class Persistent; | |||
friend class Persistent; | template<class F> friend class Handle; | |||
template<class F> | ||||
friend class Handle; | ||||
friend class Arguments; | friend class Arguments; | |||
template<class F> friend class FunctionCallbackInfo; | ||||
template<class F> friend class PropertyCallbackInfo; | ||||
friend class String; | friend class String; | |||
friend class Object; | friend class Object; | |||
friend class AccessorInfo; | friend class AccessorInfo; | |||
friend class Context; | friend class Context; | |||
friend class InternalHandleHelper; | friend class InternalHandleHelper; | |||
friend class LocalContext; | friend class LocalContext; | |||
friend class HandleScope; | ||||
V8_INLINE(static Local<T> New(Isolate* isolate, T* that)); | V8_INLINE(static Local<T> New(Isolate* isolate, T* that)); | |||
}; | }; | |||
/** | /** | |||
* An object reference that is independent of any handle scope. Where | * 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 | * 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 Persistent handle remains valid until it is explicitly | |||
* disposed. | * disposed. | |||
* | * | |||
skipping to change at line 513 | skipping to change at line 516 | |||
V8_INLINE(void Clear()) { val_ = 0; } | V8_INLINE(void Clear()) { val_ = 0; } | |||
/** | /** | |||
* A constructor that creates a new global cell pointing to that. In cont rast | * A constructor that creates a new global cell pointing to that. In cont rast | |||
* to the copy constructor, this creates a new persistent handle which ne eds | * to the copy constructor, this creates a new persistent handle which ne eds | |||
* to be separately disposed. | * to be separately disposed. | |||
*/ | */ | |||
template <class S> V8_INLINE(Persistent(Isolate* isolate, Handle<S> that) ) | template <class S> V8_INLINE(Persistent(Isolate* isolate, Handle<S> that) ) | |||
: val_(*New(isolate, that)) { } | : val_(*New(isolate, that)) { } | |||
template <class S> V8_INLINE(Persistent(Isolate* isolate, | ||||
Persistent<S>& that)) // NOLINT | ||||
: val_(*New(isolate, that)) { } | ||||
#else | #else | |||
/** | /** | |||
* Creates an empty persistent handle that doesn't point to any | * Creates an empty persistent handle that doesn't point to any | |||
* storage cell. | * storage cell. | |||
*/ | */ | |||
V8_INLINE(Persistent()) : Handle<T>() { } | V8_INLINE(Persistent()) : Handle<T>() { } | |||
/** | /** | |||
* Creates a persistent handle for the same storage cell as the | * Creates a persistent handle for the same storage cell as the | |||
* specified handle. This constructor allows you to pass persistent | * specified handle. This constructor allows you to pass persistent | |||
skipping to change at line 629 | skipping to change at line 636 | |||
#endif | #endif | |||
V8_INLINE(void Dispose()); | V8_INLINE(void Dispose()); | |||
/** | /** | |||
* Releases the storage cell referenced by this persistent handle. | * Releases the storage cell referenced by this persistent handle. | |||
* Does not remove the reference to the cell from any handles. | * Does not remove the reference to the cell from any handles. | |||
* This handle's reference, and any other references to the storage | * This handle's reference, and any other references to the storage | |||
* cell remain and IsEmpty will still return false. | * cell remain and IsEmpty will still return false. | |||
*/ | */ | |||
// TODO(dcarney): remove before cutover | // TODO(dcarney): deprecate | |||
V8_INLINE(void Dispose(Isolate* isolate)); | V8_INLINE(void Dispose(Isolate* isolate)) { Dispose(); } | |||
/** | ||||
* Make the reference to this object weak. When only weak handles | ||||
* refer to the object, the garbage collector will perform a | ||||
* callback to the given V8::NearDeathCallback function, passing | ||||
* it the object reference and the given parameters. | ||||
*/ | ||||
template<typename S, typename P> | template<typename S, typename P> | |||
V8_INLINE(void MakeWeak( | V8_INLINE(void MakeWeak( | |||
Isolate* isolate, | ||||
P* parameters, | P* parameters, | |||
typename WeakReferenceCallbacks<S, P>::Revivable callback)); | typename WeakReferenceCallbacks<S, P>::Revivable callback)); | |||
template<typename P> | template<typename P> | |||
V8_INLINE(void MakeWeak( | V8_INLINE(void MakeWeak( | |||
Isolate* isolate, | ||||
P* parameters, | P* parameters, | |||
typename WeakReferenceCallbacks<T, P>::Revivable callback)); | typename WeakReferenceCallbacks<T, P>::Revivable callback)); | |||
/** | // TODO(dcarney): deprecate | |||
* Make the reference to this object weak. When only weak handles | template<typename S, typename P> | |||
* refer to the object, the garbage collector will perform a | V8_INLINE(void MakeWeak( | |||
* callback to the given V8::NearDeathCallback function, passing | Isolate* isolate, | |||
* it the object reference and the given parameters. | P* parameters, | |||
*/ | typename WeakReferenceCallbacks<S, P>::Revivable callback)) { | |||
MakeWeak<S, P>(parameters, callback); | ||||
} | ||||
// TODO(dcarney): deprecate | ||||
template<typename P> | ||||
V8_INLINE(void MakeWeak( | ||||
Isolate* isolate, | ||||
P* parameters, | ||||
typename WeakReferenceCallbacks<T, P>::Revivable callback)) { | ||||
MakeWeak<P>(parameters, callback); | ||||
} | ||||
// TODO(dcarney): remove before cutover | // TODO(dcarney): remove before cutover | |||
V8_INLINE(void MakeWeak(Isolate* isolate, | V8_INLINE(void MakeWeak(Isolate* isolate, | |||
void* parameters, | void* parameters, | |||
NearDeathCallback callback)); | NearDeathCallback callback)); | |||
V8_INLINE(void ClearWeak()); | V8_INLINE(void ClearWeak()); | |||
// TODO(dcarney): remove before cutover | // TODO(dcarney): deprecate | |||
V8_INLINE(void ClearWeak(Isolate* isolate)); | V8_INLINE(void ClearWeak(Isolate* isolate)) { ClearWeak(); } | |||
V8_INLINE(void MarkIndependent()); | ||||
/** | /** | |||
* Marks the reference to this object independent. Garbage collector is f ree | * Marks the reference to this object independent. Garbage collector is f ree | |||
* to ignore any object groups containing this object. Weak callback for an | * to ignore any object groups containing this object. Weak callback for an | |||
* independent handle should not assume that it will be preceded by a glo bal | * independent handle should not assume that it will be preceded by a glo bal | |||
* GC prologue callback or followed by a global GC epilogue callback. | * GC prologue callback or followed by a global GC epilogue callback. | |||
*/ | */ | |||
// TODO(dcarney): remove before cutover | V8_INLINE(void MarkIndependent()); | |||
V8_INLINE(void MarkIndependent(Isolate* isolate)); | ||||
V8_INLINE(void MarkPartiallyDependent()); | // TODO(dcarney): deprecate | |||
V8_INLINE(void MarkIndependent(Isolate* isolate)) { MarkIndependent(); } | ||||
/** | /** | |||
* Marks the reference to this object partially dependent. Partially depe ndent | * Marks the reference to this object partially dependent. Partially depe ndent | |||
* handles only depend on other partially dependent handles and these | * handles only depend on other partially dependent handles and these | |||
* dependencies are provided through object groups. It provides a way to build | * dependencies are provided through object groups. It provides a way to build | |||
* smaller object groups for young objects that represent only a subset o f all | * smaller object groups for young objects that represent only a subset o f all | |||
* external dependencies. This mark is automatically cleared after each | * external dependencies. This mark is automatically cleared after each | |||
* garbage collection. | * garbage collection. | |||
*/ | */ | |||
// TODO(dcarney): remove before cutover | V8_INLINE(void MarkPartiallyDependent()); | |||
V8_INLINE(void MarkPartiallyDependent(Isolate* isolate)); | ||||
V8_INLINE(bool IsIndependent() const); | // TODO(dcarney): deprecate | |||
V8_INLINE(void MarkPartiallyDependent(Isolate* isolate)) { | ||||
MarkPartiallyDependent(); | ||||
} | ||||
// TODO(dcarney): remove before cutover | V8_INLINE(bool IsIndependent() const); | |||
V8_INLINE(bool IsIndependent(Isolate* isolate) const); | ||||
V8_INLINE(bool IsNearDeath() const); | // TODO(dcarney): deprecate | |||
V8_INLINE(bool IsIndependent(Isolate* isolate) const) { | ||||
return IsIndependent(); | ||||
} | ||||
/** Checks if the handle holds the only reference to an object. */ | /** Checks if the handle holds the only reference to an object. */ | |||
// TODO(dcarney): remove before cutover | V8_INLINE(bool IsNearDeath() const); | |||
V8_INLINE(bool IsNearDeath(Isolate* isolate) const); | ||||
V8_INLINE(bool IsWeak() const); | // TODO(dcarney): deprecate | |||
V8_INLINE(bool IsNearDeath(Isolate* isolate) const) { return IsNearDeath( | ||||
); } | ||||
/** Returns true if the handle's reference is weak. */ | /** Returns true if the handle's reference is weak. */ | |||
// TODO(dcarney): remove before cutover | V8_INLINE(bool IsWeak() const); | |||
V8_INLINE(bool IsWeak(Isolate* isolate) const); | ||||
V8_INLINE(void SetWrapperClassId(uint16_t class_id)); | // TODO(dcarney): deprecate | |||
V8_INLINE(bool IsWeak(Isolate* isolate) const) { return IsWeak(); } | ||||
/** | /** | |||
* Assigns a wrapper class ID to the handle. See RetainedObjectInfo inter face | * Assigns a wrapper class ID to the handle. See RetainedObjectInfo inter face | |||
* description in v8-profiler.h for details. | * description in v8-profiler.h for details. | |||
*/ | */ | |||
// TODO(dcarney): remove before cutover | V8_INLINE(void SetWrapperClassId(uint16_t class_id)); | |||
V8_INLINE(void SetWrapperClassId(Isolate* isolate, uint16_t class_id)); | ||||
V8_INLINE(uint16_t WrapperClassId() const); | // TODO(dcarney): deprecate | |||
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 cla ss ID | * Returns the class ID previously assigned to this handle or 0 if no cla ss ID | |||
* was previously assigned. | * was previously assigned. | |||
*/ | */ | |||
// TODO(dcarney): remove before cutover | V8_INLINE(uint16_t WrapperClassId() const); | |||
V8_INLINE(uint16_t WrapperClassId(Isolate* isolate) const); | ||||
// TODO(dcarney): deprecate | ||||
V8_INLINE(uint16_t WrapperClassId(Isolate* isolate) const) { | ||||
return WrapperClassId(); | ||||
} | ||||
/** | /** | |||
* Disposes the current contents of the handle and replaces it. | * Disposes the current contents of the handle and replaces it. | |||
*/ | */ | |||
V8_INLINE(void Reset(Isolate* isolate, const Handle<T>& other)); | V8_INLINE(void Reset(Isolate* isolate, const Handle<T>& other)); | |||
#ifndef V8_USE_UNSAFE_HANDLES | ||||
V8_INLINE(void Reset(Isolate* isolate, const Persistent<T>& other)); | ||||
#endif | ||||
/** | /** | |||
* Returns the underlying raw pointer and clears the handle. The caller i s | * Returns the underlying raw pointer and clears the handle. The caller i s | |||
* responsible of eventually destroying the underlying object (by creatin g a | * responsible of eventually destroying the underlying object (by creatin g a | |||
* Persistent handle which points to it and Disposing it). In the future, | * Persistent handle which points to it and Disposing it). In the future, | |||
* destructing a Persistent will also Dispose it. With this function, the | * destructing a Persistent will also Dispose it. With this function, the | |||
* embedder can let the Persistent go out of scope without it getting | * embedder can let the Persistent go out of scope without it getting | |||
* disposed. | * disposed. | |||
*/ | */ | |||
V8_INLINE(T* ClearAndLeak()); | V8_INLINE(T* ClearAndLeak()); | |||
skipping to change at line 773 | skipping to change at line 808 | |||
#ifndef V8_ALLOW_ACCESS_TO_PERSISTENT_ARROW | #ifndef V8_ALLOW_ACCESS_TO_PERSISTENT_ARROW | |||
private: | private: | |||
#endif | #endif | |||
// TODO(dcarney): remove before cutover | // TODO(dcarney): remove before cutover | |||
V8_INLINE(T* operator->() const) { return val_; } | V8_INLINE(T* operator->() const) { return val_; } | |||
public: | public: | |||
#endif | #endif | |||
private: | private: | |||
template<class F> | template<class F> friend class Handle; | |||
friend class Handle; | template<class F> friend class Local; | |||
template<class F> | ||||
friend class Local; | ||||
friend class ImplementationUtilities; | friend class ImplementationUtilities; | |||
friend class ObjectTemplate; | friend class ObjectTemplate; | |||
friend class Context; | friend class Context; | |||
friend class InternalHandleHelper; | friend class InternalHandleHelper; | |||
friend class LocalContext; | friend class LocalContext; | |||
V8_INLINE(static Persistent<T> New(Isolate* isolate, T* that)); | V8_INLINE(static Persistent<T> New(Isolate* isolate, T* that)); | |||
#ifndef V8_USE_UNSAFE_HANDLES | #ifndef V8_USE_UNSAFE_HANDLES | |||
T* val_; | T* val_; | |||
skipping to change at line 1207 | skipping to change at line 1240 | |||
/** | /** | |||
* Returns the name of the resource that contains the script for the | * Returns the name of the resource that contains the script for the | |||
* function for this StackFrame. | * function for this StackFrame. | |||
*/ | */ | |||
Local<String> GetScriptName() const; | Local<String> GetScriptName() const; | |||
/** | /** | |||
* Returns the name of the resource that contains the script for the | * Returns the name of the resource that contains the script for the | |||
* function for this StackFrame or sourceURL value if the script name | * function for this StackFrame or sourceURL value if the script name | |||
* is undefined and its source ends with //@ sourceURL=... string. | * is undefined and its source ends with //# sourceURL=... string or | |||
* deprecated //@ sourceURL=... string. | ||||
*/ | */ | |||
Local<String> GetScriptNameOrSourceURL() const; | Local<String> GetScriptNameOrSourceURL() const; | |||
/** | /** | |||
* Returns the name of the function associated with this stack frame. | * Returns the name of the function associated with this stack frame. | |||
*/ | */ | |||
Local<String> GetFunctionName() const; | Local<String> GetFunctionName() const; | |||
/** | /** | |||
* Returns whether or not the associated function is compiled via a call to | * Returns whether or not the associated function is compiled via a call to | |||
skipping to change at line 4010 | skipping to change at line 4044 | |||
virtual ~ExternalResourceVisitor() {} | virtual ~ExternalResourceVisitor() {} | |||
virtual void VisitExternalString(Handle<String> string) {} | virtual void VisitExternalString(Handle<String> string) {} | |||
}; | }; | |||
/** | /** | |||
* Interface for iterating through all the persistent handles in the heap. | * Interface for iterating through all the persistent handles in the heap. | |||
*/ | */ | |||
class V8EXPORT PersistentHandleVisitor { // NOLINT | class V8EXPORT PersistentHandleVisitor { // NOLINT | |||
public: | public: | |||
virtual ~PersistentHandleVisitor() {} | virtual ~PersistentHandleVisitor() {} | |||
#ifdef V8_USE_OLD_STYLE_PERSISTENT_HANDLE_VISITORS | ||||
virtual void VisitPersistentHandle(Persistent<Value> value, | virtual void VisitPersistentHandle(Persistent<Value> value, | |||
uint16_t class_id) {} | uint16_t class_id) {} | |||
#else | ||||
virtual void VisitPersistentHandle(Persistent<Value>* value, | ||||
uint16_t class_id) {} | ||||
#endif | ||||
}; | }; | |||
/** | /** | |||
* Asserts that no action is performed that could cause a handle's value | * Asserts that no action is performed that could cause a handle's value | |||
* to be modified. Useful when otherwise unsafe handle operations need to | * to be modified. Useful when otherwise unsafe handle operations need to | |||
* be performed. | * be performed. | |||
*/ | */ | |||
class V8EXPORT AssertNoGCScope { | class V8EXPORT AssertNoGCScope { | |||
#ifndef DEBUG | #ifndef DEBUG | |||
V8_INLINE(AssertNoGCScope(Isolate* isolate)) {} | V8_INLINE(AssertNoGCScope(Isolate* isolate)) {} | |||
skipping to change at line 4235 | skipping to change at line 4274 | |||
* further callbacks. | * further callbacks. | |||
*/ | */ | |||
static void AddCallCompletedCallback(CallCompletedCallback callback); | static void AddCallCompletedCallback(CallCompletedCallback callback); | |||
/** | /** | |||
* Removes callback that was installed by AddCallCompletedCallback. | * Removes callback that was installed by AddCallCompletedCallback. | |||
*/ | */ | |||
static void RemoveCallCompletedCallback(CallCompletedCallback callback); | static void RemoveCallCompletedCallback(CallCompletedCallback callback); | |||
/** | /** | |||
* 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 | ||||
* intended to be used in the before-garbage-collection callback | ||||
* function, for instance to simulate DOM tree connections among JS | ||||
* wrapper objects. Object groups for all dependent handles need to | ||||
* be provided for kGCTypeMarkSweepCompact collections, for all other | ||||
* garbage collection types it is sufficient to provide object groups | ||||
* for partially dependent handles only. | ||||
* See v8-profiler.h for RetainedObjectInfo interface description. | ||||
*/ | ||||
// TODO(marja): deprecate AddObjectGroup. Use Isolate::SetObjectGroupId a | ||||
nd | ||||
// HeapProfiler::SetRetainedObjectInfo instead. | ||||
static void AddObjectGroup(Persistent<Value>* objects, | ||||
size_t length, | ||||
RetainedObjectInfo* info = NULL); | ||||
static void AddObjectGroup(Isolate* isolate, | ||||
Persistent<Value>* objects, | ||||
size_t length, | ||||
RetainedObjectInfo* info = NULL); | ||||
/** | ||||
* Allows the host application to declare implicit references between | ||||
* the objects: if |parent| is alive, all |children| are alive too. | ||||
* After each garbage collection, all implicit references | ||||
* are removed. It is intended to be used in the before-garbage-collecti | ||||
on | ||||
* callback function. | ||||
*/ | ||||
// TODO(marja): Deprecate AddImplicitReferences. Use | ||||
// Isolate::SetReferenceFromGroup instead. | ||||
static void AddImplicitReferences(Persistent<Object> parent, | ||||
Persistent<Value>* children, | ||||
size_t length); | ||||
/** | ||||
* Initializes from snapshot if possible. Otherwise, attempts to | * Initializes from snapshot if possible. Otherwise, attempts to | |||
* initialize from scratch. This function is called implicitly if | * initialize from scratch. This function is called implicitly if | |||
* you use the API without calling it first. | * you use the API without calling it first. | |||
*/ | */ | |||
static bool Initialize(); | static bool Initialize(); | |||
/** | /** | |||
* Allows the host application to provide a callback which can be used | * Allows the host application to provide a callback which can be used | |||
* as a source of entropy for random number generators. | * as a source of entropy for random number generators. | |||
*/ | */ | |||
skipping to change at line 4501 | skipping to change at line 4505 | |||
*/ | */ | |||
static int ContextDisposedNotification(); | static int ContextDisposedNotification(); | |||
private: | private: | |||
V8(); | V8(); | |||
static internal::Object** GlobalizeReference(internal::Isolate* isolate, | static internal::Object** GlobalizeReference(internal::Isolate* isolate, | |||
internal::Object** handle); | internal::Object** handle); | |||
static void DisposeGlobal(internal::Object** global_handle); | static void DisposeGlobal(internal::Object** global_handle); | |||
typedef WeakReferenceCallbacks<Value, void>::Revivable RevivableCallback; | typedef WeakReferenceCallbacks<Value, void>::Revivable RevivableCallback; | |||
static void MakeWeak(internal::Isolate* isolate, | static void MakeWeak(internal::Object** global_handle, | |||
internal::Object** global_handle, | ||||
void* data, | void* data, | |||
RevivableCallback weak_reference_callback, | RevivableCallback weak_reference_callback, | |||
NearDeathCallback near_death_callback); | NearDeathCallback near_death_callback); | |||
static void ClearWeak(internal::Isolate* isolate, | static void ClearWeak(internal::Object** global_handle); | |||
internal::Object** global_handle); | ||||
template <class T> friend class Handle; | template <class T> friend class Handle; | |||
template <class T> friend class Local; | template <class T> friend class Local; | |||
template <class T> friend class Persistent; | template <class T> friend class Persistent; | |||
friend class Context; | friend class Context; | |||
}; | }; | |||
/** | /** | |||
* An external exception handler. | * An external exception handler. | |||
*/ | */ | |||
skipping to change at line 5378 | skipping to change at line 5380 | |||
Persistent<T> Persistent<T>::New(Isolate* isolate, T* that) { | Persistent<T> Persistent<T>::New(Isolate* isolate, T* that) { | |||
if (that == NULL) return Persistent<T>(); | if (that == NULL) return Persistent<T>(); | |||
internal::Object** p = reinterpret_cast<internal::Object**>(that); | internal::Object** p = reinterpret_cast<internal::Object**>(that); | |||
return Persistent<T>(reinterpret_cast<T*>( | return Persistent<T>(reinterpret_cast<T*>( | |||
V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), | V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), | |||
p))); | p))); | |||
} | } | |||
template <class T> | template <class T> | |||
bool Persistent<T>::IsIndependent() const { | bool Persistent<T>::IsIndependent() const { | |||
return IsIndependent(Isolate::GetCurrent()); | ||||
} | ||||
template <class T> | ||||
bool Persistent<T>::IsIndependent(Isolate* isolate) const { | ||||
typedef internal::Internals I; | typedef internal::Internals I; | |||
if (this->IsEmpty()) return false; | if (this->IsEmpty()) return false; | |||
if (!I::IsInitialized(isolate)) return false; | ||||
return I::GetNodeFlag(reinterpret_cast<internal::Object**>(this->val_), | return I::GetNodeFlag(reinterpret_cast<internal::Object**>(this->val_), | |||
I::kNodeIsIndependentShift); | I::kNodeIsIndependentShift); | |||
} | } | |||
template <class T> | template <class T> | |||
bool Persistent<T>::IsNearDeath() const { | bool Persistent<T>::IsNearDeath() const { | |||
return IsNearDeath(Isolate::GetCurrent()); | ||||
} | ||||
template <class T> | ||||
bool Persistent<T>::IsNearDeath(Isolate* isolate) const { | ||||
typedef internal::Internals I; | typedef internal::Internals I; | |||
if (this->IsEmpty()) return false; | if (this->IsEmpty()) return false; | |||
if (!I::IsInitialized(isolate)) return false; | ||||
return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) == | return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) == | |||
I::kNodeStateIsNearDeathValue; | I::kNodeStateIsNearDeathValue; | |||
} | } | |||
template <class T> | template <class T> | |||
bool Persistent<T>::IsWeak() const { | bool Persistent<T>::IsWeak() const { | |||
return IsWeak(Isolate::GetCurrent()); | ||||
} | ||||
template <class T> | ||||
bool Persistent<T>::IsWeak(Isolate* isolate) const { | ||||
typedef internal::Internals I; | typedef internal::Internals I; | |||
if (this->IsEmpty()) return false; | if (this->IsEmpty()) return false; | |||
if (!I::IsInitialized(isolate)) return false; | ||||
return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) == | return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) == | |||
I::kNodeStateIsWeakValue; | I::kNodeStateIsWeakValue; | |||
} | } | |||
template <class T> | template <class T> | |||
void Persistent<T>::Dispose() { | void Persistent<T>::Dispose() { | |||
if (this->IsEmpty()) return; | if (this->IsEmpty()) return; | |||
V8::DisposeGlobal(reinterpret_cast<internal::Object**>(this->val_)); | V8::DisposeGlobal(reinterpret_cast<internal::Object**>(this->val_)); | |||
#ifndef V8_USE_UNSAFE_HANDLES | #ifndef V8_USE_UNSAFE_HANDLES | |||
val_ = 0; | val_ = 0; | |||
#endif | #endif | |||
} | } | |||
template <class T> | template <class T> | |||
void Persistent<T>::Dispose(Isolate* isolate) { | ||||
Dispose(); | ||||
} | ||||
template <class T> | ||||
template <typename S, typename P> | template <typename S, typename P> | |||
void Persistent<T>::MakeWeak( | void Persistent<T>::MakeWeak( | |||
Isolate* isolate, | ||||
P* parameters, | P* parameters, | |||
typename WeakReferenceCallbacks<S, P>::Revivable callback) { | typename WeakReferenceCallbacks<S, P>::Revivable callback) { | |||
TYPE_CHECK(S, T); | TYPE_CHECK(S, T); | |||
typedef typename WeakReferenceCallbacks<Value, void>::Revivable Revivable ; | typedef typename WeakReferenceCallbacks<Value, void>::Revivable Revivable ; | |||
V8::MakeWeak(reinterpret_cast<internal::Isolate*>(isolate), | V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), | |||
reinterpret_cast<internal::Object**>(this->val_), | ||||
parameters, | parameters, | |||
reinterpret_cast<Revivable>(callback), | reinterpret_cast<Revivable>(callback), | |||
NULL); | NULL); | |||
} | } | |||
template <class T> | template <class T> | |||
template <typename P> | template <typename P> | |||
void Persistent<T>::MakeWeak( | void Persistent<T>::MakeWeak( | |||
Isolate* isolate, | ||||
P* parameters, | P* parameters, | |||
typename WeakReferenceCallbacks<T, P>::Revivable callback) { | typename WeakReferenceCallbacks<T, P>::Revivable callback) { | |||
MakeWeak<T, P>(isolate, parameters, callback); | MakeWeak<T, P>(parameters, callback); | |||
} | } | |||
template <class T> | template <class T> | |||
void Persistent<T>::MakeWeak(Isolate* isolate, | void Persistent<T>::MakeWeak(Isolate* isolate, | |||
void* parameters, | void* parameters, | |||
NearDeathCallback callback) { | NearDeathCallback callback) { | |||
V8::MakeWeak(reinterpret_cast<internal::Isolate*>(isolate), | V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), | |||
reinterpret_cast<internal::Object**>(this->val_), | ||||
parameters, | parameters, | |||
NULL, | NULL, | |||
callback); | callback); | |||
} | } | |||
template <class T> | template <class T> | |||
void Persistent<T>::ClearWeak() { | void Persistent<T>::ClearWeak() { | |||
ClearWeak(Isolate::GetCurrent()); | V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_)); | |||
} | ||||
template <class T> | ||||
void Persistent<T>::ClearWeak(Isolate* isolate) { | ||||
V8::ClearWeak(reinterpret_cast<internal::Isolate*>(isolate), | ||||
reinterpret_cast<internal::Object**>(this->val_)); | ||||
} | } | |||
template <class T> | template <class T> | |||
void Persistent<T>::MarkIndependent() { | void Persistent<T>::MarkIndependent() { | |||
MarkIndependent(Isolate::GetCurrent()); | ||||
} | ||||
template <class T> | ||||
void Persistent<T>::MarkIndependent(Isolate* isolate) { | ||||
typedef internal::Internals I; | typedef internal::Internals I; | |||
if (this->IsEmpty()) return; | if (this->IsEmpty()) return; | |||
if (!I::IsInitialized(isolate)) return; | ||||
I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), | I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), | |||
true, | true, | |||
I::kNodeIsIndependentShift); | I::kNodeIsIndependentShift); | |||
} | } | |||
template <class T> | template <class T> | |||
void Persistent<T>::MarkPartiallyDependent() { | void Persistent<T>::MarkPartiallyDependent() { | |||
MarkPartiallyDependent(Isolate::GetCurrent()); | ||||
} | ||||
template <class T> | ||||
void Persistent<T>::MarkPartiallyDependent(Isolate* isolate) { | ||||
typedef internal::Internals I; | typedef internal::Internals I; | |||
if (this->IsEmpty()) return; | if (this->IsEmpty()) return; | |||
if (!I::IsInitialized(isolate)) return; | ||||
I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), | I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), | |||
true, | true, | |||
I::kNodeIsPartiallyDependentShift); | I::kNodeIsPartiallyDependentShift); | |||
} | } | |||
template <class T> | template <class T> | |||
void Persistent<T>::SetWrapperClassId(uint16_t class_id) { | ||||
SetWrapperClassId(Isolate::GetCurrent(), class_id); | ||||
} | ||||
template <class T> | ||||
void Persistent<T>::Reset(Isolate* isolate, const Handle<T>& other) { | void Persistent<T>::Reset(Isolate* isolate, const Handle<T>& other) { | |||
Dispose(isolate); | Dispose(isolate); | |||
#ifdef V8_USE_UNSAFE_HANDLES | #ifdef V8_USE_UNSAFE_HANDLES | |||
*this = *New(isolate, other); | *this = *New(isolate, other); | |||
#else | #else | |||
if (other.IsEmpty()) { | if (other.IsEmpty()) { | |||
this->val_ = NULL; | this->val_ = NULL; | |||
return; | return; | |||
} | } | |||
internal::Object** p = reinterpret_cast<internal::Object**>(other.val_); | internal::Object** p = reinterpret_cast<internal::Object**>(other.val_); | |||
this->val_ = reinterpret_cast<T*>( | this->val_ = reinterpret_cast<T*>( | |||
V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), p)); | V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), p)); | |||
#endif | #endif | |||
} | } | |||
#ifndef V8_USE_UNSAFE_HANDLES | ||||
template <class T> | ||||
void Persistent<T>::Reset(Isolate* isolate, const Persistent<T>& other) { | ||||
Dispose(isolate); | ||||
if (other.IsEmpty()) { | ||||
this->val_ = NULL; | ||||
return; | ||||
} | ||||
internal::Object** p = reinterpret_cast<internal::Object**>(other.val_); | ||||
this->val_ = reinterpret_cast<T*>( | ||||
V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), | ||||
p)); | ||||
} | ||||
#endif | ||||
template <class T> | template <class T> | |||
T* Persistent<T>::ClearAndLeak() { | T* Persistent<T>::ClearAndLeak() { | |||
T* old; | T* old; | |||
#ifdef V8_USE_UNSAFE_HANDLES | #ifdef V8_USE_UNSAFE_HANDLES | |||
old = **this; | old = **this; | |||
*this = Persistent<T>(); | *this = Persistent<T>(); | |||
#else | #else | |||
old = val_; | old = val_; | |||
val_ = NULL; | val_ = NULL; | |||
#endif | #endif | |||
return old; | return old; | |||
} | } | |||
template <class T> | template <class T> | |||
void Persistent<T>::SetWrapperClassId(Isolate* isolate, uint16_t class_id) { | void Persistent<T>::SetWrapperClassId(uint16_t class_id) { | |||
typedef internal::Internals I; | typedef internal::Internals I; | |||
if (this->IsEmpty()) return; | if (this->IsEmpty()) return; | |||
if (!I::IsInitialized(isolate)) return; | ||||
internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_) ; | internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_) ; | |||
uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; | |||
*reinterpret_cast<uint16_t*>(addr) = class_id; | *reinterpret_cast<uint16_t*>(addr) = class_id; | |||
} | } | |||
template <class T> | template <class T> | |||
uint16_t Persistent<T>::WrapperClassId() const { | uint16_t Persistent<T>::WrapperClassId() const { | |||
return WrapperClassId(Isolate::GetCurrent()); | ||||
} | ||||
template <class T> | ||||
uint16_t Persistent<T>::WrapperClassId(Isolate* isolate) const { | ||||
typedef internal::Internals I; | typedef internal::Internals I; | |||
if (this->IsEmpty()) return 0; | if (this->IsEmpty()) return 0; | |||
if (!I::IsInitialized(isolate)) return 0; | ||||
internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_) ; | internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_) ; | |||
uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; | |||
return *reinterpret_cast<uint16_t*>(addr); | return *reinterpret_cast<uint16_t*>(addr); | |||
} | } | |||
template<typename T> | template<typename T> | |||
ReturnValue<T>::ReturnValue(internal::Object** slot) : value_(slot) {} | ReturnValue<T>::ReturnValue(internal::Object** slot) : value_(slot) {} | |||
template<typename T> | template<typename T> | |||
template<typename S> | template<typename S> | |||
void ReturnValue<T>::Set(const Persistent<S>& handle) { | void ReturnValue<T>::Set(const Persistent<S>& handle) { | |||
TYPE_CHECK(T, S); | TYPE_CHECK(T, S); | |||
*value_ = *reinterpret_cast<internal::Object**>(*handle); | if (V8_UNLIKELY(handle.IsEmpty())) { | |||
SetUndefined(); | ||||
} else { | ||||
*value_ = *reinterpret_cast<internal::Object**>(*handle); | ||||
} | ||||
} | } | |||
template<typename T> | template<typename T> | |||
template<typename S> | template<typename S> | |||
void ReturnValue<T>::Set(const Handle<S> handle) { | void ReturnValue<T>::Set(const Handle<S> handle) { | |||
TYPE_CHECK(T, S); | TYPE_CHECK(T, S); | |||
*value_ = *reinterpret_cast<internal::Object**>(*handle); | if (V8_UNLIKELY(handle.IsEmpty())) { | |||
SetUndefined(); | ||||
} else { | ||||
*value_ = *reinterpret_cast<internal::Object**>(*handle); | ||||
} | ||||
} | } | |||
template<typename T> | template<typename T> | |||
void ReturnValue<T>::Set(double i) { | void ReturnValue<T>::Set(double i) { | |||
Set(Number::New(GetIsolate(), i)); | Set(Number::New(GetIsolate(), i)); | |||
} | } | |||
template<typename T> | template<typename T> | |||
void ReturnValue<T>::Set(int32_t i) { | void ReturnValue<T>::Set(int32_t i) { | |||
typedef internal::Internals I; | typedef internal::Internals I; | |||
End of changes. 60 change blocks. | ||||
152 lines changed or deleted | 119 lines changed or added | |||