Bug 151026 - Destructuring Assignment: Properties are valid AssignmentElements
Summary: Destructuring Assignment: Properties are valid AssignmentElements
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
: 151324 (view as bug list)
Depends on: 151417 151419
Blocks: 151324
  Show dependency treegraph
 
Reported: 2015-11-09 07:53 PST by Caitlin Potter (:caitp)
Modified: 2016-05-10 06:48 PDT (History)
14 users (show)

See Also:


Attachments
Accept any LHS for AssignmentElements (no tests yet) (12.53 KB, patch)
2015-11-12 13:32 PST, Caitlin Potter (:caitp)
no flags Details | Formatted Diff | Diff
Patch (28.94 KB, patch)
2015-11-12 23:45 PST, Caitlin Potter (:caitp)
no flags Details | Formatted Diff | Diff
Original patch + perf fixes from bug151324 (34.07 KB, patch)
2015-11-18 18:28 PST, Caitlin Potter (:caitp)
no flags Details | Formatted Diff | Diff
Original patch + perf fixes from bug151324 (34.08 KB, patch)
2015-11-18 18:42 PST, Caitlin Potter (:caitp)
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews100 for mac-yosemite (816.54 KB, application/zip)
2015-11-18 19:11 PST, Build Bot
no flags Details
Archive of layout-test-results from ews107 for mac-yosemite-wk2 (878.92 KB, application/zip)
2015-11-18 19:16 PST, Build Bot
no flags Details
Archive of layout-test-results from ews114 for mac-yosemite (781.97 KB, application/zip)
2015-11-18 19:40 PST, Build Bot
no flags Details
Original patch + perf fixes from bug151324 v2 (36.01 KB, patch)
2015-11-18 19:43 PST, Caitlin Potter (:caitp)
no flags Details | Formatted Diff | Diff
Patch (274.88 KB, patch)
2015-11-19 13:53 PST, Caitlin Potter (:caitp)
no flags Details | Formatted Diff | Diff
Patch (272.23 KB, patch)
2015-11-19 13:59 PST, Caitlin Potter (:caitp)
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Caitlin Potter (:caitp) 2015-11-09 07:53:23 PST
Any sort of Property MemberExpression used in a destructuring assignment context results in a syntax error:

```js
({ x: this.x } = { x: true });
({ x: (function() {}).x } = { x: true });
({ x: ({}).x } = { x: true });

// etc ...
```

However, these are all legal (even if they don't make any sense), per http://tc39.github.io/ecma262/#prod-AssignmentElement
Comment 1 Caitlin Potter (:caitp) 2015-11-12 13:32:48 PST
Created attachment 265428 [details]
Accept any LHS for AssignmentElements (no tests yet)
Comment 2 Caitlin Potter (:caitp) 2015-11-12 13:37:00 PST
Added a first-stab at a fix.

This only supports the case of ObjectAssignmentPattern properties with identifier property names, so no integer/string/computed properties supported yet. Also, ArrayAssignmentPatterns aren't handled.

A test case:

```js
var foo = {};
({ a: foo.a } = { a: true });
assert(foo.a === true);
```

I'm happy to add tests and clean it up (without cleanup, there will be a pile of duplicate code), but I'd like to make sure the codegen and new AST entry make sense first.
Comment 3 Geoffrey Garen 2015-11-12 13:54:18 PST
+CC Oliver, since he wrote a lot of this parser.
Comment 4 Geoffrey Garen 2015-11-12 13:56:12 PST
I'm curious: Is an expression like this ever useful, or at least observable to the programmer?
Comment 5 Caitlin Potter (:caitp) 2015-11-12 14:03:27 PST
The most common observable use (as far as I can tell), is assigning to properties of "this", eg in a constructor.

eg:

```
class FancyNode {
  constructor(nodePosition = null) {
    ({ x: this.x, y: this.y } = nodePosition);
  }
}
```

or something similar. The other uses are legal and observable, but probably not very useful?
Comment 6 Geoffrey Garen 2015-11-12 14:55:51 PST
Wow. This destination-on-the-right JavaScript syntax is blowing my mind. In the bad way :(.
Comment 7 Geoffrey Garen 2015-11-12 15:51:17 PST
Comment on attachment 265428 [details]
Accept any LHS for AssignmentElements (no tests yet)

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

Thanks for the patch. This looks pretty good.

Please add test cases. Also, a few comments below.

> Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp:3454
> +void AssignmentElementNode::toString(StringBuilder& builder) const
> +{
> +    if (m_assignmentTarget->isResolveNode())
> +        builder.append(static_cast<ResolveNode*>(m_assignmentTarget)->identifier().string());
> +}

Can you add support for isDotAccessorNode and isBracketAccessorNode here?

> Source/JavaScriptCore/parser/Parser.cpp:864
> +                            if (!element || !context.isAssignmentLocation(element)) {
> +                                // TODO: Early SyntaxError per http://tc39.github.io/ecma262/#sec-assignment-operators-static-semantics-early-errors
> +                                return 0;

You can use "failIfFalse(element && context.isAssignmentLocation(element), message)" here.
Comment 8 Geoffrey Garen 2015-11-12 15:52:37 PST
... In addition to adding tests, you should run the run-javascriptcore-tests script to see if you've changed any expected failures to passes in Source/JavaScriptCore/tests/es6/.
Comment 9 Caitlin Potter (:caitp) 2015-11-12 18:38:59 PST
Left some comments on the diff about the `toString()` thing, and the approach for making the error message macro do something useful (propagate the correct message), which sort of depends on some hacks (the save point clears the original message, so it needs to be saved and reset manually later on in order to pass the right one in)
Comment 10 Caitlin Potter (:caitp) 2015-11-12 23:45:49 PST
Created attachment 265470 [details]
Patch
Comment 11 Geoffrey Garen 2015-11-13 10:24:37 PST
Comment on attachment 265470 [details]
Patch

r=me 👍
Comment 12 WebKit Commit Bot 2015-11-13 11:13:40 PST
Comment on attachment 265470 [details]
Patch

Clearing flags on attachment: 265470

Committed r192436: <http://trac.webkit.org/changeset/192436>
Comment 13 WebKit Commit Bot 2015-11-13 11:13:45 PST
All reviewed patches have been landed.  Closing bug.
Comment 14 Joseph Pecoraro 2015-11-16 14:28:40 PST
This seems to have caused a very long hang in Web Inspector:
<https://webkit.org/b/151324> REGRESSION(r192436): Inspector Hanging under tryParseDestructuringPatternExpression
Comment 15 Geoffrey Garen 2015-11-18 15:27:28 PST
I'm going to roll out this patch for now since I don't have enough time to review review its fixes by the end of the day.
Comment 16 WebKit Commit Bot 2015-11-18 15:51:49 PST
Re-opened since this is blocked by bug 151417
Comment 17 Caitlin Potter (:caitp) 2015-11-18 18:28:58 PST
Created attachment 265822 [details]
Original patch + perf fixes from bug151324

Original patch rebased on ToT + perf fixes from bug 151324
Comment 18 Caitlin Potter (:caitp) 2015-11-18 18:42:24 PST
Created attachment 265825 [details]
Original patch + perf fixes from bug151324

Original patch rebased on ToT + perf fixes from bug 151324 --- rebased again, my bad
Comment 19 Build Bot 2015-11-18 19:11:19 PST
Comment on attachment 265825 [details]
Original patch + perf fixes from bug151324

Attachment 265825 [details] did not pass mac-ews (mac):
Output: http://webkit-queues.webkit.org/results/448018

New failing tests:
sputnik/Conformance/12_Statement/12.6_Iteration_Statements/12.6.3_The_for_Statement/S12.6.3_A8_T3.html
Comment 20 Build Bot 2015-11-18 19:11:23 PST
Created attachment 265827 [details]
Archive of layout-test-results from ews100 for mac-yosemite

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: ews100  Port: mac-yosemite  Platform: Mac OS X 10.10.5
Comment 21 Build Bot 2015-11-18 19:16:41 PST
Comment on attachment 265825 [details]
Original patch + perf fixes from bug151324

Attachment 265825 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.webkit.org/results/448026

New failing tests:
sputnik/Conformance/12_Statement/12.6_Iteration_Statements/12.6.3_The_for_Statement/S12.6.3_A8_T3.html
Comment 22 Build Bot 2015-11-18 19:16:45 PST
Created attachment 265830 [details]
Archive of layout-test-results from ews107 for mac-yosemite-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews107  Port: mac-yosemite-wk2  Platform: Mac OS X 10.10.5
Comment 23 Build Bot 2015-11-18 19:40:30 PST
Comment on attachment 265825 [details]
Original patch + perf fixes from bug151324

Attachment 265825 [details] did not pass mac-debug-ews (mac):
Output: http://webkit-queues.webkit.org/results/448087

New failing tests:
sputnik/Conformance/12_Statement/12.6_Iteration_Statements/12.6.3_The_for_Statement/S12.6.3_A8_T3.html
Comment 24 Build Bot 2015-11-18 19:40:35 PST
Created attachment 265834 [details]
Archive of layout-test-results from ews114 for mac-yosemite

The attached test failures were seen while running run-webkit-tests on the mac-debug-ews.
Bot: ews114  Port: mac-yosemite  Platform: Mac OS X 10.10.5
Comment 25 Caitlin Potter (:caitp) 2015-11-18 19:43:22 PST
Created attachment 265835 [details]
Original patch + perf fixes from bug151324 v2

Fix the new test failure
Comment 26 Geoffrey Garen 2015-11-19 13:39:51 PST
Comment on attachment 265835 [details]
Original patch + perf fixes from bug151324 v2

Patch looks good to me. Do we have the test case that checks for the Web Inspector regression? I think that might have gotten lost.
Comment 27 Caitlin Potter (:caitp) 2015-11-19 13:41:58 PST
There's a regression test, but the inspector issue was just a really long parse-time. I don't know if there's a non-flakey way to ensure that it parses within under 2ms or something.
Comment 28 Caitlin Potter (:caitp) 2015-11-19 13:44:43 PST
oh you're right, it's gone from the patch, will re-add that...
Comment 29 Geoffrey Garen 2015-11-19 13:46:18 PST
If we can make the hang long enough (say, 5s), then we can probably test for that in a non-flaky way.
Comment 30 Caitlin Potter (:caitp) 2015-11-19 13:53:15 PST
Created attachment 265897 [details]
Patch
Comment 31 Caitlin Potter (:caitp) 2015-11-19 13:59:14 PST
Created attachment 265899 [details]
Patch
Comment 32 Caitlin Potter (:caitp) 2015-11-19 14:01:50 PST
Should be good now, sorry about that.
Comment 33 Geoffrey Garen 2015-11-19 14:07:13 PST
Comment on attachment 265899 [details]
Patch

r=me
Comment 34 WebKit Commit Bot 2015-11-19 14:54:50 PST
Comment on attachment 265899 [details]
Patch

Clearing flags on attachment: 265899

Committed r192661: <http://trac.webkit.org/changeset/192661>
Comment 35 WebKit Commit Bot 2015-11-19 14:54:57 PST
All reviewed patches have been landed.  Closing bug.
Comment 36 Yusuke Suzuki 2016-01-03 09:21:23 PST
*** Bug 151324 has been marked as a duplicate of this bug. ***