Object.freezing proxies should freeze or throw?
Claude Pache
claude.pache at gmail.com
Mon Aug 8 13:37:24 UTC 2016
> Le 8 août 2016 à 11:02, Claude Pache <claude.pache at gmail.com> a écrit :
>
> Here is another test case, with [[GetOwnPropertyDescriptor]]:
>
> ```js
> 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.)
>
> —Claude
>
Looking closer, it seems that using IsCompatiblePropertyDescriptor is in fact an overkill, because we probably don’t want the special case of conditionally mutable [[Writable]] attribute for nonconfigurable properties.
That is, I think that the following condition must hold: If either the target has a nonconfigurable property, or the proxy claims to have a nonconfigurable property, then every attribute of the property descriptor claimed by the proxy must be identical to the corresponding attribute of the property descriptor of the target.
—Claude
More information about the es-discuss
mailing list