📄 dim.java
字号:
for (int i = 0; i != function.getFunctionCount(); ++i) { collectFunctions_r(function.getFunction(i), array); } } void clearAllBreakpoints() { Enumeration e = urlToSourceInfo.elements(); while (e.hasMoreElements()) { SourceInfo si = (SourceInfo)e.nextElement(); si.removeAllBreakpoints(); } } void handleBreakpointHit(StackFrame frame, Context cx) { breakFlag = false; interrupted(cx, frame, null); } void handleExceptionThrown(Context cx, Throwable ex, StackFrame frame) { if (breakOnExceptions) { ContextData cd = frame.contextData(); if (cd.lastProcessedException != ex) { interrupted(cx, frame, ex); cd.lastProcessedException = ex; } } } /* end Debugger interface */ void contextSwitch (int frameIndex) { this.frameIndex = frameIndex; } ContextData currentContextData() { return interruptedContextData; } void setReturnValue(int returnValue) { synchronized (monitor) { this.returnValue = returnValue; monitor.notify(); } } void go() { synchronized (monitor) { this.returnValue = GO; monitor.notifyAll(); } } String eval(String expr) { String result = "undefined"; if (expr == null) { return result; } ContextData contextData = currentContextData(); if (contextData == null || frameIndex >= contextData.frameCount()) { return result; } StackFrame frame = contextData.getFrame(frameIndex); if (contextData.eventThreadFlag) { Context cx = Context.getCurrentContext(); result = do_eval(cx, frame, expr); } else { synchronized (monitor) { if (insideInterruptLoop) { evalRequest = expr; evalFrame = frame; monitor.notify(); do { try { monitor.wait(); } catch (InterruptedException exc) { Thread.currentThread().interrupt(); break; } } while (evalRequest != null); result = evalResult; } } } return result; } void compileScript(String url, String text) { DimIProxy action = new DimIProxy(this, IPROXY_COMPILE_SCRIPT); action.url = url; action.text = text; action.withContext(); } void evalScript(final String url, final String text) { DimIProxy action = new DimIProxy(this, IPROXY_EVAL_SCRIPT); action.url = url; action.text = text; action.withContext(); } String objectToString(Object object) { DimIProxy action = new DimIProxy(this, IPROXY_OBJECT_TO_STRING); action.object = object; action.withContext(); return action.stringResult; } boolean stringIsCompilableUnit(String str) { DimIProxy action = new DimIProxy(this, IPROXY_STRING_IS_COMPILABLE); action.text = str; action.withContext(); return action.booleanResult; } Object getObjectProperty(Object object, Object id) { DimIProxy action = new DimIProxy(this, IPROXY_OBJECT_PROPERTY); action.object = object; action.id = id; action.withContext(); return action.objectResult; } Object[] getObjectIds(Object object) { DimIProxy action = new DimIProxy(this, IPROXY_OBJECT_IDS); action.object = object; action.withContext(); return action.objectArrayResult; } Object getObjectPropertyImpl(Context cx, Object object, Object id) { Scriptable scriptable = (Scriptable)object; Object result; if (id instanceof String) { String name = (String)id; if (name.equals("this")) { result = scriptable; } else if (name.equals("__proto__")) { result = scriptable.getPrototype(); } else if (name.equals("__parent__")) { result = scriptable.getParentScope(); } else { result = ScriptableObject.getProperty(scriptable, name); if (result == ScriptableObject.NOT_FOUND) { result = Undefined.instance; } } } else { int index = ((Integer)id).intValue(); result = ScriptableObject.getProperty(scriptable, index); if (result == ScriptableObject.NOT_FOUND) { result = Undefined.instance; } } return result; } Object[] getObjectIdsImpl(Context cx, Object object) { if (!(object instanceof Scriptable) || object == Undefined.instance) { return Context.emptyArgs; } Object[] ids; Scriptable scriptable = (Scriptable)object; if (scriptable instanceof DebuggableObject) { ids = ((DebuggableObject)scriptable).getAllIds(); } else { ids = scriptable.getIds(); } Scriptable proto = scriptable.getPrototype(); Scriptable parent = scriptable.getParentScope(); int extra = 0; if (proto != null) { ++extra; } if (parent != null) { ++extra; } if (extra != 0) { Object[] tmp = new Object[extra + ids.length]; System.arraycopy(ids, 0, tmp, extra, ids.length); ids = tmp; extra = 0; if (proto != null) { ids[extra++] = "__proto__"; } if (parent != null) { ids[extra++] = "__parent__"; } } return ids; } private void interrupted(Context cx, final StackFrame frame, Throwable scriptException) { ContextData contextData = frame.contextData(); int line = frame.getLineNumber(); String url = frame.getUrl(); boolean eventThreadFlag = callback.isGuiEventThread(); contextData.eventThreadFlag = eventThreadFlag; boolean recursiveEventThreadCall = false; interruptedCheck: synchronized (eventThreadMonitor) { if (eventThreadFlag) { if (interruptedContextData != null) { recursiveEventThreadCall = true; break interruptedCheck; } } else { while (interruptedContextData != null) { try { eventThreadMonitor.wait(); } catch (InterruptedException exc) { return; } } } interruptedContextData = contextData; } if (recursiveEventThreadCall) { // XXX: For now the foolowing is commented out as on Linux // too deep recursion of dispatchNextGuiEvent causes GUI lockout. // Note: it can make GUI unresponsive if long-running script // will be called on GUI thread while processing another interrupt if (false) { // Run event dispatch until gui sets a flag to exit the initial // call to interrupted. while (this.returnValue == -1) { try { callback.dispatchNextGuiEvent(); } catch (InterruptedException exc) { } } } return; } if (interruptedContextData == null) Kit.codeBug(); try { do { int frameCount = contextData.frameCount(); this.frameIndex = frameCount -1; final String threadTitle = Thread.currentThread().toString(); final String alertMessage; if (scriptException == null) { alertMessage = null; } else { alertMessage = scriptException.toString(); } int returnValue = -1; if (!eventThreadFlag) { synchronized (monitor) { if (insideInterruptLoop) Kit.codeBug(); this.insideInterruptLoop = true; this.evalRequest = null; this.returnValue = -1; callback.enterInterrupt(frame, threadTitle, alertMessage); try { for (;;) { try { monitor.wait(); } catch (InterruptedException exc) { Thread.currentThread().interrupt(); break; } if (evalRequest != null) { this.evalResult = null; try { evalResult = do_eval(cx, evalFrame, evalRequest); } finally { evalRequest = null; evalFrame = null; monitor.notify(); } continue; } if (this.returnValue != -1) { returnValue = this.returnValue; break; } } } finally { insideInterruptLoop = false; } } } else { this.returnValue = -1; callback.enterInterrupt(frame, threadTitle, alertMessage); while (this.returnValue == -1) { try { callback.dispatchNextGuiEvent(); } catch (InterruptedException exc) { } } returnValue = this.returnValue; } switch (returnValue) { case STEP_OVER: contextData.breakNextLine = true; contextData.stopAtFrameDepth = contextData.frameCount(); break; case STEP_INTO: contextData.breakNextLine = true; contextData.stopAtFrameDepth = -1; break; case STEP_OUT: if (contextData.frameCount() > 1) { contextData.breakNextLine = true; contextData.stopAtFrameDepth = contextData.frameCount() -1; } break; } } while (false); } finally { synchronized (eventThreadMonitor) { interruptedContextData = null; eventThreadMonitor.notifyAll(); } } } private static String do_eval(Context cx, StackFrame frame, String expr) { String resultString; Debugger saved_debugger = cx.getDebugger(); Object saved_data = cx.getDebuggerContextData(); int saved_level = cx.getOptimizationLevel(); cx.setDebugger(null, null); cx.setOptimizationLevel(-1); cx.setGeneratingDebug(false); try { Callable script = (Callable)cx.compileString(expr, "", 0, null); Object result = script.call(cx, frame.scope, frame.thisObj, ScriptRuntime.emptyArgs); if (result == Undefined.instance) { resultString = ""; } else { resultString = ScriptRuntime.toString(result); } } catch (Exception exc) { resultString = exc.getMessage(); } finally { cx.setGeneratingDebug(true); cx.setOptimizationLevel(saved_level); cx.setDebugger(saved_debugger, saved_data); } if (resultString == null) { resultString = "null"; } return resultString; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -