michael@0: // obj.hasOwnProperty(id), Object.getOwnPropertyDescriptor(obj, id), and michael@0: // Object.defineProperty(obj, id, desc) do not look at obj's prototype. michael@0: michael@0: var angryHandler = new Proxy({}, { michael@0: has: () => true, michael@0: get: (t, id) => { michael@0: throw new Error("angryHandler should not be queried (" + id + ")"); michael@0: } michael@0: }); michael@0: var angryProto = new Proxy({}, angryHandler); michael@0: michael@0: var obj = Object.create(angryProto, { michael@0: // Define hasOwnProperty directly on obj since we are poisoning its michael@0: // prototype chain. michael@0: hasOwnProperty: { michael@0: value: Object.prototype.hasOwnProperty michael@0: } michael@0: }); michael@0: michael@0: assertEq(Object.getOwnPropertyDescriptor(obj, "foo"), undefined); michael@0: assertEq(obj.hasOwnProperty("foo"), false); michael@0: Object.defineProperty(obj, "foo", {value: 5}); michael@0: assertEq(obj.hasOwnProperty("foo"), true); michael@0: assertEq(obj.foo, 5);