Beispiel #1
0
        /// <summary>
        /// Creates a new test <see cref="JsRuntime"/>
        /// </summary>
        private JsExecutionContext NewTestExecutionContext(JsRuntime runtime)
        {
            var context = (JsExecutionContext)runtime.NewExecutionContext();

            context.RunScript("Test", "function assert(a) { if (!a) throw new Error('Failed Assertion'); };");

            context.SetValue("console", _consoleLog);

            return(context);
        }
Beispiel #2
0
        /// <summary>
        /// Creates a new test <see cref="JsRuntime"/>
        /// </summary>
        private JsExecutionContext NewTestExecutionContext(JsRuntime runtime)
        {
            var context = (JsExecutionContext)runtime.NewExecutionContext();

            context.RunScript(string.Empty, "function assert(a) { if (!a) throw new Error('Failed Assertion'); };");

            var binding = context.NewJsObject();

            binding.AddFunction("log",
                                (callee, call, arguments, count, data) =>
            {
                _totalLogCalls++;
                Console.WriteLine(arguments[1].ConvertToString().ToString());
                return(JavaScriptValue.Invalid);
            });

            context.SetValue("console", binding);

            return(context);
        }