Bug 978229 - Part 1: Remove IsSealed() from Proxy.[[HasProperty]]. (r=jorendorff)
authorEric Faust <efaustbmo@gmail.com>
Fri, 25 Apr 2014 17:10:51 -0700
changeset 180710 21d545a5ac3ff647c623358d7df541e08605004c
parent 180709 8d3be1c62d8dd3a539e390f55adcf73ee46cdf5c
child 180711 159a32e886d0371f74953ab43aa6fedf4194d7c6
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersjorendorff
bugs978229
milestone31.0a1
Bug 978229 - Part 1: Remove IsSealed() from Proxy.[[HasProperty]]. (r=jorendorff)
js/src/jit-test/tests/proxy/testDirectProxyHas6.js
js/src/jsproxy.cpp
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/proxy/testDirectProxyHas6.js
@@ -0,0 +1,12 @@
+/*
+ * Don't throw a type error if the trap reports an undefined property as
+ * non-present, regardless of extensibility.
+ */
+var target = {};
+Object.preventExtensions(target);
+assertEq(
+    'foo' in new Proxy(target, {
+        has: function (target, name) {
+            return false;
+        }
+    }), false);
--- a/js/src/jsproxy.cpp
+++ b/js/src/jsproxy.cpp
@@ -1928,32 +1928,30 @@ ScriptedDirectProxyHandler::has(JSContex
     if (!Invoke(cx, ObjectValue(*handler), trap, ArrayLength(argv), argv, &trapResult))
         return false;
 
     // step 6
     bool success = ToBoolean(trapResult);;
 
     // step 7
     if (!success) {
-        bool sealed;
-        if (!IsSealed(cx, target, id, &sealed))
-            return false;
-        if (sealed) {
-            JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_CANT_REPORT_NC_AS_NE);
+        Rooted<PropertyDescriptor> desc(cx);
+        if (!GetOwnPropertyDescriptor(cx, target, id, &desc))
             return false;
-        }
-
-        bool extensible;
-        if (!JSObject::isExtensible(cx, target, &extensible))
-            return false;
-        if (!extensible) {
-            bool isFixed;
-            if (!HasOwn(cx, target, id, &isFixed))
+
+        if (desc.object()) {
+            if (desc.isPermanent()) {
+                JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_CANT_REPORT_NC_AS_NE);
                 return false;
-            if (isFixed) {
+            }
+
+            bool extensible;
+            if (!JSObject::isExtensible(cx, target, &extensible))
+                return false;
+            if (!extensible) {
                 JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_CANT_REPORT_E_AS_NE);
                 return false;
             }
         }
     }
 
     // step 8
     *bp = success;