Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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;
        }
Exemplo n.º 6
0
 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;
 }
Exemplo n.º 7
0
        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;
        }