Commit f4d40515 authored by cbruni's avatar cbruni Committed by Commit bot

[runtime] [proxy] Runtime_HasOwnProperty and thus

Object.prototype.hasOwnProperty should use JSReceiver::HasOwnProperty for
proxies.

BUG=v8:1543
LOG=N

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

Cr-Commit-Position: refs/heads/master@{#32475}
parent 128e75cb
......@@ -183,18 +183,10 @@ function ObjectValueOf() {
}
// ECMA-262 - 15.2.4.5
// ES6 7.3.11
function ObjectHasOwnProperty(value) {
var name = TO_NAME(value);
var object = TO_OBJECT(this);
if (%_IsJSProxy(object)) {
// TODO(rossberg): adjust once there is a story for symbols vs proxies.
if (IS_SYMBOL(value)) return false;
var handler = %GetHandler(object);
return CallTrap1(handler, "hasOwn", ProxyDerivedHasOwnTrap, name);
}
return %HasOwnProperty(object, name);
}
......
......@@ -719,6 +719,11 @@ RUNTIME_FUNCTION(Runtime_HasOwnProperty) {
if (index < static_cast<uint32_t>(string->length())) {
return isolate->heap()->true_value();
}
} else if (object->IsJSProxy()) {
Maybe<bool> result =
JSReceiver::HasOwnProperty(Handle<JSProxy>::cast(object), key);
if (!result.IsJust()) return isolate->heap()->exception();
return isolate->heap()->ToBoolean(result.FromJust());
}
return isolate->heap()->false_value();
}
......
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-proxies
var handler = {};
var target = {a:1};
var proxy = new Proxy(target, handler);
assertTrue(target.hasOwnProperty('a'));
assertTrue(proxy.hasOwnProperty('a'));
assertFalse(target.hasOwnProperty('b'));
assertFalse(proxy.hasOwnProperty('b'));
handler.has = function() {
return false;
}
assertTrue(target.hasOwnProperty('a'));
assertFalse(proxy.hasOwnProperty('a'));
assertFalse(target.hasOwnProperty('b'));
assertFalse(proxy.hasOwnProperty('b'));
handler.has = function() {
return true;
}
assertTrue(target.hasOwnProperty('a'));
assertTrue(proxy.hasOwnProperty('a'));
assertFalse(target.hasOwnProperty('b'));
assertTrue(proxy.hasOwnProperty('b'));
handler.has = function() {
throw Error();
}
assertTrue(target.hasOwnProperty('a'));
assertThrows(function(){ proxy.hasOwnProperty('a') }, Error);
assertFalse(target.hasOwnProperty('b'));
assertThrows(function(){ proxy.hasOwnProperty('b') }, Error);
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