Revision: 16255
Author:   [email protected]
Date:     Wed Aug 21 10:49:29 2013 UTC
Log:      Adding missing operator!= for Handle and Persistent.

BUG=
[email protected]

Review URL: https://codereview.chromium.org/22932004

Patch from Marja Hölttä <[email protected]>.
http://code.google.com/p/v8/source/detail?r=16255

Modified:
 /branches/bleeding_edge/include/v8.h
 /branches/bleeding_edge/test/cctest/test-api.cc

=======================================
--- /branches/bleeding_edge/include/v8.h        Fri Aug  9 10:33:08 2013 UTC
+++ /branches/bleeding_edge/include/v8.h        Wed Aug 21 10:49:29 2013 UTC
@@ -303,7 +303,7 @@
    * 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 Handle<S>& that) const) {
     internal::Object** a = reinterpret_cast<internal::Object**>(**this);
     internal::Object** b = reinterpret_cast<internal::Object**>(*that);
     if (a == 0) return b == 0;
@@ -328,9 +328,16 @@
    * the objects to which they refer are different.
    * The handles' references are not checked.
    */
-  template <class S> V8_INLINE(bool operator!=(Handle<S> that) const) {
+ template <class S> V8_INLINE(bool operator!=(const Handle<S>& that) const) {
     return !operator==(that);
   }
+
+#ifndef V8_USE_UNSAFE_HANDLES
+  template <class S> V8_INLINE(
+      bool operator!=(const Persistent<S>& that) const) {
+    return !operator==(that);
+  }
+#endif

   template <class S> V8_INLINE(static Handle<T> Cast(Handle<S> that)) {
 #ifdef V8_ENABLE_CHECKS
@@ -618,13 +625,22 @@
     return *a == *b;
   }

- template <class S> V8_INLINE(bool operator==(const Handle<S> that) const) { + 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);
     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) {
+    return !operator==(that);
+  }
+
+ template <class S> V8_INLINE(bool operator!=(const Handle<S>& that) const) {
+    return !operator==(that);
+  }
 #endif

   V8_INLINE(void Dispose());
=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc Tue Aug 20 13:55:52 2013 UTC +++ /branches/bleeding_edge/test/cctest/test-api.cc Wed Aug 21 10:49:29 2013 UTC
@@ -3177,6 +3177,44 @@
   CHECK(global_string == v8::Persistent<String>::Cast(global_value));
   global_string.Dispose();
 }
+
+
+THREADED_TEST(HandleEquality) {
+  v8::Isolate* isolate = v8::Isolate::GetCurrent();
+  v8::Persistent<String> global1;
+  v8::Persistent<String> global2;
+  {
+    v8::HandleScope scope(isolate);
+    global1.Reset(isolate, v8_str("str"));
+    global2.Reset(isolate, v8_str("str2"));
+  }
+  CHECK_EQ(global1 == global1, true);
+  CHECK_EQ(global1 != global1, false);
+  {
+    v8::HandleScope scope(isolate);
+    Local<String> local1 = Local<String>::New(isolate, global1);
+    Local<String> local2 = Local<String>::New(isolate, global2);
+
+    CHECK_EQ(global1 == local1, true);
+    CHECK_EQ(global1 != local1, false);
+    CHECK_EQ(local1 == global1, true);
+    CHECK_EQ(local1 != global1, false);
+
+    CHECK_EQ(global1 == local2, false);
+    CHECK_EQ(global1 != local2, true);
+    CHECK_EQ(local2 == global1, false);
+    CHECK_EQ(local2 != global1, true);
+
+    CHECK_EQ(local1 == local2, false);
+    CHECK_EQ(local1 != local2, true);
+
+    Local<String> anotherLocal1 = Local<String>::New(isolate, global1);
+    CHECK_EQ(local1 == anotherLocal1, true);
+    CHECK_EQ(local1 != anotherLocal1, false);
+  }
+  global1.Dispose();
+  global2.Dispose();
+}


 THREADED_TEST(LocalHandle) {

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to