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

📄 dim.java

📁 java中比较著名的js引擎当属mozilla开源的rhino
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
         * Information about the function.         */        private FunctionSource fsource;        /**         * Array of breakpoint state for each source line.         */        private boolean[] breakpoints;        /**         * Current line number.         */        private int lineNumber;        /**         * Creates a new StackFrame.         */        private StackFrame(Context cx, Dim dim, FunctionSource fsource) {            this.dim = dim;            this.contextData = ContextData.get(cx);            this.fsource = fsource;            this.breakpoints = fsource.sourceInfo().breakpoints;            this.lineNumber = fsource.firstLine();        }        /**         * Called when the stack frame is entered.         */        public void onEnter(Context cx, Scriptable scope,                            Scriptable thisObj, Object[] args) {            contextData.pushFrame(this);            this.scope = scope;            this.thisObj = thisObj;            if (dim.breakOnEnter) {                dim.handleBreakpointHit(this, cx);            }        }        /**         * Called when the current position has changed.         */        public void onLineChange(Context cx, int lineno) {            this.lineNumber = lineno;            if (!breakpoints[lineno] && !dim.breakFlag) {                boolean lineBreak = contextData.breakNextLine;                if (lineBreak && contextData.stopAtFrameDepth >= 0) {                    lineBreak = (contextData.frameCount()                                 <= contextData.stopAtFrameDepth);                }                if (!lineBreak) {                    return;                }                contextData.stopAtFrameDepth = -1;                contextData.breakNextLine = false;            }            dim.handleBreakpointHit(this, cx);        }        /**         * Called when an exception has been thrown.         */        public void onExceptionThrown(Context cx, Throwable exception) {            dim.handleExceptionThrown(cx, exception, this);        }        /**         * Called when the stack frame has been left.         */        public void onExit(Context cx, boolean byThrow,                           Object resultOrException) {            if (dim.breakOnReturn && !byThrow) {                dim.handleBreakpointHit(this, cx);            }            contextData.popFrame();        }        /**         * Returns the SourceInfo object for the function.         */        public SourceInfo sourceInfo() {            return fsource.sourceInfo();        }        /**         * Returns the ContextData object for the Context.         */        public ContextData contextData() {            return contextData;        }        /**         * Returns the scope object for this frame.         */        public Object scope() {            return scope;        }        /**         * Returns the 'this' object for this frame.         */        public Object thisObj() {            return thisObj;        }        /**         * Returns the source URL.         */        public String getUrl() {            return fsource.sourceInfo().url();        }        /**         * Returns the current line number.         */        public int getLineNumber() {            return lineNumber;        }    }    /**     * Class to store information about a function.     */    public static class FunctionSource {        /**         * Information about the source of the function.         */        private SourceInfo sourceInfo;        /**         * Line number of the first line of the function.         */        private int firstLine;        /**         * The function name.         */        private String name;        /**         * Creates a new FunctionSource.         */        private FunctionSource(SourceInfo sourceInfo, int firstLine,                                 String name) {            if (name == null) throw new IllegalArgumentException();            this.sourceInfo = sourceInfo;            this.firstLine = firstLine;            this.name = name;        }        /**         * Returns the SourceInfo object that describes the source of the         * function.         */        public SourceInfo sourceInfo() {            return sourceInfo;        }        /**         * Returns the line number of the first line of the function.         */        public int firstLine() {            return firstLine;        }        /**         * Returns the name of the function.         */        public String name() {            return name;        }    }    /**     * Class to store information about a script source.     */    public static class SourceInfo {        /**         * An empty array of booleans.         */        private static final boolean[] EMPTY_BOOLEAN_ARRAY = new boolean[0];        /**         * The script.         */        private String source;        /**         * The URL of the script.         */        private String url;        /**         * The line at which the script starts.         */        private int minLine;        /**         * Array indicating which lines can have breakpoints set.         */        private boolean[] breakableLines;                /**         * Array indicating whether a breakpoint is set on the line.         */        private boolean[] breakpoints;        /**         * Array of FunctionSource objects for the functions in the script.         */        private FunctionSource[] functionSources;        /**         * Creates a new SourceInfo object.         */        private SourceInfo(String source, DebuggableScript[] functions,                             String normilizedUrl) {            this.source = source;            this.url = normilizedUrl;            int N = functions.length;            int[][] lineArrays = new int[N][];            for (int i = 0; i != N; ++i) {                lineArrays[i] = functions[i].getLineNumbers();            }            int minAll = 0, maxAll = -1;            int[] firstLines = new int[N];            for (int i = 0; i != N; ++i) {                int[] lines = lineArrays[i];                if (lines == null || lines.length == 0) {                    firstLines[i] = -1;                } else {                    int min, max;                    min = max = lines[0];                    for (int j = 1; j != lines.length; ++j) {                        int line = lines[j];                        if (line < min) {                            min = line;                        } else if (line > max) {                            max = line;                        }                    }                    firstLines[i] = min;                    if (minAll > maxAll) {                        minAll = min;                        maxAll = max;                    } else {                        if (min < minAll) {                            minAll = min;                        }                        if (max > maxAll) {                            maxAll = max;                        }                    }                }            }            if (minAll > maxAll) {                // No line information                this.minLine = -1;                this.breakableLines = EMPTY_BOOLEAN_ARRAY;                this.breakpoints = EMPTY_BOOLEAN_ARRAY;            } else {                if (minAll < 0) {                    // Line numbers can not be negative                    throw new IllegalStateException(String.valueOf(minAll));                }                this.minLine = minAll;                int linesTop = maxAll + 1;                this.breakableLines = new boolean[linesTop];                this.breakpoints = new boolean[linesTop];                for (int i = 0; i != N; ++i) {                    int[] lines = lineArrays[i];                    if (lines != null && lines.length != 0) {                        for (int j = 0; j != lines.length; ++j) {                            int line = lines[j];                            this.breakableLines[line] = true;                        }                    }                }            }            this.functionSources = new FunctionSource[N];            for (int i = 0; i != N; ++i) {                String name = functions[i].getFunctionName();                if (name == null) {                    name = "";                }                this.functionSources[i]                    = new FunctionSource(this, firstLines[i], name);            }        }        /**         * Returns the source text.         */        public String source() {            return this.source;        }        /**         * Returns the script's origin URL.         */        public String url() {            return this.url;        }        /**         * Returns the number of FunctionSource objects stored in this object.         */        public int functionSourcesTop() {            return functionSources.length;        }        /**         * Returns the FunctionSource object with the given index.         */        public FunctionSource functionSource(int i) {            return functionSources[i];        }        /**         * Copies the breakpoints from the given SourceInfo object into this         * one.         */        private void copyBreakpointsFrom(SourceInfo old) {            int end = old.breakpoints.length;            if (end > this.breakpoints.length) {                end = this.breakpoints.length;            }            for (int line = 0; line != end; ++line) {                if (old.breakpoints[line]) {                    this.breakpoints[line] = true;                }            }        }        /**         * Returns whether the given line number can have a breakpoint set on         * it.         */        public boolean breakableLine(int line) {            return (line < this.breakableLines.length)                   && this.breakableLines[line];        }        /**         * Returns whether there is a breakpoint set on the given line.         */        public boolean breakpoint(int line) {            if (!breakableLine(line)) {                throw new IllegalArgumentException(String.valueOf(line));            }            return line < this.breakpoints.length && this.breakpoints[line];        }        /**         * Sets or clears the breakpoint flag for the given line.         */        public boolean breakpoint(int line, boolean value) {            if (!breakableLine(line)) {                throw new IllegalArgumentException(String.valueOf(line));            }            boolean changed;            synchronized (breakpoints) {                if (breakpoints[line] != value) {                    breakpoints[line] = value;                    changed = true;                } else {                    changed = false;                }            }            return changed;        }        /**         * Removes all breakpoints from the script.         */        public void removeAllBreakpoints() {            synchronized (breakpoints) {                for (int line = 0; line != breakpoints.length; ++line) {                    breakpoints[line] = false;                }            }        }    }}

⌨️ 快捷键说明

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