Add isGeneratedScript to DebuggableScript and its implementations to allow debuger to distinguish between scripts and functions coming from external files or ones defined vvia exec or new Function()

This commit is contained in:
igor%mir2.org 2002-09-26 20:19:39 +00:00
parent f24613dd00
commit 5c85c4f1ae
6 changed files with 36 additions and 2 deletions

View File

@ -351,7 +351,9 @@ public class BaseFunction extends IdScriptable implements Function {
filename = "<eval'ed string>";
linep[0] = 1;
}
String sourceName = filename+'#'+linep[0]+"(Function)";
String sourceName = ScriptRuntime.
makeUrlForGeneratedScript(false, filename, linep[0]);
Scriptable global = ScriptableObject.getTopLevelScope(scope);

View File

@ -89,6 +89,10 @@ final class InterpretedFunction extends NativeFunction
return itsData.itsSourceFile;
}
public boolean isGeneratedScript() {
return ScriptRuntime.isGeneratedScript(itsData.itsSourceFile);
}
public int[] getLineNumbers() {
return Interpreter.getLineNumbers(itsData);
}

View File

@ -78,6 +78,10 @@ final class InterpretedScript extends NativeScript
return itsData.itsSourceFile;
}
public boolean isGeneratedScript() {
return ScriptRuntime.isGeneratedScript(itsData.itsSourceFile);
}
public int[] getLineNumbers() {
return Interpreter.getLineNumbers(itsData);
}

View File

@ -502,7 +502,8 @@ public class NativeGlobal implements IdFunctionMaster {
filename = "";
}
}
String sourceName = filename+'#'+lineNumber+"(eval)";
String sourceName = ScriptRuntime.
makeUrlForGeneratedScript(true, filename, lineNumber);
try {
StringReader in = new StringReader((String) x);

View File

@ -2066,6 +2066,23 @@ public class ScriptRuntime {
return false;
}
static String makeUrlForGeneratedScript
(boolean isEval, String masterScriptUrl, int masterScriptLine)
{
if (isEval) {
return masterScriptUrl+'#'+masterScriptLine+"(eval)";
} else {
return masterScriptUrl+'#'+masterScriptLine+"(Function)";
}
}
static boolean isGeneratedScript(String sourceUrl) {
// ALERT: this may clash with a valid URL containing (eval) or
// (Function)
return sourceUrl.indexOf("(eval)") >= 0
|| sourceUrl.indexOf("(Function)") >= 0;
}
private static RuntimeException errorWithClassName(String msg, Object val)
{
return Context.reportRuntimeError1(msg, val.getClass().getName());

View File

@ -64,6 +64,12 @@ public interface DebuggableScript {
*/
public String getSourceName();
/**
* Retutns true for functions constructed via <tt>Function(...)</tt>
* or eval scripts or any function defined by such functions or scripts
*/
public boolean isGeneratedScript();
/**
* Get array containing the line numbers that
* that can be passed to <code>DebugFrame.onLineChange()<code>.