Adding missing operator!= for Handle and Persistent.

BUG=
R=mstarzinger@chromium.org

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

Patch from Marja Hölttä <marja@chromium.org>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16255 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 125d3390
......@@ -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());
......
......@@ -3179,6 +3179,44 @@ THREADED_TEST(GlobalHandleUpcast) {
}
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::HandleScope scope(v8::Isolate::GetCurrent());
v8::Local<String> local = v8::Local<String>::New(v8_str("str"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment