Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Line numbers in nested document.write()s

18 views
Skip to first unread message

Henri Sivonen

unread,
Nov 6, 2009, 10:02:00 AM11/6/09
to
I don't see much logic in the line number reporting of the old HTML
parser when there are nested document.written scripts. See Error Console
with
http://hsivonen.iki.fi/test/moz/line-numbers.html

Does Firebug or anything else rely on a particular way of counting lines
in nested document.write()s? If yes, what's the expectation?

--
Henri Sivonen
hsiv...@iki.fi
http://hsivonen.iki.fi/

Boris Zbarsky

unread,
Nov 6, 2009, 10:07:03 AM11/6/09
to
On 11/6/09 10:02 AM, Henri Sivonen wrote:
> I don't see much logic in the line number reporting of the old HTML
> parser when there are nested document.written scripts. See Error Console
> with
> http://hsivonen.iki.fi/test/moz/line-numbers.html

Looks good to me: the line number listed is the line number in view
source where the relevant throw shows up, no?

-Boris

John J. Barton

unread,
Nov 6, 2009, 12:40:53 PM11/6/09
to
Henri Sivonen wrote:
> I don't see much logic in the line number reporting of the old HTML
> parser when there are nested document.written scripts. See Error Console
> with
> http://hsivonen.iki.fi/test/moz/line-numbers.html

With Firebug installed, my Error Console if FF 3.5 and 3.6b1 shows one
nonsense warning:

Warning: Non-standard document.all property was used. Use W3C standard
document.getElementById() instead.
Source File: http://hsivonen.iki.fi/test/moz/line-numbers.html
Line: 3

The line number for the warning is wrong.

In addition, I see two calls to jsd.onError:

uncaught exception:
2147500033@file:///C:/mozilla/firefox-3.6b1pre.en-US.win32/firefox/modules/utils.js:1058.0
Stack

Exception is not defined in
http://hsivonen.iki.fi/test/moz/line-numbers.html
line 5

These two errors do not show up in the Error Console.

Firebug classifies the document.write buffers as 'events', which is
probably wrong.

>
> Does Firebug or anything else rely on a particular way of counting lines
> in nested document.write()s? If yes, what's the expectation?

My expectation is that the line numbers from error messages will be
wrong. Firebug tries to fix some of these cases, but for the most part
the only time line numbers on errors are correct is in .js files.

jjb

Henri Sivonen

unread,
Nov 9, 2009, 8:24:08 AM11/9/09
to
In article <kv6dnbAyYtQKpmnX...@mozilla.org>,
Boris Zbarsky <bzba...@mit.edu> wrote:

If that were the logic, then the warning for document.all doesn't follow
that logic in the demo.

Henri Sivonen

unread,
Nov 9, 2009, 8:25:09 AM11/9/09
to
In article <iOudnUvalNSswWnX...@mozilla.org>,

"John J. Barton" <johnj...@johnjbarton.com> wrote:

> My expectation is that the line numbers from error messages will be
> wrong. Firebug tries to fix some of these cases, but for the most part
> the only time line numbers on errors are correct is in .js files.

Thanks. I take this to mean that I have some liberty in how I make the
HTML5 parser count lines in document.written content.

Boris Zbarsky

unread,
Nov 9, 2009, 9:42:01 AM11/9/09
to
On 11/9/09 8:24 AM, Henri Sivonen wrote:
> If that were the logic, then the warning for document.all doesn't follow
> that logic in the demo.

Yes, I think that warning is buggy.

-Boris

Boris Zbarsky

unread,
Nov 9, 2009, 9:42:31 AM11/9/09
to
On 11/9/09 8:25 AM, Henri Sivonen wrote:
>> My expectation is that the line numbers from error messages will be
>> wrong. Firebug tries to fix some of these cases, but for the most part
>> the only time line numbers on errors are correct is in .js files.
>
> Thanks. I take this to mean that I have some liberty in how I make the
> HTML5 parser count lines in document.written content.

It needs to count them in such a way that the links in the error console
work correctly, ideally.

-Boris

John J. Barton

unread,
Nov 9, 2009, 12:00:19 PM11/9/09
to

Boris, I don't think Henri can succeed. This is essentially the same
problems 'eval()': these new source lines are not in the "source", so
any line number relative to the "source" will be incorrect.

I think for all these dynamic cases we need a new approach. Each
compilation unit needs to be cached, assigned a unique identifier, and
chained to the compilation unit that injected the code. This is what
Firebug does for eval(), but can't do for 'new Function()' and should do
for 'document.write()'.

jjb

Henri Sivonen

unread,
Nov 10, 2009, 3:40:09 AM11/10/09
to
In article <5vSdncx2BILKt2XX...@mozilla.org>,
Boris Zbarsky <bzba...@mit.edu> wrote:

This can't be done with the current script infrastructure.
document.write() doesn't report to the parser what line it was on in the
script. Also, the line numbers for inline scripts will be wrong when
line breaks in an inline script have been escaped as numeric character
references, since the JS parser will count those as line breaks but they
aren't line breaks in the source.

Henri Sivonen

unread,
Nov 10, 2009, 7:44:56 AM11/10/09
to
In article <hsivonen-BD8D58...@news.mozilla.org>,
Henri Sivonen <hsiv...@iki.fi> wrote:

> This can't be done with the current script infrastructure.
> document.write() doesn't report to the parser what line it was on in the
> script.

Maybe it would be better not to report the line number at all when the
parser knows it can't produce a non-bogus line number?

Boris Zbarsky

unread,
Nov 10, 2009, 9:16:47 AM11/10/09
to
On 11/10/09 7:44 AM, Henri Sivonen wrote:
> Maybe it would be better not to report the line number at all when the
> parser knows it can't produce a non-bogus line number?

This is an option, but a line number that's a few lines off is slightly
more useful than no line number at all, imo....

-Boris

Mark Tyndall

unread,
Nov 11, 2009, 9:53:26 AM11/11/09
to

If the parser knows it's wrong, it could generate "near line 436" or
whatever...

Mark..

Henri Sivonen

unread,
Nov 11, 2009, 10:26:30 AM11/11/09
to
In article <RZWdnZRppuh6UmfX...@mozilla.org>,
Mark Tyndall <moz_...@tyndall.org.invalid> wrote:

There's no infrastructure for displaying approximate line numbers in the
Error Console and there's no infrastructure for letting the JS and CSS
parsers know that they got an approximate line number.

Mike Shaver

unread,
Nov 11, 2009, 10:37:06 AM11/11/09
to Henri Sivonen, dev-pl...@lists.mozilla.org

Yes, we would have to add that. Given the number of cases in which we
are seeing the "probably near" margins of error, it sounds worthwhile
from a developer ergonomics perspective.

Mike

John J. Barton

unread,
Nov 11, 2009, 11:51:33 AM11/11/09
to

If we have the resources to change this code, let's just fix the line
number system. I've already succeeded in correcting the line numbers for
eval() in Firebug so we know it's not impossible.

jjb

John J. Barton

unread,
Nov 13, 2009, 12:45:42 PM11/13/09
to

I think this feature could be added easily if we implemented support for
"compilation units".

The current callback for compilation in jsd is pathetic. For every
function compiled, you get a call giving the jsdIScript of the function.
But you don't get the window of the compile, the stack frame of the
compile, the source of the compile etc. Firebug has some truly awful
code to work around this, including setting breakpoints on every outer
global file function call.

Bug 379410 hints at a much better solution. By adding a callback for the
entire compilation unit, the natural information will be available
together. By compilation unit I mean anything sent to the compiler:
script tag content, script src= file, document.write buffer, eval
buffer, HTML element handler string, etc. The callback can give the
window, stack frames, buffer compiled and an array of jsdIScripts.

This would transform Firebug hacky code, make Firebug much faster,
enable support for 'new Function' and all variations of
document.write(), and -- finally returning the subject at hand -- allow
support of correct error messages for all dynamic code mechanisms. For
the last case we need only save the buffers keyed by a dynamic URL and
use that URL in error reports. The error console would not need to be
changed. Viewsource etc would all work.

jjb

Clint Talbert

unread,
Nov 13, 2009, 7:23:13 PM11/13/09
to
On 11/13/09 9:45 AM, John J. Barton wrote:
> John J. Barton wrote:
>> Mike Shaver wrote:
>>> On Wed, Nov 11, 2009 at 10:26 AM, Henri Sivonen <hsiv...@iki.fi> wrote:
>>>> In article <RZWdnZRppuh6UmfX...@mozilla.org>,
>>>> Mark Tyndall <moz_...@tyndall.org.invalid> wrote:
>>>>
> The current callback for compilation in jsd is pathetic. For every
> function compiled, you get a call giving the jsdIScript of the function.
> But you don't get the window of the compile, the stack frame of the
> compile, the source of the compile etc. Firebug has some truly awful
> code to work around this, including setting breakpoints on every outer
> global file function call.
>
> Bug 379410 hints at a much better solution. By adding a callback for the
> entire compilation unit, the natural information will be available
> together. By compilation unit I mean anything sent to the compiler:
> script tag content, script src= file, document.write buffer, eval
> buffer, HTML element handler string, etc. The callback can give the
> window, stack frames, buffer compiled and an array of jsdIScripts.

Not trying to derail this thread, but I have a quick question. Would
these compilation units allow us to do better JavaScript code coverage
analysis? We currently do it by hacking a tool for JavaScript code
coverage that was originally intended to be used on websites.

Thanks,

Clint

John J Barton

unread,
Nov 13, 2009, 7:44:38 PM11/13/09
to

Yes, because currently you cannot easily assign all of the functions
that are compiled to their owning windows. Given the list of compilation
units per window from this api, you can turn on the profiler, run the
test driver, then walk the compilation units and issue the coverage
report based on the time marks on each jsdIScript.

jjb

0 new messages