Bug 980565 - Remove defunct Proxy.[[HasOwnProperty]]. (r=jorendorff)
authorEric Faust <efaustbmo@gmail.com>
Wed, 18 Jun 2014 19:46:07 -0700
changeset 189450 867fabab7a851b74baf436ed1e58421f51d37d32
parent 189449 be39bbf27fac83a0bb14389e1ef38a9b174ba863
child 189451 25101d87fd9b25de7359a86917c8cc115aa6aea7
push id45067
push userefaustbmo@gmail.com
push dateThu, 19 Jun 2014 02:46:20 +0000
treeherdermozilla-inbound@867fabab7a85 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs980565
milestone33.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 980565 - Remove defunct Proxy.[[HasOwnProperty]]. (r=jorendorff)
js/src/jit-test/tests/proxy/testDirectProxyHasOwn1.js
js/src/jit-test/tests/proxy/testDirectProxyHasOwn2.js
js/src/jit-test/tests/proxy/testDirectProxyHasOwn3.js
js/src/jit-test/tests/proxy/testDirectProxyHasOwn4.js
js/src/jit-test/tests/proxy/testDirectProxyHasOwn5.js
js/src/jit-test/tests/proxy/testDirectProxyHasOwn6.js
js/src/jit-test/tests/proxy/testDirectProxyHasOwnProperty.js
js/src/jsproxy.cpp
deleted file mode 100644
--- a/js/src/jit-test/tests/proxy/testDirectProxyHasOwn2.js
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * Call the trap with the handler as the this value, the target as the first
- * argument, and the name of the property as the second argument
- */
-var target = {};
-var called = false;
-var handler = {
-    hasOwn: function (target1, name) {
-        assertEq(this, handler);
-        assertEq(target1, target);
-        assertEq(name, 'foo');
-        called = true;
-    }
-};
-({}).hasOwnProperty.call(new Proxy(target, handler), 'foo');
-assertEq(called, true);
deleted file mode 100644
--- a/js/src/jit-test/tests/proxy/testDirectProxyHasOwn3.js
+++ /dev/null
@@ -1,17 +0,0 @@
-load(libdir + "asserts.js");
-
-/*
- * Throw a TypeError if the trap reports a non-configurable own property as
- * non-existent
- */
-var target = {};
-Object.defineProperty(target, 'foo', {
-    configurable: false
-});
-assertThrowsInstanceOf(function () {
-    ({}).hasOwnProperty.call(Proxy(target, {
-        hasOwn: function (target, name) {
-            return false;
-        }
-    }), 'foo');
-}, TypeError);
deleted file mode 100644
--- a/js/src/jit-test/tests/proxy/testDirectProxyHasOwn4.js
+++ /dev/null
@@ -1,19 +0,0 @@
-load(libdir + "asserts.js");
-
-/*
- * Throw a TypeError if the trap reports an existing own property as
- * non-existent on a non-extensible object
- */
-var target = {};
-Object.defineProperty(target, 'foo', {
-    configurable: true
-});
-Object.preventExtensions(target);
-var caught = false;
-assertThrowsInstanceOf(function () {
-    ({}).hasOwnProperty.call(new Proxy(target, {
-        hasOwn: function (target, name) {
-            return false;
-        }
-    }), 'foo');
-}, TypeError);
deleted file mode 100644
--- a/js/src/jit-test/tests/proxy/testDirectProxyHasOwn5.js
+++ /dev/null
@@ -1,15 +0,0 @@
-load(libdir + "asserts.js");
-
-/*
- * Throw a TypeError if the trap reports a new own property on a non-extensible
- * object
- */
-var target = {};
-Object.preventExtensions(target);
-assertThrowsInstanceOf(function () {
-    ({}).hasOwnProperty.call(new Proxy(target, {
-        hasOwn: function (target, name) {
-            return true;
-        }
-    }), 'foo');
-}, TypeError);
deleted file mode 100644
--- a/js/src/jit-test/tests/proxy/testDirectProxyHasOwn6.js
+++ /dev/null
@@ -1,16 +0,0 @@
-// Return the trap result
-var proxy = new Proxy(Object.create(Object.create(null, {
-    'foo': {
-        configurable: true
-    }
-}), {
-    'bar': {
-        configurable: true
-    }
-}), {
-    hasOwn: function (target, name) {
-        return name == 'foo';
-    }
-});
-assertEq(({}).hasOwnProperty.call(proxy, 'foo'), true);
-assertEq(({}).hasOwnProperty.call(proxy, 'bar'), false);
rename from js/src/jit-test/tests/proxy/testDirectProxyHasOwn1.js
rename to js/src/jit-test/tests/proxy/testDirectProxyHasOwnProperty.js
--- a/js/src/jit-test/tests/proxy/testDirectProxyHasOwn1.js
+++ b/js/src/jit-test/tests/proxy/testDirectProxyHasOwnProperty.js
@@ -5,8 +5,18 @@ var proxy = Proxy(Object.create(Object.c
     }
 }), {
     'bar': {
         configurable: true
     }
 }), {});
 assertEq(({}).hasOwnProperty.call(proxy, 'foo'), false);
 assertEq(({}).hasOwnProperty.call(proxy, 'bar'), true);
+
+// Make sure only the getOwnPropertyDescriptor trap is called, and not the has
+// trap.
+var called = false;
+var handler = { getOwnPropertyDescriptor: function () { called = true; },
+                has: function () { assertEq(false, true, "has trap must not be called"); }
+              }
+proxy = new Proxy({}, handler);
+assertEq(({}).hasOwnProperty.call(proxy, 'foo'), false);
+assertEq(called, true);
--- a/js/src/jsproxy.cpp
+++ b/js/src/jsproxy.cpp
@@ -1066,17 +1066,19 @@ class ScriptedDirectProxyHandler : publi
     virtual bool defineProperty(JSContext *cx, HandleObject proxy, HandleId id,
                                 MutableHandle<PropertyDescriptor> desc) MOZ_OVERRIDE;
     virtual bool getOwnPropertyNames(JSContext *cx, HandleObject proxy, AutoIdVector &props);
     virtual bool delete_(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) MOZ_OVERRIDE;
     virtual bool enumerate(JSContext *cx, HandleObject proxy, AutoIdVector &props) MOZ_OVERRIDE;
 
     /* ES5 Harmony derived proxy traps. */
     virtual bool has(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) MOZ_OVERRIDE;
-    virtual bool hasOwn(JSContext *cx,HandleObject proxy, HandleId id, bool *bp) MOZ_OVERRIDE;
+    virtual bool hasOwn(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) MOZ_OVERRIDE {
+        return BaseProxyHandler::hasOwn(cx, proxy, id, bp);
+    }
     virtual bool get(JSContext *cx, HandleObject proxy, HandleObject receiver, HandleId id,
                      MutableHandleValue vp) MOZ_OVERRIDE;
     virtual bool set(JSContext *cx, HandleObject proxy, HandleObject receiver, HandleId id,
                      bool strict, MutableHandleValue vp) MOZ_OVERRIDE;
     virtual bool keys(JSContext *cx, HandleObject proxy, AutoIdVector &props) MOZ_OVERRIDE;
     virtual bool iterate(JSContext *cx, HandleObject proxy, unsigned flags,
                          MutableHandleValue vp) MOZ_OVERRIDE;
 
@@ -1836,92 +1838,16 @@ ScriptedDirectProxyHandler::has(JSContex
         }
     }
 
     // step 8
     *bp = success;
     return true;
 }
 
-// Proxy.[[HasOwnProperty]](P)
-bool
-ScriptedDirectProxyHandler::hasOwn(JSContext *cx, HandleObject proxy, HandleId id, bool *bp)
-{
-    // step 1
-    RootedObject handler(cx, GetDirectProxyHandlerObject(proxy));
-
-    // step 2
-    RootedObject target(cx, proxy->as<ProxyObject>().target());
-
-    // step 3
-    RootedValue trap(cx);
-    if (!JSObject::getProperty(cx, handler, handler, cx->names().hasOwn, &trap))
-        return false;
-
-    // step 4
-    if (trap.isUndefined())
-        return DirectProxyHandler::hasOwn(cx, proxy, id, bp);
-
-    // step 5
-    RootedValue value(cx);
-    if (!IdToExposableValue(cx, id, &value))
-        return false;
-    Value argv[] = {
-        ObjectOrNullValue(target),
-        value
-    };
-    RootedValue trapResult(cx);
-    if (!Invoke(cx, ObjectValue(*handler), trap, ArrayLength(argv), argv, &trapResult))
-        return false;
-
-    // step 6
-    bool success = ToBoolean(trapResult);
-
-    // steps 7-8
-    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);
-            return false;
-        }
-
-        bool extensible;
-        if (!JSObject::isExtensible(cx, target, &extensible))
-            return false;
-        if (!extensible) {
-            bool isFixed;
-            if (!HasOwn(cx, target, id, &isFixed))
-                return false;
-            if (isFixed) {
-                JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_CANT_REPORT_E_AS_NE);
-                return false;
-            }
-        }
-    } else {
-        bool extensible;
-        if (!JSObject::isExtensible(cx, target, &extensible))
-            return false;
-        if (!extensible) {
-            bool isFixed;
-            if (!HasOwn(cx, target, id, &isFixed))
-                return false;
-            if (!isFixed) {
-                JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_CANT_REPORT_NEW);
-                return false;
-            }
-        }
-    }
-
-    // step 9
-    *bp = !!success;
-    return true;
-}
-
 // Proxy.[[GetP]](P, Receiver)
 bool
 ScriptedDirectProxyHandler::get(JSContext *cx, HandleObject proxy, HandleObject receiver,
                                 HandleId id, MutableHandleValue vp)
 {
     // step 1
     RootedObject handler(cx, GetDirectProxyHandlerObject(proxy));