RESOLVED FIXED 163162
Arrow functions with concise bodies cannot return regular expressions
https://bugs.webkit.org/show_bug.cgi?id=163162
Summary Arrow functions with concise bodies cannot return regular expressions
Kevin Gibbons
Reported 2016-10-07 18:43:56 PDT
For example, the following throws an error, despite being a perfectly legal program: (()=>/a/)(); The error is Exception: SyntaxError: Unexpected token '/'. Invalid regular expression. If the function is not invoked (e.g. `(()=>/a/);`) no error is thrown. Presumably related is the fact that `(()=>/a/).toString()` gives '()=>/'.
Attachments
Patch (12.97 KB, patch)
2016-10-14 03:24 PDT, Yusuke Suzuki
no flags
Archive of layout-test-results from ews106 for mac-yosemite-wk2 (1.15 MB, application/zip)
2016-10-14 04:12 PDT, Build Bot
no flags
Archive of layout-test-results from ews114 for mac-yosemite (2.35 MB, application/zip)
2016-10-14 04:34 PDT, Build Bot
no flags
Archive of layout-test-results from ews121 for ios-simulator-wk2 (16.06 MB, application/zip)
2016-10-14 04:38 PDT, Build Bot
no flags
Archive of layout-test-results from ews103 for mac-yosemite (1.10 MB, application/zip)
2016-10-14 04:40 PDT, Build Bot
no flags
Patch (55.05 KB, patch)
2016-10-14 12:06 PDT, Yusuke Suzuki
no flags
Patch (55.05 KB, patch)
2016-10-14 12:18 PDT, Yusuke Suzuki
no flags
Archive of layout-test-results from ews117 for mac-yosemite (2.22 MB, application/zip)
2016-10-14 13:49 PDT, Build Bot
no flags
Patch (56.27 KB, patch)
2016-10-24 18:52 PDT, Yusuke Suzuki
no flags
Yusuke Suzuki
Comment 1 2016-10-14 02:32:56 PDT
OK, I've found the issue. When we encounter the RegExp, our parser first scans it as / or /=. If / or /= is evaluated under primary expression context, we rescan the character stream as RegExp. The problem is that we don't update the token while we rescan the content. So, if we pass the string, "() => /hello/", the last token becomes "/". Since the arrow function utilizes the end offset of the last token, we accidentally recognize the range of the above arrow function as "() => /". I think we should update the token with REGEXP type as the same to template literal parsing thing.
Yusuke Suzuki
Comment 2 2016-10-14 03:24:18 PDT
Build Bot
Comment 3 2016-10-14 04:12:25 PDT
Comment on attachment 291606 [details] Patch Attachment 291606 [details] did not pass mac-wk2-ews (mac-wk2): Output: http://webkit-queues.webkit.org/results/2283570 New failing tests: js/regexp-compile-crash.html sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.5_Regular_Expression_Literals/S7.8.5_A2.5_T1.html fast/regex/dom/non-pattern-characters.html sputnik/Conformance/07_Lexical_Conventions/7.4_Comments/S7.4_A4_T1.html sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.5_Regular_Expression_Literals/S7.8.5_A2.2_T1.html sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.5_Regular_Expression_Literals/S7.8.5_A1.2_T2.html sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.5_Regular_Expression_Literals/S7.8.5_A2.3_T3.html sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.5_Regular_Expression_Literals/S7.8.5_A1.3_T1.html sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.5_Regular_Expression_Literals/S7.8.5_A2.3_T1.html sputnik/Conformance/07_Lexical_Conventions/7.4_Comments/S7.4_A4_T4.html sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.5_Regular_Expression_Literals/S7.8.5_A1.3_T3.html sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.5_Regular_Expression_Literals/S7.8.5_A2.5_T3.html js/arrowfunction-syntax-errors.html sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.5_Regular_Expression_Literals/S7.8.5_A1.5_T3.html sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.5_Regular_Expression_Literals/S7.8.5_A1.5_T1.html
Build Bot
Comment 4 2016-10-14 04:12:28 PDT
Created attachment 291611 [details] Archive of layout-test-results from ews106 for mac-yosemite-wk2 The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews. Bot: ews106 Port: mac-yosemite-wk2 Platform: Mac OS X 10.10.5
Build Bot
Comment 5 2016-10-14 04:34:48 PDT
Comment on attachment 291606 [details] Patch Attachment 291606 [details] did not pass mac-debug-ews (mac): Output: http://webkit-queues.webkit.org/results/2283600 Number of test failures exceeded the failure limit.
Build Bot
Comment 6 2016-10-14 04:34:51 PDT
Created attachment 291613 [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
Build Bot
Comment 7 2016-10-14 04:38:33 PDT
Comment on attachment 291606 [details] Patch Attachment 291606 [details] did not pass ios-sim-ews (ios-simulator-wk2): Output: http://webkit-queues.webkit.org/results/2283639 New failing tests: js/regexp-compile-crash.html sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.5_Regular_Expression_Literals/S7.8.5_A2.5_T1.html fast/regex/dom/non-pattern-characters.html sputnik/Conformance/07_Lexical_Conventions/7.4_Comments/S7.4_A4_T1.html sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.5_Regular_Expression_Literals/S7.8.5_A2.2_T1.html sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.5_Regular_Expression_Literals/S7.8.5_A1.2_T2.html sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.5_Regular_Expression_Literals/S7.8.5_A2.3_T3.html sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.5_Regular_Expression_Literals/S7.8.5_A1.3_T1.html sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.5_Regular_Expression_Literals/S7.8.5_A2.3_T1.html sputnik/Conformance/07_Lexical_Conventions/7.4_Comments/S7.4_A4_T4.html sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.5_Regular_Expression_Literals/S7.8.5_A1.3_T3.html sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.5_Regular_Expression_Literals/S7.8.5_A2.5_T3.html js/arrowfunction-syntax-errors.html sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.5_Regular_Expression_Literals/S7.8.5_A1.5_T3.html sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.5_Regular_Expression_Literals/S7.8.5_A1.5_T1.html
Build Bot
Comment 8 2016-10-14 04:38:37 PDT
Created attachment 291615 [details] Archive of layout-test-results from ews121 for ios-simulator-wk2 The attached test failures were seen while running run-webkit-tests on the ios-sim-ews. Bot: ews121 Port: ios-simulator-wk2 Platform: Mac OS X 10.11.6
Build Bot
Comment 9 2016-10-14 04:40:22 PDT
Comment on attachment 291606 [details] Patch Attachment 291606 [details] did not pass mac-ews (mac): Output: http://webkit-queues.webkit.org/results/2283718 New failing tests: js/regexp-compile-crash.html sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.5_Regular_Expression_Literals/S7.8.5_A2.5_T1.html fast/regex/dom/non-pattern-characters.html sputnik/Conformance/07_Lexical_Conventions/7.4_Comments/S7.4_A4_T1.html sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.5_Regular_Expression_Literals/S7.8.5_A2.2_T1.html sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.5_Regular_Expression_Literals/S7.8.5_A1.2_T2.html sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.5_Regular_Expression_Literals/S7.8.5_A2.3_T3.html sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.5_Regular_Expression_Literals/S7.8.5_A1.3_T1.html sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.5_Regular_Expression_Literals/S7.8.5_A2.3_T1.html sputnik/Conformance/07_Lexical_Conventions/7.4_Comments/S7.4_A4_T4.html sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.5_Regular_Expression_Literals/S7.8.5_A1.3_T3.html sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.5_Regular_Expression_Literals/S7.8.5_A2.5_T3.html js/arrowfunction-syntax-errors.html sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.5_Regular_Expression_Literals/S7.8.5_A1.5_T3.html sputnik/Conformance/07_Lexical_Conventions/7.8_Literals/7.8.5_Regular_Expression_Literals/S7.8.5_A1.5_T1.html
Build Bot
Comment 10 2016-10-14 04:40:25 PDT
Created attachment 291616 [details] Archive of layout-test-results from ews103 for mac-yosemite The attached test failures were seen while running run-webkit-tests on the mac-ews. Bot: ews103 Port: mac-yosemite Platform: Mac OS X 10.10.5
Yusuke Suzuki
Comment 11 2016-10-14 11:25:34 PDT
I'll improve the error message and update the expected files.
Yusuke Suzuki
Comment 12 2016-10-14 12:00:40 PDT
I realized that so many error messages were bad due to this behavior!
Yusuke Suzuki
Comment 13 2016-10-14 12:06:19 PDT
Yusuke Suzuki
Comment 14 2016-10-14 12:09:16 PDT
Comment on attachment 291657 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=291657&action=review > JSTests/ChakraCore/test/Operators/instanceof.baseline-jsc:630 > + Exception: new Date() instanceof /a+/. /a+/ is not a function. (evaluating 'new Date() instanceof /a+/') Yeah, we produced a silly error message here!
Yusuke Suzuki
Comment 15 2016-10-14 12:10:10 PDT
Comment on attachment 291657 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=291657&action=review > Source/JavaScriptCore/ChangeLog:8 > + When we encounter the RegExp in the parser, we first scans it as / or /=. oops. "scans" => "scan".
Yusuke Suzuki
Comment 16 2016-10-14 12:18:00 PDT
Created attachment 291660 [details] Patch Fix typo in ChangeLog
Yusuke Suzuki
Comment 17 2016-10-14 13:09:39 PDT
Comment on attachment 291660 [details] Patch Need to check the crash. I think it should be easy.
Build Bot
Comment 18 2016-10-14 13:49:09 PDT
Comment on attachment 291660 [details] Patch Attachment 291660 [details] did not pass mac-debug-ews (mac): Output: http://webkit-queues.webkit.org/results/2286184 Number of test failures exceeded the failure limit.
Build Bot
Comment 19 2016-10-14 13:49:12 PDT
Created attachment 291665 [details] Archive of layout-test-results from ews117 for mac-yosemite The attached test failures were seen while running run-webkit-tests on the mac-debug-ews. Bot: ews117 Port: mac-yosemite Platform: Mac OS X 10.10.5
Yusuke Suzuki
Comment 20 2016-10-24 18:52:16 PDT
WebKit Commit Bot
Comment 21 2016-10-24 19:38:48 PDT
Comment on attachment 292700 [details] Patch Clearing flags on attachment: 292700 Committed r207798: <http://trac.webkit.org/changeset/207798>
WebKit Commit Bot
Comment 22 2016-10-24 19:38:54 PDT
All reviewed patches have been landed. Closing bug.
Note You need to log in before you can comment on or make changes to this bug.