public override System.Object ExecIdCall(IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, System.Object [] args) { if (!f.HasTag (XMLCTOR_TAG)) { return base.ExecIdCall (f, cx, scope, thisObj, args); } int id = f.MethodId; switch (id) { case Id_defaultSettings: { lib.SetDefaultSettings (); IScriptable obj = cx.NewObject (scope); WriteSetting (obj); return obj; } case Id_settings: { IScriptable obj = cx.NewObject (scope); WriteSetting (obj); return obj; } case Id_setSettings: { if (args.Length == 0 || args [0] == null || args [0] == Undefined.Value) { lib.SetDefaultSettings (); } else if (args [0] is IScriptable) { ReadSettings ((IScriptable)args [0]); } return Undefined.Value; } } throw new System.ArgumentException (System.Convert.ToString (id)); }
public override object ExecIdCall(IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, object [] args) { int id = f.MethodId; switch (id) { case Id_print: for (int i = 0; i < args.Length; i++) { if (i > 0) Console.Out.Write (" "); Console.Out.Write (ScriptConvert.ToString (args [i])); } Console.Out.WriteLine (); return Undefined.Value; case Id_version: if (args.Length > 0) { if (CliHelper.IsNumber (args [0])) { int newVer = (int)ScriptConvert.ToNumber (args [0]); if (Context.IsValidLanguageVersion (newVer)) { cx.Version = Context.ToValidLanguageVersion (newVer); } } } return (int)cx.Version; case Id_options: StringBuilder sb = new StringBuilder (); if (cx.HasFeature (Context.Features.Strict)) sb.Append ("strict"); return sb.ToString (); case Id_gc: GC.Collect (); return Undefined.Value; } throw f.Unknown (); }
public override object ExecIdCall(IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, object [] args) { if (!f.HasTag (BOOLEAN_TAG)) { return base.ExecIdCall (f, cx, scope, thisObj, args); } int id = f.MethodId; if (id == Id_constructor) { bool b = ScriptConvert.ToBoolean (args, 0); if (thisObj == null) { return new BuiltinBoolean (b); } return b; } // The rest of Boolean.prototype methods require thisObj to be Boolean if (!(thisObj is BuiltinBoolean)) throw IncompatibleCallError (f); bool value = ((BuiltinBoolean)thisObj).booleanValue; switch (id) { case Id_toString: return value ? "true" : "false"; case Id_toSource: return value ? "(new Boolean(true))" : "(new Boolean(false))"; case Id_valueOf: return value; } throw new ArgumentException (Convert.ToString (id)); }
protected internal override void FillConstructorProperties (IdFunctionObject ctor) { AddIdFunctionProperty (ctor, DATE_TAG, ConstructorId_now, "now", 0); AddIdFunctionProperty (ctor, DATE_TAG, ConstructorId_parse, "parse", 1); AddIdFunctionProperty (ctor, DATE_TAG, ConstructorId_UTC, "UTC", 1); base.FillConstructorProperties (ctor); }
protected internal override void FillConstructorProperties(IdFunctionObject ctor) { const int attr = ScriptableObject.DONTENUM | ScriptableObject.PERMANENT | ScriptableObject.READONLY; ctor.DefineProperty("NaN", NaN, attr); ctor.DefineProperty("POSITIVE_INFINITY", POSITIVE_INFINITY, attr); ctor.DefineProperty("NEGATIVE_INFINITY", NEGATIVE_INFINITY, attr); ctor.DefineProperty("MAX_VALUE", MAX_VALUE, attr); ctor.DefineProperty("MIN_VALUE", MIN_VALUE, attr); base.FillConstructorProperties(ctor); }
protected internal override void FillConstructorProperties (IdFunctionObject ctor) { const int attr = ScriptableObject.DONTENUM | ScriptableObject.PERMANENT | ScriptableObject.READONLY; ctor.DefineProperty ("NaN", NaN, attr); ctor.DefineProperty ("POSITIVE_INFINITY", POSITIVE_INFINITY, attr); ctor.DefineProperty ("NEGATIVE_INFINITY", NEGATIVE_INFINITY, attr); ctor.DefineProperty ("MAX_VALUE", MAX_VALUE, attr); ctor.DefineProperty ("MIN_VALUE", MIN_VALUE, attr); base.FillConstructorProperties (ctor); }
internal static bool isEvalFunction(object functionObj) { if (functionObj is IdFunctionObject) { IdFunctionObject function = (IdFunctionObject)functionObj; if (function.HasTag(FTAG) && function.MethodId == Id_eval) { return(true); } } return(false); }
internal static void Init (IScriptable scope, bool zealed) { BuiltinWith obj = new BuiltinWith (); obj.ParentScope = scope; obj.SetPrototype (ScriptableObject.GetObjectPrototype (scope)); IdFunctionObject ctor = new IdFunctionObject (obj, FTAG, Id_constructor, "With", 0, scope); ctor.MarkAsConstructor (obj); if (zealed) { ctor.SealObject (); } ctor.ExportAsScopeProperty (); }
public override object ExecIdCall(IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, object [] args) { if (!f.HasTag(SCRIPT_TAG)) { return(base.ExecIdCall(f, cx, scope, thisObj, args)); } int id = f.MethodId; switch (id) { case Id_constructor: { string source = (args.Length == 0) ? "" : ScriptConvert.ToString(args [0]); IScript script = compile(cx, source); BuiltinScript nscript = new BuiltinScript(script); ScriptRuntime.setObjectProtoAndParent(nscript, scope); return(nscript); } case Id_toString: { if (thisObj is BuiltinFunction) { return(((BuiltinFunction)thisObj).Decompile(0, 0)); } BuiltinScript real = realThis(thisObj, f); IScript realScript = real.script; if (realScript == null) { return(""); } return(cx.DecompileScript(realScript, 0)); } case Id_exec: { throw Context.ReportRuntimeErrorById("msg.cant.call.indirect", "exec"); } case Id_compile: { BuiltinScript real = realThis(thisObj, f); string source = ScriptConvert.ToString(args, 0); real.script = compile(cx, source); return(real); } } throw new ArgumentException(Convert.ToString(id)); }
internal static void Init(IScriptable scope, bool zealed) { BuiltinWith obj = new BuiltinWith(); obj.ParentScope = scope; obj.SetPrototype(ScriptableObject.GetObjectPrototype(scope)); IdFunctionObject ctor = new IdFunctionObject(obj, FTAG, Id_constructor, "With", 0, scope); ctor.MarkAsConstructor(obj); if (zealed) { ctor.SealObject(); } ctor.ExportAsScopeProperty(); }
public override object ExecIdCall(IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, object [] args) { int id = f.MethodId; switch (id) { case Id_print: for (int i = 0; i < args.Length; i++) { if (i > 0) { Console.Out.Write(" "); } Console.Out.Write(ScriptConvert.ToString(args [i])); } Console.Out.WriteLine(); return(Undefined.Value); case Id_version: if (args.Length > 0) { if (CliHelper.IsNumber(args [0])) { int newVer = (int)ScriptConvert.ToNumber(args [0]); if (Context.IsValidLanguageVersion(newVer)) { cx.Version = Context.ToValidLanguageVersion(newVer); } } } return((int)cx.Version); case Id_options: StringBuilder sb = new StringBuilder(); if (cx.HasFeature(Context.Features.Strict)) { sb.Append("strict"); } return(sb.ToString()); case Id_gc: GC.Collect(); return(Undefined.Value); } throw f.Unknown(); }
public override object ExecIdCall(IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, object [] args) { if (!f.HasTag (ERROR_TAG)) { return base.ExecIdCall (f, cx, scope, thisObj, args); } int id = f.MethodId; switch (id) { case Id_constructor: return make (cx, scope, f, args); case Id_toString: return js_toString (thisObj); case Id_toSource: return js_toSource (cx, scope, thisObj); } throw new ArgumentException (Convert.ToString (id)); }
internal static BuiltinError make (Context cx, IScriptable scope, IdFunctionObject ctorObj, object [] args) { IScriptable proto = (IScriptable)(ctorObj.Get ("prototype", ctorObj)); BuiltinError obj = new BuiltinError (); obj.SetPrototype (proto); obj.ParentScope = scope; if (args.Length >= 1) { ScriptableObject.PutProperty (obj, "message", ScriptConvert.ToString (args [0])); if (args.Length >= 2) { ScriptableObject.PutProperty (obj, "fileName", args [1]); if (args.Length >= 3) { int line = ScriptConvert.ToInt32 (args [2]); ScriptableObject.PutProperty (obj, "lineNumber", (object)line); } } } return obj; }
public override object ExecIdCall(IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, object [] args) { if (!f.HasTag(CALL_TAG)) { return(base.ExecIdCall(f, cx, scope, thisObj, args)); } int id = f.MethodId; if (id == Id_constructor) { if (thisObj != null) { throw Context.ReportRuntimeErrorById("msg.only.from.new", "Call"); } ScriptRuntime.checkDeprecated(cx, "Call"); BuiltinCall result = new BuiltinCall(); result.SetPrototype(GetObjectPrototype(scope)); return(result); } throw new ArgumentException(Convert.ToString(id)); }
public override object ExecIdCall(IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, object [] args) { if (!f.HasTag(NAMESPACE_TAG)) { return(base.ExecIdCall(f, cx, scope, thisObj, args)); } int id = f.MethodId; switch (id) { case Id_constructor: return(jsConstructor(cx, (thisObj == null), args)); case Id_toString: return(realThis(thisObj, f).ToString()); case Id_toSource: return(realThis(thisObj, f).js_toSource()); } throw new System.ArgumentException(System.Convert.ToString(id)); }
public override object ExecIdCall(IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, object [] args) { if (!f.HasTag(BOOLEAN_TAG)) { return(base.ExecIdCall(f, cx, scope, thisObj, args)); } int id = f.MethodId; if (id == Id_constructor) { bool b = ScriptConvert.ToBoolean(args, 0); if (thisObj == null) { return(new BuiltinBoolean(b)); } return(b); } // The rest of Boolean.prototype methods require thisObj to be Boolean if (!(thisObj is BuiltinBoolean)) { throw IncompatibleCallError(f); } bool value = ((BuiltinBoolean)thisObj).booleanValue; switch (id) { case Id_toString: return(value ? "true" : "false"); case Id_toSource: return(value ? "(new Boolean(true))" : "(new Boolean(false))"); case Id_valueOf: return(value); } throw new ArgumentException(Convert.ToString(id)); }
public override object ExecIdCall(IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, object [] args) { if (!f.HasTag(ERROR_TAG)) { return(base.ExecIdCall(f, cx, scope, thisObj, args)); } int id = f.MethodId; switch (id) { case Id_constructor: return(make(cx, scope, f, args)); case Id_toString: return(js_toString(thisObj)); case Id_toSource: return(js_toSource(cx, scope, thisObj)); } throw new ArgumentException(Convert.ToString(id)); }
public override System.Object ExecIdCall(IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, System.Object [] args) { if (!f.HasTag(XMLCTOR_TAG)) { return(base.ExecIdCall(f, cx, scope, thisObj, args)); } int id = f.MethodId; switch (id) { case Id_defaultSettings: { lib.SetDefaultSettings(); IScriptable obj = cx.NewObject(scope); WriteSetting(obj); return(obj); } case Id_settings: { IScriptable obj = cx.NewObject(scope); WriteSetting(obj); return(obj); } case Id_setSettings: { if (args.Length == 0 || args [0] == null || args [0] == Undefined.Value) { lib.SetDefaultSettings(); } else if (args [0] is IScriptable) { ReadSettings((IScriptable)args [0]); } return(Undefined.Value); } } throw new System.ArgumentException(System.Convert.ToString(id)); }
internal static BuiltinError make(Context cx, IScriptable scope, IdFunctionObject ctorObj, object [] args) { IScriptable proto = (IScriptable)(ctorObj.Get("prototype", ctorObj)); BuiltinError obj = new BuiltinError(); obj.SetPrototype(proto); obj.ParentScope = scope; if (args.Length >= 1) { ScriptableObject.PutProperty(obj, "message", ScriptConvert.ToString(args [0])); if (args.Length >= 2) { ScriptableObject.PutProperty(obj, "fileName", args [1]); if (args.Length >= 3) { int line = ScriptConvert.ToInt32(args [2]); ScriptableObject.PutProperty(obj, "lineNumber", (object)line); } } } return(obj); }
public override object ExecIdCall (IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, object [] args) { if (!f.HasTag (SCRIPT_TAG)) { return base.ExecIdCall (f, cx, scope, thisObj, args); } int id = f.MethodId; switch (id) { case Id_constructor: { string source = (args.Length == 0) ? "" : ScriptConvert.ToString (args [0]); IScript script = compile (cx, source); BuiltinScript nscript = new BuiltinScript (script); ScriptRuntime.setObjectProtoAndParent (nscript, scope); return nscript; } case Id_toString: { if (thisObj is BuiltinFunction) return ((BuiltinFunction)thisObj).Decompile (0, 0); BuiltinScript real = realThis (thisObj, f); IScript realScript = real.script; if (realScript == null) { return ""; } return cx.DecompileScript (realScript, 0); } case Id_exec: { throw Context.ReportRuntimeErrorById ("msg.cant.call.indirect", "exec"); } case Id_compile: { BuiltinScript real = realThis (thisObj, f); string source = ScriptConvert.ToString (args, 0); real.script = compile (cx, source); return real; } } throw new ArgumentException (Convert.ToString (id)); }
private static BuiltinScript realThis (IScriptable thisObj, IdFunctionObject f) { if (!(thisObj is BuiltinScript)) throw IncompatibleCallError (f); return (BuiltinScript)thisObj; }
public override object ExecIdCall(IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, object [] args) { if (!f.HasTag (STRING_TAG)) { return base.ExecIdCall (f, cx, scope, thisObj, args); } int id = f.MethodId; switch (id) { case ConstructorId_fromCharCode: { int N = args.Length; if (N < 1) return ""; System.Text.StringBuilder sb = new System.Text.StringBuilder (N); for (int i = 0; i != N; ++i) { sb.Append (ScriptConvert.ToUint16 (args [i])); } return sb.ToString (); } case Id_constructor: { string s = (args.Length >= 1) ? ScriptConvert.ToString (args [0]) : ""; if (thisObj == null) { // new String(val) creates a new String object. return new BuiltinString (s); } // String(val) converts val to a string value. return s; } case Id_toString: case Id_valueOf: // ECMA 15.5.4.2: 'the toString function is not generic. return RealThis (thisObj, f).m_Value; case Id_toSource: { string s = RealThis (thisObj, f).m_Value; return "(new String(\"" + ScriptRuntime.escapeString (s) + "\"))"; } case Id_charAt: case Id_charCodeAt: { // See ECMA 15.5.4.[4,5] string target = ScriptConvert.ToString (thisObj); double pos = ScriptConvert.ToInteger (args, 0); if (pos < 0 || pos >= target.Length) { if (id == Id_charAt) return ""; else return double.NaN; } char c = target [(int)pos]; if (id == Id_charAt) return Convert.ToString (c); else return (int)c; } case Id_indexOf: return js_indexOf (ScriptConvert.ToString (thisObj), args); case Id_lastIndexOf: return js_lastIndexOf (ScriptConvert.ToString (thisObj), args); case Id_split: return ImplSplit (cx, scope, ScriptConvert.ToString (thisObj), args); case Id_substring: return js_substring (cx, ScriptConvert.ToString (thisObj), args); case Id_toLowerCase: // See ECMA 15.5.4.11 return ScriptConvert.ToString (thisObj).ToLower (); case Id_toUpperCase: // See ECMA 15.5.4.12 return ScriptConvert.ToString (thisObj).ToUpper (); case Id_substr: return js_substr (ScriptConvert.ToString (thisObj), args); case Id_concat: return js_concat (ScriptConvert.ToString (thisObj), args); case Id_slice: return js_slice (ScriptConvert.ToString (thisObj), args); case Id_bold: return Tagify (thisObj, "b", null, null); case Id_italics: return Tagify (thisObj, "i", null, null); case Id_fixed: return Tagify (thisObj, "tt", null, null); case Id_strike: return Tagify (thisObj, "strike", null, null); case Id_small: return Tagify (thisObj, "small", null, null); case Id_big: return Tagify (thisObj, "big", null, null); case Id_blink: return Tagify (thisObj, "blink", null, null); case Id_sup: return Tagify (thisObj, "sup", null, null); case Id_sub: return Tagify (thisObj, "sub", null, null); case Id_fontsize: return Tagify (thisObj, "font", "size", args); case Id_fontcolor: return Tagify (thisObj, "font", "color", args); case Id_link: return Tagify (thisObj, "a", "href", args); case Id_anchor: return Tagify (thisObj, "a", "name", args); case Id_equals: case Id_equalsIgnoreCase: { string s1 = ScriptConvert.ToString (thisObj); string s2 = ScriptConvert.ToString (args, 0); return (id == Id_equals) ? s1.Equals (s2) : s1.ToUpper ().Equals (s2.ToUpper ()); } case Id_match: case Id_search: case Id_replace: { RegExpActions actionType; if (id == Id_match) { actionType = EcmaScript.NET.RegExpActions.Match; } else if (id == Id_search) { actionType = EcmaScript.NET.RegExpActions.Search; } else { actionType = EcmaScript.NET.RegExpActions.Replace; } return cx.regExpProxy.Perform (cx, scope, thisObj, args, actionType); } } throw new ArgumentException (Convert.ToString (id)); }
public virtual object ExecIdCall(IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, object [] args) { if (f.HasTag (FTAG)) { if (f.MethodId == Id_constructor) { throw Context.ReportRuntimeErrorById ("msg.cant.call.indirect", "With"); } } throw f.Unknown (); }
public override object ExecIdCall(IdFunctionObject f, Context cx, IScriptable scope, IScriptable 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.prototype methods require thisObj to be XML if (!(thisObj is XMLList)) { throw IncompatibleCallError(f); } XMLList realThis = (XMLList)thisObj; XMLName xmlName; switch (id) { case Id_attribute: xmlName = XMLName.Parse(lib, cx, GetArgSafe(args, 0)); return(realThis.Attribute(xmlName)); case Id_attributes: return(realThis.Attributes()); case Id_child: xmlName = XMLName.Parse(lib, cx, GetArgSafe(args, 0)); if (xmlName == null) { long index = ScriptRuntime.lastUint32Result(cx); return(realThis.Child(index)); } else { return(realThis.Child(xmlName)); } case Id_children: return(realThis.Children()); case Id_contains: return(realThis.Contains(GetArgSafe(args, 0))); case Id_copy: return(realThis.Copy()); case Id_descendants: { xmlName = (args.Length == 0) ? XMLName.FormStar() : XMLName.Parse(lib, cx, GetArgSafe(args, 0)); return(realThis.Descendants(xmlName)); } case Id_hasOwnProperty: xmlName = XMLName.Parse(lib, cx, GetArgSafe(args, 0)); return(realThis.HasOwnProperty(xmlName)); case Id_hasComplexContent: return(realThis.HasComplexContent()); case Id_hasSimpleContent: return(realThis.HasSimpleContent()); case Id_length: return(realThis.Length()); case Id_normalize: realThis.Normalize(); return(Undefined.Value); case Id_parent: return(realThis.Parent()); case Id_processingInstructions: xmlName = (args.Length > 0) ? XMLName.Parse(lib, cx, args [0]) : XMLName.FormStar(); return(realThis.ProcessingInstructions(xmlName)); case Id_propertyIsEnumerable: { return(realThis.PropertyIsEnumerable(GetArgSafe(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); case Id_addNamespace: return(realThis.DelegateTo("addNamespace").AddNamespace(GetArgSafe(args, 0))); case Id_appendChild: return(realThis.DelegateTo("appendChild").AppendChild(GetArgSafe(args, 0))); case Id_childIndex: return(realThis.DelegateTo("childIndex").ChildIndex()); case Id_inScopeNamespaces: return(realThis.DelegateTo("inScopeNamespaces").InScopeNamespaces()); case Id_insertChildAfter: return(realThis.DelegateTo("insertChildAfter").InsertChildAfter(GetArgSafe(args, 0), GetArgSafe(args, 1))); case Id_insertChildBefore: return(realThis.DelegateTo("insertChildBefore").InsertChildBefore(GetArgSafe(args, 0), GetArgSafe(args, 1))); case Id_localName: return(realThis.DelegateTo("localName").LocalName()); case Id_name: return(realThis.DelegateTo("name").Name()); case Id_namespace: return(realThis.DelegateTo("namespace").Namespace(GetArgSafe(args, 0))); case Id_namespaceDeclarations: return(realThis.DelegateTo("namespaceDeclarations").NamespaceDeclarations()); case Id_nodeKind: return(realThis.DelegateTo("nodeKind").NodeKind()); case Id_prependChild: return(realThis.DelegateTo("prependChild").PrependChild(GetArgSafe(args, 0))); case Id_removeNamespace: return(realThis.DelegateTo("removeNamespace").RemoveNamespace(GetArgSafe(args, 0))); case Id_replace: return(realThis.DelegateTo("replace").Replace(GetArgSafe(args, 0), GetArgSafe(args, 1))); case Id_setChildren: return(realThis.DelegateTo("setChildren").SetChildren(GetArgSafe(args, 0))); case Id_setLocalName: realThis.DelegateTo("setLocalName").SetLocalName(GetArgSafe(args, 0)); return(Undefined.Value); case Id_setName: realThis.DelegateTo("setName").SetName(GetArgSafe(args, 0)); return(Undefined.Value); case Id_setNamespace: realThis.DelegateTo("setNamespace").SetNamespace(GetArgSafe(args, 0)); return(Undefined.Value); } throw new System.ArgumentException(System.Convert.ToString(id)); }
protected internal override void InitPrototypeId(int id) { System.String s; int arity; switch (id) { case Id_constructor: { IdFunctionObject ctor; if (this is XML) { ctor = new XMLCtor ((XML)this, XMLOBJECT_TAG, id, 1); } else { ctor = new IdFunctionObject (this, XMLOBJECT_TAG, id, 1); } InitPrototypeConstructor (ctor); return; } case Id_addNamespace: arity = 1; s = "addNamespace"; break; case Id_appendChild: arity = 1; s = "appendChild"; break; case Id_attribute: arity = 1; s = "attribute"; break; case Id_attributes: arity = 0; s = "attributes"; break; case Id_child: arity = 1; s = "child"; break; case Id_childIndex: arity = 0; s = "childIndex"; break; case Id_children: arity = 0; s = "children"; break; case Id_comments: arity = 0; s = "comments"; break; case Id_contains: arity = 1; s = "contains"; break; case Id_copy: arity = 0; s = "copy"; break; case Id_descendants: arity = 1; s = "descendants"; break; case Id_hasComplexContent: arity = 0; s = "hasComplexContent"; break; case Id_hasOwnProperty: arity = 1; s = "hasOwnProperty"; break; case Id_hasSimpleContent: arity = 0; s = "hasSimpleContent"; break; case Id_inScopeNamespaces: arity = 0; s = "inScopeNamespaces"; break; case Id_insertChildAfter: arity = 2; s = "insertChildAfter"; break; case Id_insertChildBefore: arity = 2; s = "insertChildBefore"; break; 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; case Id_domNode: arity = 0; s = "domNode"; break; case Id_domNodeList: arity = 0; s = "domNodeList"; break; case Id_xpath: arity = 0; s = "xpath"; break; default: throw new System.ArgumentException (System.Convert.ToString (id)); } InitPrototypeMethod (XMLOBJECT_TAG, id, s, arity); }
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)); } }
public virtual object ExecIdCall(IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, object [] args) { if (f.HasTag(FTAG)) { int methodId = f.MethodId; switch (methodId) { case Id_decodeURI: case Id_decodeURIComponent: { string str = ScriptConvert.ToString(args, 0); return(decode(str, methodId == Id_decodeURI)); } case Id_encodeURI: case Id_encodeURIComponent: { string str = ScriptConvert.ToString(args, 0); return(encode(str, methodId == Id_encodeURI)); } case Id_escape: return(js_escape(args)); case Id_eval: return(ImplEval(cx, scope, thisObj, args)); case Id_isFinite: { bool result; if (args.Length < 1) { result = false; } else { double d = ScriptConvert.ToNumber(args [0]); result = (!double.IsNaN(d) && d != System.Double.PositiveInfinity && d != System.Double.NegativeInfinity); } return(result); } case Id_isNaN: { // The global method isNaN, as per ECMA-262 15.1.2.6. bool result; if (args.Length < 1) { result = true; } else { double d = ScriptConvert.ToNumber(args [0]); result = (double.IsNaN(d)); } return(result); } case Id_isXMLName: { object name = (args.Length == 0) ? Undefined.Value : args [0]; XMLLib xmlLib = XMLLib.ExtractFromScope(scope); return(xmlLib.IsXMLName(cx, name)); } case Id_parseFloat: return(js_parseFloat(args)); case Id_parseInt: return(js_parseInt(args)); case Id_unescape: return(js_unescape(args)); case Id_uneval: { object value = (args.Length != 0) ? args [0] : Undefined.Value; return(ScriptRuntime.uneval(cx, scope, value)); } case Id_new_CommonError: // The implementation of all the ECMA error constructors // (SyntaxError, TypeError, etc.) return(BuiltinError.make(cx, scope, f, args)); } } throw f.Unknown(); }
public override object ExecIdCall(IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, object [] args) { if (!f.HasTag (CALL_TAG)) { return base.ExecIdCall (f, cx, scope, thisObj, args); } int id = f.MethodId; if (id == Id_constructor) { if (thisObj != null) { throw Context.ReportRuntimeErrorById ("msg.only.from.new", "Call"); } ScriptRuntime.checkDeprecated (cx, "Call"); BuiltinCall result = new BuiltinCall (); result.SetPrototype (GetObjectPrototype (scope)); return result; } throw new ArgumentException (Convert.ToString (id)); }
public override object ExecIdCall (IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, object [] args) { if (!f.HasTag (ARRAY_TAG)) { return base.ExecIdCall (f, cx, scope, thisObj, args); } int id = f.MethodId; switch (id) { case Id_constructor: { bool inNewExpr = (thisObj == null); if (!inNewExpr) { // IdFunctionObject.construct will set up parent, proto return f.Construct (cx, scope, args); } return ImplCtor (cx, scope, args); } case Id_toString: return toStringHelper (cx, scope, thisObj, cx.HasFeature (Context.Features.ToStringAsSource), false); case Id_toLocaleString: return toStringHelper (cx, scope, thisObj, false, true); case Id_toSource: return toStringHelper (cx, scope, thisObj, true, false); case Id_join: return ImplJoin (cx, thisObj, args); case Id_reverse: return ImplReverse (cx, thisObj, args); case Id_sort: return ImplSort (cx, scope, thisObj, args); case Id_push: return ImplPush (cx, thisObj, args); case Id_pop: return ImplPop (cx, thisObj, args); case Id_shift: return ImplShift (cx, thisObj, args); case Id_unshift: return ImplUnshift (cx, thisObj, args); case Id_splice: return ImplSplice (cx, scope, thisObj, args); case Id_concat: return ImplConcat (cx, scope, thisObj, args); case Id_slice: return ImplSlice (cx, thisObj, args); } throw new ArgumentException (Convert.ToString (id)); }
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)); } }
public override object ExecIdCall(IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, object [] args) { if (!f.HasTag(STRING_TAG)) { return(base.ExecIdCall(f, cx, scope, thisObj, args)); } int id = f.MethodId; switch (id) { case ConstructorId_fromCharCode: { int N = args.Length; if (N < 1) { return(""); } System.Text.StringBuilder sb = new System.Text.StringBuilder(N); for (int i = 0; i != N; ++i) { sb.Append(ScriptConvert.ToUint16(args [i])); } return(sb.ToString()); } case Id_constructor: { string s = (args.Length >= 1) ? ScriptConvert.ToString(args [0]) : ""; if (thisObj == null) { // new String(val) creates a new String object. return(new BuiltinString(s)); } // String(val) converts val to a string value. return(s); } case Id_toString: case Id_valueOf: // ECMA 15.5.4.2: 'the toString function is not generic. return(RealThis(thisObj, f).m_Value); case Id_toSource: { string s = RealThis(thisObj, f).m_Value; return("(new String(\"" + ScriptRuntime.escapeString(s) + "\"))"); } case Id_charAt: case Id_charCodeAt: { // See ECMA 15.5.4.[4,5] string target = ScriptConvert.ToString(thisObj); double pos = ScriptConvert.ToInteger(args, 0); if (pos < 0 || pos >= target.Length) { if (id == Id_charAt) { return(""); } else { return(double.NaN); } } char c = target [(int)pos]; if (id == Id_charAt) { return(Convert.ToString(c)); } else { return((int)c); } } case Id_indexOf: return(js_indexOf(ScriptConvert.ToString(thisObj), args)); case Id_lastIndexOf: return(js_lastIndexOf(ScriptConvert.ToString(thisObj), args)); case Id_split: return(ImplSplit(cx, scope, ScriptConvert.ToString(thisObj), args)); case Id_substring: return(js_substring(cx, ScriptConvert.ToString(thisObj), args)); case Id_toLowerCase: // See ECMA 15.5.4.11 return(ScriptConvert.ToString(thisObj).ToLower()); case Id_toUpperCase: // See ECMA 15.5.4.12 return(ScriptConvert.ToString(thisObj).ToUpper()); case Id_substr: return(js_substr(ScriptConvert.ToString(thisObj), args)); case Id_concat: return(js_concat(ScriptConvert.ToString(thisObj), args)); case Id_slice: return(js_slice(ScriptConvert.ToString(thisObj), args)); case Id_bold: return(Tagify(thisObj, "b", null, null)); case Id_italics: return(Tagify(thisObj, "i", null, null)); case Id_fixed: return(Tagify(thisObj, "tt", null, null)); case Id_strike: return(Tagify(thisObj, "strike", null, null)); case Id_small: return(Tagify(thisObj, "small", null, null)); case Id_big: return(Tagify(thisObj, "big", null, null)); case Id_blink: return(Tagify(thisObj, "blink", null, null)); case Id_sup: return(Tagify(thisObj, "sup", null, null)); case Id_sub: return(Tagify(thisObj, "sub", null, null)); case Id_fontsize: return(Tagify(thisObj, "font", "size", args)); case Id_fontcolor: return(Tagify(thisObj, "font", "color", args)); case Id_link: return(Tagify(thisObj, "a", "href", args)); case Id_anchor: return(Tagify(thisObj, "a", "name", args)); case Id_equals: case Id_equalsIgnoreCase: { string s1 = ScriptConvert.ToString(thisObj); string s2 = ScriptConvert.ToString(args, 0); return((id == Id_equals) ? s1.Equals(s2) : s1.ToUpper().Equals(s2.ToUpper())); } case Id_match: case Id_search: case Id_replace: { RegExpActions actionType; if (id == Id_match) { actionType = EcmaScript.NET.RegExpActions.Match; } else if (id == Id_search) { actionType = EcmaScript.NET.RegExpActions.Search; } else { actionType = EcmaScript.NET.RegExpActions.Replace; } return(cx.regExpProxy.Perform(cx, scope, thisObj, args, actionType)); } } throw new ArgumentException(Convert.ToString(id)); }
protected internal override void FillConstructorProperties(IdFunctionObject ctor) { AddIdFunctionProperty(ctor, STRING_TAG, ConstructorId_fromCharCode, "fromCharCode", 1); base.FillConstructorProperties(ctor); }
public override object ExecIdCall (IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, object [] args) { if (!f.HasTag (DATE_TAG)) { return base.ExecIdCall (f, cx, scope, thisObj, args); } int id = f.MethodId; switch (id) { case ConstructorId_now: return now (); case ConstructorId_parse: { string dataStr = ScriptConvert.ToString (args, 0); return date_parseString (dataStr); } case ConstructorId_UTC: return jsStaticFunction_UTC (args); case Id_constructor: { // if called as a function, just return a string // representing the current time. if (thisObj != null) return date_format (now (), Id_toString); return jsConstructor (args); } } // The rest of Date.prototype methods require thisObj to be Date if (!(thisObj is BuiltinDate)) throw IncompatibleCallError (f); BuiltinDate realThis = (BuiltinDate)thisObj; double t = realThis.date; switch (id) { case Id_toString: case Id_toTimeString: case Id_toDateString: if (!double.IsNaN (t)) { return date_format (t, id); } return js_NaN_date_str; case Id_toLocaleString: case Id_toLocaleTimeString: case Id_toLocaleDateString: if (!double.IsNaN (t)) { return toLocale_helper (t, id); } return js_NaN_date_str; case Id_toUTCString: if (!double.IsNaN (t)) { return js_toUTCString (t); } return js_NaN_date_str; case Id_toSource: return "(new Date(" + ScriptConvert.ToString (t) + "))"; case Id_valueOf: case Id_getTime: return t; case Id_getYear: case Id_getFullYear: case Id_getUTCFullYear: if (!double.IsNaN (t)) { if (id != Id_getUTCFullYear) t = LocalTime (t); t = YearFromTime (t); if (id == Id_getYear) { if (cx.HasFeature (Context.Features.NonEcmaGetYear)) { if (1900 <= t && t < 2000) { t -= 1900; } } else { t -= 1900; } } } return (t); case Id_getMonth: case Id_getUTCMonth: if (!double.IsNaN (t)) { if (id == Id_getMonth) t = LocalTime (t); t = MonthFromTime (t); } return (t); case Id_getDate: case Id_getUTCDate: if (!double.IsNaN (t)) { if (id == Id_getDate) t = LocalTime (t); t = DateFromTime (t); } return (t); case Id_getDay: case Id_getUTCDay: if (!double.IsNaN (t)) { if (id == Id_getDay) t = LocalTime (t); t = WeekDay (t); } return (t); case Id_getHours: case Id_getUTCHours: if (!double.IsNaN (t)) { if (id == Id_getHours) t = LocalTime (t); t = HourFromTime (t); } return (t); case Id_getMinutes: case Id_getUTCMinutes: if (!double.IsNaN (t)) { if (id == Id_getMinutes) t = LocalTime (t); t = MinFromTime (t); } return (t); case Id_getSeconds: case Id_getUTCSeconds: if (!double.IsNaN (t)) { if (id == Id_getSeconds) t = LocalTime (t); t = SecFromTime (t); } return (t); case Id_getMilliseconds: case Id_getUTCMilliseconds: if (!double.IsNaN (t)) { if (id == Id_getMilliseconds) t = LocalTime (t); t = msFromTime (t); } return (t); case Id_getTimezoneOffset: if (!double.IsNaN (t)) { t = (t - LocalTime (t)) / msPerMinute; } return (t); case Id_setTime: t = TimeClip (ScriptConvert.ToNumber (args, 0)); realThis.date = t; return t; case Id_setMilliseconds: case Id_setUTCMilliseconds: case Id_setSeconds: case Id_setUTCSeconds: case Id_setMinutes: case Id_setUTCMinutes: case Id_setHours: case Id_setUTCHours: t = makeTime (t, args, id); realThis.date = t; return (t); case Id_setDate: case Id_setUTCDate: case Id_setMonth: case Id_setUTCMonth: case Id_setFullYear: case Id_setUTCFullYear: t = makeDate (t, args, id); realThis.date = t; return (t); case Id_setYear: { double year = ScriptConvert.ToNumber (args, 0); if (double.IsNaN (year) || double.IsInfinity (year)) { t = double.NaN; } else { if (double.IsNaN (t)) { t = 0; } else { t = LocalTime (t); } if (year >= 0 && year <= 99) year += 1900; double day = MakeDay (year, MonthFromTime (t), DateFromTime (t)); t = MakeDate (day, TimeWithinDay (t)); t = internalUTC (t); t = TimeClip (t); } } realThis.date = t; return (t); default: throw new ArgumentException (Convert.ToString (id)); } }
public override object ExecIdCall (IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, object [] args) { if (!f.HasTag (MATH_TAG)) { return base.ExecIdCall (f, cx, scope, thisObj, args); } double x, y; int methodId = f.MethodId; switch (methodId) { case Id_toSource: return "Math"; case Id_abs: x = ScriptConvert.ToNumber (args, 0); // abs(-0.0) should be 0.0, but -0.0 < 0.0 == false x = (x == 0.0) ? 0.0 : ((x < 0.0) ? -x : x); break; case Id_acos: case Id_asin: x = ScriptConvert.ToNumber (args, 0); if (!double.IsNaN (x) && -1.0 <= x && x <= 1.0) { x = (methodId == Id_acos) ? Math.Acos (x) : Math.Asin (x); } else { x = System.Double.NaN; } break; case Id_atan: x = ScriptConvert.ToNumber (args, 0); x = Math.Atan (x); break; case Id_atan2: x = ScriptConvert.ToNumber (args, 0); y = ScriptConvert.ToNumber (args, 1); if (x == double.PositiveInfinity && y == double.PositiveInfinity) { x = NET_WORKAROUND_3; } else if (x == double.PositiveInfinity && y == double.NegativeInfinity) { x = NET_WORKAROUND_1; } else if (x == double.NegativeInfinity && y == double.PositiveInfinity) { x = NET_WORKAROUND_4; } else if (x == double.NegativeInfinity && y == double.NegativeInfinity) { x = NET_WORKAROUND_2; } else { x = Math.Atan2 (x, y); } break; case Id_ceil: x = ScriptConvert.ToNumber (args, 0); x = Math.Ceiling (x); break; case Id_cos: x = ScriptConvert.ToNumber (args, 0); x = (x == System.Double.PositiveInfinity || x == System.Double.NegativeInfinity) ? System.Double.NaN : Math.Cos (x); break; case Id_exp: x = ScriptConvert.ToNumber (args, 0); x = (x == System.Double.PositiveInfinity) ? x : ((x == System.Double.NegativeInfinity) ? 0.0 : Math.Exp (x)); break; case Id_floor: x = ScriptConvert.ToNumber (args, 0); x = Math.Floor (x); break; case Id_log: x = ScriptConvert.ToNumber (args, 0); // Java's log(<0) = -Infinity; we need NaN x = (x < 0) ? System.Double.NaN : Math.Log (x); break; case Id_max: case Id_min: x = (methodId == Id_max) ? System.Double.NegativeInfinity : System.Double.PositiveInfinity; for (int i = 0; i != args.Length; ++i) { double d = ScriptConvert.ToNumber (args [i]); if (double.IsNaN (d)) { x = d; // NaN break; } if (methodId == Id_max) { // if (x < d) x = d; does not work due to -0.0 >= +0.0 x = Math.Max (x, d); } else { x = Math.Min (x, d); } } break; case Id_pow: x = ScriptConvert.ToNumber (args, 0); x = js_pow (x, ScriptConvert.ToNumber (args, 1)); break; case Id_random: x = (new Random ()).NextDouble (); break; case Id_round: x = ScriptConvert.ToNumber (args, 0); if (!double.IsNaN (x) && x != System.Double.PositiveInfinity && x != System.Double.NegativeInfinity) { long l = (long)Math.Floor (x + 0.5); if (l != 0) { x = l; } else { // We must propagate the sign of d into the result if (x < 0.0) { x = BuiltinNumber.NegativeZero; } else if (x != 0.0) { x = 0.0; } } } break; case Id_sin: x = ScriptConvert.ToNumber (args, 0); x = (x == System.Double.PositiveInfinity || x == System.Double.NegativeInfinity) ? System.Double.NaN : Math.Sin (x); break; case Id_sqrt: x = ScriptConvert.ToNumber (args, 0); x = Math.Sqrt (x); break; case Id_tan: x = ScriptConvert.ToNumber (args, 0); x = Math.Tan (x); break; default: throw new ApplicationException (Convert.ToString (methodId)); } return (x); }
public override object ExecIdCall (IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, object [] args) { if (!f.HasTag (NUMBER_TAG)) { return base.ExecIdCall (f, cx, scope, thisObj, args); } int id = f.MethodId; if (id == Id_constructor) { double val = (args.Length >= 1) ? ScriptConvert.ToNumber (args [0]) : 0.0; if (thisObj == null) { // new Number(val) creates a new Number object. return new BuiltinNumber (val); } // Number(val) converts val to a number value. return val; } // The rest of Number.prototype methods require thisObj to be Number BuiltinNumber nativeNumber = (thisObj as BuiltinNumber); if (nativeNumber == null) throw IncompatibleCallError (f); double value = nativeNumber.doubleValue; switch (id) { case Id_toLocaleString: case Id_toString: return ImplToString (value, args); case Id_toSource: return "(new Number(" + ScriptConvert.ToString (value) + "))"; case Id_valueOf: return value; case Id_toFixed: return ImplToFixed (value, args); case Id_toExponential: return ImplToExponential (value, args); case Id_toPrecision: return ImplToPrecision (value, args); default: throw new ArgumentException (Convert.ToString (id)); } }
public virtual object ExecIdCall (IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, object [] args) { if (f.HasTag (FTAG)) { int methodId = f.MethodId; switch (methodId) { case Id_decodeURI: case Id_decodeURIComponent: { string str = ScriptConvert.ToString (args, 0); return decode (str, methodId == Id_decodeURI); } case Id_encodeURI: case Id_encodeURIComponent: { string str = ScriptConvert.ToString (args, 0); return encode (str, methodId == Id_encodeURI); } case Id_escape: return js_escape (args); case Id_eval: return ImplEval (cx, scope, thisObj, args); case Id_isFinite: { bool result; if (args.Length < 1) { result = false; } else { double d = ScriptConvert.ToNumber (args [0]); result = (!double.IsNaN (d) && d != System.Double.PositiveInfinity && d != System.Double.NegativeInfinity); } return result; } case Id_isNaN: { // The global method isNaN, as per ECMA-262 15.1.2.6. bool result; if (args.Length < 1) { result = true; } else { double d = ScriptConvert.ToNumber (args [0]); result = (double.IsNaN (d)); } return result; } case Id_isXMLName: { object name = (args.Length == 0) ? Undefined.Value : args [0]; XMLLib xmlLib = XMLLib.ExtractFromScope (scope); return xmlLib.IsXMLName (cx, name); } case Id_parseFloat: return js_parseFloat (args); case Id_parseInt: return js_parseInt (args); case Id_unescape: return js_unescape (args); case Id_uneval: { object value = (args.Length != 0) ? args [0] : Undefined.Value; return ScriptRuntime.uneval (cx, scope, value); } case Id_new_CommonError: // The implementation of all the ECMA error constructors // (SyntaxError, TypeError, etc.) return BuiltinError.make (cx, scope, f, args); } } throw f.Unknown (); }
public static void Init(Context cx, IScriptable scope, bool zealed) { BuiltinGlobal obj = new BuiltinGlobal(); for (int id = 1; id <= LAST_SCOPE_FUNCTION_ID; ++id) { string name; int arity = 1; switch (id) { case Id_decodeURI: name = "decodeURI"; break; case Id_decodeURIComponent: name = "decodeURIComponent"; break; case Id_encodeURI: name = "encodeURI"; break; case Id_encodeURIComponent: name = "encodeURIComponent"; break; case Id_escape: name = "escape"; break; case Id_eval: name = "eval"; break; case Id_isFinite: name = "isFinite"; break; case Id_isNaN: name = "isNaN"; break; case Id_isXMLName: name = "isXMLName"; break; case Id_parseFloat: name = "parseFloat"; break; case Id_parseInt: name = "parseInt"; arity = 2; break; case Id_unescape: name = "unescape"; break; case Id_uneval: name = "uneval"; break; default: throw Context.CodeBug(); } IdFunctionObject f = new IdFunctionObject(obj, FTAG, id, name, arity, scope); if (zealed) { f.SealObject(); } f.ExportAsScopeProperty(); } ScriptableObject.DefineProperty(scope, "NaN", (object)double.NaN, ScriptableObject.DONTENUM); ScriptableObject.DefineProperty(scope, "Infinity", (System.Double.PositiveInfinity), ScriptableObject.DONTENUM); ScriptableObject.DefineProperty(scope, "undefined", Undefined.Value, ScriptableObject.DONTENUM); string [] errorMethods = new string [] { "ConversionError", "EvalError", "RangeError", "ReferenceError", "SyntaxError", "TypeError", "URIError", "InternalError", "JavaException" }; /* * Each error constructor gets its own Error object as a prototype, * with the 'name' property set to the name of the error. */ for (int i = 0; i < errorMethods.Length; i++) { string name = errorMethods [i]; IScriptable errorProto = ScriptRuntime.NewObject(cx, scope, "Error", ScriptRuntime.EmptyArgs); errorProto.Put("name", errorProto, name); if (zealed) { if (errorProto is ScriptableObject) { ((ScriptableObject)errorProto).SealObject(); } } IdFunctionObject ctor = new IdFunctionObject(obj, FTAG, Id_new_CommonError, name, 1, scope); ctor.MarkAsConstructor(errorProto); if (zealed) { ctor.SealObject(); } ctor.ExportAsScopeProperty(); } }
public static void Init (Context cx, IScriptable scope, bool zealed) { BuiltinGlobal obj = new BuiltinGlobal (); for (int id = 1; id <= LAST_SCOPE_FUNCTION_ID; ++id) { string name; int arity = 1; switch (id) { case Id_decodeURI: name = "decodeURI"; break; case Id_decodeURIComponent: name = "decodeURIComponent"; break; case Id_encodeURI: name = "encodeURI"; break; case Id_encodeURIComponent: name = "encodeURIComponent"; break; case Id_escape: name = "escape"; break; case Id_eval: name = "eval"; break; case Id_isFinite: name = "isFinite"; break; case Id_isNaN: name = "isNaN"; break; case Id_isXMLName: name = "isXMLName"; break; case Id_parseFloat: name = "parseFloat"; break; case Id_parseInt: name = "parseInt"; arity = 2; break; case Id_unescape: name = "unescape"; break; case Id_uneval: name = "uneval"; break; default: throw Context.CodeBug (); } IdFunctionObject f = new IdFunctionObject (obj, FTAG, id, name, arity, scope); if (zealed) { f.SealObject (); } f.ExportAsScopeProperty (); } ScriptableObject.DefineProperty (scope, "NaN", (object)double.NaN, ScriptableObject.DONTENUM); ScriptableObject.DefineProperty (scope, "Infinity", (System.Double.PositiveInfinity), ScriptableObject.DONTENUM); ScriptableObject.DefineProperty (scope, "undefined", Undefined.Value, ScriptableObject.DONTENUM); string [] errorMethods = new string [] { "ConversionError", "EvalError", "RangeError", "ReferenceError", "SyntaxError", "TypeError", "URIError", "InternalError", "JavaException" }; /* Each error constructor gets its own Error object as a prototype, with the 'name' property set to the name of the error. */ for (int i = 0; i < errorMethods.Length; i++) { string name = errorMethods [i]; IScriptable errorProto = ScriptRuntime.NewObject (cx, scope, "Error", ScriptRuntime.EmptyArgs); errorProto.Put ("name", errorProto, name); if (zealed) { if (errorProto is ScriptableObject) { ((ScriptableObject)errorProto).SealObject (); } } IdFunctionObject ctor = new IdFunctionObject (obj, FTAG, Id_new_CommonError, name, 1, scope); ctor.MarkAsConstructor (errorProto); if (zealed) { ctor.SealObject (); } ctor.ExportAsScopeProperty (); } }
public override object ExecIdCall(IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, System.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.prototype methods require thisObj to be XML if (!(thisObj is XML)) throw IncompatibleCallError (f); XML realThis = (XML)thisObj; XMLName xmlName; switch (id) { case Id_addNamespace: { return realThis.AddNamespace (GetArgSafe (args, 0)); } case Id_appendChild: return realThis.AppendChild (GetArgSafe (args, 0)); case Id_attribute: xmlName = XMLName.Parse (lib, cx, GetArgSafe (args, 0)); return realThis.Attribute (xmlName); case Id_attributes: return realThis.Attributes (); case Id_child: xmlName = XMLName.Parse (lib, cx, GetArgSafe (args, 0)); if (xmlName == null) { long index = ScriptRuntime.lastUint32Result (cx); return realThis.Child (index); } else { return realThis.Child (xmlName); } case Id_childIndex: return realThis.ChildIndex (); case Id_children: return realThis.Children (); case Id_comments: return realThis.Comments (); case Id_contains: return realThis.Contains (GetArgSafe (args, 0)); case Id_copy: return realThis.Copy (); case Id_descendants: { xmlName = (args.Length == 0) ? XMLName.FormStar () : XMLName.Parse (lib, cx, GetArgSafe (args, 0)); return realThis.Descendants (xmlName); } case Id_inScopeNamespaces: { object [] array = realThis.InScopeNamespaces (); return cx.NewArray (scope, array); } case Id_insertChildAfter: return realThis.InsertChildAfter (GetArgSafe (args, 0), GetArgSafe (args, 1)); case Id_insertChildBefore: return realThis.InsertChildBefore (GetArgSafe (args, 0), GetArgSafe (args, 1)); case Id_hasOwnProperty: xmlName = XMLName.Parse (lib, cx, GetArgSafe (args, 0)); return realThis.HasOwnProperty (xmlName); case Id_hasComplexContent: return realThis.HasComplexContent (); case Id_hasSimpleContent: return realThis.HasSimpleContent (); case Id_length: return realThis.Length (); case Id_localName: return realThis.LocalName (); case Id_name: return realThis.Name (); case Id_namespace: return realThis.Namespace (GetArgSafe (args, 0)); case Id_namespaceDeclarations: return cx.NewArray (scope, realThis.NamespaceDeclarations ()); case Id_nodeKind: return realThis.NodeKind (); case Id_normalize: realThis.Normalize (); return Undefined.Value; case Id_parent: return realThis.Parent (); case Id_prependChild: return realThis.PrependChild (GetArgSafe (args, 0)); case Id_processingInstructions: xmlName = (args.Length > 0) ? XMLName.Parse (lib, cx, args [0]) : XMLName.FormStar (); return realThis.ProcessingInstructions (xmlName); case Id_propertyIsEnumerable: { return realThis.PropertyIsEnumerable (GetArgSafe (args, 0)); } case Id_removeNamespace: { Namespace ns = E4X.Namespace.Parse (lib, cx, GetArgSafe (args, 0)); return realThis.RemoveNamespace (ns); } case Id_replace: { xmlName = XMLName.Parse (lib, cx, GetArgSafe (args, 0)); object arg1 = GetArgSafe (args, 1); if (xmlName == null) { long index = ScriptRuntime.lastUint32Result (cx); return realThis.Replace (index, arg1); } else { return realThis.Replace (xmlName, arg1); } } case Id_setChildren: return realThis.SetChildren (GetArgSafe (args, 0)); case Id_setLocalName: { string localName; object arg = GetArgSafe (args, 0); if (arg is QName) { localName = ((QName)arg).LocalName; } else { localName = ScriptConvert.ToString (arg); } realThis.SetLocalName (localName); return Undefined.Value; } case Id_setName: { object arg = (args.Length != 0) ? args [0] : Undefined.Value; QName qname; if (arg is QName) { qname = (QName)arg; if (qname.Uri == null) { qname = QName.Parse (lib, cx, qname.LocalName); } else { // E4X 13.4.4.35 requires to always construct QName qname = QName.Parse (lib, cx, qname); } } else { qname = QName.Parse (lib, cx, arg); } realThis.SetName (qname); return Undefined.Value; } case Id_setNamespace: { Namespace ns = E4X.Namespace.Parse (lib, cx, GetArgSafe (args, 0)); realThis.SetNamespace (ns); return Undefined.Value; } case Id_text: return realThis.Text (); case Id_toString: return realThis.ToString (); case Id_toXMLString: return realThis.ToXMLString (); case Id_valueOf: return realThis; } throw new System.ArgumentException (System.Convert.ToString (id)); }
public override object ExecIdCall (IdFunctionObject f, Context cx, IScriptable scope, IScriptable 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.prototype methods require thisObj to be XML if (!(thisObj is XMLList)) throw IncompatibleCallError (f); XMLList realThis = (XMLList)thisObj; XMLName xmlName; switch (id) { case Id_attribute: xmlName = XMLName.Parse (lib, cx, GetArgSafe (args, 0)); return realThis.Attribute (xmlName); case Id_attributes: return realThis.Attributes (); case Id_child: xmlName = XMLName.Parse (lib, cx, GetArgSafe (args, 0)); if (xmlName == null) { long index = ScriptRuntime.lastUint32Result (cx); return realThis.Child (index); } else { return realThis.Child (xmlName); } case Id_children: return realThis.Children (); case Id_contains: return realThis.Contains (GetArgSafe (args, 0)); case Id_copy: return realThis.Copy (); case Id_descendants: { xmlName = (args.Length == 0) ? XMLName.FormStar () : XMLName.Parse (lib, cx, GetArgSafe (args, 0)); return realThis.Descendants (xmlName); } case Id_hasOwnProperty: xmlName = XMLName.Parse (lib, cx, GetArgSafe (args, 0)); return realThis.HasOwnProperty (xmlName); case Id_hasComplexContent: return realThis.HasComplexContent (); case Id_hasSimpleContent: return realThis.HasSimpleContent (); case Id_length: return realThis.Length (); case Id_normalize: realThis.Normalize (); return Undefined.Value; case Id_parent: return realThis.Parent (); case Id_processingInstructions: xmlName = (args.Length > 0) ? XMLName.Parse (lib, cx, args [0]) : XMLName.FormStar (); return realThis.ProcessingInstructions (xmlName); case Id_propertyIsEnumerable: { return realThis.PropertyIsEnumerable (GetArgSafe (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; case Id_addNamespace: return realThis.DelegateTo ("addNamespace").AddNamespace (GetArgSafe (args, 0)); case Id_appendChild: return realThis.DelegateTo ("appendChild").AppendChild (GetArgSafe (args, 0)); case Id_childIndex: return realThis.DelegateTo ("childIndex").ChildIndex (); case Id_inScopeNamespaces: return realThis.DelegateTo ("inScopeNamespaces").InScopeNamespaces (); case Id_insertChildAfter: return realThis.DelegateTo ("insertChildAfter").InsertChildAfter (GetArgSafe (args, 0), GetArgSafe (args, 1)); case Id_insertChildBefore: return realThis.DelegateTo ("insertChildBefore").InsertChildBefore (GetArgSafe (args, 0), GetArgSafe (args, 1)); case Id_localName: return realThis.DelegateTo ("localName").LocalName (); case Id_name: return realThis.DelegateTo ("name").Name (); case Id_namespace: return realThis.DelegateTo ("namespace").Namespace (GetArgSafe (args, 0)); case Id_namespaceDeclarations: return realThis.DelegateTo ("namespaceDeclarations").NamespaceDeclarations (); case Id_nodeKind: return realThis.DelegateTo ("nodeKind").NodeKind (); case Id_prependChild: return realThis.DelegateTo ("prependChild").PrependChild (GetArgSafe (args, 0)); case Id_removeNamespace: return realThis.DelegateTo ("removeNamespace").RemoveNamespace (GetArgSafe (args, 0)); case Id_replace: return realThis.DelegateTo ("replace").Replace (GetArgSafe (args, 0), GetArgSafe (args, 1)); case Id_setChildren: return realThis.DelegateTo ("setChildren").SetChildren (GetArgSafe (args, 0)); case Id_setLocalName: realThis.DelegateTo ("setLocalName").SetLocalName (GetArgSafe (args, 0)); return Undefined.Value; case Id_setName: realThis.DelegateTo ("setName").SetName (GetArgSafe (args, 0)); return Undefined.Value; case Id_setNamespace: realThis.DelegateTo ("setNamespace").SetNamespace (GetArgSafe (args, 0)); return Undefined.Value; } throw new System.ArgumentException (System.Convert.ToString (id)); }
public override object ExecIdCall(IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, object [] args) { if (!f.HasTag(NUMBER_TAG)) { return(base.ExecIdCall(f, cx, scope, thisObj, args)); } int id = f.MethodId; if (id == Id_constructor) { double val = (args.Length >= 1) ? ScriptConvert.ToNumber(args [0]) : 0.0; if (thisObj == null) { // new Number(val) creates a new Number object. return(new BuiltinNumber(val)); } // Number(val) converts val to a number value. return(val); } // The rest of Number.prototype methods require thisObj to be Number BuiltinNumber nativeNumber = (thisObj as BuiltinNumber); if (nativeNumber == null) { throw IncompatibleCallError(f); } double value = nativeNumber.doubleValue; int toBase = 0; switch (id) { case Id_toString: toBase = (args.Length == 0) ? 10 : ScriptConvert.ToInt32(args [0]); return(ScriptConvert.ToString(value, toBase)); case Id_toLocaleString: { // toLocaleString is just an alias for toString for now toBase = (args.Length == 0) ? 10 : ScriptConvert.ToInt32(args [0]); return(ScriptConvert.ToString(value, toBase)); } case Id_toSource: return("(new Number(" + ScriptConvert.ToString(value) + "))"); case Id_valueOf: return(value); case Id_toFixed: return(num_to(value, args, DTOSTR_FIXED, DTOSTR_FIXED, -20, 0)); case Id_toExponential: return(num_to(value, args, DTOSTR_STANDARD_EXPONENTIAL, DTOSTR_EXPONENTIAL, 0, 1)); case Id_toPrecision: { if (args.Length < 0 || args [0] == Undefined.Value) { return(ScriptConvert.ToString(value)); } int precision = ScriptConvert.ToInt32(args [0]); if (precision < 0 || precision > MAX_PRECISION) { throw ScriptRuntime.ConstructError("RangeError", ScriptRuntime.GetMessage("msg.bad.precision", ScriptConvert.ToString(args [0]))); } return(value.ToString(GetFormatString(precision))); } default: throw new ArgumentException(Convert.ToString(id)); } }
protected internal override void FillConstructorProperties(IdFunctionObject ctor) { AddIdFunctionProperty (ctor, STRING_TAG, ConstructorId_fromCharCode, "fromCharCode", 1); base.FillConstructorProperties (ctor); }
public override object ExecIdCall(IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, object [] args) { if (!f.HasTag (NUMBER_TAG)) { return base.ExecIdCall (f, cx, scope, thisObj, args); } int id = f.MethodId; if (id == Id_constructor) { double val = (args.Length >= 1) ? ScriptConvert.ToNumber (args [0]) : 0.0; if (thisObj == null) { // new Number(val) creates a new Number object. return new BuiltinNumber (val); } // Number(val) converts val to a number value. return val; } // The rest of Number.prototype methods require thisObj to be Number BuiltinNumber nativeNumber = (thisObj as BuiltinNumber); if (nativeNumber == null) throw IncompatibleCallError (f); double value = nativeNumber.doubleValue; int toBase = 0; switch (id) { case Id_toString: toBase = (args.Length == 0) ? 10 : ScriptConvert.ToInt32 (args [0]); return ScriptConvert.ToString (value, toBase); case Id_toLocaleString: { // toLocaleString is just an alias for toString for now toBase = (args.Length == 0) ? 10 : ScriptConvert.ToInt32 (args [0]); return ScriptConvert.ToString (value, toBase); } case Id_toSource: return "(new Number(" + ScriptConvert.ToString (value) + "))"; case Id_valueOf: return value; case Id_toFixed: return num_to (value, args, DTOSTR_FIXED, DTOSTR_FIXED, -20, 0); case Id_toExponential: return num_to (value, args, DTOSTR_STANDARD_EXPONENTIAL, DTOSTR_EXPONENTIAL, 0, 1); case Id_toPrecision: { if (args.Length < 0 || args [0] == Undefined.Value) return ScriptConvert.ToString (value); int precision = ScriptConvert.ToInt32 (args [0]); if (precision < 0 || precision > MAX_PRECISION) { throw ScriptRuntime.ConstructError ("RangeError", ScriptRuntime.GetMessage ("msg.bad.precision", ScriptConvert.ToString (args [0]))); } return value.ToString (GetFormatString (precision)); } default: throw new ArgumentException (Convert.ToString (id)); } }
public override object ExecIdCall(IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, object [] args) { if (!f.HasTag(MATH_TAG)) { return(base.ExecIdCall(f, cx, scope, thisObj, args)); } double x, y; int methodId = f.MethodId; switch (methodId) { case Id_toSource: return("Math"); case Id_abs: x = ScriptConvert.ToNumber(args, 0); // abs(-0.0) should be 0.0, but -0.0 < 0.0 == false x = (x == 0.0) ? 0.0 : ((x < 0.0) ? -x : x); break; case Id_acos: case Id_asin: x = ScriptConvert.ToNumber(args, 0); if (!double.IsNaN(x) && -1.0 <= x && x <= 1.0) { x = (methodId == Id_acos) ? Math.Acos(x) : Math.Asin(x); } else { x = System.Double.NaN; } break; case Id_atan: x = ScriptConvert.ToNumber(args, 0); x = Math.Atan(x); break; case Id_atan2: x = ScriptConvert.ToNumber(args, 0); y = ScriptConvert.ToNumber(args, 1); if (x == double.PositiveInfinity && y == double.PositiveInfinity) { x = NET_WORKAROUND_3; } else if (x == double.PositiveInfinity && y == double.NegativeInfinity) { x = NET_WORKAROUND_1; } else if (x == double.NegativeInfinity && y == double.PositiveInfinity) { x = NET_WORKAROUND_4; } else if (x == double.NegativeInfinity && y == double.NegativeInfinity) { x = NET_WORKAROUND_2; } else { x = Math.Atan2(x, y); } break; case Id_ceil: x = ScriptConvert.ToNumber(args, 0); x = Math.Ceiling(x); break; case Id_cos: x = ScriptConvert.ToNumber(args, 0); x = (x == System.Double.PositiveInfinity || x == System.Double.NegativeInfinity) ? System.Double.NaN : Math.Cos(x); break; case Id_exp: x = ScriptConvert.ToNumber(args, 0); x = (x == System.Double.PositiveInfinity) ? x : ((x == System.Double.NegativeInfinity) ? 0.0 : Math.Exp(x)); break; case Id_floor: x = ScriptConvert.ToNumber(args, 0); x = Math.Floor(x); break; case Id_log: x = ScriptConvert.ToNumber(args, 0); // Java's log(<0) = -Infinity; we need NaN x = (x < 0) ? System.Double.NaN : Math.Log(x); break; case Id_max: case Id_min: x = (methodId == Id_max) ? System.Double.NegativeInfinity : System.Double.PositiveInfinity; for (int i = 0; i != args.Length; ++i) { double d = ScriptConvert.ToNumber(args [i]); if (double.IsNaN(d)) { x = d; // NaN break; } if (methodId == Id_max) { // if (x < d) x = d; does not work due to -0.0 >= +0.0 x = Math.Max(x, d); } else { x = Math.Min(x, d); } } break; case Id_pow: x = ScriptConvert.ToNumber(args, 0); x = ImplPow(x, ScriptConvert.ToNumber(args, 1)); break; case Id_random: x = (new Random()).NextDouble(); break; case Id_round: x = ScriptConvert.ToNumber(args, 0); if (!double.IsNaN(x) && x != System.Double.PositiveInfinity && x != System.Double.NegativeInfinity) { long l = (long)Math.Floor(x + 0.5); if (l != 0) { x = l; } else { // We must propagate the sign of d into the result if (x < 0.0) { x = BuiltinNumber.NegativeZero; } else if (x != 0.0) { x = 0.0; } } } break; case Id_sin: x = ScriptConvert.ToNumber(args, 0); x = (x == System.Double.PositiveInfinity || x == System.Double.NegativeInfinity) ? System.Double.NaN : Math.Sin(x); break; case Id_sqrt: x = ScriptConvert.ToNumber(args, 0); x = Math.Sqrt(x); break; case Id_tan: x = ScriptConvert.ToNumber(args, 0); x = Math.Tan(x); break; default: throw new ApplicationException(Convert.ToString(methodId)); } return(x); }