FromJsValue() public method

public FromJsValue ( Espresso.JsValue v ) : object
v Espresso.JsValue
return object
Exemplo n.º 1
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 = 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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        internal JsScript(int id, JsEngine engine, HandleRef engineHandle, JsConvert convert, string code, string name, Action <int> notifyDispose)
        {
            _id            = id;
            _engine        = engine;
            _notifyDispose = notifyDispose;

            _script = new HandleRef(this, jsscript_new(engineHandle));
            JsValue output = new JsValue();

            jsscript_compile(_script, code, name, ref output);

            object    res = convert.FromJsValue(ref output);
            Exception e   = res as JsException;

            if (e != null)
            {
                throw e;
            }
        }
Exemplo n.º 4
0
        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;
        }