Example #1
0
        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();
        }