1 55 56 package org.apache.bsf.engines.javascript; 57 58 import org.apache.bsf.*; 59 import org.apache.bsf.debug.jsdi.*; 60 import org.apache.bsf.debug.util.DebugLog; 61 import org.mozilla.javascript.*; 62 import org.mozilla.javascript.debug.*; 63 64 import java.util.*; 65 66 88 public class CompilationUnit { 89 90 FnOrScript m_fnOrScript; 91 int m_firstLine; 92 int m_lineCount; 93 String m_fnName; 94 DebuggableScript m_dbgScript; 95 int m_validBrkptLines[]; 96 97 100 public CompilationUnit(FnOrScript fnOrScript, DebuggableScript dbgScript) { 101 102 int lastLine, lineno; 103 104 m_fnOrScript = fnOrScript; 105 m_dbgScript = dbgScript; 106 107 try { 108 m_validBrkptLines = dbgScript.getLineNumbers(); 109 m_firstLine = 99999; 110 lastLine = 0; 111 for (int l = 0; l < m_validBrkptLines.length; l++) { 112 lineno = m_validBrkptLines[l]; 113 if (m_firstLine > lineno) 114 m_firstLine = lineno; 115 if (lastLine < lineno) 116 lastLine = lineno; 117 } 118 m_lineCount = lastLine - m_firstLine + 1; 119 } catch (Throwable t) { 120 DebugLog.stderrPrintln("\nWarning: can't get valid line numbers for breakpoints.", DebugLog.BSF_LOG_L2); 121 m_validBrkptLines = null; 122 } 123 124 Scriptable scriptable = dbgScript.getScriptable(); 125 if (scriptable instanceof NativeFunction) { 126 NativeFunction f = (NativeFunction) scriptable; 127 String name = f.getFunctionName(); 128 if (name.length() > 0 && !name.equals("anonymous")) { 129 m_fnName = name; 130 } 131 } 132 } 133 boolean contains(int lineno) { 135 return (m_firstLine <= lineno && lineno < m_firstLine + m_lineCount); 136 } 137 143 boolean contains(BreakPoint bp) { 144 try { 145 return contains(bp.getLineNo()); 146 } catch (BSFException ex) { 147 return false; 148 } 149 } 150 155 void propagate(int lineno) { 156 if (m_validBrkptLines != null) { 157 m_dbgScript.placeBreakpoint(lineno); 158 } 159 } 160 165 void unpropagate(int lineno) { 166 if (m_validBrkptLines != null) { 167 m_dbgScript.removeBreakpoint(lineno); 168 } 169 } 170 } 171 | Popular Tags |