Beispiel #1
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);
 }
Beispiel #2
0
 public NumberObject(ExecutionContext GLOBAL, double val)
 {
     mValue = val;
     NumberFun StaticNumberFun = (NumberFun)jsexec.GlobalOrNull(GLOBAL, "StaticNumberFun");
     DefProp(GLOBAL, "prototype", StaticNumberFun != null ? StaticNumberFun.GetItem(GLOBAL, "prototype").GetValue(GLOBAL) : null, false, false, false);
     DefProp(GLOBAL, "constructor", StaticNumberFun != null ? StaticNumberFun : null, false, false, false);
 }
Beispiel #3
0
 public FunctionFun(ExecutionContext GLOBAL)
 {
     Node functionNode = new Node(new Tokenizer(GLOBAL, "", null, 0), TokenType.Function);
     JSObject prototype = new FunctionObject(GLOBAL, functionNode, GLOBAL.currentContext);
     DefProp(GLOBAL, "prototype", prototype, false, false, false);
     prototype.DefProp(GLOBAL, "constructor", this);
 }
Beispiel #4
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);
 }
Beispiel #5
0
 public BoolObject(ExecutionContext GLOBAL, bool val)
 {
     mValue = val;
     BooleanFun StaticBooleanFun = (BooleanFun)jsexec.GlobalOrNull(GLOBAL, "StaticBooleanFun");
     this.DefProp(GLOBAL, "prototype", StaticBooleanFun != null ? StaticBooleanFun.GetItem(GLOBAL, "prototype").GetValue(GLOBAL) : null, false, false, false);
     DefProp(GLOBAL, "constructor", StaticBooleanFun, false, false, false, true);
 }
Beispiel #6
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;
 }
Beispiel #7
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);
 }
Beispiel #8
0
        public JSClassWrapper(ExecutionContext GLOBAL, Type t)
        {
            object thisOb = null;
            mThisType = t;
            BindingFlags flags = BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public;
            string applyMethod = null;
            object []attributes = t.GetCustomAttributes(false);
            List<MethodInfo> applying = new List<MethodInfo>();

            foreach (object attribute in attributes)
            {
                if (attribute is ApplyAttribute)
                    applyMethod = ((ApplyAttribute)attribute).MethodName;
            }

            if (t == typeof(Type))
            {
                thisOb = t;
                flags |= BindingFlags.Instance;
            }
            Dictionary<string, List<MethodInfo>> namedMethods = new Dictionary<string, List<MethodInfo>>();

            foreach (FieldInfo fieldInfo in mThisType.GetFields(flags))
            {
                this.SetItem(GLOBAL, fieldInfo.Name, new JSNativeField(thisOb, fieldInfo));
            }
            foreach (PropertyInfo propInfo in mThisType.GetProperties(flags))
            {
                this.SetItem(GLOBAL, propInfo.Name, new JSNativeProperty(thisOb, propInfo));
            }
            foreach (MethodInfo methodInfo in mThisType.GetMethods(flags))
            {
                List<MethodInfo> ml;
                if (applyMethod != null && methodInfo.Name == applyMethod && methodInfo.IsStatic)
                    applying.Add(methodInfo);
                if (!namedMethods.TryGetValue(methodInfo.Name, out ml))
                {
                    ml = new List<MethodInfo>(new MethodInfo[] { methodInfo });
                    namedMethods[methodInfo.Name] = ml;
                }
                else
                    ml.Add(methodInfo);
            }

            foreach (EventInfo eventInfo in mThisType.GetEvents(flags))
            {
                this.SetItem(GLOBAL, eventInfo.Name, new JSNativeEvent(GLOBAL, thisOb, eventInfo));
            }
            foreach (KeyValuePair<string, List<MethodInfo>> method in namedMethods)
            {
                this.SetItem(GLOBAL, method.Key, new JSNativeMethod(method.Value.ToArray()));
            }
            if (applying.Count > 0)
            {
                mApplyMethod = new JSNativeMethod(applying.ToArray());
            }
        }
Beispiel #9
0
 public BooleanFun(ExecutionContext GLOBAL)
 {
     JSObject prototype = new BoolObject(GLOBAL, false);
     DefProp(GLOBAL, "prototype", prototype, false, false, false);
     prototype.DefProp(GLOBAL, "constructor", this);
     prototype.DefProp(GLOBAL, "length", (double)1, false, false, false);
     prototype.SetItem(GLOBAL, "toString", new JSNativeMethod(typeof(BoolObject), "ToString"));
     prototype.SetItem(GLOBAL, "valueOf", new JSNativeMethod(typeof(BoolObject), "ValueOf"));
     DefProp(GLOBAL, "length", (double)1, false, false, false);
 }
Beispiel #10
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;
 }
Beispiel #11
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));
 }
Beispiel #12
0
 public FunctionObject(ExecutionContext GLOBAL, Node node, ExecutionContext scope)
 {
     this.node = node;
     if (this.node.type == TokenType.SCRIPT)
         this.node = this.node[0];
     this.scope = scope;
     this.SetItem(GLOBAL, "length", new JSSimpleProperty("length", (double)node.fparams.Count, true, true, true));
     JSObject prototype = new JSObject();
     this.SetItem(GLOBAL, "prototype", new JSSimpleProperty("prototype", prototype, true));
     prototype.SetItem(GLOBAL, "toString", new JSNativeMethod(typeof(JSObject), "ToString"));
     prototype.SetItem(GLOBAL, "valueOf", new JSNativeMethod(typeof(JSObject), "ToPrimitive"));
     this.SetItem(GLOBAL, "constructor", new JSSimpleProperty("constructor", this, false, false, true));
 }
Beispiel #13
0
 public NumberFun(ExecutionContext GLOBAL)
 {
     DefProp(GLOBAL, "MAX_VALUE", double.MaxValue, true, false, false, true);
     DefProp(GLOBAL, "MIN_VALUE", double.Epsilon, true, false, false, true);
     DefProp(GLOBAL, "NaN", double.NaN, true, false, false, true);
     DefProp(GLOBAL, "NEGATIVE_INFINITY", double.NegativeInfinity, true, false, false, true);
     DefProp(GLOBAL, "POSITIVE_INFINITY", double.PositiveInfinity, true, false, false, true);
     DefProp(GLOBAL, "length", (double)1, false, false, false, false);
     JSObject prototype = new NumberObject(GLOBAL, 0.0);
     prototype.SetItem(GLOBAL, "toString", new JSNativeMethod(typeof(JSObject), "ToString"));
     prototype.SetItem(GLOBAL, "valueOf", new JSNativeMethod(typeof(JSObject), "ToPrimitive"));
     DefProp(GLOBAL, "prototype", prototype, false, false, false);
     prototype.DefProp(GLOBAL, "constructor", this);
 }
Beispiel #14
0
 public JSDate(ExecutionContext GLOBAL, double year, double month, params double[] args)
     : this(GLOBAL, year)
 {
     if (args.Length == 0)
         mDateTime = new DateTime((int)year, (int)month, 1);
     else if (args.Length == 1)
         mDateTime = new DateTime((int)year, (int)month, (int)args[0]);
     else if (args.Length == 2)
         mDateTime = new DateTime((int)year, (int)month, (int)args[0], (int)args[1], 0, 0);
     else if (args.Length == 3)
         mDateTime = new DateTime((int)year, (int)month, (int)args[0], (int)args[1], (int)args[2], 0);
     else if (args.Length == 4)
         mDateTime = new DateTime((int)year, (int)month, (int)args[0], (int)args[1], (int)args[2], (int)args[3]);
     else
         mDateTime = new DateTime((int)year, (int)month, (int)args[0], (int)args[1], (int)args[2], (int)args[3], (int)args[4]);
 }
Beispiel #15
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;
 }
Beispiel #16
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();
 }
Beispiel #17
0
 public static long parse(ExecutionContext GLOBAL, string date)
 {
     return JSDate.getTime(new JSDate(GLOBAL, DateTime.Parse(date)));
 }
Beispiel #18
0
 public override object Construct(ExecutionContext GLOBAL, JSObjectBase a, ExecutionContext x)
 {
     return JSUndefined.Undefined;
 }
Beispiel #19
0
 public override object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x)
 {
     return "0";
 }
Beispiel #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));
     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();
 }
Beispiel #21
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));
 }
Beispiel #22
0
 public JSDate(ExecutionContext GLOBAL, DateTime dt)
     : this(GLOBAL)
 {
     mDateTime = dt;
 }
Beispiel #23
0
 public JSDate(ExecutionContext GLOBAL)
 {
     mDateTime = DateTime.UtcNow;
     JSDate mPrototype = (JSDate)jsexec.GlobalOrNull(GLOBAL, "DatePrototype");
     SetItem(GLOBAL, "prototype", new JSSimpleProperty("prototype", mPrototype));
 }
Beispiel #24
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;
 }
Beispiel #25
0
 public static void SetupPrototype(ExecutionContext GLOBAL, JSObject Prototype)
 {
     Prototype.SetItem(GLOBAL, "getDate", new JSNativeMethod(typeof(JSDate), "getDate"));
     Prototype.SetItem(GLOBAL, "getDay", new JSNativeMethod(typeof(JSDate), "getDay"));
     Prototype.SetItem(GLOBAL, "getFullYear", new JSNativeMethod(typeof(JSDate), "getFullYear"));
     Prototype.SetItem(GLOBAL, "getHours", new JSNativeMethod(typeof(JSDate), "getHours"));
     Prototype.SetItem(GLOBAL, "getMilliseconds", new JSNativeMethod(typeof(JSDate), "getMilliseconds"));
     Prototype.SetItem(GLOBAL, "getMinutes", new JSNativeMethod(typeof(JSDate), "getMinutes"));
     Prototype.SetItem(GLOBAL, "getMonth", new JSNativeMethod(typeof(JSDate), "getMonth"));
     Prototype.SetItem(GLOBAL, "getSeconds", new JSNativeMethod(typeof(JSDate), "getSeconds"));
     Prototype.SetItem(GLOBAL, "getTime", new JSNativeMethod(typeof(JSDate), "getTime"));
     Prototype.SetItem(GLOBAL, "getTimezoneOffset", new JSNativeMethod(typeof(JSDate), "getTimezoneOffset"));
     Prototype.SetItem(GLOBAL, "getUTCDate", new JSNativeMethod(typeof(JSDate), "getUTCDate"));
     Prototype.SetItem(GLOBAL, "getUTCDay", new JSNativeMethod(typeof(JSDate), "getUTCDay"));
     Prototype.SetItem(GLOBAL, "getUTCMonth", new JSNativeMethod(typeof(JSDate), "getUTCMonth"));
     Prototype.SetItem(GLOBAL, "getUTCFullYear", new JSNativeMethod(typeof(JSDate), "getUTCFullYear"));
     Prototype.SetItem(GLOBAL, "getUTCHours", new JSNativeMethod(typeof(JSDate), "getUTCHours"));
     Prototype.SetItem(GLOBAL, "getUTCMinutes", new JSNativeMethod(typeof(JSDate), "getUTCMinutes"));
     Prototype.SetItem(GLOBAL, "getUTCSeconds", new JSNativeMethod(typeof(JSDate), "getUTCSeconds"));
     Prototype.SetItem(GLOBAL, "getUTCMilliseconds", new JSNativeMethod(typeof(JSDate), "getUTCMilliseconds"));
     Prototype.SetItem(GLOBAL, "getYear", new JSNativeMethod(typeof(JSDate), "getYear"));
     Prototype.SetItem(GLOBAL, "parse", new JSNativeMethod(typeof(JSDate), "parse"));
     Prototype.SetItem(GLOBAL, "setDate", new JSNativeMethod(typeof(JSDate), "setDate"));
     Prototype.SetItem(GLOBAL, "setFullYear", new JSNativeMethod(typeof(JSDate), "setFullYear"));
     Prototype.SetItem(GLOBAL, "setHours", new JSNativeMethod(typeof(JSDate), "setHours"));
     Prototype.SetItem(GLOBAL, "setMilliseconds", new JSNativeMethod(typeof(JSDate), "setMilliseconds"));
     Prototype.SetItem(GLOBAL, "setMinutes", new JSNativeMethod(typeof(JSDate), "setMinutes"));
     Prototype.SetItem(GLOBAL, "setMonth", new JSNativeMethod(typeof(JSDate), "setMonth"));
     Prototype.SetItem(GLOBAL, "setSeconds", new JSNativeMethod(typeof(JSDate), "setSeconds"));
     Prototype.SetItem(GLOBAL, "setTime", new JSNativeMethod(typeof(JSDate), "setTime"));
     Prototype.SetItem(GLOBAL, "setUTCDate", new JSNativeMethod(typeof(JSDate), "setUTCDate"));
     Prototype.SetItem(GLOBAL, "setUTCMonth", new JSNativeMethod(typeof(JSDate), "setUTCMonth"));
     Prototype.SetItem(GLOBAL, "setUTCFullYear", new JSNativeMethod(typeof(JSDate), "setUTCFullYear"));
     Prototype.SetItem(GLOBAL, "setUTCHours", new JSNativeMethod(typeof(JSDate), "setUTCHours"));
     Prototype.SetItem(GLOBAL, "setUTCMinutes", new JSNativeMethod(typeof(JSDate), "setUTCMinutes"));
     Prototype.SetItem(GLOBAL, "setUTCSeconds", new JSNativeMethod(typeof(JSDate), "setUTCSeconds"));
     Prototype.SetItem(GLOBAL, "setUTCMilliseconds", new JSNativeMethod(typeof(JSDate), "setUTCMilliseconds"));
     Prototype.SetItem(GLOBAL, "setYear", new JSNativeMethod(typeof(JSDate), "setYear"));
     Prototype.SetItem(GLOBAL, "toDateString", new JSNativeMethod(typeof(JSDate), "toDateString"));
     Prototype.SetItem(GLOBAL, "toGMTString", new JSNativeMethod(typeof(JSDate), "toGMTString"));
     Prototype.SetItem(GLOBAL, "toLocaleDateString", new JSNativeMethod(typeof(JSDate), "toLocaleDateString"));
     Prototype.SetItem(GLOBAL, "toLocaleTimeString", new JSNativeMethod(typeof(JSDate), "toLocaleTimeString"));
     Prototype.SetItem(GLOBAL, "toLocaleString", new JSNativeMethod(typeof(JSDate), "toLocaleString"));
     //toSource() 	Represents the source code of an object 	1 	-
     Prototype.SetItem(GLOBAL, "toString", new JSNativeMethod(typeof(JSDate), "ToString"));
     Prototype.SetItem(GLOBAL, "toTimeString", new JSNativeMethod(typeof(JSDate), "toTimeString"));
     Prototype.SetItem(GLOBAL, "toUTCString", new JSNativeMethod(typeof(JSDate), "toUTCString"));
     Prototype.SetItem(GLOBAL, "UTC", new JSNativeMethod(typeof(JSDate), "UTC"));
     Prototype.SetItem(GLOBAL, "valueOf", new JSNativeMethod(typeof(JSDate), "getTime"));
 }
Beispiel #26
0
 internal static Node parse(ExecutionContext GLOBAL, string s, string f, int l)
 {
     Tokenizer t = new Tokenizer(GLOBAL, s, f, l);
     Node x = new Node(t, (TokenType)(int)CodeType.GLOBAL_CODE);
     Node n = Script(t, x);
     if (!t.done)
         throw t.newSyntaxError("Syntax error");
     return n;
 }
Beispiel #27
0
 public JSDate(ExecutionContext GLOBAL, double year)
     : this(GLOBAL)
 {
 }
Beispiel #28
0
 public override object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x)
 {
     System.Console.WriteLine("used memory " + GC.GetTotalMemory(true));
     return JSUndefined.Undefined;
 }
Beispiel #29
0
 public static long UTC(ExecutionContext GLOBAL)
 {
     return JSDate.getTime(new JSDate(GLOBAL));
 }
Beispiel #30
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);
 }