Exemplo n.º 1
0
        public override object Construct(ExecutionContext GLOBAL, JSObjectBase args, ExecutionContext x)
        {
            JSObject result = (JSObject)Call(GLOBAL, x, args, x);

            result.DefProp(GLOBAL, "constructor", this);
            return(result);
        }
Exemplo n.º 2
0
        public static void PutValue(ExecutionContext GLOBAL, object reference, object val)
        {
            Reference refer = reference as Reference;

            if (refer == null)
            {
                throw new ReferenceError(reference.ToString());
            }
            JSObjectBase baseOb = refer.GetBase();

            if (baseOb == null)
            {
                baseOb = GLOBAL.jobject;
            }
            JSProperty prop = baseOb.GetItem(GLOBAL, refer.GetPropertyName());

            if (prop == null)
            {
                baseOb.SetItem(GLOBAL, refer.GetPropertyName(), new JSSimpleProperty(refer.GetPropertyName(), GetValue(GLOBAL, val)));
            }
            else if (!prop.ReadOnly)
            {
                prop.SetValue(GLOBAL, GetValue(GLOBAL, val));
            }
        }
Exemplo n.º 3
0
 public override object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x)
 {
     int alen = (int)JSObject.ToNumber(GLOBAL, a.GetItem(GLOBAL, "length").GetValue(GLOBAL));
     if (alen == 0) return "";
     string uri = a.GetItem(GLOBAL, "0").GetValue(GLOBAL).ToString();
     return URIFunctionPrivate.Decode(uri, URIFunctionPrivate.uriReservedPlusOctothorpe);
 }
Exemplo n.º 4
0
        public static object GetValue(ExecutionContext GLOBAL, object reference)
        {
            Reference refer = reference as Reference;

            if (refer == null)
            {
                return(reference);
            }
            JSObjectBase baseOb = refer.GetBase();

            if (baseOb == null)
            {
                baseOb = GLOBAL.jobject;
            }
            JSProperty prop = baseOb.GetItem(GLOBAL, refer.GetPropertyName());

            if (prop == null && baseOb == GLOBAL.jobject)
            {
                throw new ReferenceError(baseOb.ToString() + " of type " + baseOb.Class + " doesn't have a " + (refer != null ? refer.GetPropertyName() : reference.ToString()) + " property.");
            }
            else if (prop == null)
            {
                return(JSUndefined.Undefined);
            }
            else
            {
                return(prop.GetValue(GLOBAL));
            }
        }
Exemplo n.º 5
0
            public override object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x)
            {
                JSObjectBase thisArgs = a;

                if (mMethodProp.mThisArg)
                {
                    int      i, alen = (int)JSObject.ToNumber(GLOBAL, a.GetItem(GLOBAL, "length").GetValue(GLOBAL));
                    JSObject newArgs = new JSObject();
                    newArgs.DefProp(GLOBAL, "length", (double)(alen + 1));
                    for (i = alen; i > 0; i--)
                    {
                        newArgs.SetItem(GLOBAL, i.ToString(), a.GetItem(GLOBAL, (i - 1).ToString()));
                    }
                    newArgs.DefProp(GLOBAL, "0", t);
                    thisArgs = newArgs;
                }
                foreach (MethodInfo mi in mMethodProp.mMethodInfo)
                {
                    object[] nargs = SatisfyArgumentList(GLOBAL, isThisArg(mi) ? thisArgs : a, mi.GetParameters());
                    if (nargs != null)
                    {
                        return(ToJS(GLOBAL, mi.Invoke(mi.IsStatic ? null : ToNative(t), nargs)));
                    }
                }
                throw new TypeError("Couldn't match arguments for " + mMethodProp.mOverallName);
            }
Exemplo n.º 6
0
 public override object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x)
 {
     int alen = (int)JSObject.ToNumber(GLOBAL, a.GetItem(GLOBAL, "length").GetValue(GLOBAL));
     if (alen == 0) return "";
     byte[] bytes = UTF8Encoding.UTF8.GetBytes(a.GetItem(GLOBAL, "0").GetValue(GLOBAL).ToString());
     return URIFunctionPrivate.Encode(bytes, false);
 }
Exemplo n.º 7
0
        public static void Register(ExecutionContext GLOBAL, JSObjectBase scope, Type t)
        {
            string[]       fullName = t.FullName.Split(new char[] { '.' });
            JSClassWrapper wrapper  = new JSClassWrapper(GLOBAL, t);

            RegisterNamespace(GLOBAL, scope, fullName, fullName.Length - 2);
        }
Exemplo n.º 8
0
        public override object Construct(ExecutionContext GLOBAL, JSObjectBase args, ExecutionContext x)
        {
            JSObject result = new BoolObject(GLOBAL, (int)JSObject.ToNumber(GLOBAL, args.GetItem(GLOBAL, "length").GetValue(GLOBAL)) > 0 && JSObject.ToBool(GLOBAL, args.GetItem(GLOBAL, "0").GetValue(GLOBAL)));

            result.DefProp(GLOBAL, "constructor", this);
            return(result);
        }
Exemplo n.º 9
0
 public override object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x)
 {
     ExecutionContext newScope = x;
     newScope.parent = GLOBAL.currentContext;
     newScope.thisOb = thisOb;
     GLOBAL.currentContext = newScope;
     return f.Call(GLOBAL, t, a, newScope);
 }
Exemplo n.º 10
0
 public override object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x)
 {
     object result;
     if (JSObject.ToNumber(GLOBAL, a.GetItem(GLOBAL, "length").GetValue(GLOBAL)) > 0)
         result = JSObject.ToNumber(GLOBAL, a.GetItem(GLOBAL, "0").GetValue(GLOBAL));
     else result = 0.0;
     return result;
 }
Exemplo n.º 11
0
 public override object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x)
 {
     if (mApplyMethod == null)
     {
         throw new TypeError(Class + " is not callable");
     }
     return(((JSObjectBase)mApplyMethod.GetValue(GLOBAL)).Call(GLOBAL, t, a, x));
 }
Exemplo n.º 12
0
        public override object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x)
        {
            ExecutionContext newScope = x;

            newScope.parent       = GLOBAL.currentContext;
            newScope.thisOb       = thisOb;
            GLOBAL.currentContext = newScope;
            return(f.Call(GLOBAL, t, a, newScope));
        }
Exemplo n.º 13
0
        public override object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x)
        {
            int alen = (int)JSObject.ToNumber(GLOBAL, a.GetItem(GLOBAL, "length").GetValue(GLOBAL));

            if (alen == 0)
            {
                return(false);
            }
            return(JSObject.ToBool(GLOBAL, a.GetItem(GLOBAL, "0").GetValue(GLOBAL)));
        }
Exemplo n.º 14
0
 public override object Construct(ExecutionContext GLOBAL, JSObjectBase args, ExecutionContext x)
 {
     JSObject result;
     if (JSObject.ToNumber(GLOBAL, args.GetItem(GLOBAL, "length").GetValue(GLOBAL)) > 0)
         result = new NumberObject(GLOBAL, JSObject.ToNumber(GLOBAL, args.GetItem(GLOBAL, "0").GetValue(GLOBAL)));
     else result = new NumberObject(GLOBAL, 0.0);
     result.DefProp(GLOBAL, "prototype", this.GetItem(GLOBAL, "prototype").GetValue(GLOBAL));
     result.DefProp(GLOBAL, "constructor", this);
     return result;
 }
Exemplo n.º 15
0
 public Activation(ExecutionContext GLOBAL, Node f, JSObjectBase a)
 {
     int i, j;
     for (i = 0, j = f.fparams.Count; i < j; i++)
     {
         JSProperty ares = a.GetItem(GLOBAL, i.ToString());
         this.SetItem(GLOBAL, f.fparams[i].ToString(), new JSSimpleProperty(f.fparams[i].ToString(), ares != null ? ares.GetValue(GLOBAL) : JSUndefined.Undefined, true));
     }
     this.SetItem(GLOBAL, "arguments", new JSSimpleProperty("arguments", a, true));
 }
Exemplo n.º 16
0
        public Activation(ExecutionContext GLOBAL, Node f, JSObjectBase a)
        {
            int i, j;

            for (i = 0, j = f.fparams.Count; i < j; i++)
            {
                JSProperty ares = a.GetItem(GLOBAL, i.ToString());
                this.SetItem(GLOBAL, f.fparams[i].ToString(), new JSSimpleProperty(f.fparams[i].ToString(), ares != null ? ares.GetValue(GLOBAL) : JSUndefined.Undefined, true));
            }
            this.SetItem(GLOBAL, "arguments", new JSSimpleProperty("arguments", a, true));
        }
Exemplo n.º 17
0
        public override object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x)
        {
            int alen = (int)JSObject.ToNumber(GLOBAL, a.GetItem(GLOBAL, "length").GetValue(GLOBAL));

            if (alen == 0)
            {
                return("");
            }
            byte[] bytes = UTF8Encoding.UTF8.GetBytes(a.GetItem(GLOBAL, "0").GetValue(GLOBAL).ToString());
            return(URIFunctionPrivate.Encode(bytes, true));
        }
Exemplo n.º 18
0
        public static JSObjectBase RegisterNamespace(ExecutionContext GLOBAL, JSObjectBase scope, string[] names, int idx)
        {
            JSObjectBase parent = idx == 0 ? scope : RegisterNamespace(GLOBAL, scope, names, idx - 1);

            if (!parent.HasProperty(GLOBAL, names[idx]))
            {
                JSObject wrapper = new JSObject();
                parent.GetItem(GLOBAL, names[idx]).SetValue(GLOBAL, wrapper);
                return(wrapper);
            }
            return((JSObjectBase)parent.GetItem(GLOBAL, names[idx]).GetValue(GLOBAL));
        }
Exemplo n.º 19
0
        public override object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x)
        {
            int alen = (int)JSObject.ToNumber(GLOBAL, a.GetItem(GLOBAL, "length").GetValue(GLOBAL));

            if (alen == 0)
            {
                return("");
            }
            string uri = a.GetItem(GLOBAL, "0").GetValue(GLOBAL).ToString();

            return(URIFunctionPrivate.Decode(uri, URIFunctionPrivate.uriEmptySet));
        }
Exemplo n.º 20
0
        public override object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x)
        {
            int alen = (int)JSObject.ToNumber(GLOBAL, a.GetItem(GLOBAL, "length").GetValue(GLOBAL));

            if (alen == 0)
            {
                return(false);
            }
            double val = JSObject.ToNumber(GLOBAL, a.GetItem(GLOBAL, "0").GetValue(GLOBAL));

            return(!double.IsNaN(val) && !double.IsPositiveInfinity(val) && !double.IsNegativeInfinity(val));
        }
Exemplo n.º 21
0
 public override object Construct(ExecutionContext GLOBAL, JSObjectBase args, ExecutionContext x)
 {
     object[] arglist = null;
     foreach (ConstructorInfo c in mThisType.GetConstructors())
     {
         arglist = JSObject.SatisfyArgumentList(GLOBAL, args, c.GetParameters());
         if (arglist != null)
         {
             return(JSObject.ToJS(GLOBAL, c.Invoke(arglist)));
         }
     }
     throw new TypeError("Wrong argument types for " + mThisType.Name + " constructor");
 }
Exemplo n.º 22
0
        public override object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x)
        {
            int alen = (int)JSObject.ToNumber(GLOBAL, a.GetItem(GLOBAL, "length").GetValue(GLOBAL));

            if (alen == 0)
            {
                return(Double.NaN);
            }
            else
            {
                return((double)(long)JSObject.ToNumber(GLOBAL, a.GetItem(GLOBAL, "0").GetValue(GLOBAL)));
            }
        }
Exemplo n.º 23
0
        public override object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x)
        {
            object result;

            if (JSObject.ToNumber(GLOBAL, a.GetItem(GLOBAL, "length").GetValue(GLOBAL)) > 0)
            {
                result = JSObject.ToNumber(GLOBAL, a.GetItem(GLOBAL, "0").GetValue(GLOBAL));
            }
            else
            {
                result = 0.0;
            }
            return(result);
        }
Exemplo n.º 24
0
        public void TriggerEvent(object sender, EventArgs args)
        {
            object  senderOb = JSObject.ToJS(GLOBAL, sender), argsOb = JSObject.ToJS(GLOBAL, args);
            JSArray argArray = new JSArray(GLOBAL, new object[] { senderOb, argsOb });

            foreach (object ob in mHookedUp)
            {
                JSObjectBase obBase = ob as JSObjectBase;
                if (obBase != null)
                {
                    obBase.Call(GLOBAL, ob, argArray, GLOBAL.currentContext);
                }
            }
        }
Exemplo n.º 25
0
        // Punct
        // Mask 1 excludes @*_-.
        // Mask 2 excludes @*_-.
        // Mask 4 excludes @*_-.+/
        // AlphaNumeric, spaces
        // Mask 1 excludes letters and numbers
        // Mask 2 escapes ' ' with +
        // Mask 4 excludes letters and numbers
        // 1 and 4 unexclude ' '
        public override object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x)
        {
            int alen = (int)JSObject.ToNumber(GLOBAL, a.GetItem(GLOBAL, "length").GetValue(GLOBAL));
            int mask = 4;

            if (alen == 0)
            {
                return(JSUndefined.Undefined);
            }
            else if (alen > 1)
            {
                mask = (int)JSObject.ToNumber(GLOBAL, a.GetItem(GLOBAL, "1").GetValue(GLOBAL));
            }
            string        instr  = JSObject.ToPrimitive(GLOBAL, a.GetItem(GLOBAL, "0").GetValue(GLOBAL));
            StringBuilder result = new StringBuilder();

            foreach (char ch in instr)
            {
                if (ch == ' ' && mask == 2)
                {
                    result.Append('+');
                }
                else if ((ch == '+' || ch == '/') && (mask & 4) != 0)
                {
                    result.Append(ch);
                }
                else if ((ch == '@' || ch == '*' || ch == '_' || ch == '-' || ch == '.') && mask != 0)
                {
                    result.Append(ch);
                }
                else if (char.IsLetterOrDigit(ch) && mask != 0)
                {
                    result.Append(ch);
                }
                else
                {
                    if (ch >= (char)0x100)
                    {
                        result.Append(string.Format("%u{0:X4}", (int)ch));
                    }
                    else
                    {
                        result.Append(string.Format("%{0:X2}", (int)ch));
                    }
                }
            }
            return(result.ToString());
        }
Exemplo n.º 26
0
        public override object Construct(ExecutionContext GLOBAL, JSObjectBase args, ExecutionContext x)
        {
            JSObject result;

            if (JSObject.ToNumber(GLOBAL, args.GetItem(GLOBAL, "length").GetValue(GLOBAL)) > 0)
            {
                result = new NumberObject(GLOBAL, JSObject.ToNumber(GLOBAL, args.GetItem(GLOBAL, "0").GetValue(GLOBAL)));
            }
            else
            {
                result = new NumberObject(GLOBAL, 0.0);
            }
            result.DefProp(GLOBAL, "prototype", this.GetItem(GLOBAL, "prototype").GetValue(GLOBAL));
            result.DefProp(GLOBAL, "constructor", this);
            return(result);
        }
Exemplo n.º 27
0
        public object GetValue(ExecutionContext GLOBAL)
        {
            JSObjectBase getFun = mGetter as JSObjectBase;

            if (getFun != null)
            {
                return(getFun.Call(GLOBAL, mValue, new JSArray(GLOBAL), GLOBAL.currentContext));
            }
            else if (mSetter != null)
            {
                return(JSUndefined.Undefined);
            }
            else
            {
                return(mValue);
            }
        }
Exemplo n.º 28
0
        public void SetValue(ExecutionContext GLOBAL, object value)
        {
            JSObjectBase setFun = mSetter as JSObjectBase;

            Trace.Assert(!(value is Reference));
            if (mGetter != null && setFun == null)
            {
                return;
            }
            else if (setFun != null)
            {
                setFun.Call(GLOBAL, mValue, new JSArray(GLOBAL, new object[] { value }), GLOBAL.currentContext);
            }
            else if (!ReadOnly)
            {
                mValue = value;
            }
        }
Exemplo n.º 29
0
 public override object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x)
 {
     JSObject result;
     int i, alen = (int)JSObject.ToNumber(GLOBAL, a.GetItem(GLOBAL, "length").GetValue(GLOBAL));
     string fundef = "function anonymous(";
     string comma = "";
     for (i = 0; i < alen - 1; i++)
     {
         string arg = a.GetItem(GLOBAL, i.ToString()).GetValue(GLOBAL).ToString();
         if (!argRe.IsMatch(arg)) throw new SyntaxError("Malformed parameter in function", null, 0);
         fundef += comma + arg;
         comma = ",";
     }
     fundef += ") { " + (alen > 0 ? a.GetItem(GLOBAL, i.ToString()).GetValue(GLOBAL).ToString() : "") + " }";
     Node n = jsparse.parse(GLOBAL, fundef, null, 0);
     result = new FunctionObject(GLOBAL, n, x);
     DefProp(GLOBAL, "length", (double)n.fparams.Count, false, false, false);
     return result;
 }
Exemplo n.º 30
0
        public static string join(ExecutionContext GLOBAL, object selfOb, string sep)
        {
            JSObjectBase  self    = (JSObjectBase)selfOb;
            List <string> strings = new List <string>();
            int           idx;

            for (idx = 0; idx < JSObject.ToNumber(GLOBAL, self.GetItem(GLOBAL, "length").GetValue(GLOBAL)); idx++)
            {
                string istr = idx.ToString();
                if (self.HasOwnProperty(istr) && self.GetItem(GLOBAL, istr).GetValue(GLOBAL) != null)
                {
                    strings.Add(JSObject.ToPrimitive(GLOBAL, self.GetItem(GLOBAL, istr).GetValue(GLOBAL)));
                }
                else
                {
                    strings.Add("");
                }
            }
            return(string.Join(sep, strings.ToArray()));
        }
Exemplo n.º 31
0
        void CollectArguments(JSObjectBase v, Node n, ref int k, ExecutionContext x)
        {
            int    i;
            object u;

            if (n.type == TokenType.LIST || n.type == TokenType.COMMA)
            {
                for (i = 0; i < n.Count; i++)
                {
                    CollectArguments(v, n[i], ref k, x);
                }
            }

            if (!(n.type == TokenType.LIST || n.type == TokenType.COMMA))
            {
                u = Reference.GetValue(GLOBAL, execute(n, x));
                v.SetItem(GLOBAL, k.ToString(), new JSSimpleProperty(k.ToString(), u));
                k++;
            }
        }
Exemplo n.º 32
0
        public override object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x)
        {
            Delegate   d = mThisRef as Delegate;
            MethodInfo m = d.Method;

            if (d == null)
            {
                throw new TypeError(Class + " isn't callable");
            }

            object[] arglist = JSObject.SatisfyArgumentList(GLOBAL, a, m.GetParameters());
            if (arglist != null)
            {
                return(JSObject.ToJS(GLOBAL, d.DynamicInvoke(arglist)));
            }
            else
            {
                throw new TypeError("Wrong arguments for method " + m.DeclaringType.Name + "." + m.Name);
            }
        }
Exemplo n.º 33
0
        public override object Construct(ExecutionContext GLOBAL, JSObjectBase a, ExecutionContext x)
        {
            JSObjectBase o = new JSObject();
            object       p = this.GetItem(GLOBAL, "prototype").GetValue(GLOBAL);

            if (!(p == null || p is JSUndefined || p is double || p is string || p is bool))
            {
                o.SetItem(GLOBAL, "prototype", new JSSimpleProperty("prototype", p, false, false, true));
            }

            object v = Call(GLOBAL, o, a, x);

            if (v == null || v is JSUndefined || v is double || v is string || v is bool)
            {
                return(o);
            }
            else
            {
                return(v);
            }
        }
Exemplo n.º 34
0
        public override object Construct(ExecutionContext GLOBAL, JSObjectBase a, ExecutionContext x)
        {
            JSArray ar   = new JSArray(GLOBAL);
            long    alen = (long)JSObject.ToNumber(GLOBAL, a.GetItem(GLOBAL, "length").GetValue(GLOBAL));

            if (alen == 1 && a.GetItem(GLOBAL, "0").GetValue(GLOBAL) is double)
            {
                ar = new JSArray(GLOBAL, (long)JSObject.ToNumber(GLOBAL, a.GetItem(GLOBAL, "0").GetValue(GLOBAL)));
            }
            else
            {
                long i;
                for (i = 0; i < alen; i++)
                {
                    ar.push(a.GetItem(GLOBAL, i.ToString()).GetValue(GLOBAL));
                }
            }
            ar.DefProp(GLOBAL, "prototype", mPrototype, false);
            ar.DefProp(GLOBAL, "constructor", this);
            return(ar);
        }
Exemplo n.º 35
0
        public override object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x)
        {
            if (!a.HasProperty(GLOBAL, "length"))
            {
                return(JSUndefined.Undefined);
            }
            int alen = (int)JSObject.ToNumber(GLOBAL, a.GetItem(GLOBAL, "length").GetValue(GLOBAL));

            if (alen < 1)
            {
                return(JSUndefined.Undefined);
            }

            object s = a.GetItem(GLOBAL, "0").GetValue(GLOBAL);

            if (!(s is string))
            {
                return(s);
            }
            //string str = (string)s;

            ExecutionContext x2 = new ExecutionContext(CodeType.EVAL_CODE);

            x2.thisOb             = x.thisOb;
            x2.caller             = x.caller;
            x2.callee             = x.callee;
            x2.scope              = x.scope;
            GLOBAL.currentContext = x2;
            try {
                jsexec JSExec = (jsexec)GLOBAL.jobject.GetItem(GLOBAL, "JSExec").GetValue(GLOBAL);
                JSExec.execute(jsparse.parse(GLOBAL, s.ToString(), null, 0), x2);
            } catch (ThrownException) {
                x.result = x2.result;
                throw;
            } finally {
                GLOBAL.currentContext = x;
            }
            return(x2.result);
        }
Exemplo n.º 36
0
        internal object apply(bool callMe, JSObjectBase f, object t, JSObjectBase args, ExecutionContext x)
        {
            // Curse ECMA again!
            if (t == JSUndefined.Undefined || t == null)
            {
                t = x;
            }

            if (!(t is JSObjectBase))
            {
                t = JSObject.ToObject(GLOBAL, t);
            }

            if (args == JSUndefined.Undefined || args == null)
            {
                args = new JSObject();
                args.SetItem(GLOBAL, "length", new JSSimpleProperty("length", 0.0, false, false, true));
            }
            else if (args is JSArray)
            {
                var vv = new JSObject();
                int ii, jj;
                for (ii = 0, jj = (int)JSObject.ToNumber(GLOBAL, args.GetItem(GLOBAL, "length").GetValue(GLOBAL)); ii < jj; ii++)
                {
                    vv.SetItem(GLOBAL, ii.ToString(), new JSSimpleProperty(ii.ToString(), args.GetItem(GLOBAL, ii.ToString()).GetValue(GLOBAL), false, false, true));
                }
                vv.SetItem(GLOBAL, "length", new JSSimpleProperty("length", (double)ii, false, false, true));
                args = vv;
            }

            if (callMe)
            {
                return(f.Call(GLOBAL, t, args, x));
            }
            else
            {
                return(f.Construct(GLOBAL, args, x));
            }
        }
Exemplo n.º 37
0
 // Punct
 // Mask 1 excludes @*_-.
 // Mask 2 excludes @*_-.
 // Mask 4 excludes @*_-.+/
 // AlphaNumeric, spaces
 // Mask 1 excludes letters and numbers
 // Mask 2 escapes ' ' with +
 // Mask 4 excludes letters and numbers
 // 1 and 4 unexclude ' '
 public override object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x)
 {
     int alen = (int)JSObject.ToNumber(GLOBAL, a.GetItem(GLOBAL, "length").GetValue(GLOBAL));
     int mask = 4;
     if (alen == 0) return JSUndefined.Undefined;
     else if (alen > 1)
     {
         mask = (int)JSObject.ToNumber(GLOBAL, a.GetItem(GLOBAL, "1").GetValue(GLOBAL));
     }
     string instr = JSObject.ToPrimitive(GLOBAL, a.GetItem(GLOBAL, "0").GetValue(GLOBAL));
     StringBuilder result = new StringBuilder();
     foreach (char ch in instr)
     {
         if (ch == ' ' && mask == 2)
         {
             result.Append('+');
         }
         else if ((ch == '+' || ch == '/') && (mask & 4) != 0)
         {
             result.Append(ch);
         }
         else if ((ch == '@' || ch == '*' || ch == '_' || ch == '-' || ch == '.') && mask != 0)
         {
             result.Append(ch);
         }
         else if (char.IsLetterOrDigit(ch) && mask != 0)
         {
             result.Append(ch);
         }
         else
         {
             if (ch >= (char)0x100)
                 result.Append(string.Format("%u{0:X4}", (int)ch));
             else
                 result.Append(string.Format("%{0:X2}", (int)ch));
         }
     }
     return result.ToString();
 }
Exemplo n.º 38
0
        public override object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x)
        {
            ExecutionContext x2 = new ExecutionContext(CodeType.FUNCTION_CODE);

            x2.thisOb = (JSObjectBase)(JSObject.ToBool(GLOBAL, t) ? t : GLOBAL.jobject);
            x2.caller = x;
            x2.callee = this;
            a.SetItem(GLOBAL, "callee", new JSSimpleProperty("callee", this, false, false, true));
            Node f = this.node;

            x2.scope         = new ExecutionContext();
            x2.scope.parent  = this.scope;
            x2.scope.jobject = new Activation(GLOBAL, f, a);

            GLOBAL.currentContext = x2;

            try
            {
                jsexec JSExec = (jsexec)GLOBAL.jobject.GetItem(GLOBAL, "JSExec").GetValue(GLOBAL);
                JSExec.execute(f.body == null ? f : f.body, x2);
            }
            catch (ReturnException)
            {
                return(x2.result);
            }
            catch (ThrownException)
            {
                x.result = x2.result;
                throw;
            }
            finally
            {
                GLOBAL.currentContext = x;
            }

            return(JSUndefined.Undefined);
        }
Exemplo n.º 39
0
 public override object Construct(ExecutionContext GLOBAL, JSObjectBase args, ExecutionContext x)
 {
     object[] arglist = null;
     foreach (ConstructorInfo c in mThisType.GetConstructors())
     {
         arglist = JSObject.SatisfyArgumentList(GLOBAL, args, c.GetParameters());
         if (arglist != null)
         {
             return JSObject.ToJS(GLOBAL, c.Invoke(arglist));
         }
     }
     throw new TypeError("Wrong argument types for " + mThisType.Name + " constructor");
 }
Exemplo n.º 40
0
 public override object Construct(ExecutionContext GLOBAL, JSObjectBase a, ExecutionContext x)
 {
     return JSUndefined.Undefined;
 }
Exemplo n.º 41
0
        public override object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x)
        {
            Delegate d = mThisRef as Delegate;
            MethodInfo m = d.Method;

            if (d == null) throw new TypeError(Class + " isn't callable");

            object[] arglist = JSObject.SatisfyArgumentList(GLOBAL, a, m.GetParameters());
            if (arglist != null)
                return JSObject.ToJS(GLOBAL, d.DynamicInvoke(arglist));
            else
                throw new TypeError("Wrong arguments for method " + m.DeclaringType.Name + "." + m.Name);
        }
Exemplo n.º 42
0
 public override object Construct(ExecutionContext GLOBAL, JSObjectBase args, ExecutionContext x)
 {
     JSObject result = new BoolObject(GLOBAL, (int)JSObject.ToNumber(GLOBAL, args.GetItem(GLOBAL, "length").GetValue(GLOBAL)) > 0 && JSObject.ToBool(GLOBAL, args.GetItem(GLOBAL, "0").GetValue(GLOBAL)));
     result.DefProp(GLOBAL, "constructor", this);
     return result;
 }
Exemplo n.º 43
0
 public override object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x)
 {
     return "0";
 }
Exemplo n.º 44
0
 public Thunk(JSObjectBase thisOb, JSObjectBase f, ExecutionContext x)
 {
     this.thisOb = thisOb;
     this.f = f;
     this.x = x;
 }
Exemplo n.º 45
0
 public static void Register(ExecutionContext GLOBAL, JSObjectBase scope, Type t)
 {
     string[] fullName = t.FullName.Split(new char[] { '.' });
     JSClassWrapper wrapper = new JSClassWrapper(GLOBAL, t);
     RegisterNamespace(GLOBAL, scope, fullName, fullName.Length - 2);
 }
Exemplo n.º 46
0
 public virtual object Construct(ExecutionContext GLOBAL, JSObjectBase args, ExecutionContext x)
 {
     throw new TypeError(Class + " is not a constructor");
 }
Exemplo n.º 47
0
 public override object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x)
 {
     System.Console.WriteLine("used memory " + GC.GetTotalMemory(true));
     return JSUndefined.Undefined;
 }
Exemplo n.º 48
0
        void CollectArguments(JSObjectBase v, Node n, ref int k, ExecutionContext x)
        {
            int i;
            object u;

            if (n.type == TokenType.LIST || n.type == TokenType.COMMA)
            {
                for (i = 0; i < n.Count; i++)
                    CollectArguments(v, n[i], ref k, x);
            }

            if (!(n.type == TokenType.LIST || n.type == TokenType.COMMA))
            {
                u = Reference.GetValue(GLOBAL, execute(n, x));
                v.SetItem(GLOBAL, k.ToString(), new JSSimpleProperty(k.ToString(), u));
                k++;
            }
        }
Exemplo n.º 49
0
        public override object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x)
        {
            if (!a.HasProperty(GLOBAL, "length")) return JSUndefined.Undefined;
            int alen = (int)JSObject.ToNumber(GLOBAL, a.GetItem(GLOBAL, "length").GetValue(GLOBAL));
            if (alen < 1) return JSUndefined.Undefined;

            object s = a.GetItem(GLOBAL, "0").GetValue(GLOBAL);
            if (!(s is string)) return s;
            string str = (string)s;

            ExecutionContext x2 = new ExecutionContext(CodeType.EVAL_CODE);
            x2.thisOb = x.thisOb;
            x2.caller = x.caller;
            x2.callee = x.callee;
            x2.scope = x.scope;
            GLOBAL.currentContext = x2;
            try {
                jsexec JSExec = (jsexec)GLOBAL.jobject.GetItem(GLOBAL, "JSExec").GetValue(GLOBAL);
                JSExec.execute(jsparse.parse(GLOBAL, s.ToString(), null, 0), x2);
            } catch (ThrownException) {
                x.result = x2.result;
                throw;
            } finally {
                GLOBAL.currentContext = x;
            }
            return x2.result;
        }
Exemplo n.º 50
0
        public override object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x)
        {
            ExecutionContext x2 = new ExecutionContext(CodeType.FUNCTION_CODE);
            x2.thisOb = (JSObjectBase)(JSObject.ToBool(GLOBAL, t) ? t : GLOBAL.jobject);
            x2.caller = x;
            x2.callee = this;
            a.SetItem(GLOBAL, "callee", new JSSimpleProperty("callee", this, false, false, true));
            Node f = this.node;
            x2.scope = new ExecutionContext();
            x2.scope.parent = this.scope;
            x2.scope.jobject = new Activation(GLOBAL, f, a);

            GLOBAL.currentContext = x2;

            try
            {
                jsexec JSExec = (jsexec)GLOBAL.jobject.GetItem(GLOBAL, "JSExec").GetValue(GLOBAL);
                JSExec.execute(f.body == null ? f : f.body, x2);
            }
            catch (ReturnException)
            {
                return x2.result;
            }
            catch (ThrownException)
            {
                x.result = x2.result;
                throw;
            }
            finally
            {
                GLOBAL.currentContext = x;
            }

            return JSUndefined.Undefined;
        }
Exemplo n.º 51
0
        public override object Construct(ExecutionContext GLOBAL, JSObjectBase a, ExecutionContext x)
        {
            JSObjectBase o = new JSObject();
            object p = this.GetItem(GLOBAL, "prototype").GetValue(GLOBAL);

            if (!(p == null || p is JSUndefined || p is double || p is string || p is bool))
                o.SetItem(GLOBAL, "prototype", new JSSimpleProperty("prototype", p, false, false, true));

            object v = Call(GLOBAL, o, a, x);
            if (v == null || v is JSUndefined || v is double || v is string || v is bool)
                return o;
            else
                return v;
        }
Exemplo n.º 52
0
 public override object Construct(ExecutionContext GLOBAL, JSObjectBase args, ExecutionContext x)
 {
     JSObject result = (JSObject)Call(GLOBAL, x, args, x);
     result.DefProp(GLOBAL, "constructor", this);
     return result;
 }
Exemplo n.º 53
0
 public override object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x)
 {
     if (mApplyMethod == null) throw new TypeError(Class + " is not callable");
     return ((JSObjectBase)mApplyMethod.GetValue(GLOBAL)).Call(GLOBAL, t, a, x);
 }
Exemplo n.º 54
0
 public override object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x)
 {
     int alen = (int)JSObject.ToNumber(GLOBAL, a.GetItem(GLOBAL, "length").GetValue(GLOBAL));
     if (alen == 0) return false;
     double val = JSObject.ToNumber(GLOBAL, a.GetItem(GLOBAL, "0").GetValue(GLOBAL));
     return !double.IsNaN(val) && !double.IsPositiveInfinity(val) && !double.IsNegativeInfinity(val);
 }
Exemplo n.º 55
0
 public object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x)
 {
     throw new TypeError("undefined is not a function");
 }
Exemplo n.º 56
0
 public override object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x)
 {
     int alen = (int)JSObject.ToNumber(GLOBAL, a.GetItem(GLOBAL, "length").GetValue(GLOBAL));
     if (alen == 0) return Double.NaN;
     else return (double)(long)JSObject.ToNumber(GLOBAL, a.GetItem(GLOBAL, "0").GetValue(GLOBAL));
 }
Exemplo n.º 57
0
 public static JSObjectBase RegisterNamespace(ExecutionContext GLOBAL, JSObjectBase scope, string[] names, int idx)
 {
     JSObjectBase parent = idx == 0 ? scope : RegisterNamespace(GLOBAL, scope, names, idx - 1);
     if (!parent.HasProperty(GLOBAL, names[idx]))
     {
         JSObject wrapper = new JSObject();
         parent.GetItem(GLOBAL, names[idx]).SetValue(GLOBAL, wrapper);
         return wrapper;
     }
     return (JSObjectBase)parent.GetItem(GLOBAL, names[idx]).GetValue(GLOBAL);
 }
Exemplo n.º 58
0
 public override object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x)
 {
     int alen = (int)JSObject.ToNumber(GLOBAL, a.GetItem(GLOBAL, "length").GetValue(GLOBAL));
     StringBuilder result = new StringBuilder();
     Match escChar;
     if (alen == 0) return JSUndefined.Undefined;
     string instr = JSObject.ToPrimitive(GLOBAL, a.GetItem(GLOBAL, "0").GetValue(GLOBAL));
     int startAt = 0;
     int lastUsed = 0;
     while (startAt < instr.Length && (escChar = escapedChar.Match(instr, startAt)).Success)
     {
         startAt = escChar.Index;
         result.Append(instr.Substring(lastUsed, startAt - lastUsed));
         if (escChar.Groups[0].Value[1] == 'u')
         {
             startAt += 6;
             result.Append((char)int.Parse(escChar.Groups[0].Value.Substring(2), NumberStyles.HexNumber));
         }
         else
         {
             startAt += 3;
             result.Append((char)int.Parse(escChar.Groups[0].Value.Substring(1), NumberStyles.HexNumber));
         }
         lastUsed = startAt;
     }
     if (lastUsed < instr.Length)
         result.Append(instr.Substring(lastUsed));
     return result.ToString();
 }
Exemplo n.º 59
0
 public override object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x)
 {
     int alen = (int)JSObject.ToNumber(GLOBAL, a.GetItem(GLOBAL, "length").GetValue(GLOBAL));
     if (alen == 0) return false;
     return JSObject.ToBool(GLOBAL, a.GetItem(GLOBAL, "0").GetValue(GLOBAL));
 }
Exemplo n.º 60
0
        internal object apply(bool callMe, JSObjectBase f, object t, JSObjectBase args, ExecutionContext x)
        {
            // Curse ECMA again!
            if (t == JSUndefined.Undefined || t == null)
                t = x;

            if (!(t is JSObjectBase))
                t = JSObject.ToObject(GLOBAL, t);

            if (args == JSUndefined.Undefined || args == null)
            {
                args = new JSObject();
                args.SetItem(GLOBAL, "length", new JSSimpleProperty("length", 0.0, false, false, true));
            }
            else if (args is JSArray)
            {
                var vv = new JSObject();
                int ii, jj;
                for (ii = 0, jj = (int)JSObject.ToNumber(GLOBAL, args.GetItem(GLOBAL, "length").GetValue(GLOBAL)); ii < jj; ii++)
                    vv.SetItem(GLOBAL, ii.ToString(), new JSSimpleProperty(ii.ToString(), args.GetItem(GLOBAL, ii.ToString()).GetValue(GLOBAL), false, false, true));
                vv.SetItem(GLOBAL, "length", new JSSimpleProperty("length", (double)ii, false, false, true));
                args = vv;
            }

            if (callMe)
                return f.Call(GLOBAL, t, args, x);
            else
                return f.Construct(GLOBAL, args, x);
        }