Revision: 6555
Author: [email protected]
Date: Tue Feb  1 05:29:37 2011
Log: Compare JSObjects by identity immediately.

When invoking EQUALS JS builtin, 1st argument is passed as a receiver and
if it's a global object, it gets overwritten with global proxy object and
thus one gets incorrect results.

BUG=v8::1082

Review URL: http://codereview.chromium.org/6287018
http://code.google.com/p/v8/source/detail?r=6555

Modified:
 /branches/bleeding_edge/src/api.cc
 /branches/bleeding_edge/test/cctest/test-api.cc

=======================================
--- /branches/bleeding_edge/src/api.cc  Wed Jan 19 03:16:23 2011
+++ /branches/bleeding_edge/src/api.cc  Tue Feb  1 05:29:37 2011
@@ -2200,6 +2200,12 @@
   ENTER_V8;
   i::Handle<i::Object> obj = Utils::OpenHandle(this);
   i::Handle<i::Object> other = Utils::OpenHandle(*that);
+  // If both obj and other are JSObjects, we'd better compare by identity
+  // immediately when going into JS builtin.  The reason is Invoke
+  // would overwrite global object receiver with global proxy.
+  if (obj->IsJSObject() && other->IsJSObject()) {
+    return *obj == *other;
+  }
   i::Object** args[1] = { other.location() };
   EXCEPTION_PREAMBLE();
   i::Handle<i::Object> result =
=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc     Tue Feb  1 04:31:16 2011
+++ /branches/bleeding_edge/test/cctest/test-api.cc     Tue Feb  1 05:29:37 2011
@@ -12211,6 +12211,25 @@
   context->Global()->Set(v8_str("ex"), try_catch.Exception());
   ExpectTrue("ex instanceof SyntaxError");
 }
+
+
+THREADED_TEST(Equals) {
+  v8::HandleScope handleScope;
+  LocalContext localContext;
+
+  v8::Handle<v8::Object> globalProxy = localContext->Global();
+  v8::Handle<Value> global = globalProxy->GetPrototype();
+
+  CHECK(global->StrictEquals(global));
+  CHECK(!global->StrictEquals(globalProxy));
+  CHECK(!globalProxy->StrictEquals(global));
+  CHECK(globalProxy->StrictEquals(globalProxy));
+
+  CHECK(global->Equals(global));
+  CHECK(!global->Equals(globalProxy));
+  CHECK(!globalProxy->Equals(global));
+  CHECK(globalProxy->Equals(globalProxy));
+}


 static v8::Handle<v8::Value> Getter(v8::Local<v8::String> property,

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to