Revision: 6612
Author: [email protected]
Date: Thu Feb  3 02:19:41 2011
Log: 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
http://code.google.com/p/v8/source/detail?r=6612

Modified:
 /branches/bleeding_edge/src/objects.cc
 /branches/bleeding_edge/src/runtime.cc
 /branches/bleeding_edge/test/mjsunit/get-own-property-descriptor.js

=======================================
--- /branches/bleeding_edge/src/objects.cc      Thu Feb  3 02:07:22 2011
+++ /branches/bleeding_edge/src/objects.cc      Thu Feb  3 02:19:41 2011
@@ -6678,6 +6678,13 @@
     Top::ReportFailedAccessCheck(this, v8::ACCESS_HAS);
     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()) {
=======================================
--- /branches/bleeding_edge/src/runtime.cc      Thu Feb  3 02:07:22 2011
+++ /branches/bleeding_edge/src/runtime.cc      Thu Feb  3 02:19:41 2011
@@ -779,6 +779,12 @@
       }

       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);
=======================================
--- /branches/bleeding_edge/test/mjsunit/get-own-property-descriptor.js Tue Dec 7 03:01:02 2010 +++ /branches/bleeding_edge/test/mjsunit/get-own-property-descriptor.js Thu Feb 3 02:19:41 2011
@@ -103,3 +103,19 @@
 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