Object.freezing proxies should freeze or throw?

Claude Pache claude.pache at gmail.com
Mon Aug 8 09:02:52 UTC 2016

Here is another test case, with [[GetOwnPropertyDescriptor]]:

var target = Object.seal({x: 2});
var proxy = new Proxy(target, {
    getOwnPropertyDescriptor(o, p) {
        var d = Reflect.getOwnPropertyDescriptor(o, p)
        if (d && 'writable' in d)
            d.writable = false
        return d

Object.getOwnPropertyDescriptor(proxy, 'x'); // { value: 2, writable: false, configurable: false }

Object.defineProperty(proxy, 'x', { value: 3 })

Object.getOwnPropertyDescriptor(proxy, 'x'); // { value: 3, writable: false, configurable: false }

IMHO, the most robust fix is the following: Both the [[DefineOwnProperty]] and the [[GetOwnPropertyDescriptor]] contain the following check:

* If IsCompatiblePropertyDescriptor(extensibleTarget, resultDesc, targetDesc) is false, throw a TypeError exception.

I think there should be also the following check (except when targetDesc is undefined, in which case another appropriate check is used):

* If IsCompatiblePropertyDescriptor(extensibleTarget, targetDesc, resultDesc) is false, throw a TypeError exception.

That would replace the weaker adhoc check about the [[Configurable]] attribute (search for settingConfigFalse) in those algorithms.

(Alternatively, in order to avoid double checks, define an AreBothWaysCompatiblePropertyDescriptors(extensibleTarget, desc1, desc2) abstract operation.)


More information about the es-discuss mailing list