Commit 47a22dce authored by antonm@chromium.org's avatar antonm@chromium.org

Reapply http://code.google.com/p/v8/source/detail?r=6555

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

TBR=ricow@chromium.org

Review URL: http://codereview.chromium.org/6461028

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@6708 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent dc91c421
......@@ -2206,6 +2206,12 @@ bool Value::Equals(Handle<Value> that) const {
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 =
......
......@@ -12523,6 +12523,25 @@ TEST(RegExp) {
}
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,
const v8::AccessorInfo& info ) {
return v8_str("42!");
......
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