archives

« Bugzilla Issues Index

#3160 — Should multiple __proto__: PropertyDefinitions be permitted?


Currently, there's a special rule banning them:

http://people.mozilla.org/~jorendorff/es6-draft.html#sec-__proto__-property-names-in-object-initializers
> * It is a Syntax Error if PropertyNameList of PropertyDefinitionList
> contains any duplicate entries for "__proto__" and at least two of those
> entries were obtained from productions of the form
> `PropertyDefinition : PropertyName : AssignmentExpression`.

Since all other rules about duplicate property definitions have been dropped in ES6, I think it would make sense to drop this one.


I disagree. I think prototype mutation is bad, and multiple mutations bad enough, that this is a perfectly reasonable thing to have.

The rationale for removing the restriction on normal properties was that computed property names could produce conflicts just as easily, conflicts not detectable until runtime. Because no property form but p:n can trigger prototype mutation, the rationale is not valid as concerns this duplication-removal.


We've talked about this at TC39 meetings.

__proto__: expr

and
"__proto__": expr

are considered a special form and are not regular property definitions. And we decided that the special form should only be allowed to occur only once in each object literal.

However,
["__proto__"]: expr
"__proto__" () { }

etc. are regular property definitions and can occur multiple times.

You can even say:

{__proto__: obj, //set [[Prototype]]
["__proto__"]: undefined //disable access to O.p.__prototype
}

I don't think we need to revisit that decisions so I'm going to close this as WONTFIX