16:46 | <Richard Gibson> | Uhm, does the spec (+ AnnexB) disallow --> as the first line in a script? It seems so (--> must be preceded by a line terminator), but all browsers accept eval("-->") my reading of https://tc39.es/ecma262/multipage/additional-ecmascript-features-for-web-browsers.html#sec-html-like-comments agrees with this; |HTMLCloseComment| is the only nonterminal that can start with --> and is only valid after a |LineTerminatorSequence| (possibly wrapped in /*…*/ ). And PerformEval step 11 does ParseText(StringToCodePoints(x), |Script|), which per ParseText and The Syntactic Grammar and The Lexical and RegExp Grammars begins with application of the lexical grammar and should fail in the case of text starting with "-->".
All implementations that I tested reject a script starting with "-->", but JSC and SM and V8 incorrectly fail to reject eval input that does so:
$ eshost -si htmlcomment.js
## Source
print("HTML-like comments supported");
-->
eval("/*\n*/-->\nprint('eval with leading `/*<LineTerminator>*/-->` supported')");
eval("-->\nprint('eval with leading `-->` supported')");
#### ChakraCore
HTML-like comments supported
eval with leading `/*<LineTerminator>*/-->` supported
SyntaxError: Syntax error
#### engine262
SyntaxError: Unexpected token
#### GraalJS
HTML-like comments supported
eval with leading `/*<LineTerminator>*/-->` supported
SyntaxError: <eval>:1:2 Expected an operand but found >
#### Hermes
SyntaxError: invalid expression
#### JavaScriptCore, SpiderMonkey, V8
HTML-like comments supported
eval with leading `/*<LineTerminator>*/-->` supported
eval with leading `-->` supported
#### Moddable XS
SyntaxError: missing expression
#### QuickJS
HTML-like comments supported
eval with leading `/*<LineTerminator>*/-->` supported
SyntaxError: unexpected token in expression: '>'
|