Bug 142895 - ES6: Allow duplicate property names
Summary: ES6: Allow duplicate property names
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:
 
Reported: 2015-03-19 20:19 PDT by Joseph Pecoraro
Modified: 2016-06-06 21:21 PDT (History)
8 users (show)

See Also:


Attachments
[PATCH] Work in Progress - Numerous issues (11.16 KB, patch)
2015-03-19 20:23 PDT, Joseph Pecoraro
no flags Details | Formatted Diff | Diff
[PATCH] Proposed Fix (88.89 KB, patch)
2015-03-21 00:42 PDT, Joseph Pecoraro
no flags Details | Formatted Diff | Diff
[PATCH] For Bots 1 (88.78 KB, patch)
2015-03-21 00:54 PDT, Joseph Pecoraro
buildbot: commit-queue-
Details | Formatted Diff | Diff
Archive of layout-test-results from ews105 for mac-mavericks-wk2 (612.50 KB, application/zip)
2015-03-21 01:46 PDT, Build Bot
no flags Details
Archive of layout-test-results from ews101 for mac-mavericks (582.45 KB, application/zip)
2015-03-21 02:06 PDT, Build Bot
no flags Details
[PATCH] Proposed Fix (97.05 KB, patch)
2015-03-21 17:22 PDT, Joseph Pecoraro
buildbot: commit-queue-
Details | Formatted Diff | Diff
Archive of layout-test-results from ews102 for mac-mavericks (653.14 KB, application/zip)
2015-03-21 18:38 PDT, Build Bot
no flags Details
Archive of layout-test-results from ews104 for mac-mavericks-wk2 (580.06 KB, application/zip)
2015-03-21 18:42 PDT, Build Bot
no flags Details
[PATCH] Proposed Fix (97.40 KB, patch)
2015-03-21 18:55 PDT, Joseph Pecoraro
no flags Details | Formatted Diff | Diff
[PATCH] Proposed Fix (98.12 KB, patch)
2015-03-21 20:07 PDT, Joseph Pecoraro
ggaren: review+
Details | Formatted Diff | Diff
[PATCH] For Landing (97.99 KB, patch)
2015-05-13 15:20 PDT, Joseph Pecoraro
no flags 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-19 20:19:19 PDT
* SUMMARY
ES6 allows duplicate property names where ES5 (strict mode) did not:
<https://people.mozilla.org/~jorendorff/es6-draft.html#sec-additions-and-changes-that-introduce-incompatibilities-with-prior-editions>

> Annex E: Additions and Changes That Introduce Incompatibilities with Prior Editions
> 12.2.5.1: In Edition 6, it is no longer an early error to have duplicate property names in Object Initializers.

> July 18, 2014 Draft Rev 26
> Eliminated duplicate property name restrictions on object literals and class definitions

> Deleted:
> ObjectLiteral : { PropertyDefinitionList }
> ObjectLiteral : { PropertyDefinitionList , }
> 
> <#>It is a Syntax Error if PropertyNameList of PropertyDefinitionList contains any duplicate entries, unless one of the following conditions aretrueforeachduplicateentry: 
> <#>The source code corresponding to PropertyDefinitionList is not strict code and all occurrences in the list of the duplicated entry were obtained from productions of the form PropertyDefinition : PropertyName : AssignmentExpression.
> <#>The duplicated entry occurs exactly twice in the list and one occurrence was obtained from a get accessor MethodDefinition and the other occurrence was obtained from a set accessor MethodDefinition.



Removing duplicate detection offers us an opportunity to also fix these cases:


* TESTS

/* Test 1 - ensure computed property eliminates the getter, and then the setter eliminates the property */
x = 0;
var o = {
    ["foo"]:++x,
    get foo() { return -2; },
    ["foo"]:++x,
    set foo(x) { return 0; },
};
console.log(Object.getOwnPropertyDescriptor(o)); // only setter
console.log(o.foo); // undefined
console.log(x); // 2

/* Test 2 - ensure getter doesn't get erased when setting setter*/
x = 0;
var o = {    
    ["foo"]:++x,
    get foo() { return -2; },
    set foo(x) { return 0; },
};

console.log(Object.getOwnPropertyDescriptor(o)); // getter and setter
console.log(o.foo); // -2
console.log(x); // 1


/* Test 3 - ensure getter doesn't get erased */
x = 0;
var o = {
    ["foo"]:++x,
    get foo() { return -2; },
    set foo(x) { return 0; },
    foo:99,
};

console.log(Object.getOwnPropertyDescriptor(o)); // value
console.log(o.foo); // 99
console.log(x); // 1
Comment 1 Joseph Pecoraro 2015-03-19 20:23:25 PDT
Created attachment 249079 [details]
[PATCH] Work in Progress - Numerous issues

I took the naive approach, and just "emit everything" if there is a computed property. And for getters/setters instead of emitting in pairs, just emit them individually. This ran into two issues:

  - emitting an individual getter/setter individually with emitPutGetterSetter wipes out any preexisting getter/setter
  - trying to putDirect a constant if a getter/setter is not supported (ASSERTs in JSC::PropertyDescriptor::setDescriptor)

If anyone wants to move this forward, please do!
Comment 2 Joseph Pecoraro 2015-03-20 02:16:34 PDT
> If anyone wants to move this forward, please do!

Looking into this more I think I can manage this. I'll take this and give it a shot.
Comment 3 Joseph Pecoraro 2015-03-21 00:42:59 PDT
Created attachment 249166 [details]
[PATCH] Proposed Fix

This works! A few pre-existing issues were discovered while writing tests that should be addressed separately.
Comment 4 Joseph Pecoraro 2015-03-21 00:49:38 PDT
Comment on attachment 249166 [details]
[PATCH] Proposed Fix

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

> Source/JavaScriptCore/runtime/JSObject.h:1342
> +            if ((attributes & Accessor) != (currentAttributes & Accessor)) {

I suppose this could be an xor. I wasn't sure if that would be frowned on: ((attributes ^ currentAttributes) & Accessor)
Comment 5 Joseph Pecoraro 2015-03-21 00:54:40 PDT
Created attachment 249167 [details]
[PATCH] For Bots 1
Comment 6 Build Bot 2015-03-21 01:46:04 PDT
Comment on attachment 249167 [details]
[PATCH] For Bots 1

Attachment 249167 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.appspot.com/results/6007228142190592

New failing tests:
ietestcenter/Javascript/11.1.5_4-4-c-2.html
js/mozilla/strict/11.1.5.html
ietestcenter/Javascript/11.1.5_4-4-d-1.html
ietestcenter/Javascript/11.1.5_4-4-b-1.html
ietestcenter/Javascript/11.1.5_4-4-d-4.html
ietestcenter/Javascript/11.1.5_4-4-d-3.html
ietestcenter/Javascript/11.1.5_4-4-b-2.html
ietestcenter/Javascript/11.1.5_4-4-c-1.html
ietestcenter/Javascript/11.1.5_4-4-d-2.html
Comment 7 Build Bot 2015-03-21 01:46:07 PDT
Created attachment 249169 [details]
Archive of layout-test-results from ews105 for mac-mavericks-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews105  Port: mac-mavericks-wk2  Platform: Mac OS X 10.9.5
Comment 8 Build Bot 2015-03-21 02:06:42 PDT
Comment on attachment 249167 [details]
[PATCH] For Bots 1

Attachment 249167 [details] did not pass mac-ews (mac):
Output: http://webkit-queues.appspot.com/results/4900378562789376

New failing tests:
ietestcenter/Javascript/11.1.5_4-4-c-2.html
js/mozilla/strict/11.1.5.html
ietestcenter/Javascript/11.1.5_4-4-d-1.html
ietestcenter/Javascript/11.1.5_4-4-b-1.html
ietestcenter/Javascript/11.1.5_4-4-d-4.html
ietestcenter/Javascript/11.1.5_4-4-d-3.html
ietestcenter/Javascript/11.1.5_4-4-b-2.html
ietestcenter/Javascript/11.1.5_4-4-c-1.html
ietestcenter/Javascript/11.1.5_4-4-d-2.html
Comment 9 Build Bot 2015-03-21 02:06:45 PDT
Created attachment 249170 [details]
Archive of layout-test-results from ews101 for mac-mavericks

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: ews101  Port: mac-mavericks  Platform: Mac OS X 10.9.5
Comment 10 Joseph Pecoraro 2015-03-21 09:05:11 PDT
Comment on attachment 249166 [details]
[PATCH] Proposed Fix

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

> Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp:334
>      for (; p && p->m_node->m_type == PropertyNode::Constant; p = p->m_next)
>          emitPutConstantProperty(generator, dst, *p->m_node);

Nit: This fast path can still be for Constant | Computed. Since the slow path is to handle getters/setters getting overriden by computed properties, we only care if there is a computed property once we've seen a getter/setter.
Comment 11 Joseph Pecoraro 2015-03-21 09:07:52 PDT
I have not looked yet, but these tests are likely failing because they expect ES5 behavior that is changing, so the should just need updated results.
Comment 12 Joseph Pecoraro 2015-03-21 17:22:56 PDT
Created attachment 249179 [details]
[PATCH] Proposed Fix
Comment 13 Build Bot 2015-03-21 18:38:53 PDT
Comment on attachment 249179 [details]
[PATCH] Proposed Fix

Attachment 249179 [details] did not pass mac-ews (mac):
Output: http://webkit-queues.appspot.com/results/6292978221973504

New failing tests:
js/basic-computed-property-name.html
Comment 14 Build Bot 2015-03-21 18:38:56 PDT
Created attachment 249183 [details]
Archive of layout-test-results from ews102 for mac-mavericks

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: ews102  Port: mac-mavericks  Platform: Mac OS X 10.9.5
Comment 15 Build Bot 2015-03-21 18:41:58 PDT
Comment on attachment 249179 [details]
[PATCH] Proposed Fix

Attachment 249179 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.appspot.com/results/5300034396487680

New failing tests:
js/basic-computed-property-name.html
Comment 16 Build Bot 2015-03-21 18:42:01 PDT
Created attachment 249185 [details]
Archive of layout-test-results from ews104 for mac-mavericks-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews104  Port: mac-mavericks-wk2  Platform: Mac OS X 10.9.5
Comment 17 Joseph Pecoraro 2015-03-21 18:46:24 PDT
> New failing tests:
> js/basic-computed-property-name.html

Heh, this is interesting. It is actually a bug in the existing computed properties implementation. I'll file a separate bug to address this separately.
Comment 18 Joseph Pecoraro 2015-03-21 18:55:48 PDT
Created attachment 249186 [details]
[PATCH] Proposed Fix

This also tried to fix the other builds!
Comment 19 Joseph Pecoraro 2015-03-21 20:07:26 PDT
Created attachment 249188 [details]
[PATCH] Proposed Fix

Try to fix Windows.
Comment 20 Joseph Pecoraro 2015-04-17 19:03:55 PDT
This patch probably needs to be rebased at this point, but can it get a review to see if it was the correct direction? I'm willing to rebaseline it and make further changes.
Comment 21 Mark Lam 2015-04-21 09:44:20 PDT
Comment on attachment 249188 [details]
[PATCH] Proposed Fix

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

> LayoutTests/js/mozilla/strict/11.1.5-expected.txt:1
> -PASS Function("'use strict'; ({x:1, x:1})") threw exception of type SyntaxError.
> +FAIL Function("'use strict'; ({x:1, x:1})") should throw an instance of SyntaxError

I thought duplication in strict code is not allowed.  Your description (with excerpt of Annex E) said: "It is a Syntax Error if PropertyNameList of PropertyDefinitionList contains any duplicate entries, unless … The source code corresponding to PropertyDefinitionList is not strict code”.
Comment 22 Joseph Pecoraro 2015-04-21 10:35:09 PDT
(In reply to comment #21)
> Comment on attachment 249188 [details]
> [PATCH] Proposed Fix
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=249188&action=review
> 
> > LayoutTests/js/mozilla/strict/11.1.5-expected.txt:1
> > -PASS Function("'use strict'; ({x:1, x:1})") threw exception of type SyntaxError.
> > +FAIL Function("'use strict'; ({x:1, x:1})") should throw an instance of SyntaxError
> 
> I thought duplication in strict code is not allowed.  Your description (with
> excerpt of Annex E) said: "It is a Syntax Error if PropertyNameList of
> PropertyDefinitionList contains any duplicate entries, unless … The source
> code corresponding to PropertyDefinitionList is not strict code”.

You are quoting the part of the spec that was "Deleted". The top sentence says, "it is no longer an early error to have duplicate property names in Object Initializers."
Comment 23 Mark Lam 2015-04-21 10:40:58 PDT
(In reply to comment #22)
> (In reply to comment #21)
> > Comment on attachment 249188 [details]
> > [PATCH] Proposed Fix
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=249188&action=review
> > 
> > > LayoutTests/js/mozilla/strict/11.1.5-expected.txt:1
> > > -PASS Function("'use strict'; ({x:1, x:1})") threw exception of type SyntaxError.
> > > +FAIL Function("'use strict'; ({x:1, x:1})") should throw an instance of SyntaxError
> > 
> > I thought duplication in strict code is not allowed.  Your description (with
> > excerpt of Annex E) said: "It is a Syntax Error if PropertyNameList of
> > PropertyDefinitionList contains any duplicate entries, unless … The source
> > code corresponding to PropertyDefinitionList is not strict code”.
> 
> You are quoting the part of the spec that was "Deleted". The top sentence
> says, "it is no longer an early error to have duplicate property names in
> Object Initializers."

I see.  Thanks for clarifying.
Comment 24 Joseph Pecoraro 2015-05-01 22:28:51 PDT
Bump!
Comment 25 Geoffrey Garen 2015-05-05 13:58:43 PDT
Comment on attachment 249188 [details]
[PATCH] Proposed Fix

Does this patch mean that functions that initialize objects with getters and setters will no longer compile in DFG or FTL?
Comment 26 Joseph Pecoraro 2015-05-05 14:01:39 PDT
(In reply to comment #25)
> Comment on attachment 249188 [details]
> [PATCH] Proposed Fix
> 
> Does this patch mean that functions that initialize objects with getters and
> setters will no longer compile in DFG or FTL?

The existing op_put_getter_setter is not compiled to the DFG or FTL, so there is no change in capabilities for object literals with getters/setters.
Comment 27 Geoffrey Garen 2015-05-05 14:04:03 PDT
Comment on attachment 249188 [details]
[PATCH] Proposed Fix

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

r=me

> Source/JavaScriptCore/runtime/JSObject.cpp:1253
> +void JSObject::putGetter(ExecState* exec, PropertyName propertyName, JSValue getter)
> +{
> +    PropertyDescriptor descriptor;
> +    descriptor.setGetter(getter);
> +    descriptor.setEnumerable(true);
> +    descriptor.setConfigurable(true);
> +    defineOwnProperty(this, exec, propertyName, descriptor, false);
> +}
> +
> +void JSObject::putSetter(ExecState* exec, PropertyName propertyName, JSValue setter)
> +{
> +    PropertyDescriptor descriptor;
> +    descriptor.setSetter(setter);
> +    descriptor.setEnumerable(true);
> +    descriptor.setConfigurable(true);
> +    defineOwnProperty(this, exec, propertyName, descriptor, false);
> +}

Is this really better than just emitting bytecode to call defineOwnProperty?
Comment 28 Joseph Pecoraro 2015-05-13 15:15:26 PDT
> Is this really better than just emitting bytecode to call defineOwnProperty?

Do you mean adding a single opcode with more flags that calls defineOwnProperty or something else?
Comment 29 Joseph Pecoraro 2015-05-13 15:20:16 PDT
Created attachment 253064 [details]
[PATCH] For Landing
Comment 30 WebKit Commit Bot 2015-05-13 18:33:53 PDT
Comment on attachment 253064 [details]
[PATCH] For Landing

Clearing flags on attachment: 253064

Committed r184324: <http://trac.webkit.org/changeset/184324>