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

📄 xmlobjectimpl.java

📁 這是一個javascript 的 interpreter是了解 web browser的好材料
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            case Id_length:            arity=0; s="length";            break;            case Id_localName:         arity=0; s="localName";         break;            case Id_name:              arity=0; s="name";              break;            case Id_namespace:         arity=1; s="namespace";         break;            case Id_namespaceDeclarations:                arity=0; s="namespaceDeclarations"; break;            case Id_nodeKind:          arity=0; s="nodeKind";          break;            case Id_normalize:         arity=0; s="normalize";         break;            case Id_parent:            arity=0; s="parent";            break;            case Id_prependChild:      arity=1; s="prependChild";      break;            case Id_processingInstructions:                arity=1; s="processingInstructions"; break;            case Id_propertyIsEnumerable:                arity=1; s="propertyIsEnumerable"; break;            case Id_removeNamespace:   arity=1; s="removeNamespace";   break;            case Id_replace:           arity=2; s="replace";           break;            case Id_setChildren:       arity=1; s="setChildren";       break;            case Id_setLocalName:      arity=1; s="setLocalName";      break;            case Id_setName:           arity=1; s="setName";           break;            case Id_setNamespace:      arity=1; s="setNamespace";      break;            case Id_text:              arity=0; s="text";              break;            case Id_toString:          arity=0; s="toString";          break;            case Id_toXMLString:       arity=1; s="toXMLString";       break;            case Id_valueOf:           arity=0; s="valueOf";           break;            default: throw new IllegalArgumentException(String.valueOf(id));        }        initPrototypeMethod(XMLOBJECT_TAG, id, s, arity);    }    private Object[] toObjectArray(Object[] typed) {        Object[] rv = new Object[typed.length];        for (int i=0; i<rv.length; i++) {            rv[i] = typed[i];        }        return rv;    }    private void xmlMethodNotFound(Object object, String name) {        throw ScriptRuntime.notFunctionError(object, name);    }    public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope, Scriptable thisObj, Object[] args) {        if (!f.hasTag(XMLOBJECT_TAG)) {            return super.execIdCall(f, cx, scope, thisObj, args);        }        int id = f.methodId();        if (id == Id_constructor) {            return jsConstructor(cx, thisObj == null, args);        }        // All (XML|XMLList).prototype methods require thisObj to be XML        if (!(thisObj instanceof XMLObjectImpl))            throw incompatibleCallError(f);        XMLObjectImpl realThis = (XMLObjectImpl)thisObj;        XML xml = realThis.getXML();        switch (id) {            case Id_appendChild: {                if (xml == null) xmlMethodNotFound(realThis, "appendChild");                return xml.appendChild(arg(args, 0));            }            case Id_addNamespace: {                if (xml == null) xmlMethodNotFound(realThis, "addNamespace");                Namespace ns = lib.castToNamespace(cx, arg(args, 0));                return xml.addNamespace(ns);            }            case Id_childIndex: {                if (xml == null) xmlMethodNotFound(realThis, "childIndex");                return ScriptRuntime.wrapInt(xml.childIndex());            }            case Id_inScopeNamespaces: {                if (xml == null) xmlMethodNotFound(realThis, "inScopeNamespaces");                return cx.newArray(scope, toObjectArray(xml.inScopeNamespaces()));            }            case Id_insertChildAfter: {                if (xml == null) xmlMethodNotFound(realThis, "insertChildAfter");                Object arg0 = arg(args, 0);                if (arg0 == null || arg0 instanceof XML) {                    return xml.insertChildAfter((XML)arg0, arg(args, 1));                }                return Undefined.instance;            }            case Id_insertChildBefore: {                if (xml == null) xmlMethodNotFound(realThis, "insertChildBefore");                Object arg0 = arg(args, 0);                if (arg0 == null || arg0 instanceof XML) {                    return xml.insertChildBefore((XML)arg0, arg(args, 1));                }                return Undefined.instance;            }            case Id_localName: {                if (xml == null) xmlMethodNotFound(realThis, "localName");                return xml.localName();            }            case Id_name: {                if (xml == null) xmlMethodNotFound(realThis, "name");                return xml.name();            }            case Id_namespace: {                if (xml == null) xmlMethodNotFound(realThis, "namespace");                String prefix = (args.length > 0) ? ScriptRuntime.toString(args[0]) : null;                Namespace rv = xml.namespace(prefix);                if (rv == null) {                    return Undefined.instance;                } else {                    return rv;                }            }            case Id_namespaceDeclarations: {                if (xml == null) xmlMethodNotFound(realThis, "namespaceDeclarations");                Namespace[] array = xml.namespaceDeclarations();                return cx.newArray(scope, toObjectArray(array));            }            case Id_nodeKind: {                if (xml == null) xmlMethodNotFound(realThis, "nodeKind");                return xml.nodeKind();            }            case Id_prependChild: {                if (xml == null) xmlMethodNotFound(realThis, "prependChild");                return xml.prependChild(arg(args, 0));            }            case Id_removeNamespace: {                if (xml == null) xmlMethodNotFound(realThis, "removeNamespace");                Namespace ns = lib.castToNamespace(cx, arg(args, 0));                return xml.removeNamespace(ns);            }            case Id_replace: {                if (xml == null) xmlMethodNotFound(realThis, "replace");                XMLName xmlName = lib.toXMLNameOrIndex(cx, arg(args, 0));                Object arg1 = arg(args, 1);                if (xmlName == null) {                    //    I refuse to believe that this number will exceed 2^31                    int index = (int)ScriptRuntime.lastUint32Result(cx);                    return xml.replace(index, arg1);                } else {                    return xml.replace(xmlName, arg1);                }            }            case Id_setChildren: {                if (xml == null) xmlMethodNotFound(realThis, "setChildren");                return xml.setChildren(arg(args, 0));            }            case Id_setLocalName: {                if (xml == null) xmlMethodNotFound(realThis, "setLocalName");                String localName;                Object arg = arg(args, 0);                if (arg instanceof QName) {                    localName = ((QName)arg).localName();                } else {                    localName = ScriptRuntime.toString(arg);                }                xml.setLocalName(localName);                return Undefined.instance;            }            case Id_setName: {                if (xml == null) xmlMethodNotFound(realThis, "setName");                Object arg = (args.length != 0) ? args[0] : Undefined.instance;                QName qname = lib.constructQName(cx, arg);                xml.setName(qname);                return Undefined.instance;            }            case Id_setNamespace: {                if (xml == null) xmlMethodNotFound(realThis, "setNamespace");                Namespace ns = lib.castToNamespace(cx, arg(args, 0));                xml.setNamespace(ns);                return Undefined.instance;            }            case Id_attribute: {                XMLName xmlName = XMLName.create( lib.toNodeQName(cx, arg(args, 0), true), true, false );                return realThis.getMatches(xmlName);            }            case Id_attributes:                return realThis.getMatches(XMLName.create(XmlNode.QName.create(null, null), true, false));            case Id_child: {                XMLName xmlName = lib.toXMLNameOrIndex(cx, arg(args, 0));                if (xmlName == null) {                    //    Two billion or so is a fine upper limit, so we cast to int                    int index = (int)ScriptRuntime.lastUint32Result(cx);                    return realThis.child(index);                } else {                    return realThis.child(xmlName);                }            }            case Id_children:                return realThis.children();            case Id_comments:                return realThis.comments();            case Id_contains:                return ScriptRuntime.wrapBoolean(                    realThis.contains(arg(args, 0)));            case Id_copy:                return realThis.copy();            case Id_descendants: {                XmlNode.QName qname = (args.length == 0) ? XmlNode.QName.create(null, null) : lib.toNodeQName(cx, args[0], false);                return realThis.getMatches( XMLName.create(qname, false, true) );            }            case Id_elements: {                XMLName xmlName = (args.length == 0)                ? XMLName.formStar()                : lib.toXMLName(cx, args[0]);                return realThis.elements(xmlName);            }            case Id_hasOwnProperty: {                XMLName xmlName = lib.toXMLName(cx, arg(args, 0));                return ScriptRuntime.wrapBoolean(                    realThis.hasOwnProperty(xmlName));            }            case Id_hasComplexContent:                return ScriptRuntime.wrapBoolean(realThis.hasComplexContent());            case Id_hasSimpleContent:                return ScriptRuntime.wrapBoolean(realThis.hasSimpleContent());            case Id_length:                return ScriptRuntime.wrapInt(realThis.length());            case Id_normalize:                realThis.normalize();                return Undefined.instance;            case Id_parent:                return realThis.parent();            case Id_processingInstructions: {                XMLName xmlName = (args.length > 0)                ? lib.toXMLName(cx, args[0])                : XMLName.formStar();                return realThis.processingInstructions(xmlName);            }            case Id_propertyIsEnumerable: {                return ScriptRuntime.wrapBoolean(                    realThis.propertyIsEnumerable(arg(args, 0)));            }            case Id_text:                return realThis.text();            case Id_toString:                return realThis.toString();            case Id_toXMLString: {                return realThis.toXMLString();            }            case Id_valueOf:                return realThis.valueOf();        }        throw new IllegalArgumentException(String.valueOf(id));    }    private static Object arg(Object[] args, int i) {        return (i < args.length) ? args[i] : Undefined.instance;    }    final XML newTextElementXML(XmlNode reference, XmlNode.QName qname, String value) {        return lib.newTextElementXML(reference, qname, value);    }    /** @deprecated Hopefully this can be replaced with ecmaToXml below. */    final XML newXMLFromJs(Object inputObject) {        return lib.newXMLFromJs(inputObject);    }    final XML ecmaToXml(Object object) {        return lib.ecmaToXml(object);    }    final String ecmaEscapeAttributeValue(String s) {        //    TODO    Check this        String quoted = lib.escapeAttributeValue(s);        return quoted.substring(1, quoted.length() - 1);    }    final XML createEmptyXML() {        return newXML(XmlNode.createEmpty(getProcessor()));    }}

⌨️ 快捷键说明

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