Properly process getOwnPropertyDescriptor for elements on global proxy object.

We need to go down to actual global object to perform those operations.

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@6612 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
antonm@chromium.org 2011-02-03 10:19:41 +00:00
parent e4a4804546
commit 0da3dc3e43
3 changed files with 29 additions and 0 deletions

View File

@ -6679,6 +6679,13 @@ JSObject::LocalElementType JSObject::HasLocalElement(uint32_t index) {
return UNDEFINED_ELEMENT; return UNDEFINED_ELEMENT;
} }
if (IsJSGlobalProxy()) {
Object* proto = GetPrototype();
if (proto->IsNull()) return UNDEFINED_ELEMENT;
ASSERT(proto->IsJSGlobalObject());
return JSObject::cast(proto)->HasLocalElement(index);
}
// Check for lookup interceptor // Check for lookup interceptor
if (HasIndexedInterceptor()) { if (HasIndexedInterceptor()) {
return HasElementWithInterceptor(this, index) ? INTERCEPTED_ELEMENT return HasElementWithInterceptor(this, index) ? INTERCEPTED_ELEMENT

View File

@ -779,6 +779,12 @@ static MaybeObject* Runtime_GetOwnProperty(Arguments args) {
} }
case JSObject::DICTIONARY_ELEMENT: { case JSObject::DICTIONARY_ELEMENT: {
if (obj->IsJSGlobalProxy()) {
Object* proto = obj->GetPrototype();
if (proto->IsNull()) return Heap::undefined_value();
ASSERT(proto->IsJSGlobalObject());
obj = Handle<JSObject>(JSObject::cast(proto));
}
NumberDictionary* dictionary = obj->element_dictionary(); NumberDictionary* dictionary = obj->element_dictionary();
int entry = dictionary->FindEntry(index); int entry = dictionary->FindEntry(index);
ASSERT(entry != NumberDictionary::kNotFound); ASSERT(entry != NumberDictionary::kNotFound);

View File

@ -103,3 +103,19 @@ objWithProto.prototype = proto;
objWithProto[0] = 'bar'; objWithProto[0] = 'bar';
var descWithProto = Object.getOwnPropertyDescriptor(objWithProto, '10'); var descWithProto = Object.getOwnPropertyDescriptor(objWithProto, '10');
assertEquals(undefined, descWithProto); assertEquals(undefined, descWithProto);
// Test elements on global proxy object.
var global = (function() { return this; })();
global[42] = 42;
function el_getter() { return 239; };
function el_setter() {};
Object.defineProperty(global, '239', {get: el_getter, set: el_setter});
var descRegularElement = Object.getOwnPropertyDescriptor(global, '42');
assertEquals(42, descRegularElement.value);
var descAccessorElement = Object.getOwnPropertyDescriptor(global, '239');
assertEquals(el_getter, descAccessorElement.get);
assertEquals(el_setter, descAccessorElement.set);