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 Construct(ExecutionContext GLOBAL, JSObjectBase args, ExecutionContext x) { JSObject result = (JSObject)Call(GLOBAL, x, args, x); result.DefProp(GLOBAL, "constructor", this); return(result); }
public jsexec() { GLOBAL.jobject = new JSObject(); GLOBAL.jobject = GLOBAL.thisOb = new JSObject(); StaticObjectFun = new ObjectFun(GLOBAL); GLOBAL.jobject.SetItem(GLOBAL, "StaticObjectFun", new JSSimpleProperty("StaticObjectFun", StaticObjectFun)); StaticStringFun = new StringFun(GLOBAL); GLOBAL.jobject.SetItem(GLOBAL, "StaticStringFun", new JSSimpleProperty("StaticStringFun", StaticStringFun)); StaticBooleanFun = new BooleanFun(GLOBAL); GLOBAL.jobject.SetItem(GLOBAL, "StaticBooleanFun", new JSSimpleProperty("StaticBooleanFun", StaticBooleanFun)); StaticArrayFun = new ArrayFun(GLOBAL); GLOBAL.jobject.SetItem(GLOBAL, "StaticArrayFun", new JSSimpleProperty("StaticArrayFun", StaticArrayFun)); StaticNumberFun = new NumberFun(GLOBAL); GLOBAL.jobject.SetItem(GLOBAL, "StaticNumberFun", new JSSimpleProperty("StaticNumberFun", StaticNumberFun)); StaticFunctionFun = new FunctionFun(GLOBAL); GLOBAL.jobject.SetItem(GLOBAL, "StaticFunctionFun", new JSSimpleProperty("StaticFunctionFun", StaticFunctionFun)); //StaticNumberObject = new NumberObject(GLOBAL, 0.0); #if !JS_SLIM DatePrototype = new JSDate(GLOBAL); GLOBAL.jobject.SetItem(GLOBAL, "DatePrototype", new JSSimpleProperty("DatePrototype", DatePrototype)); JSDate.SetupPrototype(GLOBAL, DatePrototype); #endif GLOBAL.jobject.SetItem(GLOBAL, "toString", new JSNativeMethod(typeof(JSObject), "StaticToString")); /* Core types */ JSObject thisOb = (JSObject)GLOBAL.thisOb; thisOb.DefProp(GLOBAL, "Object", StaticObjectFun); thisOb.DefProp(GLOBAL, "Function", StaticFunctionFun); thisOb.DefProp(GLOBAL, "Boolean", StaticBooleanFun); thisOb.DefProp(GLOBAL, "Number", StaticNumberFun); thisOb.DefProp(GLOBAL, "String", StaticStringFun); thisOb.DefProp(GLOBAL, "Array", StaticArrayFun); /* Types that work like classes */ #if !JS_SLIM thisOb.DefProp(GLOBAL, "Math", JSClassWrapper.RegisterClass(GLOBAL, typeof(pygmalion.JSMath))); thisOb.DefProp(GLOBAL, "Date", JSClassWrapper.RegisterClass(GLOBAL, typeof(pygmalion.JSDate))); thisOb.DefProp(GLOBAL, "Error", JSClassWrapper.RegisterClass(GLOBAL, typeof(pygmalion.JSError))); /* Standard library */ thisOb.DefProp(GLOBAL, "decodeURI", new DecodeURIFun()); thisOb.DefProp(GLOBAL, "decodeURIComponent", new DecodeURIComponentFun()); thisOb.DefProp(GLOBAL, "encodeURI", new EncodeURIFun()); thisOb.DefProp(GLOBAL, "encodeURIComponent", new EncodeURIComponentFun()); thisOb.DefProp(GLOBAL, "escape", new EscapeFun()); #endif thisOb.DefProp(GLOBAL, "eval", new EvalFun()); thisOb.DefProp(GLOBAL, "gc", new GcFun()); thisOb.DefProp(GLOBAL, "Infinity", double.PositiveInfinity, false, false, false); thisOb.DefProp(GLOBAL, "isFinite", new isFiniteFun()); thisOb.SetItem(GLOBAL, "isNaN", new JSNativeMethod(typeof(Double), "IsNaN")); thisOb.DefProp(GLOBAL, "parseFloat", new ParseFloat(), false, false, false); thisOb.DefProp(GLOBAL, "parseInt", new ParseInt(), false, false, false); thisOb.DefProp(GLOBAL, "NaN", double.NaN, false, false, false); thisOb.DefProp(GLOBAL, "unescape", new UnescapeFun()); thisOb.DefProp(GLOBAL, "version", new VersionFun()); GLOBAL.jobject.SetItem(GLOBAL, "JSExec", new JSSimpleProperty("JSExec", this)); GLOBAL.thisOb = GLOBAL.jobject; GLOBAL.currentContext = new ExecutionContext(GLOBAL); GLOBAL.scope = GLOBAL.currentContext; }
public ArrayFun(ExecutionContext GLOBAL) { mPrototype = new JSArray(GLOBAL); DefProp(GLOBAL, "prototype", mPrototype, false, false, false); mPrototype.DefProp(GLOBAL, "constructor", this); }