public JSInstanceWrapper(ExecutionContext GLOBAL, object thisRef) { mThisRef = thisRef; mClassWrapper = JSClassWrapper.RegisterClass(GLOBAL, mThisRef.GetType()); Dictionary <string, List <MethodInfo> > namedMethods = new Dictionary <string, List <MethodInfo> >(); Type myType = mThisRef.GetType(); foreach (FieldInfo fieldInfo in myType.GetFields(BindingFlags.FlattenHierarchy | BindingFlags.Instance | BindingFlags.Public)) { this.SetItem(GLOBAL, fieldInfo.Name, new JSNativeField(mThisRef, fieldInfo)); } foreach (PropertyInfo propInfo in myType.GetProperties(BindingFlags.FlattenHierarchy | BindingFlags.Instance | BindingFlags.Public)) { this.SetItem(GLOBAL, propInfo.Name, new JSNativeProperty(mThisRef, propInfo)); } foreach (MethodInfo methodInfo in myType.GetMethods(BindingFlags.FlattenHierarchy | BindingFlags.Instance | BindingFlags.Public)) { List <MethodInfo> ml; if (!namedMethods.TryGetValue(methodInfo.Name, out ml)) { ml = new List <MethodInfo>(new MethodInfo[] { methodInfo }); namedMethods[methodInfo.Name] = ml; } } foreach (EventInfo eventInfo in myType.GetEvents(BindingFlags.FlattenHierarchy | BindingFlags.Instance | BindingFlags.Public)) { this.SetItem(GLOBAL, eventInfo.Name, new JSNativeEvent(GLOBAL, mThisRef, eventInfo)); } DefProp(GLOBAL, "prototype", JSClassWrapper.RegisterClass(GLOBAL, thisRef.GetType())); foreach (KeyValuePair <string, List <MethodInfo> > method in namedMethods) { this.SetItem(GLOBAL, method.Key, new JSNativeMethod(method.Value.ToArray())); } }
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; }