Commit 32a631d8 authored by antonm@chromium.org's avatar antonm@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@6555 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 93f8e3d8
...@@ -2200,6 +2200,12 @@ bool Value::Equals(Handle<Value> that) const { ...@@ -2200,6 +2200,12 @@ bool Value::Equals(Handle<Value> that) const {
ENTER_V8; ENTER_V8;
i::Handle<i::Object> obj = Utils::OpenHandle(this); i::Handle<i::Object> obj = Utils::OpenHandle(this);
i::Handle<i::Object> other = Utils::OpenHandle(*that); 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() }; i::Object** args[1] = { other.location() };
EXCEPTION_PREAMBLE(); EXCEPTION_PREAMBLE();
i::Handle<i::Object> result = i::Handle<i::Object> result =
......
...@@ -12213,6 +12213,25 @@ TEST(RegExp) { ...@@ -12213,6 +12213,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, static v8::Handle<v8::Value> Getter(v8::Local<v8::String> property,
const v8::AccessorInfo& info ) { const v8::AccessorInfo& info ) {
return v8_str("42!"); 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