Nicholas Nethercote wrote:
> I'm not saying that JSScript::lineno is useless, but I suspect if
> there is a //@line comment there will always be a corresponding
> SRC_SETLINE.
Almost always -- if the line numbers don't differ enough there'll be one
or two SRC_NEWLINEs. If the lines happen to match then nothing.
>> JSScript::lineno is the starting line number,
Argh, I used the ambiguous phrase. Sorry, should have written starting
line number according to prior //@line directives but not any nested in
the embedded (function) script case. More below.
>> and source notes notes can
>> override it, including for multiple embedded //@line uses.
>
> Nope, precisely because of the:
>
> script->lineno = bce->firstLine;
>
> in NewScriptFromEmitter().
Yes, but bce->firstLine is set directly by BytecodeEmitter's ctor from
the ctor's lineno parameter. There are three calls to this ctor:
$ grep 'BytecodeEmitter [a-zA-Z_][a-zA-Z0-9_]*(' *cpp */*cpp
frontend/BytecodeCompiler.cpp: BytecodeEmitter bce(&parser, &sc,
lineno, noScriptRval, needScriptGlobal);
frontend/BytecodeCompiler.cpp: BytecodeEmitter funbce(&parser,
&funsc, lineno,
frontend/BytecodeEmitter.cpp: BytecodeEmitter bce2(bce->parser,
&sc, pn->pn_pos.begin.lineno,
The first two are API entry points, so the starting line number is
whatever the API caller wants. The last is for a function nested in
another script or function, and pn->pn_pos.begin.lineno is the starting
line number of the nested function.
A function pn's pn_pos.begin.lineno is set under Parser::functionDef
before the function's body is parsed, and so it may have been farbled by
a prior //@line, but not by any in the nested function. Any //@line
comments embedded in the function may, depending on deltas, cause source
notes to be emitted.
> Anyway, the starting point of this thread was that filename and lineno
> are handled inconsistently. To summarize:
>
> - JSScript::lineno is the line number for the start of the script. It
> is not affected by //@line comments within the script.
> JSScript::startLine would arguably be a better name.
Sure. This name dates from 1995, there must be a better name! But this
is "just a name", not a functional change. I was hoping for a bug! :-P
> - JSScript::filename is assigned to TokenStream::getFilename() at the
> end of script compilation. In the absence of //@line comments in the
> script, this is the filename inherited from the surrounding context.
> In the presence of //@line comments that have a filename, it's the
> filename from the last such comment. There's an unstated assumption
> that there will only be one such //@line comment per script.
Yes, this is the pigeon-hole design limit, good enough for one filename
change per script, not meant for #include scenarios.
Should we assert that the name is only changed via //@line to a novel
string (not only changed, just never changed to a different string
value) more than once?
> Now that this is clear, I can move forward. Thanks for the clarifications!
Thanks for clarifying!. The filename pigeon-hole is worth a comment or
perhaps even an assertion.
> (Actually, now that I think of it: is there an unstated assumption
> that line numbers specified by //@line comments increase
> monotonically?
No, SRC_SETLINE can handle reducing the current line number. Translators
such as the XULpp do not do this, AFAIK, but any line number
discontinuity will cause a SRC_SETLINE to be emitted.
Even though SRC_SETLINE can reduce the current line number for a given
next-bytecode, if no one needs this we can do without. What does the
SourceMap spec say?
https://wiki.mozilla.org/DevTools/Features/SourceMap
Out of time to find myself, appreciate anyone answering definitively.
/be