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

📄 scriptruntime.java

📁 這是一個javascript 的 interpreter是了解 web browser的好材料
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                    return null;                }                break;            }            nsObject = scope.get(DEFAULT_NS_TAG, scope);            if (nsObject != Scriptable.NOT_FOUND) {                break;            }            scope = parent;        }        return nsObject;    }    public static Object getTopLevelProp(Scriptable scope, String id) {        scope = ScriptableObject.getTopLevelScope(scope);        return ScriptableObject.getProperty(scope, id);    }    static Function getExistingCtor(Context cx, Scriptable scope,                                    String constructorName)    {        Object ctorVal = ScriptableObject.getProperty(scope, constructorName);        if (ctorVal instanceof Function) {            return (Function)ctorVal;        }        if (ctorVal == Scriptable.NOT_FOUND) {            throw Context.reportRuntimeError1(                "msg.ctor.not.found", constructorName);        } else {            throw Context.reportRuntimeError1(                "msg.not.ctor", constructorName);        }    }    /**     * Return -1L if str is not an index or the index value as lower 32     * bits of the result.     */    private static long indexFromString(String str)    {        // The length of the decimal string representation of        //  Integer.MAX_VALUE, 2147483647        final int MAX_VALUE_LENGTH = 10;        int len = str.length();        if (len > 0) {            int i = 0;            boolean negate = false;            int c = str.charAt(0);            if (c == '-') {                if (len > 1) {                    c = str.charAt(1);                    i = 1;                    negate = true;                }            }            c -= '0';            if (0 <= c && c <= 9                && len <= (negate ? MAX_VALUE_LENGTH + 1 : MAX_VALUE_LENGTH))            {                // Use negative numbers to accumulate index to handle                // Integer.MIN_VALUE that is greater by 1 in absolute value                // then Integer.MAX_VALUE                int index = -c;                int oldIndex = 0;                i++;                if (index != 0) {                    // Note that 00, 01, 000 etc. are not indexes                    while (i != len && 0 <= (c = str.charAt(i) - '0') && c <= 9)                    {                        oldIndex = index;                        index = 10 * index - c;                        i++;                    }                }                // Make sure all characters were consumed and that it couldn't                // have overflowed.                if (i == len &&                    (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 (i == d) {            return new Integer(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 (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) {            // TODO: Change XMLObject to just use Scriptable interface            // to avoid paying cost of instanceof check on *every property            // lookup* !            XMLObject xmlObject = (XMLObject)obj;            return xmlObject.ecmaGet(cx, property);        }        Object result = ScriptableObject.getProperty(obj, property);        if (result == Scriptable.NOT_FOUND) {            if (cx.hasFeature(Context.FEATURE_STRICT_MODE)) {                Context.reportWarning(ScriptRuntime.getMessage1(                    "msg.ref.undefined.prop", property));            }            result = Undefined.instance;        }        return result;    }        public static Object getObjectPropNoWarn(Object obj, String property,                                             Context cx)    {        Scriptable sobj = toObjectOrNull(cx, obj);        if (sobj == null) {            throw undefReadError(obj, property);        }        if (obj instanceof XMLObject) {            // TODO: fix as mentioned in note in method above            getObjectProp(sobj, property, cx);        }        Object result = ScriptableObject.getProperty(sobj, property);        if (result == Scriptable.NOT_FOUND) {          return 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 (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 (index == dblIndex) {            return setObjectIndex(sobj, index, value, cx);

⌨️ 快捷键说明

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