Automatic Semicolon Insertion in <iframe> src with multi-line <script> working in Chrome but not Firefox/Safari
Categories
(Core :: DOM: Core & HTML, defect)
Tracking
()
People
(Reporter: duncanjdiii, Unassigned)
Details
Attachments
(6 files)
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:88.0) Gecko/20100101 Firefox/88.0
Steps to reproduce:
I wrote three different <iframe> elements. Each iframe contains embedded inline html with a single <script> tag. The script tag declares a couple of const variables and then prints them to the console.
Actual results:
<iframe src=""> with an embedded multi-line script tag leveraging Automatic Semicolon Insertion (ASI, as in a multi-line script tag that elides all semicolons and uses newlines instead) causes Uncaught SyntaxError: unexpected token: keyword 'const' in Firefox 88 and Safari 14.1, but works in Chrome 90.0.4430.85.
Interestingly, changing <iframe src=""> to <iframe srcdoc=""> causes ASI to behave correctly in all three browsers.
Expected results:
Firefox and Safari should not have thrown Uncaught SyntaxError: unexpected token: keyword 'const' in the third example of the attached test.html file.
I believe this error is related to the Automatic Semicolon Insertion parsing logic, though I am not positive.
Please feel free to close/ignore this bug if this is indeed the intended behavior. If that is the case, it might be worth it to open a bug over at https://bugs.chromium.org/p/chromium/issues/list in order to figure out the discrepancy between major browsers.
https://tc39.es/ecma262/#sec-rules-of-automatic-semicolon-insertion
https://262.ecma-international.org/11.0/#sec-automatic-semicolon-insertion
https://brendaneich.com/2012/04/the-infernal-semicolon/
https://flaviocopes.com/javascript-automatic-semicolon-insertion/
| Reporter | ||
Comment 1•5 years ago
|
||
test_advanced.html contains a real world example from a project I was working on at work recently (srcdoc version works, src does not unless I manually add semicolons).
| Reporter | ||
Comment 2•5 years ago
|
||
Firefox 88.0
| Reporter | ||
Comment 3•5 years ago
|
||
Safari 14.1
| Reporter | ||
Comment 4•5 years ago
|
||
Chrome 90.0.4430.85
Comment 5•5 years ago
|
||
The Bugbug bot thinks this bug should belong to the 'Core::DOM: Core & HTML' component, and is moving the bug to that component. Please revert this change in case you think the bot is wrong.
Comment 6•5 years ago
•
|
||
Per https://url.spec.whatwg.org/#concept-basic-url-parser new lines should be removed from the url.
So when JS is executed, there is no new line. This looks like a Chrome bug.
srcdoc doesn't use url parsing.
Comment 7•5 years ago
|
||
I filed https://bugs.chromium.org/p/chromium/issues/detail?id=1204473 on Chrome.
| Reporter | ||
Comment 8•5 years ago
|
||
Thanks for the quick triage here!
For the sake of posterity, here is the simpler minimum reproducible error case from the Chromium ticket opened above.
http://software.hixie.ch/utilities/js/live-dom-viewer/saved/9236
http://software.hixie.ch/utilities/js/live-dom-viewer/saved/9239
Description
•