From 202a97c88eb6807915135a1e6be9aa921cd8efac Mon Sep 17 00:00:00 2001 From: dcarney Date: Tue, 21 Apr 2015 01:16:12 -0700 Subject: [PATCH] make Handle a synonym of Local R=svenpanne@chromium.org BUG= Review URL: https://codereview.chromium.org/679143002 Cr-Commit-Position: refs/heads/master@{#27951} --- include/v8.h | 146 +++++++++++------------------------------------------------ src/checks.h | 1 - 2 files changed, 27 insertions(+), 120 deletions(-) diff --git a/include/v8.h b/include/v8.h index 3bc0c71..bca6bf1 100644 --- a/include/v8.h +++ b/include/v8.h @@ -106,7 +106,6 @@ class Private; class Uint32; class Utils; class Value; -template class Handle; template class Local; template class MaybeLocal; @@ -203,28 +202,16 @@ class UniqueId { * * It is safe to extract the object stored in the handle by * dereferencing the handle (for instance, to extract the Object* from - * a Handle); the value will still be governed by a handle + * a Local); the value will still be governed by a handle * behind the scenes and the same rules apply to these values as to * their handles. */ -template class Handle { +template +class Local { public: - /** - * Creates an empty handle. - */ - V8_INLINE Handle() : val_(0) {} - - /** - * Creates a handle for the contents of the specified handle. This - * constructor allows you to pass handles as arguments by value and - * to assign between handles. However, if you try to assign between - * incompatible handles, for instance from a Handle to a - * Handle it will cause a compile-time error. Assigning - * between compatible handles, for instance assigning a - * Handle to a variable declared as Handle, is legal - * because String is a subclass of Value. - */ - template V8_INLINE Handle(Handle that) + V8_INLINE Local() : val_(0) {} + template + V8_INLINE Local(Local that) : val_(reinterpret_cast(*that)) { /** * This check fails when trying to convert between incompatible @@ -254,7 +241,8 @@ template class Handle { * to which they refer are identical. * The handles' references are not checked. */ - template V8_INLINE bool operator==(const Handle& that) const { + template + V8_INLINE bool operator==(const Local& that) const { internal::Object** a = reinterpret_cast(this->val_); internal::Object** b = reinterpret_cast(that.val_); if (a == 0) return b == 0; @@ -277,7 +265,8 @@ template class Handle { * the objects to which they refer are different. * The handles' references are not checked. */ - template V8_INLINE bool operator!=(const Handle& that) const { + template + V8_INLINE bool operator!=(const Local& that) const { return !operator==(that); } @@ -286,79 +275,6 @@ template class Handle { return !operator==(that); } - template V8_INLINE static Handle Cast(Handle that) { -#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()) return Handle(); -#endif - return Handle(T::Cast(*that)); - } - - template V8_INLINE Handle As() { - return Handle::Cast(*this); - } - - V8_INLINE static Handle New(Isolate* isolate, Handle that) { - return New(isolate, that.val_); - } - V8_INLINE static Handle New(Isolate* isolate, - const PersistentBase& that) { - return New(isolate, that.val_); - } - - private: - friend class Utils; - template friend class Persistent; - template friend class PersistentBase; - template friend class Handle; - template friend class Local; - template - friend class MaybeLocal; - template friend class FunctionCallbackInfo; - template friend class PropertyCallbackInfo; - template friend class internal::CustomArguments; - friend Handle Undefined(Isolate* isolate); - friend Handle Null(Isolate* isolate); - friend Handle True(Isolate* isolate); - friend Handle False(Isolate* isolate); - friend class Context; - friend class HandleScope; - friend class Object; - friend class Private; - - /** - * Creates a new handle for the specified value. - */ - V8_INLINE explicit Handle(T* val) : val_(val) {} - - V8_INLINE static Handle New(Isolate* isolate, T* that); - - T* val_; -}; - - -/** - * A light-weight stack-allocated object handle. All operations - * that return objects from within v8 return them in local handles. They - * are created within HandleScopes, and all local handles allocated within a - * handle scope are destroyed when the handle scope is destroyed. Hence it - * is not necessary to explicitly deallocate local handles. - */ -template class Local : public Handle { - public: - V8_INLINE Local(); - template V8_INLINE Local(Local that) - : Handle(reinterpret_cast(*that)) { - /** - * This check fails when trying to convert between incompatible - * handles. For example, converting from a Handle to a - * Handle. - */ - TYPE_CHECK(T, S); - } - - template V8_INLINE static Local Cast(Local that) { #ifdef V8_ENABLE_CHECKS // If we're going to perform the type check then we have to check @@ -367,10 +283,7 @@ template class Local : public Handle { #endif return Local(T::Cast(*that)); } - template V8_INLINE Local(Handle that) - : Handle(reinterpret_cast(*that)) { - TYPE_CHECK(T, S); - } + template V8_INLINE Local As() { return Local::Cast(*this); @@ -381,7 +294,7 @@ template class Local : public Handle { * The referee is kept alive by the local handle even when * the original handle is destroyed/disposed. */ - V8_INLINE static Local New(Isolate* isolate, Handle that); + V8_INLINE static Local New(Isolate* isolate, Local that); V8_INLINE static Local New(Isolate* isolate, const PersistentBase& that); @@ -390,7 +303,6 @@ template class Local : public Handle { template friend class Eternal; template friend class PersistentBase; template friend class Persistent; - template friend class Handle; template friend class Local; template friend class MaybeLocal; @@ -399,18 +311,31 @@ template class Local : public Handle { friend class String; friend class Object; friend class Context; + friend class Private; template friend class internal::CustomArguments; + friend Local Undefined(Isolate* isolate); + friend Local Null(Isolate* isolate); + friend Local True(Isolate* isolate); + friend Local False(Isolate* isolate); friend class HandleScope; friend class EscapableHandleScope; template friend class PersistentValueMapBase; template friend class PersistentValueVector; - template V8_INLINE Local(S* that) : Handle(that) { } + template + V8_INLINE Local(S* that) + : val_(that) {} V8_INLINE static Local New(Isolate* isolate, T* that); + T* val_; }; +// Handle is an alias for Local for historical reasons. +template +using Handle = Local; + + /** * A MaybeLocal<> is a wrapper around Local<> that enforces a check whether * the Local<> is empty before it can be used. @@ -694,7 +619,6 @@ template class PersistentBase { private: friend class Isolate; friend class Utils; - template friend class Handle; template friend class Local; template friend class Persistent; template @@ -837,7 +761,6 @@ template class Persistent : public PersistentBase { private: friend class Isolate; friend class Utils; - template friend class Handle; template friend class Local; template friend class Persistent; template friend class ReturnValue; @@ -6087,8 +6010,6 @@ class V8_EXPORT V8 { static void FromJustIsNothing(); static void ToLocalEmpty(); static void InternalFieldOutOfBounds(int index); - - template friend class Handle; template friend class Local; template friend class MaybeLocal; @@ -6890,11 +6811,7 @@ class Internals { template -Local::Local() : Handle() { } - - -template -Local Local::New(Isolate* isolate, Handle that) { +Local Local::New(Isolate* isolate, Local that) { return New(isolate, that.val_); } @@ -6903,15 +6820,6 @@ Local Local::New(Isolate* isolate, const PersistentBase& that) { return New(isolate, that.val_); } -template -Handle Handle::New(Isolate* isolate, T* that) { - if (that == NULL) return Handle(); - T* that_ptr = that; - internal::Object** p = reinterpret_cast(that_ptr); - return Handle(reinterpret_cast(HandleScope::CreateHandle( - reinterpret_cast(isolate), *p))); -} - template Local Local::New(Isolate* isolate, T* that) { diff --git a/src/checks.h b/src/checks.h index 54ac926..bd79866 100644 --- a/src/checks.h +++ b/src/checks.h @@ -11,7 +11,6 @@ namespace v8 { class Value; -template class Handle; namespace internal { -- 2.7.4