//
        // This method is invoked when the application has loaded and is ready to run. In this
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        //
        // You have 17 seconds to return from this method, or iOS will terminate your application.
        //
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            // Example 1
            JSContext context = new JSContext();
            JSValue   result  = context.EvaluateScript("2 + 2");

            Console.WriteLine(result);

            // Example 2
            context.EvaluateScript("var square = function (x) { return x * x; }");
            JSValue function = context [(NSString)"square"];
            JSValue input    = JSValue.From(3, context);

            result = function.Call(input);
            Console.WriteLine(result);

            // Example 3
            JSValue value = context.EvaluateScript("a = 3");

            context.EvaluateScript("var square = function (x) { return x * x; }");
            function = context [(NSString)"square"];
            result   = function.Call(context [(NSString)"a"]);
            Console.WriteLine(result);

            // create a new window instance based on the screen size
            window = new UIWindow(UIScreen.MainScreen.Bounds);

            // If you have defined a root view controller, set it here:
            // window.RootViewController = myViewController;

            // make the window visible
            window.MakeKeyAndVisible();

            return(true);
        }
Пример #2
0
        private void test3ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            JSContext ctx = (JSContext)currentPage.browser.GetGlobalScriptContext();
            JSObject  dog = ctx.EvaluateScript("someDog(12, \"Golden Retriever\");").ToObject();

            if (dog != null)
            {
                if (dog.HasProperty("breed"))
                {
                    /*MessageBox.Show("breed = " + dog.GetProperty("breed").ToString());
                     * dog.SetProperty("breed", "Border Collie");
                     * MessageBox.Show("breed = " + dog.GetProperty("breed").ToString());
                     * dog.SetProperty("name", "Holly");
                     * MessageBox.Show("name = " + dog.GetProperty("name").ToString());*/
                    ctx.EvaluateScript("printDog(myDog)");
                    TestClass myTest = new TestClass()
                    {
                        x = "testing"
                    };
                    dog.SetProperty("test", myTest);
                    ctx.EvaluateScript("testtest(myDog)");
                    //ctx.GarbageCollect();

                    MessageBox.Show(String.Format("y = {0}, i = {1}, b = {2}", myTest.y, myTest.i, myTest.b));
                }
            }
        }
Пример #3
0
        public void ExportTest()
        {
            if (!TestRuntime.CheckSystemAndSDKVersion(7, 0))
            {
                Assert.Ignore("requires iOS7+");
            }

            if (RegistrarTest.CurrentRegistrar != Registrars.Static)
            {
                Assert.Ignore("Exporting protocols to JavaScriptCore requires the static registrar.");
            }

            var     context = new JSContext();
            JSValue exc     = null;

            context.ExceptionHandler = (JSContext context2, JSValue exception) => {
                exc = exception;
            };
            var obj = new MyJavaExporter();

            context [(NSString)"obj"] = JSValue.From(obj, context);
            context.EvaluateScript("obj.myFunc ();");
            Assert.IsNull(exc, "JS exception");
            Assert.IsTrue(obj.MyFuncCalled, "Called");

            context.EvaluateScript("obj.hello (42);");
            context.EvaluateScript("obj.callMeBack (function() { return 314; });");
        }
Пример #4
0
        public void EvaluateScript_Context()
        {
            TestRuntime.AssertXcodeVersion(5, 0, 1);

            using (var context = new JSContext())
                using (JSValue value = context.EvaluateScript("a = 3"))
                    using (JSValue script = context.EvaluateScript("var square = function (x) { return x * x; }"))
                        using (JSValue function = context [(NSString)"square"])
                            using (JSValue result = function.Call(context [(NSString)"a"])) {
                                Assert.That(result.ToInt32(), Is.EqualTo(9), "9");
                            }
        }
Пример #5
0
        public void EvaluateScript_Context()
        {
            if (!TestRuntime.CheckSystemAndSDKVersion(7, 0))
            {
                Assert.Ignore("requires iOS7+");
            }

            using (var context = new JSContext())
                using (JSValue value = context.EvaluateScript("a = 3"))
                    using (JSValue script = context.EvaluateScript("var square = function (x) { return x * x; }"))
                        using (JSValue function = context [(NSString)"square"])
                            using (JSValue result = function.Call(context [(NSString)"a"])) {
                                Assert.That(result.ToInt32(), Is.EqualTo(9), "9");
                            }
        }
Пример #6
0
        private void test2ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            JSContext ctx = (JSContext)currentPage.browser.GetGlobalScriptContext();
            JSValue   val = ctx.EvaluateScript("f()");

            MessageBox.Show(val.ToString());
        }
Пример #7
0
		public MarkdownService()
		{
			_ctx = new JSContext(_vm);
			var script = System.IO.File.ReadAllText("Markdown/marked.js", System.Text.Encoding.UTF8);
			_ctx.EvaluateScript(script);
			_val = _ctx[new NSString("marked")];
		}
Пример #8
0
        public MarkdownService()
        {
            _ctx = new JSContext(_vm);
            var script = System.IO.File.ReadAllText("Markdown/marked.js", System.Text.Encoding.UTF8);

            _ctx.EvaluateScript(script);
            _val = _ctx[new NSString("marked")];
        }
Пример #9
0
        public Statement Execute(Statement statement)
        {
            JSValue value = context.EvaluateScript(statement.Code);

            statement = statement.WithResult(value);
            _history.Enqueue(statement);
            return(statement);
        }
Пример #10
0
        public void EvaluateScript()
        {
            TestRuntime.AssertXcodeVersion(5, 0, 1);

            using (var c = new JSContext())
                using (JSValue r = c.EvaluateScript("function FourthyTwo () { return 42; }; FourthyTwo ()")) {
                    Assert.That(r.ToInt32(), Is.EqualTo(42), "42");
                }
        }
Пример #11
0
        public MarkdownService()
        {
            var scriptPath     = System.IO.Path.Combine(NSBundle.MainBundle.BundlePath, "WebResources", "marked.js");
            var scriptContents = System.IO.File.ReadAllText(scriptPath);

            _ctx = new JSContext(_vm);
            _ctx.EvaluateScript(scriptContents);
            _val = _ctx[new NSString("marked")];
        }
Пример #12
0
        public void EvaluateScript_Param()
        {
            TestRuntime.AssertXcodeVersion(5, 0, 1);

            using (var context = new JSContext())
                using (JSValue script = context.EvaluateScript("var square = function (x) { return x * x; }"))
                    using (JSValue function = context [(NSString)"square"])
                        using (JSValue input = JSValue.From(2, context))
                            using (JSValue result = function.Call(input)) {
                                Assert.That(result.ToInt32(), Is.EqualTo(4), "4");
                            }
        }
Пример #13
0
        public void EvaluateScript()
        {
            if (!TestRuntime.CheckSystemAndSDKVersion(7, 0))
            {
                Assert.Ignore("requires iOS7+");
            }

            using (var c = new JSContext())
                using (JSValue r = c.EvaluateScript("function FourthyTwo () { return 42; }; FourthyTwo ()")) {
                    Assert.That(r.ToInt32(), Is.EqualTo(42), "42");
                }
        }
Пример #14
0
        public void TestArguments()
        {
            var r = new List <JSValue> ();

            context.GlobalObject.SetProperty("go", new JSFunction(context, "go", (fn, ths, args) => {
                r.AddRange(args);
                return(new JSValue(fn.Context, 42));
            }));

            var go = context.GlobalObject.GetProperty("go");

            Assert.AreEqual(JSType.Object, go.JSType);
            Assert.AreEqual("function go() {\n    [native code]\n}", go.ToString());

            context.EvaluateScript("this.go = go (1, 'hi', false, go ({a:'str', b:go ()}, go (0.272, true, go)))");

            Assert.AreEqual(JSType.Number, r[0].JSType);
            Assert.AreEqual(0.272, r[0].NumberValue);
            Assert.AreEqual(JSType.Boolean, r[1].JSType);
            Assert.AreEqual(true, r[1].BooleanValue);
            Assert.AreEqual(JSType.Object, r[2].JSType);
            Assert.AreEqual("function go() {\n    [native code]\n}", r[2].ToString());

            Assert.AreEqual(JSType.Object, r[3].JSType);
            Assert.AreEqual("{\"a\":\"str\",\"b\":42}", r[3].ToString());
            Assert.AreEqual(JSType.Number, r[4].JSType);
            Assert.AreEqual(42, r[4].NumberValue);

            Assert.AreEqual(JSType.Number, r[5].JSType);
            Assert.AreEqual(1, r[5].NumberValue);
            Assert.AreEqual(JSType.String, r[6].JSType);
            Assert.AreEqual("hi", r[6].StringValue);
            Assert.AreEqual(JSType.Boolean, r[7].JSType);
            Assert.AreEqual(false, r[7].BooleanValue);

            go = context.GlobalObject.GetProperty("go");
            Assert.AreEqual(JSType.Number, go.JSType);
            Assert.AreEqual(42, go.NumberValue);
        }
Пример #15
0
		public string ConvertMarkdown(string c)
		{
			if (string.IsNullOrEmpty(c))
				return string.Empty;

			using (var vm = new JSVirtualMachine())
			{
				var ctx = new JSContext(vm);
				var script = System.IO.File.ReadAllText("Markdown/marked.js", System.Text.Encoding.UTF8);
				ctx.EvaluateScript(script);
				var val = ctx[new NSString("marked")];
				return val.Call(JSValue.From(c, ctx)).ToString();
			}
		}
Пример #16
0
        private void test2ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            JSContext ctx = (JSContext)currentPage.browser.GetGlobalScriptContext();
            JSValue   val = ctx.EvaluateScript("f()");

            if (val != null)
            {
                MessageBox.Show(val.ToString());
            }
            else
            {
                MessageBox.Show("Execute 'Test Page', first.", "Uggggmmmm...");
            }
        }
Пример #17
0
        public string ConvertMarkdown(string c)
        {
            if (string.IsNullOrEmpty(c))
            {
                return(string.Empty);
            }

            using (var vm = new JSVirtualMachine())
            {
                var ctx    = new JSContext(vm);
                var script = System.IO.File.ReadAllText("Markdown/marked.js", System.Text.Encoding.UTF8);
                ctx.EvaluateScript(script);
                var val = ctx[new NSString("marked")];
                return(val.Call(JSValue.From(c, ctx)).ToString());
            }
        }
Пример #18
0
        public static Task<Stage> Load(string scriptName)
        {
            return	Task.Factory.StartNew(()=>{

                var script = File.ReadAllText (scriptName);
                if(script.Contains("(  function($, Edge, compId){"))
                    script = script.Replace("(  function($, Edge, compId){","");
                var endIndex= script.IndexOf("Edge.registerC");
                if(endIndex > 0)
                    script = script.Substring(0,endIndex);
                script += Environment.NewLine + "var js = JSON.stringify(symbols);";
                var context = new JSContext();
                var test = context.EvaluateScript (script);

                var result = context[(NSString)"js"].ToString();
                result = result.Replace("\"${_", "\"").Replace("}\"","\"");
                var stage = StageParser.Parse(result);
                return stage;
            });
        }
Пример #19
0
        public static Task <Stage> Load(string scriptName)
        {
            return(Task.Factory.StartNew(() => {
                var script = File.ReadAllText(scriptName);
                if (script.Contains("(  function($, Edge, compId){"))
                {
                    script = script.Replace("(  function($, Edge, compId){", "");
                }
                var endIndex = script.IndexOf("Edge.registerC");
                if (endIndex > 0)
                {
                    script = script.Substring(0, endIndex);
                }
                script += Environment.NewLine + "var js = JSON.stringify(symbols);";
                var context = new JSContext();
                var test = context.EvaluateScript(script);

                var result = context[(NSString)"js"].ToString();
                result = result.Replace("\"${_", "\"").Replace("}\"", "\"");
                var stage = StageParser.Parse(result);
                return stage;
            }));
        }
        /// <summary>
        /// Runs the given script.
        /// </summary>
        /// <param name="script">The script.</param>
        /// <param name="sourceUrl">The source URL.</param>
        public void RunScript(string script, string sourceUrl)
        {
            if (script == null)
            {
                throw new ArgumentNullException(nameof(script));
            }

            //if (sourceUrl == null)
            //    throw new ArgumentNullException(nameof(sourceUrl));

            string source = LoadScriptAsync(script).Result;

            try
            {
                _context.EvaluateScript(source, null, sourceUrl, 0);
            }
            catch (JSErrorException ex)
            {
                Log.Error(ReactConstants.Tag, "## Enter LoadScriptAsync ## JSErrorException:" + ex.ToString());
                var message = ex.Error.ToJsonString();
                throw new Modules.Core.JavaScriptException(message, "no stack info", ex);
            }
            catch (JSException ex)
            {
                Log.Error(ReactConstants.Tag, "## Enter LoadScriptAsync ## JSException:" + ex.ToString());
                var jsonError = JSValueToJTokenConverter.Convert(ex.Error);
                var message   = "line: " + jsonError.Value <string>("line") + ", column: " + jsonError.Value <string>("column")
                                + ", sourceURL: " + jsonError.Value <string>("sourceURL");
                var stackTrace = jsonError.Value <string>("stack");
                if (stackTrace == null)
                {
                    stackTrace = "no stack info";
                }
                throw new Modules.Core.JavaScriptException(message, stackTrace, ex);
            }
        }
Пример #21
0
 public void TestEnsureJavaScriptCoreVoidReturnIsUndefined()
 {
     Assert.AreEqual(JSType.Undefined, context.EvaluateScript("(function f () { })()").JSType);
 }
 public static object ExecuteScript(this JSContext target, string script, string source, int line = 0)
 {
     return(target.EvaluateScript(script, source, line));
 }
Пример #23
0
 public MarkdownService()
 {
     _ctx = new JSContext(_vm);
     _ctx.EvaluateScript(Resources.MarkdownScript);
     _val = _ctx[new NSString("marked")];
 }
Пример #24
0
 public string Execute(string script)
 {
     return(_ctx.EvaluateScript(script).ToString());
 }
Пример #25
0
 public void TestExceptionBoundaryJsCatch()
 {
     context.EvaluateScript("try { mjs.import = 'foo'; } catch (e) { this.p = e.toString (); }");
     Assert.AreEqual("IllegalOperationError: Setting properties on this object is not allowed",
                     context.GlobalObject.GetProperty("p").StringValue);
 }
Пример #26
0
		public MarkdownService()
		{
			_ctx = new JSContext(_vm);
            _ctx.EvaluateScript(Resources.MarkdownScript);
			_val = _ctx[new NSString("marked")];
		}
Пример #27
0
        public void TestSimpleProperties()
        {
            JSValue result = Context.EvaluateScript("simpleProperties");

            Assert.IsNotNull(result);
            Assert.IsFalse(result.IsUndefined);

            JSObject o = result.ToObject();

            Assert.AreEqual("stringProp", o.GetProperty("noGetterStringProperty").ToString());
            Assert.AreEqual("stringPropertyValue", o.GetProperty("stringProperty").ToString());
            Assert.AreEqual(3, o.GetProperty("intProperty").ToNumber());
            Assert.IsTrue(precisionEquals(Math.PI, o.GetProperty("floatProperty").ToNumber()));
            Assert.IsTrue(precisionEquals(GOLDEN_RATIO, o.GetProperty("doubleProperty").ToNumber()));
            Assert.IsTrue(o.GetProperty("boolProperty").ToBoolean());
        }