private void WireUpJavaScriptConfigurationObject(CSharp.Context context) { var prototype = context.Environment.NewObject(); var constructor = IronJS.Native.Utils.CreateConstructor<Func<FunctionObject, CommonObject, CommonObject>>( context.Environment, 0, (ctor, _) => { var proto = ctor.GetT<CommonObject>("prototype"); return new ConfigJsObject(ctor.Env, this, proto); }); prototype.Prototype = context.Environment.Prototypes.Object; prototype.Put("run", IronJS.Native.Utils.CreateFunction<Action<FunctionObject, CommonObject, BoxedValue>>( context.Environment, 1, ConfigJsObject.Run)); prototype.Put("use", IronJS.Native.Utils.CreateFunction<Action<FunctionObject, CommonObject, CommonObject>>( context.Environment, 1, ConfigJsObject.Use)); prototype.Put("map", IronJS.Native.Utils.CreateFunction<Action<FunctionObject, CommonObject, string, BoxedValue>>( context.Environment, 1, ConfigJsObject.Map)); constructor.Put("prototype", prototype); context.SetGlobal("Config", constructor); }
public static void AttachToContext(CSharp.Context context) { CommonObject prototype = context.Environment.NewObject(); FunctionObject constructor = Utils.CreateConstructor<Func<FunctionObject, CommonObject, CommonObject>> (context.Environment, 0, Construct); FunctionObject log = Utils.CreateFunction<Action<FunctionObject, CommonObject, object>> (context.Environment, 1, ConsoleObject.Log); FunctionObject dir = Utils.CreateFunction<Action<FunctionObject, CommonObject, object>> (context.Environment, 1, ConsoleObject.Dir); prototype.Prototype = context.Environment.Prototypes.Object; prototype.Put("log", log, DescriptorAttrs.Immutable); prototype.Put("dir", dir, DescriptorAttrs.Immutable); constructor.Put("prototype", prototype, DescriptorAttrs.Immutable); context.SetGlobal("Console", constructor); context.Execute("console = new Console();"); }
public static void AttachToContext(CSharp.Context context, IMainWindow window) { var jsWindow = new WindowObject( context.Environment, context.Environment.Prototypes.Object, window); var setTitle = Utils.CreateFunction( context.Environment, 1, (Action<FunctionObject, CommonObject, string>)SetTitle); var getTitle = Utils.CreateFunction( context.Environment, 0, (Func<FunctionObject, CommonObject, string>)GetTitle); var addCommand = Utils.CreateFunction( context.Environment, 1, (Action<FunctionObject, CommonObject, CommonObject>)AddCommand); var removeCommand = Utils.CreateFunction( context.Environment, 1, (Action<FunctionObject, CommonObject, CommonObject>)RemoveCommand); var addApplicationCommand = Utils.CreateFunction( context.Environment, 1, (Action<FunctionObject, CommonObject, CommonObject>)AddApplicationCommand); var removeApplicationCommand = Utils.CreateFunction( context.Environment, 1, (Action<FunctionObject, CommonObject, CommonObject>)RemoveApplicationCommand); var exit = Utils.CreateFunction( context.Environment, 0, (Action<FunctionObject, CommonObject>)Exit); var editors = new EditorProviderObject(context.Environment, context.Environment.Prototypes.Object, window.Editors); jsWindow.Put("setTitle", setTitle, DescriptorAttrs.Immutable); jsWindow.Put("getTitle", getTitle, DescriptorAttrs.Immutable); jsWindow.Put("addCommand", addCommand, DescriptorAttrs.Immutable); jsWindow.Put("removeCommand", removeCommand, DescriptorAttrs.Immutable); jsWindow.Put("addApplicationCommand", addApplicationCommand, DescriptorAttrs.Immutable); jsWindow.Put("removeApplicationCommand", removeApplicationCommand, DescriptorAttrs.Immutable); jsWindow.Put("exit", exit, DescriptorAttrs.Immutable); jsWindow.Put("editors", editors, DescriptorAttrs.Immutable); context.SetGlobal("window", jsWindow); }
/// <summary> /// Attaches the EventObject type to the Javascript context. /// </summary> /// <param name="context">The context to attach to.</param> public static void Attach(CSharp.Context context) { context.SetGlobal("EventObject", Create(context)); }
public static new void Attach(CSharp.Context context) { context.SetGlobal("Command", Create(context)); }