michael@0: load(libdir + "asserts.js"); michael@0: michael@0: /* michael@0: * Throw a TypeError if the trap reports a different value for a non-writable, michael@0: * non-configurable property michael@0: */ michael@0: var target = {}; michael@0: Object.defineProperty(target, 'foo', { michael@0: value: 'bar', michael@0: writable: false, michael@0: configurable: false michael@0: }); michael@0: assertThrowsInstanceOf(function () { michael@0: new Proxy(target, { michael@0: get: function (target, name, receiver) { michael@0: return 'baz'; michael@0: } michael@0: })['foo']; michael@0: }, TypeError); michael@0: michael@0: /* michael@0: * Don't throw a TypeError if the trap reports the same value for a non-writable, michael@0: * non-configurable property michael@0: */ michael@0: assertEq(new Proxy(target, { michael@0: get: function (target, name, receiver) { michael@0: return 'bar'; michael@0: } michael@0: })['foo'], michael@0: 'bar'); michael@0: michael@0: michael@0: /* michael@0: * Don't throw a TypeError if the trap reports a different value for a writable, michael@0: * non-configurable property michael@0: */ michael@0: Object.defineProperty(target, 'prop', { michael@0: value: 'bar', michael@0: writable: true, michael@0: configurable: false michael@0: }); michael@0: assertEq(new Proxy(target, { michael@0: get: function (target, name, receiver) { michael@0: return 'baz'; michael@0: } michael@0: })['prop'], michael@0: 'baz'); michael@0: michael@0: michael@0: /* michael@0: * Don't throw a TypeError if the trap reports a different value for a non-writable, michael@0: * configurable property michael@0: */ michael@0: Object.defineProperty(target, 'prop2', { michael@0: value: 'bar', michael@0: writable: false, michael@0: configurable: true michael@0: }); michael@0: assertEq(new Proxy(target, { michael@0: get: function (target, name, receiver) { michael@0: return 'baz'; michael@0: } michael@0: })['prop2'], michael@0: 'baz');