1 55 56 package org.apache.bsf.engines.javascript; 57 58 import org.mozilla.javascript.*; 59 import org.mozilla.javascript.debug.*; 60 61 import org.apache.bsf.debug.*; 62 import org.apache.bsf.debug.jsdi.*; 63 64 import java.rmi.RemoteException ; 65 70 71 public class JsContextStub 72 extends org.apache.bsf.debug.util.Skeleton 73 implements JsContext { 74 75 RhinoContextProxy m_rcp; 76 RhinoEngineDebugger m_rhinoDbg; 77 DebugFrame m_frame; 78 int m_frameno; 79 boolean m_atBreakpoint; 80 boolean m_invalid; 81 82 85 public JsContextStub(RhinoContextProxy rcp, DebugFrame frame, int frameno) 86 throws RemoteException { 87 super(org.apache.bsf.debug.util.DebugConstants.JS_CONTEXT_TID); 88 89 m_rhinoDbg = rcp.getRhinoEngineDebugger(); 90 m_rcp = rcp; 91 m_frame = frame; 92 m_frameno = frameno; 93 m_invalid = false; 94 m_atBreakpoint = true; 95 } 96 void atBreakpoint(boolean atbrkpt) { 98 m_atBreakpoint = atbrkpt; 99 } 100 public JsObject bind(String id) throws RemoteException { 101 try { 102 Context.enter(); 103 Scriptable obj = m_frame.getVariableObject(); 104 Object prop; 105 while (obj != null) { 106 Scriptable m = obj; 107 do { 108 if (m.has(id, obj)) 109 return m_rhinoDbg.marshallScriptable(obj); 110 m = m.getPrototype(); 111 } while (m != null); 112 obj = obj.getParentScope(); 113 } 114 throw new JsdiException("Name not in scope."); 115 } finally { 116 Context.exit(); 117 } 118 } 119 public JsCode getCode() { 121 if (m_invalid) 122 throw new JsdiException("This context no longer exists."); 123 if (!m_atBreakpoint) 124 throw new JsdiException("Resumed context, can't get the code."); 125 126 try { 127 Context.enter(); 128 return null; 129 } finally { 130 Context.exit(); 131 } 132 } 133 public int getDepth() { 134 return m_frameno; 135 } 136 public JsEngine getEngine() { 138 RhinoEngineDebugger redbg; 139 redbg = m_rcp.getRhinoEngineDebugger(); 140 return (JsEngine) redbg.getDebugInterface(); 141 142 } 143 public int getLineNumber() { 145 if (m_invalid) 146 throw new JsdiException("This context no longer exists."); 147 if (!m_atBreakpoint) 148 throw new JsdiException("Resumed context, can't get line number."); 149 150 try { 151 Context.enter(); 152 return m_frame.getLineNumber(); 153 } finally { 154 Context.exit(); 155 } 156 } 157 public JsObject getScope() throws RemoteException { 159 160 if (m_invalid) 161 throw new JsdiException("This context no longer exists."); 162 if (!m_atBreakpoint) 163 throw new JsdiException("Resumed context, can't get line number."); 164 165 try { 166 Context.enter(); 167 Scriptable varobj = m_frame.getVariableObject(); 168 JsObject scope = m_rhinoDbg.marshallScriptable(varobj); 169 return scope; 170 } finally { 171 Context.exit(); 172 } 173 } 174 public String getSourceName() { 176 if (m_invalid) 177 throw new JsdiException("This context no longer exists."); 178 if (!m_atBreakpoint) 179 throw new JsdiException("Resumed context, can't get line number."); 180 181 try { 182 Context.enter(); 183 return m_frame.getSourceName(); 184 } finally { 185 Context.exit(); 186 } 187 } 188 public JsObject getThis() throws RemoteException { 190 191 if (m_invalid) 192 throw new JsdiException("This context no longer exists."); 193 if (!m_atBreakpoint) 194 throw new JsdiException("Resumed context, can't get line number."); 195 196 try { 197 Context.enter(); 198 JsObject thisobj = null; 199 Scriptable obj = null; 200 NativeCall call = null; 201 Scriptable varobj = m_frame.getVariableObject(); 202 if (varobj instanceof NativeCall) { 203 call = (NativeCall) varobj; 204 obj = call.getThisObj(); 205 thisobj = m_rhinoDbg.marshallScriptable(varobj); 206 } 207 return thisobj; 208 } finally { 209 Context.exit(); 210 } 211 } 212 void invalidate() { 214 m_invalid = true; 215 } 216 public boolean isEvalContext() { 218 if (m_invalid) 219 throw new JsdiException("This context no longer exists."); 220 if (!m_atBreakpoint) 221 throw new JsdiException("Resumed context, can't get line number."); 222 223 try { 224 Context.enter(); 225 return false; 226 } finally { 227 Context.exit(); 228 } 229 } 230 public boolean isFunctionContext() { 232 if (m_invalid) 233 throw new JsdiException("This context no longer exists."); 234 if (!m_atBreakpoint) 235 throw new JsdiException("Resumed context, can't get line number."); 236 237 try { 238 Context.enter(); 239 return false; 240 } finally { 241 Context.exit(); 242 } 243 } 244 public boolean isScriptContext() { 246 if (m_invalid) 247 throw new JsdiException("This context no longer exists."); 248 if (!m_atBreakpoint) 249 throw new JsdiException("Resumed context, can't get line number."); 250 try { 251 Context.enter(); 252 return true; 253 } finally { 254 Context.exit(); 255 } 256 } 257 public Object lookupName(String name) { 258 259 try { 260 Context.enter(); 261 Scriptable obj = m_frame.getVariableObject(); 262 Object prop; 263 while (obj != null) { 264 Scriptable m = obj; 265 do { 266 Object result = m.get(name, obj); 267 if (result != Scriptable.NOT_FOUND) 268 return result; 269 m = m.getPrototype(); 270 } while (m != null); 271 obj = obj.getParentScope(); 272 } 273 throw new JsdiException("Name is not in scope."); 274 } finally { 275 Context.exit(); 276 } 277 } 278 281 public Object lookupName(Scriptable scopeChain, String id) { 282 283 try { 284 Context.enter(); 285 Scriptable obj = scopeChain; 286 Object prop; 287 while (obj != null) { 288 Scriptable m = obj; 289 do { 290 Object result = m.get(id, obj); 291 if (result != Scriptable.NOT_FOUND) 292 return result; 293 m = m.getPrototype(); 294 } while (m != null); 295 obj = obj.getParentScope(); 296 } 297 return null; 298 } finally { 299 Context.exit(); 300 } 301 } 302 } 303 | Popular Tags |