For some reason this did not moderate through before, but here it is:

Begin forwarded message:

From: Igor Bukanov <[EMAIL PROTECTED]>
Date: Wed Jan 15, 2003 08:53:17 America/Phoenix
To: [EMAIL PROTECTED]
Subject: Javascript patch for new Rhino release



The forthcoming 1.5R4 release of Rhino (the latest release candidate is at http://mozilla.org/rhino/download.html ) contains incompatible debug API changes, see http://mozilla.org/rhino/changes.html for details. The following patch against bsf-2.3.0 updates it to the new API. I believe with the new API implementation can be simplified but as I am not familiar with BSF debug subsystem, the patch takes the minimalist approach of just making code to compile and work as before.
diff -ru bsf-2.3.0/src/bsf/src/org/apache/bsf/engines/javascript/ CompilationUnit.java bsf-2.3.0-rhino-update/src/bsf/src/org/apache/bsf/engines/javascript/ CompilationUnit.java
--- bsf-2.3.0/src/bsf/src/org/apache/bsf/engines/javascript/ CompilationUnit.java 2002-11-13 07:28:54.000000000 +0100
+++ bsf-2.3.0-rhino-update/src/bsf/src/org/apache/bsf/engines/javascript/ CompilationUnit.java 2003-01-15 16:23:55.000000000 +0100
@@ -92,42 +92,36 @@
int m_lineCount;
String m_fnName;
DebuggableScript m_dbgScript;
- int m_validBrkptLines[];
+ boolean[] m_breakpoints;

/**
* CompilationUnit constructor comment.
*/
public CompilationUnit(FnOrScript fnOrScript, DebuggableScript dbgScript) {

- int lastLine, lineno;
-
m_fnOrScript = fnOrScript;
m_dbgScript = dbgScript;

- try {
- m_validBrkptLines = dbgScript.getLineNumbers();
- m_firstLine = 99999;
- lastLine = 0;
- for (int l = 0; l < m_validBrkptLines.length; l++) {
- lineno = m_validBrkptLines[l];
- if (m_firstLine > lineno)
+ int[] lines = dbgScript.getLineNumbers();
+ if (lines.length != 0) {
+ int lastLine;
+ m_firstLine = lines[0];
+ lastLine = m_firstLine;
+ for (int i = 1; i != lines.length; ++i) {
+ int lineno = lines[i];
+ if (m_firstLine > lineno) {
m_firstLine = lineno;
- if (lastLine < lineno)
+ } else if (lastLine < lineno) {
lastLine = lineno;
+ }
}
m_lineCount = lastLine - m_firstLine + 1;
- } catch (Throwable t) {
- DebugLog.stderrPrintln("\nWarning: can't get valid line numbers for breakpoints.", DebugLog.BSF_LOG_L2);
- m_validBrkptLines = null;
+ m_breakpoints = new boolean[m_lineCount];
}

- Scriptable scriptable = dbgScript.getScriptable();
- if (scriptable instanceof NativeFunction) {
- NativeFunction f = (NativeFunction) scriptable;
- String name = f.getFunctionName();
- if (name.length() > 0 && !name.equals("anonymous")) {
- m_fnName = name;
- }
+ String name = dbgScript.getFunctionName();
+ if (name != null && name.length() != 0 && !name.equals("anonymous")) {
+ m_fnName = name;
}
}
//----------------------------------------------------------
@@ -148,23 +142,35 @@
}
}
/**
- * Propagates (i.e. set) this breakpoint to the underlying Rhino
- * engine if Rhino has provided us with the valid lines
- * information. Otherwise, Rhino crashes with a NullPointerException.
+ * Set a breakpoint at the given line if Rhino has provided us with the
+ * valid lines information.
*/
void propagate(int lineno) {
- if (m_validBrkptLines != null) {
- m_dbgScript.placeBreakpoint(lineno);
+ if (m_breakpoints != null) {
+ int i = lineno - m_firstLine;
+ if (0 <= i && i < m_lineCount) {
+ m_breakpoints[i] = true;
+ }
}
}
/**
- * Unpropagates (i.e. unset) this breakpoint to the underlying Rhino
- * engine if Rhino has provided us with the valid lines
- * information. Otherwise, Rhino crashes with a NullPointerException.
+ * Clear a breakpoint at the given line if Rhino has provided us with the
+ * valid lines information.
*/
void unpropagate(int lineno) {
- if (m_validBrkptLines != null) {
- m_dbgScript.removeBreakpoint(lineno);
+ if (m_breakpoints != null) {
+ int i = lineno - m_firstLine;
+ if (0 <= i && i < m_lineCount) {
+ m_breakpoints[i] = false;
+ }
+ }
+ }
+
+ boolean hasBreakpoint(int lineno) {
+ if (m_breakpoints != null) {
+ int i = lineno - m_firstLine;
+ return 0 <= i && i < m_lineCount && m_breakpoints[i];
}
+ return false;
}
}
diff -ru bsf-2.3.0/src/bsf/src/org/apache/bsf/engines/javascript/ FnOrScript.java bsf-2.3.0-rhino-update/src/bsf/src/org/apache/bsf/engines/javascript/ FnOrScript.java
--- bsf-2.3.0/src/bsf/src/org/apache/bsf/engines/javascript/ FnOrScript.java 2002-11-13 07:28:54.000000000 +0100
+++ bsf-2.3.0-rhino-update/src/bsf/src/org/apache/bsf/engines/javascript/ FnOrScript.java 2003-01-15 16:40:47.000000000 +0100
@@ -103,9 +103,11 @@

protected StringBuffer m_text;

- protected Vector m_units; // of CompilationUnit.
protected Script m_script;

+ private Vector m_units; // of CompilationUnit.
+ private Hashtable m_functionToUnit;
+
protected Hashtable m_functionMap;

public FnOrScript(DocumentCell cell) {
@@ -118,6 +120,7 @@
m_text = new StringBuffer();

m_units = new Vector();
+ m_functionToUnit = new Hashtable();
m_functionMap = new Hashtable();
}

@@ -360,12 +363,13 @@

public void addCompilationUnit(Context cx,
DebuggableScript dbgScript,
- StringBuffer source) {
+ String source) {

CompilationUnit unit;

unit = new CompilationUnit(this, dbgScript);
m_units.addElement(unit);
+ m_functionToUnit.put(dbgScript, unit);
if (unit.m_fnName != null) {
m_functionMap.put(unit.m_fnName, unit);
}
@@ -382,6 +386,10 @@
}
propagateAll();
}
+
+ CompilationUnit getCompilationUnit(DebuggableScript dbgScript) {
+ return (CompilationUnit)m_functionToUnit.get(dbgScript);
+ }

public void compile(Context cx, Scriptable global)
throws BSFException, IOException {
diff -ru bsf-2.3.0/src/bsf/src/org/apache/bsf/engines/javascript/ RhinoEngineDebugger.java bsf-2.3.0-rhino-update/src/bsf/src/org/apache/bsf/engines/javascript/ RhinoEngineDebugger.java
--- bsf-2.3.0/src/bsf/src/org/apache/bsf/engines/javascript/ RhinoEngineDebugger.java 2002-11-13 07:28:55.000000000 +0100
+++ bsf-2.3.0-rhino-update/src/bsf/src/org/apache/bsf/engines/javascript/ RhinoEngineDebugger.java 2003-01-15 16:37:33.000000000 +0100
@@ -305,7 +305,7 @@
// to implement STEP_IN, STEP_OUT, and STEP_OVER.
//---------------------------------------------------------

- public void handleBreakpointHit(Context cx) {
+ void handleBreakpointHit(Context cx) {
JsCallbacks debugger;
BreakPoint bp;
Enumeration e;
@@ -458,13 +458,19 @@

public void handleCompilationDone(Context cx,
DebuggableScript fnOrScript,
- StringBuffer source) {
+ String source) {

m_thread = Thread.currentThread();
m_compilingFnOrScript.addCompilationUnit(cx, fnOrScript, source);
}

- public void handleExceptionThrown(Context cx, Object exceptionThrown) {
+ public DebugFrame getFrame(Context cx, DebuggableScript fnOrScript) {
+ CompilationUnit unit;
+ unit = m_compilingFnOrScript.getCompilationUnit(fnOrScript);
+ return new RhinoDebugFrame(this, unit);
+ }
+
+ void handleExceptionThrown(Context cx, Throwable exceptionThrown) {
JsContext stub;
JsCallbacks debugger;
BreakPoint bp;
@@ -473,7 +479,6 @@
String name,msg;
Exception ex;
int lineno;
- NativeError error;

m_thread = Thread.currentThread();
m_rcp = getStub(cx);
@@ -494,11 +499,10 @@
// First, search if we have breakpoints for the current documents
name = m_rcp.getSourceName();
lineno = m_rcp.getLineNumber();
- try {
- error = (NativeError)exceptionThrown;
- msg = error.getName() + ": " + error.getMessage();
- } catch (ClassCastException ccex) {
- msg = "Unknown JavaScript Exception";
+ if (exceptionThrown instanceof EcmaError) {
+ msg = ((EcmaError)exceptionThrown).getErrorObject().toString();
+ } else {
+ msg = exceptionThrown.toString();
}
ex = new Exception(msg);

@@ -587,3 +591,33 @@
m_callbacks = debugger;
}
}
+
+class RhinoDebugFrame implements DebugFrame {
+
+ RhinoEngineDebugger debugger;
+ CompilationUnit unit;
+
+ RhinoDebugFrame(RhinoEngineDebugger debugger, CompilationUnit unit) {
+ this.debugger = debugger;
+ this.unit = unit;
+ }
+
+ public void onEnter(Context cx, Scriptable activation,
+ Scriptable thisObj, Object[] args)
+ {
+ }
+
+ public void onExit(Context cx, boolean byThrow, Object resultOrException)
+ {
+ }
+
+ public void onExceptionThrown(Context cx, Throwable ex) {
+ debugger.handleExceptionThrown(cx, ex);
+ }
+
+ public void onLineChange(Context cx, int lineNumber) {
+ if (unit.hasBreakpoint(lineNumber)) {
+ debugger.handleBreakpointHit(cx);
+ }
+ }
+}
Only in bsf-2.3.0-rhino-update/src: extra



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to