Bug 163162

Summary: Arrow functions with concise bodies cannot return regular expressions
Product: WebKit Reporter: Kevin Gibbons <bakkot>
Component: JavaScriptCoreAssignee: Yusuke Suzuki <ysuzuki>
Status: RESOLVED FIXED    
Severity: Normal CC: bakkot, buildbot, commit-queue, keith_miller, mark.lam, msaboff, rniwa, saam, ysuzuki
Priority: P2    
Version: Safari 10   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Archive of layout-test-results from ews106 for mac-yosemite-wk2
none
Archive of layout-test-results from ews114 for mac-yosemite
none
Archive of layout-test-results from ews121 for ios-simulator-wk2
none
Archive of layout-test-results from ews103 for mac-yosemite
none
Patch
none
Patch
none
Archive of layout-test-results from ews117 for mac-yosemite
none
Patch none

Description Kevin Gibbons 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 '()=>/'.
Comment 1 Yusuke Suzuki 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.
Comment 2 Yusuke Suzuki 2016-10-14 03:24:18 PDT
Created attachment 291606 [details]
Patch
Comment 3 Build Bot 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
Comment 4 Build Bot 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
Comment 5 Build Bot 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.
Comment 6 Build Bot 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
Comment 7 Build Bot 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
Comment 8 Build Bot 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
Comment 9 Build Bot 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
Comment 10 Build Bot 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
Comment 11 Yusuke Suzuki 2016-10-14 11:25:34 PDT
I'll improve the error message and update the expected files.
Comment 12 Yusuke Suzuki 2016-10-14 12:00:40 PDT
I realized that so many error messages were bad due to this behavior!
Comment 13 Yusuke Suzuki 2016-10-14 12:06:19 PDT
Created attachment 291657 [details]
Patch
Comment 14 Yusuke Suzuki 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!
Comment 15 Yusuke Suzuki 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".
Comment 16 Yusuke Suzuki 2016-10-14 12:18:00 PDT
Created attachment 291660 [details]
Patch

Fix typo in ChangeLog
Comment 17 Yusuke Suzuki 2016-10-14 13:09:39 PDT
Comment on attachment 291660 [details]
Patch

Need to check the crash. I think it should be easy.
Comment 18 Build Bot 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.
Comment 19 Build Bot 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
Comment 20 Yusuke Suzuki 2016-10-24 18:52:16 PDT
Created attachment 292700 [details]
Patch
Comment 21 WebKit Commit Bot 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>
Comment 22 WebKit Commit Bot 2016-10-24 19:38:54 PDT
All reviewed patches have been landed.  Closing bug.