Reviewers: Rico,

Message:
Rico,

may you have a look?

Description:
Properly process getOwnPropertyDescriptor for elements on global proxy object.

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

Please review this at http://codereview.chromium.org/6246054/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
  M src/objects.cc
  M src/runtime.cc
  M test/mjsunit/get-own-property-descriptor.js


Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 8bced586b39dd4938495750421ef15bc3ae3c6a6..1ccb1424b51ecef6ef81518f0f7522bd81558e96 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -6679,6 +6679,13 @@ JSObject::LocalElementType JSObject::HasLocalElement(uint32_t index) {
     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
   if (HasIndexedInterceptor()) {
     return HasElementWithInterceptor(this, index) ? INTERCEPTED_ELEMENT
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index 9911e1e3a3251620c68297902e4655875d6d9e86..e1a8954f50ef1e680a0f799ba3e6f165f6fdf53f 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -779,6 +779,12 @@ static MaybeObject* Runtime_GetOwnProperty(Arguments args) {
       }

       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();
         int entry = dictionary->FindEntry(index);
         ASSERT(entry != NumberDictionary::kNotFound);
Index: test/mjsunit/get-own-property-descriptor.js
diff --git a/test/mjsunit/get-own-property-descriptor.js b/test/mjsunit/get-own-property-descriptor.js index ceb771538421d4f2be3b2601478e8af0502233d4..79c1fac6ae84f1f69146a88a6a1179f82bdd3b97 100644
--- a/test/mjsunit/get-own-property-descriptor.js
+++ b/test/mjsunit/get-own-property-descriptor.js
@@ -103,3 +103,19 @@ objWithProto.prototype = proto;
 objWithProto[0] = 'bar';
 var descWithProto = Object.getOwnPropertyDescriptor(objWithProto, '10');
 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);


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

Reply via email to