> From: Fred Schott <[email protected]>
> To: [email protected]
> Cc:
> Date: Sun, 4 Jan 2015 23:06:56 -0600
> Subject: Question regarding duplicate computed __proto__ properties
> In Section B.3.1 on "__proto__ Property Names in Object Initializers" there 
> is a paragraph explaining when duplicate properties will result in a syntax 
> error. It says:
>
>> 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 .
>
>
> Where PropertyName is defined as:
>
>> PropertyName[Yield,GeneratorParameter] :
>>   LiteralPropertyName
>>   [+GeneratorParameter] ComputedPropertyName
>>   [~GeneratorParameter] ComputedPropertyName[?Yield]
>>
>> LiteralPropertyName :
>>   IdentifierName
>>   StringLiteral
>>   NumericLiteral
>
>
> That paragraph (using the definitions provided) seems to assert that it is a 
> syntax error if there are any duplicate uses of __proto__ with an 
> IdentifierName, StringLiteral, or ComputedPropertyName. To translate this 
> into an example, it seems to assert that in ES6 this is not valid:
>
>> var obj = {
>>   __proto__: somePrototype,
>>   ["__proto__"]: somePrototype
>> }
>>
>> // Error: SyntaxError
>
>
> Is that correct? Step 6 of Section B.3.1 explicitly states that the computed 
> ["__proto__"] does not have the same special behavior as the literal 
> property. But from my understanding of other es-discuss topics & resources, 
> the restriction on duplicate "__proto__" properties also does not apply to 
> computed properties. If that is true, then the quoted paragraph above seems 
> to be incorrect or misleading.
>
> Can anyone clarify this? I may just be misunderstanding the docs and/or the 
> recent discussions. Or it could be that the definition has changed around 
> that quoted paragraph and it needs to be updated.
>
> _______________________________________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
>

As far as my understanding goes, that rule should not apply. The
rationale I guess is that having that inconsistency helps eliminate
issues with dynamic properties and potential gotchas like these:

```js
class A {}
class B {}

var foo = {};
var bar = {};
foo.__proto__ = A.prototype;
bar.__proto__ = B.prototype;

for (var prop in foo) {
  bar[prop] = foo[prop];
}

// If this is false, then that's a problem.
assert(bar instanceof B);
```

Also, AFAICT, these should never throw, for the same reason:

```js
class A {}
var proto = '__proto__';
{
  __proto__: A.prototype
  [proto]: null
}
{
  __proto__: A.prototype
  ['__proto__']: null
}
```

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

Reply via email to