Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Unified Diff: include/v8.h

Issue 679143002: make Handle a synonym of Local (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/checks.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index f70f45769bb5ca58ff6d178b7129f92448301e8c..e314958f48a03890614922bb2889afd22d0a512d 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -103,7 +103,6 @@ class Private;
class Uint32;
class Utils;
class Value;
-template <class T> class Handle;
template <class T> class Local;
template <class T> class Eternal;
template<class T> class NonCopyablePersistentTraits;
@@ -196,28 +195,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<Object>); the value will still be governed by a handle
+ * a Local<Object>); 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 T> class Handle {
+template <class T>
+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<String> to a
- * Handle<Number> it will cause a compile-time error. Assigning
- * between compatible handles, for instance assigning a
- * Handle<String> to a variable declared as Handle<Value>, is legal
- * because String is a subclass of Value.
- */
- template <class S> V8_INLINE Handle(Handle<S> that)
+ V8_INLINE Local() : val_(0) {}
+ template <class S>
+ V8_INLINE Local(Local<S> that)
: val_(reinterpret_cast<T*>(*that)) {
Sven Panne 2014/10/29 07:15:27 Not really related to this CL: I think that we can
/**
* This check fails when trying to convert between incompatible
@@ -247,7 +234,8 @@ template <class T> class Handle {
* to which they refer are identical.
* The handles' references are not checked.
*/
- template <class S> V8_INLINE bool operator==(const Handle<S>& that) const {
+ template <class S>
+ V8_INLINE bool operator==(const Local<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;
@@ -270,7 +258,8 @@ template <class T> class Handle {
* the objects to which they refer are different.
* The handles' references are not checked.
*/
- template <class S> V8_INLINE bool operator!=(const Handle<S>& that) const {
+ template <class S>
+ V8_INLINE bool operator!=(const Local<S>& that) const {
return !operator==(that);
}
@@ -279,77 +268,6 @@ template <class T> class Handle {
return !operator==(that);
}
- template <class S> V8_INLINE static Handle<T> Cast(Handle<S> 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<T>();
-#endif
- return Handle<T>(T::Cast(*that));
- }
-
- template <class S> V8_INLINE Handle<S> As() {
- return Handle<S>::Cast(*this);
- }
-
- 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 PersistentBase<T>& that) {
- return New(isolate, that.val_);
- }
-
- 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;
- template<class F> friend class internal::CustomArguments;
- friend Handle<Primitive> Undefined(Isolate* isolate);
- friend Handle<Primitive> Null(Isolate* isolate);
- friend Handle<Boolean> True(Isolate* isolate);
- friend Handle<Boolean> 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<T> 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 T> class Local : public Handle<T> {
- public:
- V8_INLINE Local();
- template <class S> V8_INLINE Local(Local<S> that)
- : Handle<T>(reinterpret_cast<T*>(*that)) {
- /**
- * This check fails when trying to convert between incompatible
- * handles. For example, converting from a Handle<String> to a
- * Handle<Number>.
- */
- TYPE_CHECK(T, S);
- }
-
-
template <class S> V8_INLINE static Local<T> Cast(Local<S> that) {
#ifdef V8_ENABLE_CHECKS
// If we're going to perform the type check then we have to check
@@ -358,10 +276,7 @@ template <class T> class Local : public Handle<T> {
#endif
return Local<T>(T::Cast(*that));
}
- template <class S> V8_INLINE Local(Handle<S> that)
- : Handle<T>(reinterpret_cast<T*>(*that)) {
- TYPE_CHECK(T, S);
- }
+
template <class S> V8_INLINE Local<S> As() {
return Local<S>::Cast(*this);
@@ -372,7 +287,7 @@ 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(Isolate* isolate, Handle<T> that);
+ V8_INLINE static Local<T> New(Isolate* isolate, Local<T> that);
V8_INLINE static Local<T> New(Isolate* isolate,
const PersistentBase<T>& that);
@@ -381,24 +296,37 @@ template <class T> class Local : public Handle<T> {
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;
friend class Object;
friend class Context;
+ friend class Private;
template<class F> friend class internal::CustomArguments;
+ friend Local<Primitive> Undefined(Isolate* isolate);
+ friend Local<Primitive> Null(Isolate* isolate);
+ friend Local<Boolean> True(Isolate* isolate);
+ friend Local<Boolean> False(Isolate* isolate);
friend class HandleScope;
friend class EscapableHandleScope;
template<class F1, class F2, class F3> friend class PersistentValueMap;
template<class F1, class F2> friend class PersistentValueVector;
- template <class S> V8_INLINE Local(S* that) : Handle<T>(that) { }
+ template <class S>
+ V8_INLINE Local(S* that)
+ : val_(that) {}
V8_INLINE static Local<T> New(Isolate* isolate, T* that);
+
+ T* val_;
};
+// Handle is a synonym for Local for historical reason.
+template <class T>
+using Handle = Local<T>;
+
+
// Eternal handles are set-once handles that live for the life of the isolate.
template <class T> class Eternal {
public:
@@ -563,7 +491,6 @@ template <class T> class PersistentBase {
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;
@@ -704,7 +631,6 @@ template <class T, class M> class Persistent : public PersistentBase<T> {
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;
@@ -5344,7 +5270,6 @@ class V8_EXPORT V8 {
int* index);
static Local<Value> GetEternal(Isolate* isolate, int index);
- template <class T> friend class Handle;
template <class T> friend class Local;
template <class T> friend class Eternal;
template <class T> friend class PersistentBase;
@@ -6066,11 +5991,7 @@ class Internals {
template <class T>
-Local<T>::Local() : Handle<T>() { }
-
-
-template <class T>
-Local<T> Local<T>::New(Isolate* isolate, Handle<T> that) {
+Local<T> Local<T>::New(Isolate* isolate, Local<T> that) {
return New(isolate, that.val_);
}
@@ -6079,15 +6000,6 @@ Local<T> Local<T>::New(Isolate* isolate, const PersistentBase<T>& that) {
return New(isolate, that.val_);
}
-template <class T>
-Handle<T> Handle<T>::New(Isolate* isolate, T* that) {
- if (that == NULL) return Handle<T>();
- T* that_ptr = that;
- internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr);
- return Handle<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(
- reinterpret_cast<internal::Isolate*>(isolate), *p)));
-}
-
template <class T>
Local<T> Local<T>::New(Isolate* isolate, T* that) {
« no previous file with comments | « no previous file | src/checks.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698