protected virtual void Dispose(bool disposing) { CheckDisposed(); _disposed = true; //? here? if (disposing) { foreach (var aliveContext in _aliveContexts) { JsContext.jscontext_dispose(aliveContext.Value.Handle); } _aliveContexts.Clear(); foreach (var aliveScript in _aliveScripts) { JsScript.jsscript_dispose(aliveScript.Value.Handle); } } #if DEBUG_TRACE_API Console.WriteLine("Calling jsEngine dispose: " + _engine.Handle.ToInt64()); #endif jsengine_dispose(_engine); }
public JsScript CompileScript(string code, string name = "<Unamed Script>") { CheckDisposed(); int id = Interlocked.Increment(ref _currentScriptId); JsScript script = new JsScript(id, this, _engine, new JsConvert(null), code, name, ScriptDisposed); _aliveScripts.Add(id, script); return(script); }
public object Execute(JsScript script, TimeSpan?executionTimeout = null) { if (script == null) { throw new ArgumentNullException("script"); } CheckDisposed(); bool executionTimedOut = false; Timer timer = null; if (executionTimeout.HasValue) { timer = new Timer(executionTimeout.Value.TotalMilliseconds); timer.Elapsed += (sender, args) => { timer.Stop(); executionTimedOut = true; _engine.TerminateExecution(); }; timer.Start(); } object res; try { JsValue v = new JsValue(); jscontext_execute_script(_context, script.Handle, ref v); res = _convert.FromJsValue(ref v); #if DEBUG_TRACE_API Console.WriteLine("Cleaning up return value from execution"); #endif v.Dispose(); } finally { if (executionTimeout.HasValue) { timer.Dispose(); } } if (executionTimedOut) { throw new JsExecutionTimedOutException(); } Exception e = res as JsException; if (e != null) { throw e; } return(res); }
public JsScript CompileScript(string code, string name = "<Unamed Script>") { CheckDisposed(); int id = Interlocked.Increment(ref _currentScriptId); JsScript script = new JsScript(id, this, _engine, new JsConvert(null), code, name, ScriptDisposed); _aliveScripts.Add(id, script); return script; }