Bug 1090636, part 13 - Reimplement the mHasPrototype part of Proxy::set as a call to BaseProxyHandler::set. r=bholley.
authorJason Orendorff <jorendorff@mozilla.com>
Wed, 15 Oct 2014 11:07:41 -0500
changeset 219575 38c02eda337d38f013432994bff0f9168f8a5f29
parent 219574 1fe6d2492dc891e88452d9049916143c46c1fd12
child 219576 6a71021584ff322cac4d5371a23a72ec95ae7839
push id10400
push userryanvm@gmail.com
push dateMon, 15 Dec 2014 18:54:54 +0000
treeherderfx-team@5d6e0d038f95 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs1090636
milestone37.0a1
Bug 1090636, part 13 - Reimplement the mHasPrototype part of Proxy::set as a call to BaseProxyHandler::set. r=bholley.
js/src/proxy/Proxy.cpp
--- a/js/src/proxy/Proxy.cpp
+++ b/js/src/proxy/Proxy.cpp
@@ -324,46 +324,21 @@ Proxy::set(JSContext *cx, HandleObject p
            MutableHandleValue vp)
 {
     JS_CHECK_RECURSION(cx, return false);
     const BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
     AutoEnterPolicy policy(cx, handler, proxy, id, BaseProxyHandler::SET, true);
     if (!policy.allowed())
         return policy.returnValue();
 
-    // If the proxy doesn't require that we consult its prototype for the
-    // non-own cases, we can sink to the |set| trap.
-    if (!handler->hasPrototype())
-        return handler->set(cx, proxy, receiver, id, strict, vp);
-
-    // If we have an existing (own or non-own) property with a setter, we want
-    // to invoke that.
-    Rooted<PropertyDescriptor> desc(cx);
-    if (!Proxy::getPropertyDescriptor(cx, proxy, id, &desc))
-        return false;
-    if (desc.object() && desc.setter()) {
-        MOZ_ASSERT(desc.setter() != JS_StrictPropertyStub);
-        return CallSetter(cx, receiver, id, desc.setter(), desc.attributes(), strict, vp);
-    }
+    // Special case. See the comment on BaseProxyHandler::mHasPrototype.
+    if (handler->hasPrototype())
+        return handler->BaseProxyHandler::set(cx, proxy, receiver, id, strict, vp);
 
-    if (desc.isReadonly()) {
-        return strict ? Throw(cx, id, JSMSG_READ_ONLY) : true;
-    }
-
-    // Ok. Either there was no pre-existing property, or it was a value prop
-    // that we're going to shadow. Either way, define a new own property.
-    unsigned attrs =
-        (desc.object() == proxy)
-        ? JSPROP_IGNORE_ENUMERATE | JSPROP_IGNORE_READONLY | JSPROP_IGNORE_PERMANENT
-        : JSPROP_ENUMERATE;
-    const Class *clasp = receiver->getClass();
-    MOZ_ASSERT(clasp->getProperty != JS_PropertyStub);
-    MOZ_ASSERT(clasp->setProperty != JS_StrictPropertyStub);
-    return JSObject::defineGeneric(cx, receiver, id, vp, clasp->getProperty, clasp->setProperty,
-                                   attrs);
+    return handler->set(cx, proxy, receiver, id, strict, vp);
 }
 
 bool
 Proxy::getOwnEnumerablePropertyKeys(JSContext *cx, HandleObject proxy, AutoIdVector &props)
 {
     JS_CHECK_RECURSION(cx, return false);
     const BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
     AutoEnterPolicy policy(cx, handler, proxy, JSID_VOIDHANDLE, BaseProxyHandler::ENUMERATE, true);