internal static JsException Create(JsConvert convert, JsError error) { string type = (string)convert.FromJsValue(error.Type); string resource = (string)convert.FromJsValue(error.Resource); string message = (string)convert.FromJsValue(error.Message); int line = error.Line; int column = error.Column + 1; // because zero based. // JsException exception; if (error.Exception.Type == JsValueType.String) { exception = new JsException(type, resource, message, line, column, null); } else if (type == "SyntaxError") { exception = new JsSyntaxError(type, resource, message, line, column); } else { JsObject nativeException = (JsObject)convert.FromJsValue(error.Exception); exception = new JsException(type, resource, message, line, column, nativeException); } return(exception); }
public object Execute(JsScript script) { if (script == null) { throw new ArgumentNullException("script"); } CheckDisposed(); object res; try { JsValue v = jscontext_execute_script(_context, script.Handle); res = _convert.FromJsValue(v); #if DEBUG_TRACE_API Console.WriteLine("Cleaning up return value from execution"); #endif jsvalue_dispose(v); } finally { } Exception e = res as JsException; if (e != null) { throw e; } return(res); }
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 = jscontext_execute_script(_context, script.Handle); res = _convert.FromJsValue(v); #if DEBUG_TRACE_API Console.WriteLine("Cleaning up return value from execution"); #endif jsvalue_dispose(v); } finally { if (executionTimeout.HasValue) { timer.Dispose(); } } if (executionTimedOut) { throw new JsExecutionTimedOutException(); } Exception e = res as JsException; if (e != null) { throw e; } return(res); }
internal JsScript(int id, JsEngine engine, IntPtr engineHandle, JsConvert convert, string code, string name, Action<int> notifyDispose) { _id = id; _engine = engine; _notifyDispose = notifyDispose; _script = jsscript_new(engineHandle); JsValue v = jsscript_compile(_script, code, name); object res = convert.FromJsValue(v); Exception e = res as JsException; if (e != null) { throw e; } }
internal JsScript(int id, JsEngine engine, IntPtr engineHandle, JsConvert convert, string code, string name, Action <int> notifyDispose) { _id = id; _engine = engine; _notifyDispose = notifyDispose; _script = jsscript_new(engineHandle); JsValue v = jsscript_compile(_script, code, name); object res = convert.FromJsValue(v); Exception e = res as JsException; if (e != null) { throw e; } }
public object Execute(string code) { if (code == null) { throw new ArgumentNullException("code"); } CheckDisposed(); JsValue v = jsengine_execute(_engine, code); object res = _convert.FromJsValue(v); jsvalue_dispose(v); Exception e = res as JsException; if (e != null) { throw e; } return(res); }
internal static JsException Create(JsConvert convert, JsError error) { string type = (string)convert.FromJsValue(error.Type); string resource = (string)convert.FromJsValue(error.Resource); string message = (string)convert.FromJsValue(error.Message); int line = error.Line; int column = error.Column + 1; // because zero based. JsObject nativeException = (JsObject)convert.FromJsValue(error.Exception); JsException exception; if (type == "SyntaxError") { exception = new JsSyntaxError(type, resource, message, line, column); } else { exception = new JsException(type, resource, message, line, column, nativeException); } return exception; }