Bug 142382 - __proto__ shorthand property should not modify prototype in Object Literal construction
Summary: __proto__ shorthand property should not modify prototype in Object Literal co...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Joseph Pecoraro
URL:
Keywords:
Depends on:
Blocks: 215769
  Show dependency treegraph
 
Reported: 2015-03-05 20:29 PST by Joseph Pecoraro
Modified: 2020-08-25 11:24 PDT (History)
3 users (show)

See Also:


Attachments
[PATCH] Proposed Fix (18.50 KB, patch)
2015-03-05 23:41 PST, Joseph Pecoraro
ggaren: review+
ggaren: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
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>