Example #1
0
        internal static void Init(IScriptable scope, bool zealed)
        {
            BuiltinError obj = new BuiltinError();

            ScriptableObject.PutProperty(obj, "name", "Error");
            ScriptableObject.PutProperty(obj, "message", "");
            ScriptableObject.PutProperty(obj, "fileName", "");
            ScriptableObject.PutProperty(obj, "lineNumber", 0);

            // TODO: Implement as non-ecma feature
            ScriptableObject.PutProperty(obj, "stack", "NOT IMPLEMENTED");

            obj.ExportAsJSClass(MAX_PROTOTYPE_ID, scope, zealed
                                , ScriptableObject.DONTENUM | ScriptableObject.READONLY | ScriptableObject.PERMANENT);
        }
Example #2
0
        internal static void Init (IScriptable scope, bool zealed)
        {
            BuiltinError obj = new BuiltinError ();
            
            ScriptableObject.PutProperty (obj, "name", "Error");
            ScriptableObject.PutProperty (obj, "message", "");
            ScriptableObject.PutProperty (obj, "fileName", "");
            ScriptableObject.PutProperty (obj, "lineNumber", 0);
            
            // TODO: Implement as non-ecma feature
            ScriptableObject.PutProperty (obj, "stack", "NOT IMPLEMENTED");

            obj.ExportAsJSClass (MAX_PROTOTYPE_ID, scope, zealed
                , ScriptableObject.DONTENUM | ScriptableObject.READONLY | ScriptableObject.PERMANENT);
        }
Example #3
0
        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;
        }
Example #4
0
        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);
        }
Example #5
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();
        }