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

📄 scriptruntime.java

📁 java中比较著名的js引擎当属mozilla开源的rhino
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                    (oldIndex > (Integer.MIN_VALUE / 10) ||                     (oldIndex == (Integer.MIN_VALUE / 10) &&                      c <= (negate ? -(Integer.MIN_VALUE % 10)                                   : (Integer.MAX_VALUE % 10)))))                {                    return 0xFFFFFFFFL & (negate ? index : -index);                }            }        }        return -1L;    }    /**     * If str is a decimal presentation of Uint32 value, return it as long.     * Othewise return -1L;     */    public static long testUint32String(String str)    {        // The length of the decimal string representation of        //  UINT32_MAX_VALUE, 4294967296        final int MAX_VALUE_LENGTH = 10;        int len = str.length();        if (1 <= len && len <= MAX_VALUE_LENGTH) {            int c = str.charAt(0);            c -= '0';            if (c == 0) {                // Note that 00,01 etc. are not valid Uint32 presentations                return (len == 1) ? 0L : -1L;            }            if (1 <= c && c <= 9) {                long v = c;                for (int i = 1; i != len; ++i) {                    c = str.charAt(i) - '0';                    if (!(0 <= c && c <= 9)) {                        return -1;                    }                    v = 10 * v + c;                }                // Check for overflow                if ((v >>> 32) == 0) {                    return v;                }            }        }        return -1;    }    /**     * If s represents index, then return index value wrapped as Integer     * and othewise return s.     */    static Object getIndexObject(String s)    {        long indexTest = indexFromString(s);        if (indexTest >= 0) {            return new Integer((int)indexTest);        }        return s;    }    /**     * If d is exact int value, return its value wrapped as Integer     * and othewise return d converted to String.     */    static Object getIndexObject(double d)    {        int i = (int)d;        if ((double)i == d) {            return new Integer((int)i);        }        return toString(d);    }    /**     * If toString(id) is a decimal presentation of int32 value, then id     * is index. In this case return null and make the index available     * as ScriptRuntime.lastIndexResult(cx). Otherwise return toString(id).     */    static String toStringIdOrIndex(Context cx, Object id)    {        if (id instanceof Number) {            double d = ((Number)id).doubleValue();            int index = (int)d;            if (((double)index) == d) {                storeIndexResult(cx, index);                return null;            }            return toString(id);        } else {            String s;            if (id instanceof String) {                s = (String)id;            } else {                s = toString(id);            }            long indexTest = indexFromString(s);            if (indexTest >= 0) {                storeIndexResult(cx, (int)indexTest);                return null;            }            return s;        }    }    /**     * Call obj.[[Get]](id)     */    public static Object getObjectElem(Object obj, Object elem, Context cx)    {        Scriptable sobj = toObjectOrNull(cx, obj);        if (sobj == null) {            throw undefReadError(obj, elem);        }        return getObjectElem(sobj, elem, cx);    }    public static Object getObjectElem(Scriptable obj, Object elem,                                       Context cx)    {        if (obj instanceof XMLObject) {            XMLObject xmlObject = (XMLObject)obj;            return xmlObject.ecmaGet(cx, elem);        }        Object result;        String s = toStringIdOrIndex(cx, elem);        if (s == null) {            int index = lastIndexResult(cx);            result = ScriptableObject.getProperty(obj, index);        } else {            result = ScriptableObject.getProperty(obj, s);        }        if (result == Scriptable.NOT_FOUND) {            result = Undefined.instance;        }        return result;    }    /**     * Version of getObjectElem when elem is a valid JS identifier name.     */    public static Object getObjectProp(Object obj, String property,                                       Context cx)    {        Scriptable sobj = toObjectOrNull(cx, obj);        if (sobj == null) {            throw undefReadError(obj, property);        }        return getObjectProp(sobj, property, cx);    }    public static Object getObjectProp(Scriptable obj, String property,                                       Context cx)    {        if (obj instanceof XMLObject) {            XMLObject xmlObject = (XMLObject)obj;            return xmlObject.ecmaGet(cx, property);        }        Object result = ScriptableObject.getProperty(obj, property);        if (result == Scriptable.NOT_FOUND) {            result = Undefined.instance;        }        return result;    }    /*     * A cheaper and less general version of the above for well-known argument     * types.     */    public static Object getObjectIndex(Object obj, double dblIndex,                                        Context cx)    {        Scriptable sobj = toObjectOrNull(cx, obj);        if (sobj == null) {            throw undefReadError(obj, toString(dblIndex));        }        int index = (int)dblIndex;        if ((double)index == dblIndex) {            return getObjectIndex(sobj, index, cx);        } else {            String s = toString(dblIndex);            return getObjectProp(sobj, s, cx);        }    }    public static Object getObjectIndex(Scriptable obj, int index,                                        Context cx)    {        if (obj instanceof XMLObject) {            XMLObject xmlObject = (XMLObject)obj;            return xmlObject.ecmaGet(cx, new Integer(index));        }        Object result = ScriptableObject.getProperty(obj, index);        if (result == Scriptable.NOT_FOUND) {            result = Undefined.instance;        }        return result;    }    /*     * Call obj.[[Put]](id, value)     */    public static Object setObjectElem(Object obj, Object elem, Object value,                                       Context cx)    {        Scriptable sobj = toObjectOrNull(cx, obj);        if (sobj == null) {            throw undefWriteError(obj, elem, value);        }        return setObjectElem(sobj, elem, value, cx);    }    public static Object setObjectElem(Scriptable obj, Object elem,                                       Object value, Context cx)    {        if (obj instanceof XMLObject) {            XMLObject xmlObject = (XMLObject)obj;            xmlObject.ecmaPut(cx, elem, value);            return value;        }        String s = toStringIdOrIndex(cx, elem);        if (s == null) {            int index = lastIndexResult(cx);            ScriptableObject.putProperty(obj, index, value);        } else {            ScriptableObject.putProperty(obj, s, value);        }        return value;    }    /**     * Version of setObjectElem when elem is a valid JS identifier name.     */    public static Object setObjectProp(Object obj, String property,                                       Object value, Context cx)    {        Scriptable sobj = toObjectOrNull(cx, obj);        if (sobj == null) {            throw undefWriteError(obj, property, value);        }        return setObjectProp(sobj, property, value, cx);    }    public static Object setObjectProp(Scriptable obj, String property,                                       Object value, Context cx)    {        if (obj instanceof XMLObject) {            XMLObject xmlObject = (XMLObject)obj;            xmlObject.ecmaPut(cx, property, value);        } else {            ScriptableObject.putProperty(obj, property, value);        }        return value;    }    /*     * A cheaper and less general version of the above for well-known argument     * types.     */    public static Object setObjectIndex(Object obj, double dblIndex,                                        Object value, Context cx)    {        Scriptable sobj = toObjectOrNull(cx, obj);        if (sobj == null) {            throw undefWriteError(obj, String.valueOf(dblIndex), value);        }        int index = (int)dblIndex;        if ((double)index == dblIndex) {            return setObjectIndex(sobj, index, value, cx);        } else {            String s = toString(dblIndex);            return setObjectProp(sobj, s, value, cx);        }    }    public static Object setObjectIndex(Scriptable obj, int index, Object value,                                        Context cx)    {        if (obj instanceof XMLObject) {            XMLObject xmlObject = (XMLObject)obj;            xmlObject.ecmaPut(cx, new Integer(index), value);        } else {            ScriptableObject.putProperty(obj, index, value);        }        return value;    }    public static boolean deleteObjectElem(Scriptable target, Object elem,                                           Context cx)    {        boolean result;        if (target instanceof XMLObject) {            XMLObject xmlObject = (XMLObject)target;            result = xmlObject.ecmaDelete(cx, elem);        } else {            String s = toStringIdOrIndex(cx, elem);            if (s == null) {                int index = lastIndexResult(cx);                result = ScriptableObject.deleteProperty(target, index);            } else {                result = ScriptableObject.deleteProperty(target, s);            }        }        return result;    }    public static boolean hasObjectElem(Scriptable target, Object elem,                                        Context cx)    {        boolean result;        if (target instanceof XMLObject) {            XMLObject xmlObject = (XMLObject)target;            result = xmlObject.ecmaHas(cx, elem);        } else {            String s = toStringIdOrIndex(cx, elem);            if (s == null) {                int index = lastIndexResult(cx);                result = ScriptableObject.hasProperty(target, index);            } else {                result = ScriptableObject.hasProperty(target, s);            }        }        return result;    }    public static Object refGet(Ref ref, Context cx)    {        return ref.get(cx);    }    public static Object refSet(Ref ref, Object value, Context cx)    {        return ref.set(cx, value);    }    public static Object refDel(Ref ref, Context cx)    {        return wrapBoolean(ref.delete(cx));    }    static boolean isSpecialProperty(String s)    {        return s.equals("__proto__") || s.equals("__parent__");    }    public static Ref specialRef(Object obj, String specialProperty,                                 Context cx)    {        return SpecialRef.createSpecial(cx, obj, specialProperty);    }    /**     * The delete operator     *     * See ECMA 11.4.1     *     * In ECMA 0.19, the description of the delete operator (11.4.1)     * assumes that the [[Delete]] method returns a value. However,     * the definition of the [[Delete]] operator (8.6.2.5) does not     * define a return value. Here we assume that the [[Delete]]     * method doesn't return a value.     */    public static Object delete(Object obj, Object id, Context cx)    {        Scriptable sobj = toObjectOrNull(cx, obj);        if (sobj == null) {            String idStr = (id == null) ? "null" : id.toString();            throw typeError2("msg.undef.prop.delete", toString(obj), idStr);        }        boolean result = deleteObjectElem(sobj, id, cx);        return wrapBoolean(result);    }    /**     * Looks up a name in the scope chain and returns its value.     */    public static Object name(Context cx, Scriptable scope, String name)

⌨️ 快捷键说明

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