Exemple #1
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));

            IntPtr v2 = jsscript_compile(_script, code, name);
            //JsValue v = jsscript_compile(_script, code, name);

            //object res = convert.FromJsValue(v);
            //Exception e = res as JsException;
            //if (e != null)
            //{
            //    throw e;
            //}
        }
Exemple #2
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));

            IntPtr v2 = jsscript_compile(_script, code, name);
            //JsValue v = jsscript_compile(_script, code, name);

            //object res = convert.FromJsValue(v);
            //Exception e = res as JsException;
            //if (e != null)
            //{
            //    throw e;
            //}
        }
Exemple #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;
            }
        }
Exemple #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);
        }
Exemple #5
0
        internal JsContext(int id,
                           JsEngine engine,
                           Action <int> notifyDispose,
                           JsTypeDefinitionBuilder jsTypeDefBuilder)
        {
            _id            = id;
            _notifyDispose = notifyDispose;
            _engine        = engine;
            _keepalives    = new KeepAliveDictionaryStore();
            //create native js context
            _context = new HandleRef(this, jscontext_new(id, engine.UnmanagedEngineHandler));
            _convert = new JsConvert(this);

            this.jsTypeDefBuilder = jsTypeDefBuilder;

            engineMethodCallbackDel = new ManagedMethodCallDel(EngineListener_MethodCall);
            NativeV8JsInterOp.CtxRegisterManagedMethodCall(this, engineMethodCallbackDel);
            registerMethods.Add(null);    //first is null
            registerProperties.Add(null); //first is null


            proxyStore = new NativeObjectProxyStore(this);
        }
Exemple #6
0
        internal JsContext(int id,
                           JsEngine engine,
                           Action <int> notifyDispose,
                           IntPtr nativeJsContext,
                           JsTypeDefinitionBuilder jsTypeDefBuilder)
        {
            //constructor setup
            _id            = id;
            _notifyDispose = notifyDispose;
            _engine        = engine;
            _keepalives    = new KeepAliveDictionaryStore();
            //create native js context
            _context = new HandleRef(this, nativeJsContext);
            _convert = new JsConvert(this);

            _jsTypeDefBuilder = jsTypeDefBuilder;

            _engineMethodCallbackDel = new ManagedMethodCallDel(EngineListener_MethodCall);
            NativeV8JsInterOp.CtxRegisterManagedMethodCall(this, _engineMethodCallbackDel);
            _registerMethods.Add(null);    //first is null
            _registerProperties.Add(null); //first is null
            _proxyStore = new NativeObjectProxyStore(this);
        }
Exemple #7
0
        internal static JsException Create(JsConvert convert, IntPtr nativeErrorObject)
        {
            unsafe
            {
                JsError *jsErr           = (JsError *)nativeErrorObject;
                string   type            = (string)convert.FromJsValuePtr((JsValue *)jsErr->type);
                string   res             = (string)convert.FromJsValuePtr((JsValue *)jsErr->resource);
                string   msg             = (string)convert.FromJsValuePtr((JsValue *)jsErr->message);
                JsObject nativeException = (JsObject)convert.FromJsValuePtr((JsValue *)jsErr->exception);

                JsException exception;
                if (type == "SyntaxError")
                {
                    //from syntax error?
                    exception = new JsSyntaxError(type, res, msg, jsErr->line, jsErr->column);
                }
                else
                {
                    exception = new JsException(type, res, msg, jsErr->line, jsErr->column, nativeException);
                }
                return(exception);
            }
        }
Exemple #8
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;
        }