RESOLVED FIXED Bug 151026
Destructuring Assignment: Properties are valid AssignmentElements
https://bugs.webkit.org/show_bug.cgi?id=151026
Summary Destructuring Assignment: Properties are valid AssignmentElements
Caitlin Potter (:caitp)
Reported 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
Attachments
Accept any LHS for AssignmentElements (no tests yet) (12.53 KB, patch)
2015-11-12 13:32 PST, Caitlin Potter (:caitp)
no flags
Patch (28.94 KB, patch)
2015-11-12 23:45 PST, Caitlin Potter (:caitp)
no flags
Original patch + perf fixes from bug151324 (34.07 KB, patch)
2015-11-18 18:28 PST, Caitlin Potter (:caitp)
no flags
Original patch + perf fixes from bug151324 (34.08 KB, patch)
2015-11-18 18:42 PST, Caitlin Potter (:caitp)
no flags
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
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
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
Original patch + perf fixes from bug151324 v2 (36.01 KB, patch)
2015-11-18 19:43 PST, Caitlin Potter (:caitp)
no flags
Patch (274.88 KB, patch)
2015-11-19 13:53 PST, Caitlin Potter (:caitp)
no flags
Patch (272.23 KB, patch)
2015-11-19 13:59 PST, Caitlin Potter (:caitp)
no flags
Caitlin Potter (:caitp)
Comment 1 2015-11-12 13:32:48 PST
Created attachment 265428 [details] Accept any LHS for AssignmentElements (no tests yet)
Caitlin Potter (:caitp)
Comment 2 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.
Geoffrey Garen
Comment 3 2015-11-12 13:54:18 PST
+CC Oliver, since he wrote a lot of this parser.
Geoffrey Garen
Comment 4 2015-11-12 13:56:12 PST
I'm curious: Is an expression like this ever useful, or at least observable to the programmer?
Caitlin Potter (:caitp)
Comment 5 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?
Geoffrey Garen
Comment 6 2015-11-12 14:55:51 PST
Wow. This destination-on-the-right JavaScript syntax is blowing my mind. In the bad way :(.
Geoffrey Garen
Comment 7 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.
Geoffrey Garen
Comment 8 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/.
Caitlin Potter (:caitp)
Comment 9 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)
Caitlin Potter (:caitp)
Comment 10 2015-11-12 23:45:49 PST
Geoffrey Garen
Comment 11 2015-11-13 10:24:37 PST
Comment on attachment 265470 [details] Patch r=me 👍
WebKit Commit Bot
Comment 12 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>
WebKit Commit Bot
Comment 13 2015-11-13 11:13:45 PST
All reviewed patches have been landed. Closing bug.
Joseph Pecoraro
Comment 14 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
Geoffrey Garen
Comment 15 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.
WebKit Commit Bot
Comment 16 2015-11-18 15:51:49 PST
Re-opened since this is blocked by bug 151417
Caitlin Potter (:caitp)
Comment 17 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
Caitlin Potter (:caitp)
Comment 18 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
Build Bot
Comment 19 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
Build Bot
Comment 20 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
Build Bot
Comment 21 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
Build Bot
Comment 22 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
Build Bot
Comment 23 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
Build Bot
Comment 24 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
Caitlin Potter (:caitp)
Comment 25 2015-11-18 19:43:22 PST
Created attachment 265835 [details] Original patch + perf fixes from bug151324 v2 Fix the new test failure
Geoffrey Garen
Comment 26 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.
Caitlin Potter (:caitp)
Comment 27 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.
Caitlin Potter (:caitp)
Comment 28 2015-11-19 13:44:43 PST
oh you're right, it's gone from the patch, will re-add that...
Geoffrey Garen
Comment 29 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.
Caitlin Potter (:caitp)
Comment 30 2015-11-19 13:53:15 PST
Caitlin Potter (:caitp)
Comment 31 2015-11-19 13:59:14 PST
Caitlin Potter (:caitp)
Comment 32 2015-11-19 14:01:50 PST
Should be good now, sorry about that.
Geoffrey Garen
Comment 33 2015-11-19 14:07:13 PST
Comment on attachment 265899 [details] Patch r=me
WebKit Commit Bot
Comment 34 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>
WebKit Commit Bot
Comment 35 2015-11-19 14:54:57 PST
All reviewed patches have been landed. Closing bug.
Yusuke Suzuki
Comment 36 2016-01-03 09:21:23 PST
*** Bug 151324 has been marked as a duplicate of this bug. ***
Note You need to log in before you can comment on or make changes to this bug.