Close review of Language Overview whitepaper
brendan at mozilla.org
Thu Nov 15 09:48:31 PST 2007
On Nov 14, 2007, at 5:34 PM, Brendan Eich wrote:
>> Things I didn't see:
>> What about standardizing the de facto <!-- comment syntax that is
>> necessary for web compatibility?
> Please write the spec ;-). Don't forget the --> mess.
We did talk about this at some point. I'm not sure everyone is aware
of this web compatibility constraint, so I'll describe it briefly and
When I embedded JS in HTML in 1995, I had a backward compatibility
problem: Netscape 1.x and every other browser would see the inline
script tag's content, as marked up text. So I took advantage of a
content model that HTML-as-it-is inherited from SGML, CDATA, and made
the script tag's content model be CDATA. This means that < does not
need to be spelled < -- thank goodness -- but it also allows SGML
comments (or the approximation of them supported by HTML browsers) to
wrap the entire inline content of <script>:
<!-- hide from old browsers
for (i = 0; i < N; i++) do_stuff(i);
This two-way comment hiding hack works because JS in browsers (not
necessarily in other embeddings, see below) treats <!-- as the
starting delimiter of a comment till end of line. I required
programmers to use a JS one-line comment to hide the closing -->.
Unfortunately, and I'm going from memory so this may be off slightly,
IE at least does not require --> to be commented in JS. This is bad
in general since --> looks like post-decrement immediately followed
by greater-than. There's a heuristic that insists on only leading
horizontal whitespace on the line before the -->, and (I may have
this part wrong in particular) nothing after the --> but whitespace.
Postel's Law bites back, so of course by the Web's law of copy and
paste programming (cut and paste, actually), you find <!-- in the
middle of .js files included via <script src="foo.js">. These must be
treated by JS as comment to end of line initiators.
This ends my tale of woe, except that I think embeddings on DVDs and
in firmware that do not see web script should not have to deal with
this nonsense. So I'm not sure a spec for this de-facto web standard
is appropriate in ES4 or any normative core language spec. Of course,
the copy/paste argument applies across embedding domains, but not so
much. What do you think?
More information about the Es4-discuss