private string NodeKind() { if (Length() == 1) { return((m_Nodes [0] as XML).NodeKind()); } throw ScriptRuntime.TypeError("The nodeKind method works only on lists containing one item"); }
private object Namespace(string prefix) { if (Length() == 1) { return((m_Nodes [0] as XML).Namespace(prefix)); } throw ScriptRuntime.TypeError("The namespace method works only on lists containing one item"); }
private XML DelegateTo(string methodName) { if (Length() != 1) { throw ScriptRuntime.TypeError("The " + methodName + " method works only on lists containing one item"); } return(this [0]); }
public static Namespace Parse(XMLLib lib, Context cx, Object prefixValue, Object uriValue) { String prefix; String uri; if (uriValue is QName) { QName qname = (QName)uriValue; uri = qname.Uri; if (uri == null) { uri = qname.ToString(); } } else { uri = ScriptConvert.ToString(uriValue); } if (uri.Length == 0) { if (prefixValue == Undefined.Value) { prefix = ""; } else { prefix = ScriptConvert.ToString(prefixValue); if (prefix.Length != 0) { throw ScriptRuntime.TypeError( "Illegal prefix '" + prefix + "' for 'no namespace'."); } } } else if (prefixValue == Undefined.Value) { prefix = ""; } else if (!lib.IsXMLName(cx, prefixValue)) { prefix = ""; } else { prefix = ScriptConvert.ToString(prefixValue); } return(new Namespace(lib, prefix, uri)); }
internal static EcmaScriptError BadXMLName(object value) { String msg; if (CliHelper.IsNumber(value)) { msg = "Can not construct XML name from number: "; } else if (value is Boolean) { msg = "Can not construct XML name from boolean: "; } else if (value == Undefined.Value || value == null) { msg = "Can not construct XML name from "; } else { throw new ArgumentException(value.ToString()); } return(ScriptRuntime.TypeError(msg + ScriptConvert.ToString(value))); }
public XMLList(XMLLib lib, object inputObject) : this(lib) { string frag; if (inputObject == null || inputObject is Undefined) { frag = ""; } else if (inputObject is XML) { XML xml = (XML)inputObject; Add(xml); } else if (inputObject is XMLList) { XMLList xmll = (XMLList)inputObject; AddRange(xmll); } else { frag = ScriptConvert.ToString(inputObject).Trim(); if (!frag.StartsWith("<>")) { frag = "<>" + frag + "</>"; } frag = "<fragment>" + frag.Substring(2); if (!frag.EndsWith("</>")) { throw ScriptRuntime.TypeError("XML with anonymous tag missing end anonymous tag"); } frag = frag.Substring(0, frag.Length - 3) + "</fragment>"; XML orgXML = XML.CreateFromJS(lib, frag); // Now orphan the children and add them to our XMLList. XMLList children = (XMLList)orgXML.Children(); AddRange(children); } }
protected internal override void PutXMLProperty(XMLName name, object value) { if (isPrototype) { return; } if (value == null) { value = "null"; } else if (value is Undefined) { value = "undefined"; } if (Length() > 1) { throw ScriptRuntime.TypeError("Assignment to lists with more that one item is not supported"); } throw new NotImplementedException(); }
public override object ExecIdCall(IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, object [] args) { if (!f.HasTag(OBJECT_TAG)) { return(base.ExecIdCall(f, cx, scope, thisObj, args)); } int id = f.MethodId; switch (id) { case Id_constructor: { if (thisObj != null) { // BaseFunction.construct will set up parent, proto return(f.Construct(cx, scope, args)); } if (args.Length == 0 || args [0] == null || args [0] == Undefined.Value) { return(new BuiltinObject()); } return(ScriptConvert.ToObject(cx, scope, args [0])); } case Id_toLocaleString: // For now just alias toString case Id_toString: { if (cx.HasFeature(Context.Features.ToStringAsSource)) { string s = ScriptRuntime.defaultObjectToSource(cx, scope, thisObj, args); int L = s.Length; if (L != 0 && s [0] == '(' && s [L - 1] == ')') { // Strip () that surrounds toSource s = s.Substring(1, (L - 1) - (1)); } return(s); } return(ScriptRuntime.DefaultObjectToString(thisObj)); } case Id_valueOf: return(thisObj); case Id_hasOwnProperty: { bool result; if (args.Length == 0) { result = false; } else { string s = ScriptRuntime.ToStringIdOrIndex(cx, args [0]); if (s == null) { int index = ScriptRuntime.lastIndexResult(cx); result = thisObj.Has(index, thisObj); } else { result = thisObj.Has(s, thisObj); } } return(result); } case Id_propertyIsEnumerable: { bool result; if (args.Length == 0) { result = false; } else { string s = ScriptRuntime.ToStringIdOrIndex(cx, args [0]); if (s == null) { int index = ScriptRuntime.lastIndexResult(cx); result = thisObj.Has(index, thisObj); if (result && thisObj is ScriptableObject) { ScriptableObject so = (ScriptableObject)thisObj; int attrs = so.GetAttributes(index); result = ((attrs & ScriptableObject.DONTENUM) == 0); } } else { result = thisObj.Has(s, thisObj); if (result && thisObj is ScriptableObject) { ScriptableObject so = (ScriptableObject)thisObj; int attrs = so.GetAttributes(s); result = ((attrs & ScriptableObject.DONTENUM) == 0); } } } return(result); } case Id_isPrototypeOf: { bool result = false; if (args.Length != 0 && args [0] is IScriptable) { IScriptable v = (IScriptable)args [0]; do { v = v.GetPrototype(); if (v == thisObj) { result = true; break; } }while (v != null); } return(result); } case Id_toSource: return(ScriptRuntime.defaultObjectToSource(cx, scope, thisObj, args)); case Id___lookupGetter__: case Id___lookupSetter__: { if (args.Length < 1) { return(Undefined.Value); } string name = ScriptRuntime.ToStringIdOrIndex(cx, args [0]); int index = (name != null) ? name.GetHashCode() : ScriptRuntime.lastIndexResult(cx); // TODO: delegate way up to prototypes? ScriptableObject so = (thisObj as ScriptableObject); if (so == null) { throw ScriptRuntime.TypeError("this is not a scriptable object."); } if (id == Id___lookupGetter__) { return(so.LookupGetter(name)); } else { return(so.LookupSetter(name)); } } case Id___defineGetter__: case Id___defineSetter__: { if (args.Length < 2 || args.Length > 0 && !(args [1] is ICallable)) { object badArg = (args.Length > 1 ? args [1] : Undefined.Value); throw ScriptRuntime.NotFunctionError(badArg); } string name = ScriptRuntime.ToStringIdOrIndex(cx, args [0]); int index = (name != null) ? name.GetHashCode() : ScriptRuntime.lastIndexResult(cx); // TODO: delegate way up to prototypes? ScriptableObject so = (thisObj as ScriptableObject); if (so == null) { throw ScriptRuntime.TypeError("this is not a scriptable object."); } ICallable getterOrSetter = (ICallable)args [1]; if (id == Id___defineGetter__) { if (name == null) { so.DefineGetter(index, getterOrSetter); } else { so.DefineGetter(name, getterOrSetter); } } else { if (name == null) { so.DefineSetter(index, getterOrSetter); } else { so.DefineSetter(name, getterOrSetter); } } return(Undefined.Value); break; } default: throw new ArgumentException(Convert.ToString(id)); } }