Ejemplo n.º 1
0
        /// <summary>
        /// Evaluates JavaScript code represented as a <see cref="String"/> in this V8 context.
        /// </summary>
        /// <param name="code">The JavaScript code.</param>
        /// <param name="scriptUrl">The URL where the script in question can be found, if any.</param>
        /// <param name="line">The base line number to use for error reporting.</param>
        /// <returns>The completion value of evaluating the given code.</returns>
        /// <exception cref="CefNetJSExcepton">
        /// Thrown when an exception is raised in the JavaScript engine.
        /// </exception>
        public CefV8Value Eval(string code, string scriptUrl, int line = 1)
        {
            if (line <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(line));
            }
            if (code is null)
                throw new ArgumentNullException(nameof(code));

            fixed(char *s0 = code)
            fixed(char *s1 = scriptUrl)
            {
                var cstr0 = new cef_string_t {
                    Str = s0, Length = code.Length
                };
                var cstr1 = new cef_string_t {
                    Str = s1, Length = scriptUrl != null ? scriptUrl.Length : 0
                };


                cef_v8value_t *     rv    = null;
                cef_v8value_t **    pRv   = &rv;
                cef_v8exception_t * jsex  = null;
                cef_v8exception_t **pJsex = &jsex;

                if (NativeInstance->Eval(&cstr0, &cstr1, line, pRv, pJsex) != 0)
                {
                    return(CefV8Value.Wrap(CefV8Value.Create, rv));
                }
                GC.KeepAlive(this);

                throw new CefNetJSExcepton(CefV8Exception.Wrap(CefV8Exception.Create, jsex));
            }
        }
Ejemplo n.º 2
0
 public unsafe int GetByIndex(int index, cef_v8value_t * @object, cef_v8value_t **retval, cef_string_t *exception)
 {
     fixed(cef_v8interceptor_t *self = &this)
     {
         return(((delegate * unmanaged[Stdcall] < cef_v8interceptor_t *, int, cef_v8value_t *, cef_v8value_t **, cef_string_t *, int >)get_byindex)(self, index, @object, retval, exception));
     }
 }
Ejemplo n.º 3
0
        internal unsafe void Invoke(object instance, int argumentsCount, cef_v8value_t **arguments, cef_v8value_t **retval)
        {
            if (!this.Compiled)
            {
                this.Compile();
            }

            this.invoker(instance, argumentsCount, arguments, retval);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Execute the function using the specified V8 context. |object| is the
        /// receiver (&apos;this&apos; object) of the function. If |object| is NULL the specified
        /// context&apos;s global object will be used. |arguments| is the list of arguments
        /// that will be passed to the function. Returns the function return value on
        /// success. Returns NULL if this function is called incorrectly or an
        /// exception is thrown.
        /// </summary>
        public unsafe virtual CefV8Value ExecuteFunctionWithContext(CefV8Context context, CefV8Value @object, CefV8Value[] arguments)
        {
            cef_v8value_t **arr3 = (cef_v8value_t **)Marshal.AllocHGlobal(sizeof(cef_v8value_t *) * arguments.Length);

            for (int i = 0; i < arguments.Length; i++)
            {
                var e3 = arguments[i];
                *(arr3 + i) = e3 != null?e3.GetNativeInstance() : null;
            }
            var rv = CefV8Value.Wrap(CefV8Value.Create, NativeInstance->ExecuteFunctionWithContext((context != null) ? context.GetNativeInstance() : null, (@object != null) ? @object.GetNativeInstance() : null, new UIntPtr((uint)arguments.Length), arr3));

            Marshal.FreeHGlobal((IntPtr)arr3);
            GC.KeepAlive(this);
            return(rv);
        }
Ejemplo n.º 5
0
        public static int eval(cef_v8context_t *self, cef_string_t *code, cef_v8value_t **retval, cef_v8exception_t **exception)
        {
            eval_delegate d;
            var           p = self->_eval;

            if (p == _pb)
            {
                d = _db;
            }
            else
            {
                d = (eval_delegate)Marshal.GetDelegateForFunctionPointer(p, typeof(eval_delegate));
                if (_pb == IntPtr.Zero)
                {
                    _db = d; _pb = p;
                }
            }
            return(d(self, code, retval, exception));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Execute a string of JavaScript code in this V8 context. The |script_url|
        /// parameter is the URL where the script in question can be found, if any. The
        /// |start_line| parameter is the base line number to use for error reporting.
        /// On success |retval| will be set to the return value, if any, and the
        /// function will return true (1). On failure |exception| will be set to the
        /// exception, if any, and the function will return false (0).
        /// </summary>
        public unsafe virtual bool Eval(string code, string scriptUrl, int startLine, ref CefV8Value retval, ref CefV8Exception exception)
        {
            fixed(char *s0 = code)
            fixed(char *s1 = scriptUrl)
            {
                var cstr0 = new cef_string_t {
                    Str = s0, Length = code != null ? code.Length : 0
                };
                var cstr1 = new cef_string_t {
                    Str = s1, Length = scriptUrl != null ? scriptUrl.Length : 0
                };
                cef_v8value_t *     p3  = (retval != null) ? retval.GetNativeInstance() : null;
                cef_v8value_t **    pp3 = &p3;
                cef_v8exception_t * p4  = (exception != null) ? exception.GetNativeInstance() : null;
                cef_v8exception_t **pp4 = &p4;
                var rv = NativeInstance->Eval(&cstr0, &cstr1, startLine, pp3, pp4) != 0;

                retval    = CefV8Value.Wrap(CefV8Value.Create, p3);
                exception = CefV8Exception.Wrap(CefV8Exception.Create, p4);
                GC.KeepAlive(this);
                return(rv);
            }
        }
 /// <summary>
 /// Evaluates the specified JavaScript code using this context's global object.
 /// On success |retval| will be set to the return value, if any, and the
 /// function will return true. On failure |exception| will be set to the
 /// exception, if any, and the function will return false.
 /// </summary>
 public int Eval(cef_string_t *code, cef_v8value_t **retval, cef_v8exception_t **exception)
 {
     throw new NotImplementedException(); // TODO: CefV8Context.Eval
 }
Ejemplo n.º 8
0
 public unsafe int Eval([Immutable] cef_string_t *code, [Immutable] cef_string_t *script_url, int start_line, cef_v8value_t **retval, cef_v8exception_t **exception)
 {
     fixed(cef_v8context_t *self = &this)
     {
         return(((delegate * unmanaged[Stdcall] < cef_v8context_t *, cef_string_t *, cef_string_t *, int, cef_v8value_t **, cef_v8exception_t **, int >)eval)(self, code, script_url, start_line, retval, exception));
     }
 }
        internal unsafe override int execute(cef_v8handler_t *self, cef_string_t *name, cef_v8value_t * @object, int argumentCount, cef_v8value_t **arguments, cef_v8value_t **retval, cef_string_t *exception)
        {
            var method = this.dispatchTable.GetOrDefault(name);

            if (method == null)
            {
                return(0);
            }

            // check method visibility
            var methodAttributes = method.Attributes;

            if ((methodAttributes & MethodDefAttributes.Hidden) != 0)
            {
                if ((methodAttributes & (MethodDefAttributes.Getter | MethodDefAttributes.Setter)) != 0)
                {
                    if (this.v8Extension)
                    {
                        // allow invoke of hidden property accessor's method for v8 extension handler
                    }
                    else
                    {
                        return(0);
                    }
                }
                else
                {
                    return(0);
                }
            }

            var instance = this.instance;

            if (instance == null)
            {
                // TODO: self must be got from obj's userdata
                throw new NotImplementedException();
            }

            // TODO: invoke method
            try
            {
                method.Invoke(instance, argumentCount, arguments, retval);
            }
            catch (Exception ex)
            {
                // TODO: how exceptions must be formatted ?
                // TODO: message for invoke errors
                cef_string_t.Copy(ex.ToString(), exception);
            }

            // release v8 values
            // TODO: this method must be typed (i.e. cef_v8value_t.invoke_release(@object);)
            cef_v8value_t.invoke_release((cef_base_t *)@object);
            for (var i = 0; i < argumentCount; i++)
            {
                cef_v8value_t.invoke_release((cef_base_t *)arguments[i]);
            }

            return(1);
        }
Ejemplo n.º 10
0
 public unsafe extern int Eval([Immutable] cef_string_t *code, [Immutable] cef_string_t *script_url, int start_line, cef_v8value_t **retval, cef_v8exception_t **exception);
        private int get(cef_v8accessor_t *self, cef_string_t *name, cef_v8value_t * @object, cef_v8value_t **retval, cef_string_t *exception)
        {
            CheckSelf(self);

            var        m_name = cef_string_t.ToString(name);
            var        m_obj  = CefV8Value.FromNative(@object);
            CefV8Value m_returnValue;
            string     mException;

            var handled = Get(m_name, m_obj, out m_returnValue, out mException);

            if (handled)
            {
                if (mException != null)
                {
                    cef_string_t.Copy(mException, exception);
                }
                else if (m_returnValue != null)
                {
                    *retval = m_returnValue.ToNative();
                }
            }

            return(handled ? 1 : 0);
        }
Ejemplo n.º 12
0
 public unsafe extern cef_v8value_t *ExecuteFunctionWithContext(cef_v8context_t *context, cef_v8value_t * @object, UIntPtr argumentsCount, [Immutable] cef_v8value_t **arguments);
 private int execute(cef_v8handler_t *self, cef_string_t *name, cef_v8value_t * @object, UIntPtr argumentsCount, cef_v8value_t **arguments, cef_v8value_t **retval, cef_string_t *exception)
 {
     CheckSelf(self);
     throw new NotImplementedException(); // TODO: CefV8Handler.Execute
 }
Ejemplo n.º 14
0
 public unsafe int GetByName([Immutable] cef_string_t *name, cef_v8value_t * @object, cef_v8value_t **retval, cef_string_t *exception)
 {
     fixed(cef_v8interceptor_t *self = &this)
     {
         return(((delegate * unmanaged[Stdcall] < cef_v8interceptor_t *, cef_string_t *, cef_v8value_t *, cef_v8value_t **, cef_string_t *, int >)get_byname)(self, name, @object, retval, exception));
     }
 }
Ejemplo n.º 15
0
        private int execute(cef_v8handler_t *self, cef_string_t *name, cef_v8value_t * @object, UIntPtr argumentsCount, cef_v8value_t **arguments, cef_v8value_t **retval, cef_string_t *exception)
        {
            CheckSelf(self);

            var m_name = cef_string_t.ToString(name);
            var m_obj  = CefV8Value.FromNative(@object);
            var argc   = (int)argumentsCount;

            CefV8Value[] m_arguments;
            if (argc == 0)
            {
                m_arguments = emtpyArgs;
            }
            else
            {
                m_arguments = new CefV8Value[argc];
                for (var i = 0; i < argc; i++)
                {
                    m_arguments[i] = CefV8Value.FromNative(arguments[i]);
                }
            }

            CefV8Value m_returnValue;
            string     m_exception;

            var handled = Execute(m_name, m_obj, m_arguments, out m_returnValue, out m_exception);

            if (handled)
            {
                if (m_exception != null)
                {
                    cef_string_t.Copy(m_exception, exception);
                }
                else if (m_returnValue != null)
                {
                    *retval = m_returnValue.ToNative();
                }
            }

            return(handled ? 1 : 0);
        }
Ejemplo n.º 16
0
 public unsafe extern int Get([Immutable] cef_string_t *name, cef_v8value_t * @object, cef_v8value_t **retval, cef_string_t *exception);
        private int get_byindex(cef_v8interceptor_t *self, int index, cef_v8value_t * @object, cef_v8value_t **retval, cef_string_t *exception)
        {
            CheckSelf(self);

            var m_obj = CefV8Value.FromNative(@object);

            CefV8Value m_retval;
            string     m_exception;

            if (GetByIndex(index, m_obj, out m_retval, out m_exception))
            {
                *retval = m_retval != null?m_retval.ToNative() : null;

                cef_string_t.Copy(m_exception, exception);
                return(1);
            }
            else
            {
                return(0);
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Execute with the specified argument list and return value. Return
        /// true if the method was handled. To invoke V8 callback functions
        /// outside the scope of this method you need to keep references to the
        /// current V8 context (CefV8Context) along with any necessary callback
        /// objects.
        /// </summary>
        internal virtual int execute(cef_v8handler_t *self, /*const*/ cef_string_t *name, cef_v8value_t * @object, int argumentCount, cef_v8value_t * /*const*/ *arguments, cef_v8value_t **retval, cef_string_t *exception)
        {
            ThrowIfObjectDisposed();

            var m_name = cef_string_t.ToString(name);
            var m_obj  = CefV8Value.From(@object);

            CefV8Value[] m_arguments;
            if (argumentCount == 0)
            {
                m_arguments = null;
            }
            else
            {
                m_arguments = new CefV8Value[argumentCount];
                for (var i = 0; i < argumentCount; i++)
                {
                    m_arguments[i] = CefV8Value.From(arguments[i]);
                }
            }

            CefV8Value m_returnValue;
            string     m_exception;

            var handled = this.Execute(m_name, m_obj, m_arguments, out m_returnValue, out m_exception);

            if (handled)
            {
                if (m_exception != null)
                {
                    cef_string_t.Copy(m_exception, exception);
                }
                else if (m_returnValue != null)
                {
                    *retval = m_returnValue.GetNativePointerAndAddRef();
                }
            }

            return(handled ? 1 : 0);
        }
Ejemplo n.º 19
0
 public unsafe extern int GetByIndex(int index, cef_v8value_t * @object, cef_v8value_t **retval, cef_string_t *exception);
Ejemplo n.º 20
0
        /// <summary>
        /// Called to get an accessor value. |name| is the name of the property
        /// being accessed. |object| is the This() object from V8's AccessorInfo
        /// structure. |retval| is the value to return for this property. Return
        /// true if handled.
        /// </summary>
        internal virtual int get(cef_v8accessor_t *self, /*const*/ cef_string_t *name, cef_v8value_t * @object, cef_v8value_t **retval, cef_string_t *exception)
        {
            ThrowIfObjectDisposed();

            var        m_name = cef_string_t.ToString(name);
            var        m_obj  = CefV8Value.From(@object);
            CefV8Value m_returnValue;
            string     mException;

            var handled = this.Get(m_name, m_obj, out m_returnValue, out mException);

            if (handled)
            {
                if (mException != null)
                {
                    cef_string_t.Copy(mException, exception);
                }
                else if (m_returnValue != null)
                {
                    *retval = m_returnValue.GetNativePointerAndAddRef();
                }
            }

            return(handled ? 1 : 0);
        }
Ejemplo n.º 21
0
        public static cef_v8value_t *execute_function_with_context(cef_v8value_t *self, cef_v8context_t *context, cef_v8value_t * @object, UIntPtr argumentsCount, cef_v8value_t **arguments)
        {
            execute_function_with_context_delegate d;
            var p = self->_execute_function_with_context;

            if (p == _p2e)
            {
                d = _d2e;
            }
            else
            {
                d = (execute_function_with_context_delegate)Marshal.GetDelegateForFunctionPointer(p, typeof(execute_function_with_context_delegate));
                if (_p2e == IntPtr.Zero)
                {
                    _d2e = d; _p2e = p;
                }
            }
            return(d(self, context, @object, argumentsCount, arguments));
        }
Ejemplo n.º 22
0
 public unsafe cef_v8value_t *ExecuteFunctionWithContext(cef_v8context_t *context, cef_v8value_t * @object, UIntPtr argumentsCount, [Immutable] cef_v8value_t **arguments)
 {
     fixed(cef_v8value_t *self = &this)
     {
         return(((delegate * unmanaged[Stdcall] < cef_v8value_t *, cef_v8context_t *, cef_v8value_t *, UIntPtr, cef_v8value_t **, cef_v8value_t * >)execute_function_with_context)(self, context, @object, argumentsCount, arguments));
     }
 }
 /// <summary>
 /// Execute the function using the specified V8 context. |object| is the
 /// receiver ('this' object) of the function. If |object| is empty the
 /// specified context's global object will be used. |arguments| is the list of
 /// arguments that will be passed to the function. Returns the function return
 /// value on success. Returns NULL if this method is called incorrectly or an
 /// exception is thrown.
 /// </summary>
 public cef_v8value_t *ExecuteFunctionWithContext(cef_v8context_t *context, cef_v8value_t * @object, UIntPtr argumentsCount, cef_v8value_t **arguments)
 {
     throw new NotImplementedException(); // TODO: CefV8Value.ExecuteFunctionWithContext
 }
Ejemplo n.º 24
0
 private int get(cef_v8accessor_t *self, cef_string_t *name, cef_v8value_t * @object, cef_v8value_t **retval, cef_string_t *exception)
 {
     CheckSelf(self);
     throw new NotImplementedException(); // TODO: CefV8Accessor.Get
 }
Ejemplo n.º 25
0
 public unsafe extern cef_v8value_t *ExecuteFunction(cef_v8value_t * @object, UIntPtr argumentsCount, [Immutable] cef_v8value_t **arguments);
        internal unsafe override int get(cef_v8accessor_t *self, cef_string_t *name, cef_v8value_t * @object, cef_v8value_t **retval, cef_string_t *exception)
        {
            var prop = this.dispatchTable.GetOrDefault(name);

            if (prop == null)
            {
                return(0);
            }

            var method = prop.GetMethod;

            if (method == null)
            {
                return(0);
            }

            var instance = this.instance;

            if (instance == null)
            {
                // TODO: self must be got from obj's userdata
                throw new NotImplementedException();
            }

            try
            {
                method.Invoke(instance, 0, null, retval);
            }
            catch (Exception ex)
            {
                // TODO: how exceptions must be formatted ?
                cef_string_t.Copy(ex.ToString(), exception);
            }

            // TODO: this pointer must be typed
            cef_v8value_t.invoke_release((cef_base_t *)@object);

            return(1);
        }
Ejemplo n.º 27
0
 public unsafe int Execute([Immutable] cef_string_t *name, cef_v8value_t * @object, UIntPtr argumentsCount, [Immutable] cef_v8value_t **arguments, cef_v8value_t **retval, cef_string_t *exception)
 {
     fixed(cef_v8handler_t *self = &this)
     {
         return(((delegate * unmanaged[Stdcall] < cef_v8handler_t *, cef_string_t *, cef_v8value_t *, UIntPtr, cef_v8value_t **, cef_v8value_t **, cef_string_t *, int >)execute)(self, name, @object, argumentsCount, arguments, retval, exception));
     }
 }
Ejemplo n.º 28
0
 public unsafe extern int Execute([Immutable] cef_string_t *name, cef_v8value_t * @object, UIntPtr argumentsCount, [Immutable] cef_v8value_t **arguments, cef_v8value_t **retval, cef_string_t *exception);