In Proxy get(own)PropertyDescriptor return undefined if property doesn't exist (bug 582967, r=brendan/jorendorff).
authorAndreas Gal <gal@mozilla.com>
Wed, 26 Jan 2011 10:43:10 -0800
changeset 61441 df6e9f32a9463a95b036aa546c4b2dea2f755145
parent 61440 82727ded88e6a38cdbe2b96ad148c7d5f079d16e
child 61442 6962ba9824d70e91245fef9b1d2edc17c9cefaca
push idunknown
push userunknown
push dateunknown
reviewersbrendan, jorendorff
bugs582967
milestone2.0b10pre
In Proxy get(own)PropertyDescriptor return undefined if property doesn't exist (bug 582967, r=brendan/jorendorff).
js/src/jsproxy.cpp
--- a/js/src/jsproxy.cpp
+++ b/js/src/jsproxy.cpp
@@ -373,16 +373,23 @@ ParsePropertyDescriptorObject(JSContext 
     desc->attrs = d->attrs;
     desc->getter = d->getter();
     desc->setter = d->setter();
     desc->shortid = 0;
     return true;
 }
 
 static bool
+IndicatePropertyNotFound(JSContext *cx, PropertyDescriptor *desc)
+{
+    desc->obj = NULL;
+    return true;
+}
+
+static bool
 MakePropertyDescriptorObject(JSContext *cx, jsid id, PropertyDescriptor *desc, Value *vp)
 {
     if (!desc->obj) {
         vp->setUndefined();
         return true;
     }
     uintN attrs = desc->attrs;
     Value getter = (attrs & JSPROP_GETTER) ? CastAsObjectJsval(desc->getter) : UndefinedValue();
@@ -491,30 +498,32 @@ GetProxyHandlerObject(JSContext *cx, JSO
 bool
 JSScriptedProxyHandler::getPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, bool set,
                                               PropertyDescriptor *desc)
 {
     JSObject *handler = GetProxyHandlerObject(cx, proxy);
     AutoValueRooter tvr(cx);
     return GetFundamentalTrap(cx, handler, ATOM(getPropertyDescriptor), tvr.addr()) &&
            Trap1(cx, handler, tvr.value(), id, tvr.addr()) &&
-           ReturnedValueMustNotBePrimitive(cx, proxy, ATOM(getPropertyDescriptor), tvr.value()) &&
-           ParsePropertyDescriptorObject(cx, proxy, id, tvr.value(), desc);
+           ((tvr.value().isUndefined() && IndicatePropertyNotFound(cx, desc)) ||
+            ReturnedValueMustNotBePrimitive(cx, proxy, ATOM(getPropertyDescriptor), tvr.value()) &&
+            ParsePropertyDescriptorObject(cx, proxy, id, tvr.value(), desc));
 }
 
 bool
 JSScriptedProxyHandler::getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, bool set,
                                                  PropertyDescriptor *desc)
 {
     JSObject *handler = GetProxyHandlerObject(cx, proxy);
     AutoValueRooter tvr(cx);
     return GetFundamentalTrap(cx, handler, ATOM(getOwnPropertyDescriptor), tvr.addr()) &&
            Trap1(cx, handler, tvr.value(), id, tvr.addr()) &&
-           ReturnedValueMustNotBePrimitive(cx, proxy, ATOM(getPropertyDescriptor), tvr.value()) &&
-           ParsePropertyDescriptorObject(cx, proxy, id, tvr.value(), desc);
+           ((tvr.value().isUndefined() && IndicatePropertyNotFound(cx, desc)) ||
+            ReturnedValueMustNotBePrimitive(cx, proxy, ATOM(getPropertyDescriptor), tvr.value()) &&
+            ParsePropertyDescriptorObject(cx, proxy, id, tvr.value(), desc));
 }
 
 bool
 JSScriptedProxyHandler::defineProperty(JSContext *cx, JSObject *proxy, jsid id,
                                        PropertyDescriptor *desc)
 {
     JSObject *handler = GetProxyHandlerObject(cx, proxy);
     AutoValueRooter tvr(cx);