⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dim.java

📁 java中比较著名的js引擎当属mozilla开源的rhino
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
            Enumeration e = functionNames.keys();            a = new String[functionNames.size()];            int i = 0;            while (e.hasMoreElements()) {                a[i++] = (String)e.nextElement();            }        }        return a;    }    /**     * Returns the FunctionSource object for the function with the given name.     */    public FunctionSource functionSourceByName(String functionName) {        return (FunctionSource)functionNames.get(functionName);    }    /**     * Returns the SourceInfo object for the given URL.     */    public SourceInfo sourceInfo(String url) {        return (SourceInfo)urlToSourceInfo.get(url);    }    /**     * Returns the source URL for the given script or function.     */    private String getNormalizedUrl(DebuggableScript fnOrScript) {        String url = fnOrScript.getSourceName();        if (url == null) { url = "<stdin>"; }        else {            // Not to produce window for eval from different lines,            // strip line numbers, i.e. replace all #[0-9]+\(eval\) by            // (eval)            // Option: similar teatment for Function?            char evalSeparator = '#';            StringBuffer sb = null;            int urlLength = url.length();            int cursor = 0;            for (;;) {                int searchStart = url.indexOf(evalSeparator, cursor);                if (searchStart < 0) {                    break;                }                String replace = null;                int i = searchStart + 1;                boolean hasDigits = false;                while (i != urlLength) {                    int c = url.charAt(i);                    if (!('0' <= c && c <= '9')) {                        break;                    }                    ++i;                }                if (i != searchStart + 1) {                    // i points after #[0-9]+                    if ("(eval)".regionMatches(0, url, i, 6)) {                        cursor = i + 6;                        replace = "(eval)";                    }                }                if (replace == null) {                    break;                }                if (sb == null) {                    sb = new StringBuffer();                    sb.append(url.substring(0, searchStart));                }                sb.append(replace);            }            if (sb != null) {                if (cursor != urlLength) {                    sb.append(url.substring(cursor));                }                url = sb.toString();            }        }        return url;    }    /**     * Returns an array of all functions in the given script.     */    private static DebuggableScript[] getAllFunctions            (DebuggableScript function) {        ObjArray functions = new ObjArray();        collectFunctions_r(function, functions);        DebuggableScript[] result = new DebuggableScript[functions.size()];        functions.toArray(result);        return result;    }    /**     * Helper function for {@link #getAllFunctions(DebuggableScript)}.     */    private static void collectFunctions_r(DebuggableScript function,                                             ObjArray array) {        array.add(function);        for (int i = 0; i != function.getFunctionCount(); ++i) {            collectFunctions_r(function.getFunction(i), array);        }    }    /**     * Clears all breakpoints.     */    public void clearAllBreakpoints() {        Enumeration e = urlToSourceInfo.elements();        while (e.hasMoreElements()) {            SourceInfo si = (SourceInfo)e.nextElement();            si.removeAllBreakpoints();        }    }    /**     * Called when a breakpoint has been hit.     */    private void handleBreakpointHit(StackFrame frame, Context cx) {        breakFlag = false;        interrupted(cx, frame, null);    }    /**     * Called when a script exception has been thrown.     */    private 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;            }        }    }    /**     * Returns the current ContextData object.     */    public ContextData currentContextData() {        return interruptedContextData;    }    /**     * Sets the action to perform to end interruption.     */    public void setReturnValue(int returnValue) {        synchronized (monitor) {            this.returnValue = returnValue;            monitor.notify();        }    }    /**     * Resumes execution of script.     */    public void go() {        synchronized (monitor) {            this.returnValue = GO;            monitor.notifyAll();        }    }    /**     * Evaluates the given script.     */    public 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;    }    /**     * Compiles the given script.     */    public void compileScript(String url, String text) {        DimIProxy action = new DimIProxy(this, IPROXY_COMPILE_SCRIPT);        action.url = url;        action.text = text;        action.withContext();    }    /**     * Evaluates the given script.     */    public void evalScript(final String url, final String text) {        DimIProxy action = new DimIProxy(this, IPROXY_EVAL_SCRIPT);        action.url = url;        action.text = text;        action.withContext();    }    /**     * Converts the given script object to a string.     */    public String objectToString(Object object) {        DimIProxy action = new DimIProxy(this, IPROXY_OBJECT_TO_STRING);        action.object = object;        action.withContext();        return action.stringResult;    }    /**     * Returns whether the given string is syntactically valid script.     */    public boolean stringIsCompilableUnit(String str) {        DimIProxy action = new DimIProxy(this, IPROXY_STRING_IS_COMPILABLE);        action.text = str;        action.withContext();        return action.booleanResult;    }    /**     * Returns the value of a property on the given script object.     */    public 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;    }    /**     * Returns an array of the property names on the given script object.     */    public Object[] getObjectIds(Object object) {        DimIProxy action = new DimIProxy(this, IPROXY_OBJECT_IDS);        action.object = object;        action.withContext();        return action.objectArrayResult;    }    /**     * Returns the value of a property on the given script object.     */    private 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;    }    /**     * Returns an array of the property names on the given script object.     */    private 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;    }    /**     * Interrupts script execution.     */    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 following 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();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -