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

Do line/column numbers start at 0 or 1?

14 views
Skip to first unread message

Eddy Bruel

unread,
Aug 25, 2016, 11:10:26 AM8/25/16
to dev-developer-tools, Jim Blandy, Nick Fitzgerald
The debugger API allows you to get the line number of a script relative to
the source from which it was compiled (via
Debugger.Script.prototype.startLine). I'm currently working on an API that
allows you to get the line number of a source relative to the resource that
introduced it (see bug 1288084
<https://bugzilla.mozilla.org/show_bug.cgi?id=1288084>). Eventually, I
would like the same information for column numbers as well.

It's not 100% clear to me whether line/column numbers are supposed to start
at 0 or 1. I *think* line numbers are supposed to start at 1 in the JS
engine. However, I've also seen places where we use 0 for the line number.
To add to the confusion, we also seem to use 0 and 1 as default values for
when the line number is unknown. Columns numbers are similarly confusing.

I'd like to establish what the desired convention is here before I start
landing any patches in bug 1288084. Should line/column numbers start at 0
or at 1? And what should be the default value if those numbers are unknown?

Nick Fitzgerald

unread,
Aug 25, 2016, 12:33:19 PM8/25/16
to Eddy Bruel, Jim Blandy, dev-developer-tools
Error().stack uses 1-based lines and 1-based columns across all browsers.
We should be consistent with that.

Jim Blandy

unread,
Aug 25, 2016, 3:18:58 PM8/25/16
to Nick Fitzgerald, Jim Blandy, dev-developer-tools, Eddy Bruel
I think numbering the first line of the file 1 is pretty much the standard.

On Thu, Aug 25, 2016 at 9:33 AM, Nick Fitzgerald <nfitz...@mozilla.com>
wrote:

Tom Tromey

unread,
Aug 29, 2016, 11:40:41 AM8/29/16
to Nick Fitzgerald, Jim Blandy, dev-developer-tools, Eddy Bruel
>>>>> "Nick" == Nick Fitzgerald <nfitz...@mozilla.com> writes:

Nick> Error().stack uses 1-based lines and 1-based columns across all browsers.
Nick> We should be consistent with that.

What we choose for our tools is up to us, but it's worth remembering
that the browser isn't internally consistent: Error uses 1-based
columns, but the Reflect.parse AST uses 0-based columns (and this is
baked into the estree spec now). This is bound to cause confusion, so
I'd suggest comments everywhere explaining the local choices.

Tom

Jim Blandy

unread,
Aug 29, 2016, 5:39:29 PM8/29/16
to Tom Tromey, Jim Blandy, dev-developer-tools, Eddy Bruel, Nick Fitzgerald
+1

Eddy Bruel

unread,
Aug 30, 2016, 2:43:03 AM8/30/16
to Jim Blandy, Tom Tromey, Jim Blandy, dev-developer-tools, Nick Fitzgerald
or is it +0?

Mike Ratcliffe

unread,
Sep 1, 2016, 5:41:56 AM9/1/16
to dev-devel...@lists.mozilla.org
If I remember rightly, DOM 0 events e.g. onclick="blah()" use line 0.


On 25/08/2016 16:10, Eddy Bruel wrote:
> The debugger API allows you to get the line number of a script relative to
> the source from which it was compiled (via
> Debugger.Script.prototype.startLine). I'm currently working on an API that
> allows you to get the line number of a source relative to the resource that
> introduced it (see bug 1288084
> <https://bugzilla.mozilla.org/show_bug.cgi?id=1288084>). Eventually, I
> would like the same information for column numbers as well.
>
> It's not 100% clear to me whether line/column numbers are supposed to start
> at 0 or 1. I *think* line numbers are supposed to start at 1 in the JS
> engine. However, I've also seen places where we use 0 for the line number.
> To add to the confusion, we also seem to use 0 and 1 as default values for
> when the line number is unknown. Columns numbers are similarly confusing.
>
> I'd like to establish what the desired convention is here before I start
> landing any patches in bug 1288084. Should line/column numbers start at 0
> or at 1? And what should be the default value if those numbers are unknown?
> _______________________________________________
> dev-developer-tools mailing list
> dev-devel...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-developer-tools

0 new messages