I looked into this somewhat and I noticed the following:

1) There is a bug in Interpreter.java, line 1695. It sets the variable "i" to
the line number of the special call, but overwrites it on line 1699.  It then
passes this value to ScriptRuntime.callSpecial
2) In "generateScriptICode" in Interpreter.java the variable
itsData.itsSourceFile fails to be set to itsSourceFile.  This causes a null
source file name to be passed to handleCompilationDone when "Widget.js" is
compiled.  That is why you
initially see "<stdin>, line 6" when the debugger comes up (the debugger
interprets a null source name as "stdin").  I simply modified it as follows
(this might not be the right thing to do?):

  private InterpretedScript generateScriptICode(Context cx,
                                                  Scriptable scope,
                                                  Node tree,
                                                  Object securityDomain)
    {
        itsSourceFile = (String) tree.getProp(Node.SOURCENAME_PROP);
        itsData.itsSourceFile = itsSourceFile;
        ...

and that corrected the problem.

However there seems to be no way for the debugger to detect that the script
passed to handleCompilationDone() is the argument of an "eval()". So I modifed
NativeGlobal.evalSpecial() to munge the filename to indicate this (by appending
"(eval)" to it).  That way a separate window is created in the debugger to hold
the compiled eval code.  This is probably not be the best way to solve the
problem.

I have attached the files I modified.

Cheers,

Chris

Simon Massey wrote:

> Christopher,
>
> Attached is the code that trips the debugger up. The debugger comes up. You
minimize the console to reveal Widget.js file window. You click 'Go'. The
Widget.js window looses all the code in it and is just replaced by the evaluated
code:
>
>   this.invokedByEval()
>
> The rhino tip I have is rhino15R2pre.zip
>
> I am running it with the command:
>
> start javaw org.mozilla.javascript.tools.debugger.JSDebugger -f Widget.js -f
Main.js
>
> using the JVM:
>
>   java version "1.3.0"
>   Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
>   Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
>
> on Win2k.
>
> Just in case you are wondering why on earth my code wants to do this, it is
because I want to do some introspection. The real Widget invokes all its methods
that have a particular substring in their names:
>
>         for( key in this ){
>                 if( key.indexOf('reflect') == 0 ){
>                         var evalStr = "this."+key+"()";
>                         eval(evalStr);
>                 }
>         }
>
> Thanks for the great code. I have the real Widget stabilized and am happily
using the debugger on my other files.
>
> Thanks again!
>
> Simon Massey
>
This commit is contained in:
nboyd%atg.com 2001-06-19 19:27:21 +00:00
Родитель cffb1bcb02
Коммит 6e07ba105c
2 изменённых файлов: 9 добавлений и 7 удалений

Просмотреть файл

@ -116,6 +116,7 @@ public class Interpreter extends LabelTable {
Object securityDomain)
{
itsSourceFile = (String) tree.getProp(Node.SOURCENAME_PROP);
itsData.itsSourceFile = itsSourceFile;
itsFunctionList = (Vector) tree.getProp(Node.FUNCTION_PROP);
debugSource = (StringBuffer) tree.getProp(Node.DEBUGSOURCE_PROP);
if (itsFunctionList != null)
@ -786,8 +787,8 @@ public class Interpreter extends LabelTable {
iCodeTop = addByte((byte) TokenStream.ONE, iCodeTop);
else {
iCodeTop = addByte((byte) TokenStream.NUMBER, iCodeTop);
iCodeTop = addNumber(num, iCodeTop);
}
iCodeTop = addNumber(num, iCodeTop);
}
}
itsStackDepth++;
if (itsStackDepth > itsData.itsMaxStack)
@ -1691,7 +1692,7 @@ public class Interpreter extends LabelTable {
stack[++stackTop] = local[slot];
break;
case TokenStream.CALLSPECIAL :
i = (iCode[pc + 1] << 8) | (iCode[pc + 2] & 0xFF);
int lineNum = (iCode[pc + 1] << 8) | (iCode[pc + 2] & 0xFF);
name = getString(theData.itsStringTable, iCode, pc + 3);
count = (iCode[pc + 5] << 8) | (iCode[pc + 6] & 0xFF);
outArgs = new Object[count];
@ -1701,7 +1702,7 @@ public class Interpreter extends LabelTable {
lhs = stack[stackTop];
stack[stackTop] = ScriptRuntime.callSpecial(
cx, lhs, rhs, outArgs,
thisObj, scope, name, i);
thisObj, scope, name, lineNum);
pc += 6;
break;
case TokenStream.CALL :

Просмотреть файл

@ -486,10 +486,11 @@ public class NativeGlobal implements IdFunctionMaster {
if (filename == null) {
filename = Context.getSourcePositionFromStack(linep);
if (filename == null) {
filename = "<eval'ed string>";
filename = "";
linep[0] = 1;
}
}
}
}
filename += "(eval)";
try {
StringReader in = new StringReader((String) x);