testDirectProxyHasOwnProperty.js (1210B)
1 // Forward to the target if the trap is not defined 2 var proto = Object.create(null, { 3 'foo': { 4 configurable: true 5 } 6 }); 7 var descs = { 8 'bar': { 9 configurable: true 10 } 11 }; 12 descs[Symbol.for("quux")] = {configurable: true}; 13 var target = Object.create(proto, descs); 14 15 for (let p of [new Proxy(target, {}), Proxy.revocable(target, {}).proxy]) { 16 assertEq(({}).hasOwnProperty.call(p, 'foo'), false); 17 assertEq(({}).hasOwnProperty.call(p, 'bar'), true); 18 assertEq(({}).hasOwnProperty.call(p, 'quux'), false); 19 assertEq(({}).hasOwnProperty.call(p, Symbol('quux')), false); 20 assertEq(({}).hasOwnProperty.call(p, 'Symbol(quux)'), false); 21 assertEq(({}).hasOwnProperty.call(p, Symbol.for('quux')), true); 22 } 23 24 // Make sure only the getOwnPropertyDescriptor trap is called, and not the has 25 // trap. 26 var called; 27 var handler = { getOwnPropertyDescriptor: function () { called = true; }, 28 has: function () { assertEq(false, true, "has trap must not be called"); } 29 } 30 31 for (let p of [new Proxy({}, handler), Proxy.revocable({}, handler).proxy]) { 32 called = false; 33 assertEq(({}).hasOwnProperty.call(p, 'foo'), false); 34 assertEq(called, true); 35 }