Example #1
0
        public void Extensions_ToRestrictedHostObject()
        {
            IConvertible convertible = 123;

            engine.Script.convertible = convertible.ToRestrictedHostObject(engine);
            Assert.AreEqual(TypeCode.Int32, engine.Evaluate("convertible.GetTypeCode()"));

            engine.AddHostType(typeof(IConvertible));
            Assert.AreEqual(TypeCode.Int32, engine.Evaluate("Extensions.ToRestrictedHostObject(IConvertible, 456).GetTypeCode()"));
        }
 public void TestInitialize()
 {
     engine = new V8ScriptEngine(V8ScriptEngineFlags.EnableDebugging);
     engine.AddHostObject("testObject", testInterface = testObject = new TestObject());
     engine.AddHostObject("testInterface", HostItem.Wrap(engine, testObject, typeof(ITestInterface)));
     engine.AddHostObject("blockedTestObject", blockedTestObject     = new BlockedTestObject());
     engine.AddHostObject("unblockedTestObject", unblockedTestObject = new UnblockedTestObject());
     engine.AddHostType(typeof(BlockedTestObject));
     engine.AddHostType(typeof(UnblockedTestObject));
     engine.AddHostType("Guid", typeof(Guid));
 }
        public void TestInitialize()
        {
            engine = new V8ScriptEngine(V8ScriptEngineFlags.EnableDebugging);

            engine.AddHostType(typeof(AccessContextTestBase));
            engine.AddHostType(typeof(AccessContextTestObject));

            engine.Script.dateTime   = DateTime.Now;
            engine.Script.timeSpan   = TimeSpan.Zero;
            engine.Script.testBase   = new AccessContextTestBase();
            engine.Script.testObject = new AccessContextTestBase();
        }
Example #4
0
 public Specter(Options options)
 {
     Options = options;
     engine  = new V8ScriptEngine();
     engine.AddHostObject("phantom", new Phantom(this));
     engine.AddHostType("Timer", typeof(Bindings.Timer));
 }
Example #5
0
        private void frmEvents_Load(object sender, EventArgs e)
        {
            var oFrmTestForm = new frmTestForm();

            engine = ClearScript.Create(EngineType.V8);
            engine.AddHostObject("form", this);
            engine.AddHostType("Form2", typeof(frmTestForm));
            engine.AddHostType("alert", typeof(AlertBox));
            engine.AddHostType("msgBox", typeof(MessageBox));

            engine.Execute(@"
                
                form.btnForm.Click.connect((s,e) => {
                 form.btnForm.Text = 'Clicked';
                 let form2 = new Form2();
                 form2.label1.Text = 'Opened from an event connected to ClearScript';
                 form2.Show();
            });
            ");

            engine.Execute(@"
                form.txtKeyPress.KeyPress.connect((s,e) => {
                 form.lblKeyPressResult.Text = 'Key pressed: '+e.KeyChar;
            });
            ");


            engine.Execute(@"
                form.btnAlert.Click.connect((s,e) => {
                 alert.Show('Hello from ClearScript');
            });
            ");


            if (!oFrmTestForm.IsDisposed)
            {
                engine.Execute(@"
                form.btnMsgBox.Click.connect((s,e) => {
                 msgBox.Show('Hello, I came from ClearScript :D');
            });
            ");
            }
            else
            {
                engine.AddHostObject("form2", oFrmTestForm);
            }
        }
Example #6
0
 public void TestInitialize()
 {
     engine = new V8ScriptEngine(V8ScriptEngineFlags.EnableDebugging);
     engine.DisableCaseInsensitivePropertyLookups     = true;
     engine.AddHostObject("testObject", testInterface = testObject = new TestObject());
     engine.AddHostObject("testInterface", HostItem.Wrap(engine, testObject, typeof(ITestInterface)));
     engine.AddHostType("Guid", typeof(Guid));
 }
Example #7
0
 public void Init()
 {
     _eng = ScriptFactory.GetScriptEngine(this.ScriptingLanguage);
     for (int i = 0; i < _source.FieldCount; i++)
     {
         _fields.Add(_source.GetName(i));
     }
     _eng.AddHostObject("Record", _rec);
     _eng.AddHostType("Console", typeof(Console));
 }
Example #8
0
 public void MemberAccess_Method_GetType_Blocked_Exception_Interface()
 {
     engine.AddHostType(typeof(_Exception));
     TestUtil.AssertException <UnauthorizedAccessException>(() => engine.Execute(@"
         try {
             testObject.GetType();
         }
         catch (exception)
         {
             host.cast(_Exception, exception.hostException).GetType();
         }
     "));
 }
Example #9
0
        public static ScriptEngine ApplyOptions(this ScriptEngine engine, ExecutionOptions options)
        {
            if (options != null)
            {
                if (options.HostObjects != null)
                {
                    foreach (HostObject hostObject in options.HostObjects)
                    {
                        engine.AddHostObject(hostObject);
                    }
                }

                if (options.HostTypes != null)
                {
                    foreach (HostType hostType in options.HostTypes)
                    {
                        engine.AddHostType(hostType);
                    }
                }
            }

            return(engine);
        }
Example #10
0
 public void HostFunctions_isTypeObj_True_TypeArg()
 {
     engine.AddHostType("Int32", typeof(int));
     Assert.IsTrue((bool)engine.Evaluate("host.isTypeObj(Int32)"));
 }
Example #11
0
        public static ScriptEngine AddHostType(this ScriptEngine engine, HostType hostType)
        {
            engine.AddHostType(hostType.Name, hostType.Flags, hostType.Type);

            return(engine);
        }
Example #12
0
 public void TestInitialize()
 {
     engine = new V8ScriptEngine(V8ScriptEngineFlags.EnableDebugging);
     engine.AddHostType(typeof(Extensions));
     engine.AddHostType(typeof(JavaScriptExtensions));
 }
Example #13
0
 public void Init()
 {
     _eng = ScriptFactory.GetScriptEngine(this.ScriptingLanguage);
     for (int i = 0; i < _source.FieldCount; i++)
     {
         _fields.Add(_source.GetName(i));
     }
     _eng.AddHostObject("Record", _rec);
     _eng.AddHostType("Console", typeof(Console));
 }