Closed Bug 1708064 Opened 5 years ago Closed 5 years ago

Automatic Semicolon Insertion in <iframe> src with multi-line <script> working in Chrome but not Firefox/Safari

Categories

(Core :: DOM: Core & HTML, defect)

Firefox 88
defect

Tracking

()

RESOLVED INVALID

People

(Reporter: duncanjdiii, Unassigned)

Details

Attachments

(6 files)

Attached file test.html —

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://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#automatic_semicolon_insertion

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/

Attached file test_advanced.html —

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).

Attached image Firefox-88.0.png —

Firefox 88.0

Attached image Safari-14.1.png —

Safari 14.1

Attached image Chrome-90.0.4430.85.png —

Chrome 90.0.4430.85

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.

Component: Untriaged → DOM: Core & HTML
Product: Firefox → Core

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.

Status: UNCONFIRMED → RESOLVED
Closed: 5 years ago
Resolution: --- → INVALID
Attached file test.html —

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

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: