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

📄 context.java

📁 java中比较著名的js引擎当属mozilla开源的rhino
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     * Get the implementation version.     *     * <p>     * The implementation version is of the form     * <pre>     *    "<i>name langVer</i> <code>release</code> <i>relNum date</i>"     * </pre>     * where <i>name</i> is the name of the product, <i>langVer</i> is     * the language version, <i>relNum</i> is the release number, and     * <i>date</i> is the release date for that specific     * release in the form "yyyy mm dd".     *     * @return a string that encodes the product, language version, release     *         number, and date.     */    public final String getImplementationVersion()    {        // XXX Probably it would be better to embed this directly into source        // with special build preprocessing but that would require some ant        // tweaking and then replacing token in resource files was simpler        if (implementationVersion == null) {            implementationVersion                = ScriptRuntime.getMessage0("implementation.version");        }        return implementationVersion;    }    /**     * Get the current error reporter.     *     * @see org.mozilla.javascript.ErrorReporter     */    public final ErrorReporter getErrorReporter()    {        if (errorReporter == null) {            return DefaultErrorReporter.instance;        }        return errorReporter;    }    /**     * Change the current error reporter.     *     * @return the previous error reporter     * @see org.mozilla.javascript.ErrorReporter     */    public final ErrorReporter setErrorReporter(ErrorReporter reporter)    {        if (sealed) onSealedMutation();        if (reporter == null) throw new IllegalArgumentException();        ErrorReporter old = getErrorReporter();        if (reporter == old) {            return old;        }        Object listeners = propertyListeners;        if (listeners != null) {            firePropertyChangeImpl(listeners, errorReporterProperty,                                   old, reporter);        }        this.errorReporter = reporter;        return old;    }    /**     * Get the current locale.  Returns the default locale if none has     * been set.     *     * @see java.util.Locale     */    public final Locale getLocale()    {        if (locale == null)            locale = Locale.getDefault();        return locale;    }    /**     * Set the current locale.     *     * @see java.util.Locale     */    public final Locale setLocale(Locale loc)    {        if (sealed) onSealedMutation();        Locale result = locale;        locale = loc;        return result;    }    /**     * Register an object to receive notifications when a bound property     * has changed     * @see java.beans.PropertyChangeEvent     * @see #removePropertyChangeListener(java.beans.PropertyChangeListener)     * @param l the listener     */    public final void addPropertyChangeListener(PropertyChangeListener l)    {        if (sealed) onSealedMutation();        propertyListeners = Kit.addListener(propertyListeners, l);    }    /**     * Remove an object from the list of objects registered to receive     * notification of changes to a bounded property     * @see java.beans.PropertyChangeEvent     * @see #addPropertyChangeListener(java.beans.PropertyChangeListener)     * @param l the listener     */    public final void removePropertyChangeListener(PropertyChangeListener l)    {        if (sealed) onSealedMutation();        propertyListeners = Kit.removeListener(propertyListeners, l);    }    /**     * Notify any registered listeners that a bounded property has changed     * @see #addPropertyChangeListener(java.beans.PropertyChangeListener)     * @see #removePropertyChangeListener(java.beans.PropertyChangeListener)     * @see java.beans.PropertyChangeListener     * @see java.beans.PropertyChangeEvent     * @param  property  the bound property     * @param  oldValue  the old value     * @param  newVale   the new value     */    final void firePropertyChange(String property, Object oldValue,                                  Object newValue)    {        Object listeners = propertyListeners;        if (listeners != null) {            firePropertyChangeImpl(listeners, property, oldValue, newValue);        }    }    private void firePropertyChangeImpl(Object listeners, String property,                                        Object oldValue, Object newValue)    {        for (int i = 0; ; ++i) {            Object l = Kit.getListener(listeners, i);            if (l == null)                break;            if (l instanceof PropertyChangeListener) {                PropertyChangeListener pcl = (PropertyChangeListener)l;                pcl.propertyChange(new PropertyChangeEvent(                    this, property, oldValue, newValue));            }        }    }    /**     * Report a warning using the error reporter for the current thread.     *     * @param message the warning message to report     * @param sourceName a string describing the source, such as a filename     * @param lineno the starting line number     * @param lineSource the text of the line (may be null)     * @param lineOffset the offset into lineSource where problem was detected     * @see org.mozilla.javascript.ErrorReporter     */    public static void reportWarning(String message, String sourceName,                                     int lineno, String lineSource,                                     int lineOffset)    {        Context cx = Context.getContext();        cx.getErrorReporter().warning(message, sourceName, lineno,                                      lineSource, lineOffset);    }    /**     * Report a warning using the error reporter for the current thread.     *     * @param message the warning message to report     * @see org.mozilla.javascript.ErrorReporter     */    public static void reportWarning(String message)    {        int[] linep = { 0 };        String filename = getSourcePositionFromStack(linep);        Context.reportWarning(message, filename, linep[0], null, 0);    }    /**     * Report an error using the error reporter for the current thread.     *     * @param message the error message to report     * @param sourceName a string describing the source, such as a filename     * @param lineno the starting line number     * @param lineSource the text of the line (may be null)     * @param lineOffset the offset into lineSource where problem was detected     * @see org.mozilla.javascript.ErrorReporter     */    public static void reportError(String message, String sourceName,                                   int lineno, String lineSource,                                   int lineOffset)    {        Context cx = getCurrentContext();        if (cx != null) {            cx.getErrorReporter().error(message, sourceName, lineno,                                        lineSource, lineOffset);        } else {            throw new EvaluatorException(message, sourceName, lineno,                                         lineSource, lineOffset);        }    }    /**     * Report an error using the error reporter for the current thread.     *     * @param message the error message to report     * @see org.mozilla.javascript.ErrorReporter     */    public static void reportError(String message)    {        int[] linep = { 0 };        String filename = getSourcePositionFromStack(linep);        Context.reportError(message, filename, linep[0], null, 0);    }    /**     * Report a runtime error using the error reporter for the current thread.     *     * @param message the error message to report     * @param sourceName a string describing the source, such as a filename     * @param lineno the starting line number     * @param lineSource the text of the line (may be null)     * @param lineOffset the offset into lineSource where problem was detected     * @return a runtime exception that will be thrown to terminate the     *         execution of the script     * @see org.mozilla.javascript.ErrorReporter     */    public static EvaluatorException reportRuntimeError(String message,                                                        String sourceName,                                                        int lineno,                                                        String lineSource,                                                        int lineOffset)    {        Context cx = getCurrentContext();        if (cx != null) {            return cx.getErrorReporter().                            runtimeError(message, sourceName, lineno,                                         lineSource, lineOffset);        } else {            throw new EvaluatorException(message, sourceName, lineno,                                         lineSource, lineOffset);        }    }    static EvaluatorException reportRuntimeError0(String messageId)    {        String msg = ScriptRuntime.getMessage0(messageId);        return reportRuntimeError(msg);    }    static EvaluatorException reportRuntimeError1(String messageId,                                                  Object arg1)    {        String msg = ScriptRuntime.getMessage1(messageId, arg1);        return reportRuntimeError(msg);    }    static EvaluatorException reportRuntimeError2(String messageId,                                                  Object arg1, Object arg2)    {        String msg = ScriptRuntime.getMessage2(messageId, arg1, arg2);        return reportRuntimeError(msg);    }    static EvaluatorException reportRuntimeError3(String messageId,                                                  Object arg1, Object arg2,                                                  Object arg3)    {        String msg = ScriptRuntime.getMessage3(messageId, arg1, arg2, arg3);        return reportRuntimeError(msg);    }    static EvaluatorException reportRuntimeError4(String messageId,                                                  Object arg1, Object arg2,                                                  Object arg3, Object arg4)    {        String msg            = ScriptRuntime.getMessage4(messageId, arg1, arg2, arg3, arg4);        return reportRuntimeError(msg);    }    /**     * Report a runtime error using the error reporter for the current thread.     *     * @param message the error message to report     * @see org.mozilla.javascript.ErrorReporter     */    public static EvaluatorException reportRuntimeError(String message)    {        int[] linep = { 0 };        String filename = getSourcePositionFromStack(linep);        return Context.reportRuntimeError(message, filename, linep[0], null, 0);    }    /**     * Initialize the standard objects.     *     * Creates instances of the standard objects and their constructors     * (Object, String, Number, Date, etc.), setting up 'scope' to act     * as a global object as in ECMA 15.1.<p>     *     * This method must be called to initialize a scope before scripts     * can be evaluated in that scope.<p>     *     * This method does not affect the Context it is called upon.     *     * @return the initialized scope     */    public final ScriptableObject initStandardObjects()    {        return initStandardObjects(null, false);    }    /**     * Initialize the standard objects.     *     * Creates instances of the standard objects and their constructors     * (Object, String, Number, Date, etc.), setting up 'scope' to act     * as a global object as in ECMA 15.1.<p>     *     * This method must be called to initialize a scope before scripts     * can be evaluated in that scope.<p>     *     * This method does not affect the Context it is called upon.     *     * @param scope the scope to initialize, or null, in which case a new     *        object will be created to serve as the scope     * @return the initialized scope. The method returns the value of the scope     *         argument if it is not null or newly allocated scope object which     *         is an instance {@link ScriptableObject}.     */    public final Scriptable initStandardObjects(ScriptableObject scope)    {        return initStandardObjects(scope, false);    }    /**     * Initialize the standard objects.     *     * Creates instances of the standard objects and their constructors     * (Object, String, Number, Date, etc.), setting up 'scope' to act     * as a global object as in ECMA 15.1.<p>     *     * This method must be called to initialize a scope before scripts     * can be evaluated in that scope.<p>     *     * This method does not affect the Context it is called upon.<p>     *     * This form of the method also allows for creating "sealed" standard     * objects. An object that is sealed cannot have properties added, changed,     * or removed. This is useful to create a "superglobal" that can be shared     * among several top-level objects. Note that sealing is not allowed in     * the current ECMA/ISO language specification, but is likely for     * the next version.     *     * @param scope the scope to initialize, or null, in which case a new     *        object will be created to serve as the scope     * @param sealed whether or not to create sealed standard objects that     *        cannot be modified.

⌨️ 快捷键说明

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