Bug 142382

Summary: __proto__ shorthand property should not modify prototype in Object Literal construction
Product: WebKit Reporter: Joseph Pecoraro <joepeck>
Component: JavaScriptCoreAssignee: Joseph Pecoraro <joepeck>
Status: RESOLVED FIXED    
Severity: Normal CC: ggaren, joepeck, rniwa
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 215769    
Attachments:
Description Flags
[PATCH] Proposed Fix ggaren: review+, ggaren: commit-queue-

Description Joseph Pecoraro 2015-03-05 20:29:14 PST
* SUMMARY
__proto__ shorthand property should not modify prototype in Object Literal construction.

<https://kangax.github.io/compat-table/es6/> has a section that __proto__ should not be supported as a shorthand, citing:
"Annex b ยง __proto__ in object literals".

{__proto__} should not be equivalent to {__proto__:...}.

Seems to be because:

  PropertyDefinition : IdentifierReference
  ...
  7. Return CreateDataPropertyOrThrow(object, propName, propValue).

And that does not fall under the Annex's special case handling of __proto__ in literals for grammar rule:

  PropertyDefinition : PropertyName : AssignmentExpression

So we shouldn't get the special handling.

--

Seems the expected behavior of __proto__ as a shorthand would be the equivalent of a Object.defineProperty(obj, "__proto__", { value: ... }) which sets the property but doesn't change the prototype.
Comment 1 Joseph Pecoraro 2015-03-05 23:41:41 PST
Created attachment 248045 [details]
[PATCH] Proposed Fix
Comment 2 Geoffrey Garen 2015-03-06 12:11:26 PST
Comment on attachment 248045 [details]
[PATCH] Proposed Fix

View in context: https://bugs.webkit.org/attachment.cgi?id=248045&action=review

r=me

> Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp:379
> +        generator.emitDirectPutById(newObj, *node.name(), generator.emitNode(node.m_assign), node.putType() == PropertyNode::KnownDirect);

I think it would be slightly clearer to pass through the put type instead of a bool.
Comment 3 Joseph Pecoraro 2015-05-18 16:31:56 PDT
This landed a while ago: r181179
<http://trac.webkit.org/changeset/181179>