Question regarding duplicate __proto__ properties

# Nicholas C. Zakas (10 years ago)

In Rev 28, B.3.1 it states:

It is a Syntax Error
ifPropertyNameListofPropertyDefinitionListcontains any duplicate
entries for|"__proto__"|and at least two of those entries were
obtained from productions of the
formPropertyDefinition:PropertyName|:|AssignmentExpression.

I noted that the duplicate name restriction was eliminated back in July1 and was just wondering if __proto__ is indeed a special case?

# Allen Wirfs-Brock (10 years ago)

Yes, __proto__ : <expr> in an object literal is a special form with different semantics than the other PropertyDefinition forms. The relaxation of the duplicate entry was explicitly not applied to it.

It's worth noting that:

__proto__:  <expr>

and

["__proto__"] : <expr>

do not mean the same thing.

The first form does a [[SetPrototypeOf]] and is the form that the above early error applies to. The second form does a [[DefineProperty]] and does not place any restrictions of duplicates.

# Michał Wadas (10 years ago)

Should it be possible to have property named "__proto__" which is inaccessible in modern implementations?

# Jeff Walden (10 years ago)

It's perfectly accessible.

var obj = { ["__proto__"]: 42, __proto__: null };
assert(obj.__proto__ === 42);
assert("__proto__" in obj);
assert(Reflect.get(obj, "__proto__") === 42); // ...if I remember R.get's name/semantics
assert(Object.getOwnPropertyDescriptor(obj, "__proto__").value === 42);
assert(Object.getPrototypeOf(obj) === null);

And so on.