org.apache.bsf.engines.javascript
public class: CompilationUnit [javadoc |
source]
java.lang.Object
org.apache.bsf.engines.javascript.CompilationUnit
A compilation unit is a Rhino concept.
When a piece of script is provided for eval or
execute to a Rhino engine, it is compiled down
to either JavaScript or Java bytecode.
In debug mode, only the compilation down to JavaScript
bytecode is supported.
During the compilation process, the original piece
of script is sliced into compilation units.
For instance, the script text may contain a function
declaration and an expression to eval. The compilation
will result in two compilation units: the function and
the expression. Each compilation unit will correspond
to a range of the lines of the original script compiled.
All line numbers are global to the document the compiled
script is part of.
It is on compilation units that breakpoints can be set
or removed, more exactly on the DebuggableScript attached
to them. See Rhino for more details.
- author::
Olivier - Gruber.
| Field Summary |
|---|
| FnOrScript | m_fnOrScript | |
| int | m_firstLine | |
| int | m_lineCount | |
| String | m_fnName | |
| DebuggableScript | m_dbgScript | |
| int[] | m_validBrkptLines | |
| Constructor: |
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)
m_firstLine = lineno;
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;
}
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;
}
}
}
CompilationUnit constructor comment. |
| Method from org.apache.bsf.engines.javascript.CompilationUnit Detail: |
boolean contains(int lineno) {
return (m_firstLine < = lineno && lineno < m_firstLine + m_lineCount);
}
|
boolean contains(BreakPoint bp) {
try {
return contains(bp.getLineNo());
} catch (BSFException ex) {
return false;
}
}
Returns true if the compilation unit contains
the breakpoint.
Notice only breakpoint defined at a line number
are supported here. |
void propagate(int lineno) {
if (m_validBrkptLines != null) {
m_dbgScript.placeBreakpoint(lineno);
}
}
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. |
void unpropagate(int lineno) {
if (m_validBrkptLines != null) {
m_dbgScript.removeBreakpoint(lineno);
}
}
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. |