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); }
public void MappingEngineLoadErrorDuringOutOfMemoryIsCorrect() { // Arrange IJsEngine jsEngine = null; JsEngineLoadException exception = null; // Act try { jsEngine = new ChakraCoreJsEngine( new ChakraCoreSettings { MemoryLimit = new UIntPtr(8 * 1024) } ); } catch (JsEngineLoadException e) { exception = e; } finally { jsEngine?.Dispose(); } // Assert Assert.NotNull(exception); Assert.Equal("Engine load error", exception.Category); Assert.Equal("Out of memory.", exception.Description); }
private ChakraCoreJsEngine EngineFactory() { var engine = new ChakraCoreJsEngine(_config.EngineSettings); var thisAssembly = typeof(ReactConfiguration).GetTypeInfo().Assembly; LoadResource(engine, "ZeroReact.Resources.shims.js", thisAssembly); if (_config.LoadReact) { LoadResource( engine, _config.UseDebugReact ? "ZeroReact.Resources.react.generated.js" : "ZeroReact.Resources.react.generated.min.js", thisAssembly ); } LoadUserScripts(engine); if (!_config.LoadReact && _scriptLoadException == null) { EnsureReactLoaded(engine); } return(engine); }
private void MaintenanceEngine(ChakraCoreJsEngine engine) { if (_disposedFlag.IsSet()) //test { DisposeEngine(engine); return; } _engineMaintenance.Set(); }
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"); } }
// Note: I believe this is thread-safe based on the documentation and comments here: // https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/static-constructors // https://github.com/dotnet/docs/issues/10243 static MidiComposer() { scripts = new List <IPrecompiledScript>(); // Load all required scripts from embedded resource and precompile them using (var compilationEngine = new ChakraCoreJsEngine()) { foreach (var resource in resources) { scripts.Add(compilationEngine.PrecompileResource(resource, typeof(MidiComposer))); } } }
/// <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))); } }
/* * Get the value from `tests` in the Elm module `Main`. */ static string GetTestsValueFromModuleMain( IImmutableDictionary <IImmutableList <string>, IImmutableList <byte> > elmAppFiles) { var javascriptFromElmMake = Kalmit.ProcessFromElm019Code.CompileElmToJavascript( elmAppFiles, ImmutableList.Create("src", "Main.elm")); var javascriptEngine = new ChakraCoreJsEngine( new ChakraCoreSettings { DisableEval = true, EnableExperimentalFeatures = true } ); var javascriptPreparedToRun = Kalmit.ProcessFromElm019Code.PublishFunctionsFromJavascriptFromElmMake( Kalmit.ProcessFromElm019Code.JavascriptMinusCrashes(javascriptFromElmMake), new[]
private void Initialize() { if (_initialized) { return; } try { _jsEngine = new ChakraCoreJsEngine(); OnInitialize(); } catch { _jsEngine?.Dispose(); _jsEngine = null; throw; } _initialized = true; }
public void DisposeEngine(ChakraCoreJsEngine engine) { _engines.TryRemove(engine, out _); try { engine._dispatcher?.Invoke( () => { engine._dispatcher._sharedQueue = null; engine._dispatcher._sharedQueueEnqeued = null; }); } catch (Exception ex) { // ignored } engine.Dispose(); _enginePopulater?.Set(); }
public void InitializeEngine() { _jsEngine = new ChakraCoreJsEngine(); }
void IDisposable.Dispose() { _jsEngine?.Dispose(); _jsEngine = null; }
public ChakraBaseProgram(ChakraRuntimeService service) { engine = service.GetEngine(); Console = new BasicConsoleInterface(); InitializeEngine(); }