Nicholas C. Zakas wrote:
Thanks for the clarifications. I understand wanting to make the distinction from an implementer point of view, I'm just not sure that developers make the distinction between [[Put]] and [[DefineOwnProperty]] even using regular object literals. Is there a reason that this:

var obj = {};
obj.{
    name: "JS"
};

Can't act the same as this:

var obj = {};
obj.name = "JS";

Wherein, if the property is already defined that acts as [[Put]] and otherwise acts as [[DefineOwnProperty]]?

There's a big reason, which came up recently as if it were still exploitable in modern browsers (fixed in 2009 era, at least in Firefox):

http://fafadiatech.blogspot.de/2012/04/json-hijacking.html

SpiderMonkey bug fixed in 2009:

https://bugzilla.mozilla.org/show_bug.cgi?id=474501

Note that the modern DOM and WebIDL are being spec'ed so typical DOM accessors are on prototypes, so you can't "fix" the bug by using [[Put]] only when the property is "own".

There really is a difference between assigning and defining in JS. Assigning runs setters, even inherited ones. Defining overrides or shadows. EIBTI.

/be

Thanks,
Nicholas

On 5/28/2012 2:27 PM, Allen Wirfs-Brock wrote:
On May 28, 2012, at 1:23 PM, Erik Arvidsson wrote:

On Mon, May 28, 2012 at 12:19 PM, Nicholas C. Zakas
<[email protected]>  wrote:
Is it intentional that the first example uses colons between the property
and value while all others use the equals sign?
Yes this is intentional. We discussed this a bit at the F2F meeting
and we came up with the proposal to use = for [[Put]] and : for
[[DefineOwnProperty]]. Having a way to do [[Put]] is important because
it is common to want to trigger setters.
At added a clarification of this to the strawman....



For example:

class Monster {
  set health(value) {
    this.barColor = value<  10 ? 'red' : 'green';
    this._health = value;
  }
}

class GiantSpider extends Monster {
  constructor() {
    this.{
      health = 100
    }
  }
}

If you use .{health: 100} then the setter would not be invoked and the
object would not be in a correct state. This example might be a bit
contrived but using [[DefineOwnProperty]] is not the right answer in a
lot of cases.

This is especially important for setting values of DOM node properties which are generally implemented as accessor properties (ie, getters/setters). That is why I used (thanks to dherman) a DOM element in most of the example that use +.

Allen




_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to