Re: jsdIScript.functionName semantics
"John J. Barton" <[email protected]>
| Newsgroups | gmane.comp.mozilla.devel.jsdebugger |
|---|---|
| Message-ID | <[email protected]> |
Here's another way to think about the "empty-function-name" functions.
Consider the code:
---
var a = 1; // 1: not in named function body
a += 1; // 2: ditto
function foo() {
return 2; // 4: Function "foo"
}
--
If this code is in a web page, then lines 1 and 2 are part of the
__top_level__ function with an empty name.
If this code is eval()ed, then lines 1 and 2 are part of ... ah, er,
the eval-level function with an empty name.
In both cases the bytecodes for this out-of-body code can only be
executed once, which I suppose is why the engine does not keep it
around. Also in both cases the function "foo" is a JavaScript function
with a name that can be called.
The top-level function runs at the top of the stack while the eval-level
function with an empty name runs in a stack frame with at least one
caller. Of course a significant difference between these cases is the
subject of bug #332176: the debugger does not have the source for the
eval-level or for foo() in the eval case.
John.
James Ross wrote:
> John J. Barton wrote:
>> James Ross wrote:
>>> Venkman identifies __top_level__ scripts by their name (i.e. empty),
>>> but uses some logic about sealed scripts I don't follow to pick out
>>> the eval scripts.
>>
>> Oh that's a great hint. I could not figure out what Venkman was up
>> to. But now I have a guess. It analyzes all scripts on creation. It
>> uses the first empty name to mark __top_level__. Because it knows
>> that no function at compile time will be empty name except top level
>> and that script comes last in the compile sequence. At the same time
>> it marks the page ("instance") as "sealed", ie "I saw the top level".
>> After that all scripts that are created must be EvalScript. (Granted
>> there is some funky code about _lastScriptWrapper but it seems
>> consistent with this model).
>>
>> The key assertion is "no function at compile time will be empty name
>> except top level". Or "every empty name other than top level must be
>> from runtime, ie eval".
>>
>> You buying that ;-)
>
> I'll buy that alright; I never did log all the script wrapper and
> instances and sealing stuff, but counting all non-function scripts after
> the first as evals would fit.
>