public void can_compile_script_million_times() { _loadModuleDelegate = name => IntPtr.Zero; for (var i = 0; i < 10000000; i++) { IntPtr prelude = Js1.CompilePrelude("return {};", "test.js", _loadModuleDelegate, _logDelegate); Js1.DisposeScript(prelude); } }
private void Dispose(bool disposing) { if (_disposed) { return; } if (!disposing) { throw new Exception( "CompiledScript finalizer has been called, but scripts cannot be disposed from other threads. Original script file name: " + _fileName); } else { var scriptHandle = _script; _script = IntPtr.Zero; Js1.DisposeScript(scriptHandle); } _disposed = true; }
public static void CheckResult(IntPtr scriptHandle, bool disposeScriptOnException) { int? errorCode = null; string errorMessage = null; _reportErrorCallback = // NOTE: this local delegate must go to a field to keep references while ReportErrors is being executed (code, message) => { //NOTE: do not throw exceptions directly in this handler // let the CPP code clean up errorCode = code; errorMessage = message; }; Js1.ReportErrors(scriptHandle, _reportErrorCallback); if (errorCode != null) { if (disposeScriptOnException) { Js1.DisposeScript(scriptHandle); } throw new Js1Exception(errorCode.Value, errorMessage); } }