defineProperty invariants

# David Bruant (13 years ago)

I think it's the dual of the getOwnPropertyDescriptor invariant I talked about recently.

var t = {a:1};

var p = new Proxy(t, { defineProperty: function(target, name, desc){ return true; // pretend it's always successful } });

Object.defineProperty(p, 'a', {configurable: false});

My reading of the current spec is that this doesn't throw, so it means that Object.defineProperty pretends that 'a' has been successfully made non-configurable while it's actually not the case. Programs relying Object.defineProperty output being true can be fooled. I think the invariant should be: ToBoolean(definePropertyTrapOutput) === true => (descArgument.configurable === targetDesc.configurable)

Basically, it says that if the operation succeeded, the new target descriptor and the descriptor on the target after the trap call are the same.

Do we want invariants regarding when ToBoolean(definePropertyTrapOutput) is false?

# Tom Van Cutsem (13 years ago)

2012/10/4 David Bruant <bruant.d at gmail.com>

Hi,

I think it's the dual of the getOwnPropertyDescriptor invariant I talked about recently.

Yep. That's exactly it. I'll patch the spec.

I think the invariant should be: ToBoolean(definePropertyTrapOutput) === true => (descArgument.configurable === targetDesc.configurable)

I would formulate it as: ToBoolean(definePropertyTrapOutput) === true && descArgument.configurable === false => targetDesc !== undefined && targetDesc.configurable === false

(in words: if Object.defineProperty succeeds for a non-configurable property, then the property must exist on the target and also be non-configurable)

Basically, it says that if the operation succeeded, the new target descriptor and the descriptor on the target after the trap call are the same.

With the minor detail that defining a configurable property can succeed without the property having to exist on the target at all.

Do we want invariants regarding when ToBoolean(definePropertyTrapOutput) is false?

I don't think that is necessary: if the trap returns false, Object.defineProperty will throw anyway. Trying to enforce some invariant would only lead to the same effect.

# David Bruant (13 years ago)

Le 05/10/2012 15:05, Tom Van Cutsem a écrit :

2012/10/4 David Bruant <bruant.d at gmail.com <mailto:bruant.d at gmail.com>>

I think the invariant should be:
ToBoolean(definePropertyTrapOutput) === true
=> (descArgument.configurable === targetDesc.configurable)

I would formulate it as: ToBoolean(definePropertyTrapOutput) === true && descArgument.configurable === false => targetDesc !== undefined && targetDesc.configurable === false

(in words: if Object.defineProperty succeeds for a non-configurable property, then the property must exist on the target and also be non-configurable)

Your invariant is more accurate indeed.