Skip to content

Commit f7ed7f7

Browse files
nicolas-albertgbrail
authored andcommitted
Fix debugger eval for Script
* Fix debugger eval for Script * Fix debugger eval scope for top-level scripts
1 parent 936745a commit f7ed7f7

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

  • rhino-tools/src/main/java/org/mozilla/javascript/tools/debugger

rhino-tools/src/main/java/org/mozilla/javascript/tools/debugger/Dim.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
import java.util.HashMap;
1818
import java.util.List;
1919
import java.util.Map;
20-
import org.mozilla.javascript.Callable;
2120
import org.mozilla.javascript.Context;
2221
import org.mozilla.javascript.ContextAction;
2322
import org.mozilla.javascript.ContextFactory;
2423
import org.mozilla.javascript.ImporterTopLevel;
2524
import org.mozilla.javascript.Kit;
2625
import org.mozilla.javascript.NativeCall;
2726
import org.mozilla.javascript.NativeObject;
27+
import org.mozilla.javascript.Script;
2828
import org.mozilla.javascript.ScriptRuntime;
2929
import org.mozilla.javascript.Scriptable;
3030
import org.mozilla.javascript.ScriptableObject;
@@ -745,8 +745,15 @@ private static String do_eval(Context cx, StackFrame frame, String expr) {
745745
cx.setInterpretedMode(false);
746746
cx.setGeneratingDebug(false);
747747
try {
748-
Callable script = (Callable) cx.compileString(expr, "", 0, null);
749-
Object result = script.call(cx, frame.scope, frame.thisObj, ScriptRuntime.emptyArgs);
748+
Scriptable scope = frame.scope;
749+
if (!frame.isFunction && scope != null) {
750+
Scriptable parentScope = scope.getParentScope();
751+
if (parentScope != null) {
752+
scope = parentScope;
753+
}
754+
}
755+
Script script = cx.compileString(expr, "", 0, null);
756+
Object result = script.exec(cx, scope, frame.thisObj);
750757
if (result == Undefined.instance) {
751758
resultString = "";
752759
} else {
@@ -896,7 +903,7 @@ public DebugFrame getFrame(Context cx, DebuggableScript fnOrScript) {
896903
// Can not debug if source is not available
897904
return null;
898905
}
899-
return new StackFrame(cx, dim, item);
906+
return new StackFrame(cx, dim, item, fnOrScript.isFunction());
900907
}
901908

902909
/** Called when compilation is finished. */
@@ -974,6 +981,9 @@ public static class StackFrame implements DebugFrame {
974981
/** The 'this' object. */
975982
private Scriptable thisObj;
976983

984+
/** Whether this frame represents a function (vs a top-level script). */
985+
private boolean isFunction;
986+
977987
/** Information about the function. */
978988
private FunctionSource fsource;
979989

@@ -984,10 +994,11 @@ public static class StackFrame implements DebugFrame {
984994
private int lineNumber;
985995

986996
/** Creates a new StackFrame. */
987-
private StackFrame(Context cx, Dim dim, FunctionSource fsource) {
997+
private StackFrame(Context cx, Dim dim, FunctionSource fsource, boolean isFunction) {
988998
this.dim = dim;
989999
this.contextData = ContextData.get(cx);
9901000
this.fsource = fsource;
1001+
this.isFunction = isFunction;
9911002
this.breakpoints = fsource.sourceInfo().breakpoints;
9921003
this.lineNumber = fsource.firstLine();
9931004
}

0 commit comments

Comments
 (0)