Re: jsdIScript.functionName semantics

"John J. Barton" <[email protected]>
Newsgroups gmane.comp.mozilla.devel.jsdebugger
Message-ID <[email protected]>
James Ross wrote:
> John J. Barton wrote:
>> In other words,  is "functionName == null plus a stack frame above the 
>> one containing this script" a test for an eval() frame?

Oops...my C++/Java background showing... I should say:

Is "functionName == false plus a stack frame above a test for eval()?"
So both null and "" count.
Now let me try your examples...

> 
> Not according to what I can see/know.
> 
> The stack frame and script objects both have functionNames. The stack 
> frame has no functionName (you get null) for top-level execution. The 
> script (stackFrame.script) has an empty ("") functionName for eval 
> frames. That's about all I know.
> 
> For example, the following code gives:
>   var f = function () {
>     eval("var a = 1;\ndebugger;\nvar b = 2 * a;");
>   };
>   f();
> 
>    Stack Frame         Script              Venkman Display
>    ------------------------------------------------------------
> 1. "anonymous"         ""                  [EvalScript]
> 2. "anonymous"         "anonymous"         anonymous
> 3. null                ""                  __top_level__

The center column is false, true, false. #3 is false but top level. So 
false and not-top works to identify EvalScript using the Script col.

> 
> If I give the function a name, "_foo", the stack is:
> 
>    Stack Frame         Script              Venkman Display
>    ------------------------------------------------------------
> 1. "_foo"              ""                  [EvalScript]
> 2. "_foo"              "_foo"              _foo
> 3. null                ""                  __top_level__

Ditto.


> And for fun, the script:
>   eval("var a = 1;\ndebugger;\nvar b = 2 * a;");
> 
>    Stack Frame         Script              Venkman Display
>    ------------------------------------------------------------
> 1. null                ""                  [EvalScript]
> 2. null                ""                  __top_level__

Ditto.
Hey, three examples, must be so ;-)

> 
> 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 ;-)

JOhn.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.