Пример #1
0
 protected override void Prepare()
 {
     engine = new ChakraCoreJsEngine();
     engine.EmbedHostObject("log", new Action <object>(Console.WriteLine));
     engine.Execute("const window = this;");
     engine.Execute("const exports = {};");
     engine.Execute(Compiler);
     if (!engine.HasVariable("transform"))
     {
         throw new InvalidOperationException("Missing compiler");
     }
 }
Пример #2
0
        public void MappingRuntimeErrorDuringOutOfMemoryIsCorrect()
        {
            // Arrange
            const string input = @"var arr = [];

for (var i = 0; i < 10000; i++) {
	arr.push('Current date: ' + new Date());
}";

            JsRuntimeException exception = null;

            // Act
            using (IJsEngine jsEngine = new ChakraCoreJsEngine(
                       new ChakraCoreSettings
            {
                MemoryLimit = new UIntPtr(2 * 1024 * 1024)
            }
                       ))
            {
                try
                {
                    jsEngine.Execute(input);
                }
                catch (JsRuntimeException e)
                {
                    exception = e;
                }
            }

            // Assert
            Assert.NotNull(exception);
            Assert.Equal("Runtime error", exception.Category);
            Assert.Equal("Out of memory", exception.Description);
        }
Пример #3
0
        /// <summary>
        /// Composes a new MIDI file based on the given seed
        /// </summary>
        /// <param name="seed"></param>
        /// <returns></returns>
        public static Composition Compose(string seed)
        {
            using (var engine = new ChakraCoreJsEngine())
            {
                foreach (var script in scripts)
                {
                    engine.Execute(script);
                }

                var result    = engine.CallFunction <string>("exportMidi", seed);
                var midiBytes = result.Split(',').Select(str => Convert.ToByte(str)).ToArray();

                return(new Composition(seed, new MemoryStream(midiBytes)));
            }
        }
Пример #4
0
 public void Execute(string code)
 {
     _scriptEngine.Execute(code);
 }
Пример #5
0
 public void Execute(string expression)
 {
     _jsEngine.Execute(expression);
 }
Пример #6
0
 protected void Execute(string code)
 {
     _jsEngine.Execute(code);
 }