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); }
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)); } }
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); }
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)); } }
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); }
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); }
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); }
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); }
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); }
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; }
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)); }
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)); }
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))); }
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; }
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)); }
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)); }
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)); }
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)); }
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)); }
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"); }
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))); } }
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); }
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); } } }
// 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()); }
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); }
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); } }
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; } }
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; }
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())); }
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++; } }
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); } }
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); } }
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); }
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); }
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)); } }
// 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(); }
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); }
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"); }
public override object Construct(ExecutionContext GLOBAL, JSObjectBase a, ExecutionContext x) { return JSUndefined.Undefined; }
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); }
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; }
public override object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x) { return "0"; }
public Thunk(JSObjectBase thisOb, JSObjectBase f, ExecutionContext x) { this.thisOb = thisOb; this.f = f; this.x = x; }
public virtual object Construct(ExecutionContext GLOBAL, JSObjectBase args, ExecutionContext x) { throw new TypeError(Class + " is not a constructor"); }
public override object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x) { System.Console.WriteLine("used memory " + GC.GetTotalMemory(true)); return JSUndefined.Undefined; }
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++; } }
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; }
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; }
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; }
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; }
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); }
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); }
public object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x) { throw new TypeError("undefined is not a function"); }
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)); }
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); }
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(); }
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)); }
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); }