Reviewers: Michael Starzinger,
Message:
mstarzinger, ptal at this trivial change :)
Description:
Adding missing operator!= for Handle and Persistent.
BUG=
Please review this at https://codereview.chromium.org/22932004/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M include/v8.h
M test/cctest/test-api.cc
Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index
3252602bcf19d8fabba52e0c7fbbd274615f7ff2..b81645081e577a21685f0f4d1f61ffb124e5c61f
100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -303,7 +303,7 @@ 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 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,10 +328,17 @@ 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!=(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
// If we're going to perform the type check then we have to check
@@ -618,13 +625,22 @@ template <class T> class Persistent // NOLINT
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());
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index
6c71de4ce2e2b282e229f6fcfcba3aa432badfb3..abd86f21bf6ff4f5ee97dc14c002c0aff715c430
100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -3188,6 +3188,44 @@ THREADED_TEST(GlobalHandleUpcast) {
}
+THREADED_TEST(LocalHandleBasedOnGlobalHandle) {
+ 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::HandleScope scope(v8::Isolate::GetCurrent());
v8::Local<String> local = v8::Local<String>::New(v8_str("str"));
--
--
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.