You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bsf-dev@jakarta.apache.org by Chuck Murcko <ch...@topsail.org> on 2003/01/27 23:34:50 UTC

Fwd: MODERATE for bsf-dev@jakarta.apache.org

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

Begin forwarded message:

> From: Igor Bukanov <ig...@icesoft.no>
> Date: Wed Jan 15, 2003  08:53:17 America/Phoenix
> To: bsf-dev@jakarta.apache.org
> 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
>
>


Re: Fwd: MODERATE for bsf-dev@jakarta.apache.org

Posted by Igor Bukanov <ig...@icesoft.no>.
Victor J. Orlikowski wrote:
> Thanks; when I tried your patch w/ the latest rhino cvs, it was
> not working (is the API unsettled *again*)?

No, that did not change and future updates if any will be 100% 
compatible (the debugger API was not a part of the official public API 
in Rhino, but perhaps it is time to chnage that status). I will check 
the patch.

> Hmmm. I see that http://www.mozilla.org/rhino/download.html says
> that 1.rR4 is available, but 1.5R3 is the last "qualified"
> release.
> 
> Whatever that means. Perhaps they have yet to update that page
> completely.

Thanks for spotting this, the page will be updated.

Regards, Igor


Re: Fwd: MODERATE for bsf-dev@jakarta.apache.org

Posted by "Victor J. Orlikowski" <vj...@dulug.duke.edu>.
On Thu, Feb 13, 2003 at 12:16:51PM +0100, Igor Bukanov wrote:
> With the patch I was able to rebuild BSF OK, but I can try to do it one 
> more time.
> 
Thanks; when I tried your patch w/ the latest rhino cvs, it was
not working (is the API unsettled *again*)?

> The new API is a part of Rhino 1.5R4, which was released on 2003-02-12. 
> The main difference is that now Rhino does not checks for breakpoints 
> itself, instead it asks the debugger if it wants to monitor execution a 
> particular function or not and if yes, the debugger will get control on 
> each script line. Then debugger can check for breakpoints, for example, 
> via itself via a bit array. In this way it is very easy to monitor 
> execution of generated scripts or scripts loaded before the debugger was 
> attached to Rhino.
> 
Hmmm. I see that http://www.mozilla.org/rhino/download.html says
that 1.rR4 is available, but 1.5R3 is the last "qualified"
release.

Whatever that means. Perhaps they have yet to update that page
completely.

Re: Fwd: MODERATE for bsf-dev@jakarta.apache.org

Posted by Igor Bukanov <ig...@icesoft.no>.
Victor J. Orlikowski wrote:
 > I was able to get part way
> through adapting the current Rhino engine to the 1.5r4 API with
> this patch. However, significant changes need to be made against
> RhinoContextProxy and JsContextStub to make it compile.
> 
> Furthermore, I will heartily agree that the current implementation
> does not quite map onto the new Rhino API.
> 
> I would be curious to see if you have done any more work on this.

With the patch I was able to rebuild BSF OK, but I can try to do it one 
more time.

> 
> That said, work probably should not progress, until 1) Rhino's
> debug API settles down - 1.5r3 is still (supposedly) the current
> release, and 2) BSF's debug API/architecture is a bit better
> hashed out - the current bit is based very closely on Rhino.

The new API is a part of Rhino 1.5R4, which was released on 2003-02-12. 
The main difference is that now Rhino does not checks for breakpoints 
itself, instead it asks the debugger if it wants to monitor execution a 
particular function or not and if yes, the debugger will get control on 
each script line. Then debugger can check for breakpoints, for example, 
via itself via a bit array. In this way it is very easy to monitor 
execution of generated scripts or scripts loaded before the debugger was 
attached to Rhino.

Regards, Igor


Re: Fwd: MODERATE for bsf-dev@jakarta.apache.org

Posted by "Victor J. Orlikowski" <vj...@dulug.duke.edu>.
> > From: Igor Bukanov <ig...@icesoft.no>
> > Date: Wed Jan 15, 2003  08:53:17 America/Phoenix
> > To: bsf-dev@jakarta.apache.org
> > Subject: Javascript patch for new Rhino release
> >

Igor,

This is a somewhat good start ... I was able to get part way
through adapting the current Rhino engine to the 1.5r4 API with
this patch. However, significant changes need to be made against
RhinoContextProxy and JsContextStub to make it compile.

Furthermore, I will heartily agree that the current implementation
does not quite map onto the new Rhino API.

I would be curious to see if you have done any more work on this.

That said, work probably should not progress, until 1) Rhino's
debug API settles down - 1.5r3 is still (supposedly) the current
release, and 2) BSF's debug API/architecture is a bit better
hashed out - the current bit is based very closely on Rhino.

Victor
-- 
Victor J. Orlikowski   | The Wall is Down, But the Threat Remains!
==================================================================
orlikowski@apache.org  | vjo@dulug.duke.edu | vjo@us.ibm.com