public void NewEditorTest() { var mock = new EditorProviderMock(); var context = new CSharp.Context(); var provider = new EditorProviderObject( context.Environment, context.Environment.Prototypes.Object, mock); context.SetGlobal("editors", provider); // Create the editor context.Execute("var edit = editors.newEditor()"); var edit = context.GetGlobal("edit"); Assert.IsFalse(edit.IsUndefined); Assert.IsNotNull(edit.Clr); Assert.AreEqual(1, mock.Editors.Count); // Make sure it is an editor bool result = (bool)context.Execute("('setText' in edit)"); Assert.IsTrue(result); }
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); }