public override object ExecIdCall(IdFunctionObject f, Context cx, Scriptable scope, Scriptable thisObj, object[] args)
{
if (!f.HasTag(XMLOBJECT_TAG))
{
return base.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 is Rhino.Xmlimpl.XMLObjectImpl))
{
throw IncompatibleCallError(f);
}
Rhino.Xmlimpl.XMLObjectImpl realThis = (Rhino.Xmlimpl.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 is 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 is 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;
}
goto case Id_namespaceDeclarations;
}
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);
}
goto case Id_setChildren;
}
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 is 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(Rhino.Xmlimpl.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);
}
goto case Id_children;
}
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:
{
Rhino.Xmlimpl.XmlNode.QName qname = (args.Length == 0) ? Rhino.Xmlimpl.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_toSource:
{
int indent = ScriptRuntime.ToInt32(args, 0);
return realThis.ToSource(indent);
}
case Id_toXMLString:
{
return realThis.ToXMLString();
}
case Id_valueOf:
{
return realThis.ValueOf();
}
}
throw new ArgumentException(id.ToString());
}