Exemplo n.º 1
0
        /// <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 bool Eval(string code, out CefV8Value retval, out CefV8Exception exception)
        {
            cef_v8value_t* n_retval = null;
            cef_v8exception_t* n_exception = null;
            fixed (char* code_str = code)
            {
                var n_code = new cef_string_t(code_str, code != null ? code.Length : 0);

                var n_result = cef_v8context_t.invoke_eval(this.ptr, &n_code, &n_retval, &n_exception);
                if (n_result != 0)
                {
                    retval = CefV8Value.From(n_retval);
                    exception = null;
                    return true;
                }
                else
                {
                    retval = null;
                    exception = CefV8Exception.From(n_exception);
                    return false;
                }
            }
        }
Exemplo n.º 2
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;
        }
Exemplo n.º 3
0
 /// <summary>
 /// Create a new CefV8Value object of type double.
 /// </summary>
 public static CefV8Value CreateDouble(double value)
 {
     return(CefV8Value.From(
                NativeMethods.cef_v8value_create_double(value)
                ));
 }
Exemplo n.º 4
0
 /// <summary>
 /// Associates a value with the specified identifier and returns true on
 /// success. Returns false if this method is called incorrectly or an exception
 /// is thrown. For read-only values this method will return true even though
 /// assignment failed.
 /// </summary>
 public bool SetValue(int index, CefV8Value value)
 {
     ThrowIfObjectIsInvalid();
     return cef_v8value_t.invoke_set_value_byindex(this.ptr, index, value.GetNativePointerAndAddRef()) != 0;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Create a new CefV8Value object of type unsigned int.
 /// </summary>
 public static CefV8Value CreateUInt(uint value)
 {
     return(CefV8Value.From(
                NativeMethods.cef_v8value_create_uint(value)
                ));
 }
Exemplo n.º 6
0
 public static sbyte ToSByte(CefV8Value value)
 {
     return(ToSByte(value.NativePointer));
 }
Exemplo n.º 7
0
 /// <summary>
 /// Called to set an accessor value.
 /// |name| is the name of the property being accessed.
 /// |value| is the new value being assigned to this property.
 /// |object| is the This() object from V8's AccessorInfo structure.
 /// Return true if handled.
 /// </summary>
 protected virtual bool Set(string name, CefV8Value obj, CefV8Value value, out string exception)
 {
     exception = null;
     return false;
 }
Exemplo n.º 8
0
 public static float? ToNullableSingle(CefV8Value value)
 {
     return ToNullableSingle(value.NativePointer);
 }
Exemplo n.º 9
0
 public static string ToString(CefV8Value value)
 {
     return ToString(value.NativePointer);
 }
Exemplo n.º 10
0
 public static bool?ToNullableBoolean(CefV8Value value)
 {
     return(ToNullableBoolean(value.NativePointer));
 }
Exemplo n.º 11
0
 public static int?ToNullableInt32(CefV8Value value)
 {
     return(ToNullableInt32(value.NativePointer));
 }
Exemplo n.º 12
0
 public static char ToChar(CefV8Value value)
 {
     return(ToChar(value.NativePointer));
 }
Exemplo n.º 13
0
 public static float ToSingle(CefV8Value value)
 {
     return(ToSingle(value.NativePointer));
 }
Exemplo n.º 14
0
 public static CefV8Value ToV8Value(ushort value)
 {
     return(CefV8Value.From(ToNativeV8Value(value)));
 }
Exemplo n.º 15
0
 public static ushort ToUInt16(CefV8Value value)
 {
     return(ToUInt16(value.NativePointer));
 }
Exemplo n.º 16
0
 public static CefV8Value ToV8Value(sbyte value)
 {
     return(CefV8Value.From(ToNativeV8Value(value)));
 }
Exemplo n.º 17
0
 public static DateTime? ToNullableDateTime(CefV8Value value)
 {
     return ToNullableDateTime(value.NativePointer);
 }
Exemplo n.º 18
0
 public static int ToInt32(CefV8Value value)
 {
     return(ToInt32(value.NativePointer));
 }
Exemplo n.º 19
0
 public static int? ToNullableInt32(CefV8Value value)
 {
     return ToNullableInt32(value.NativePointer);
 }
Exemplo n.º 20
0
 public static double?ToNullableDouble(CefV8Value value)
 {
     return(ToNullableDouble(value.NativePointer));
 }
Exemplo n.º 21
0
 public static object ToObject(CefV8Value value)
 {
     return ToObject(value.NativePointer);
 }
Exemplo n.º 22
0
 public static DateTime?ToNullableDateTime(CefV8Value value)
 {
     return(ToNullableDateTime(value.NativePointer));
 }
Exemplo n.º 23
0
 public static byte ToByte(CefV8Value value)
 {
     return ToByte(value.NativePointer);
 }
Exemplo n.º 24
0
 public static CefV8Value ToV8Value(DateTime?value)
 {
     return(CefV8Value.From(ToNativeV8Value(value)));
 }
Exemplo n.º 25
0
 public static bool? ToNullableBoolean(CefV8Value value)
 {
     return ToNullableBoolean(value.NativePointer);
 }
Exemplo n.º 26
0
 public static sbyte?ToNullableSByte(CefV8Value value)
 {
     return(ToNullableSByte(value.NativePointer));
 }
Exemplo n.º 27
0
 /// <summary>
 /// Returns true if this object is pointing to the same handle as |that| object.
 /// </summary>
 public bool IsSame(CefV8Value that)
 {
     ThrowIfObjectIsInvalid();
     return cef_v8value_t.invoke_is_same(this.ptr, that.GetNativePointerAndAddRef()) != 0;
 }
Exemplo n.º 28
0
 public static ushort?ToNullableUInt16(CefV8Value value)
 {
     return(ToNullableUInt16(value.NativePointer));
 }
Exemplo n.º 29
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>
 protected virtual bool Execute(string name, CefV8Value obj, CefV8Value[] arguments, out CefV8Value returnValue, out string exception)
 {
     returnValue = null;
     exception = null;
     return false;
 }
Exemplo n.º 30
0
 public static char?ToNullableChar(CefV8Value value)
 {
     return(ToNullableChar(value.NativePointer));
 }
Exemplo n.º 31
0
 /// <summary>
 /// Associates a value with the specified identifier and returns true on
 /// success. Returns false if this method is called incorrectly or an exception
 /// is thrown. For read-only values this method will return true even though
 /// assignment failed.
 /// </summary>
 public bool SetValue(int index, CefV8Value value)
 {
     ThrowIfObjectIsInvalid();
     return(cef_v8value_t.invoke_set_value_byindex(this.ptr, index, value.GetNativePointerAndAddRef()) != 0);
 }
Exemplo n.º 32
0
 public static double ToDouble(CefV8Value value)
 {
     return(ToDouble(value.NativePointer));
 }
Exemplo n.º 33
0
 public static char? ToNullableChar(CefV8Value value)
 {
     return ToNullableChar(value.NativePointer);
 }
Exemplo n.º 34
0
 public static float?ToNullableSingle(CefV8Value value)
 {
     return(ToNullableSingle(value.NativePointer));
 }
Exemplo n.º 35
0
 public static double? ToNullableDouble(CefV8Value value)
 {
     return ToNullableDouble(value.NativePointer);
 }
Exemplo n.º 36
0
 public static CefV8Value ToV8Value(float?value)
 {
     return(CefV8Value.From(ToNativeV8Value(value)));
 }
Exemplo n.º 37
0
 public static sbyte? ToNullableSByte(CefV8Value value)
 {
     return ToNullableSByte(value.NativePointer);
 }
Exemplo n.º 38
0
 /// <summary>
 /// Returns the global object for this context. The context must be entered
 /// before calling this method.
 /// </summary>
 public CefV8Value GetGlobal()
 {
     return(CefV8Value.From(
                cef_v8context_t.invoke_get_global(this.ptr)
                ));
 }
Exemplo n.º 39
0
 public static ushort? ToNullableUInt16(CefV8Value value)
 {
     return ToNullableUInt16(value.NativePointer);
 }
Exemplo n.º 40
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>
 protected virtual bool Execute(string name, CefV8Value obj, CefV8Value[] arguments, out CefV8Value returnValue, out string exception)
 {
     returnValue = null;
     exception   = null;
     return(false);
 }
Exemplo n.º 41
0
 public static float ToSingle(CefV8Value value)
 {
     return ToSingle(value.NativePointer);
 }
Exemplo n.º 42
0
 public static DateTime ToDateTime(CefV8Value value)
 {
     return ToDateTime(value.NativePointer);
 }
Exemplo n.º 43
0
 public static bool ToBoolean(CefV8Value value)
 {
     return ToBoolean(value.NativePointer);
 }
Exemplo n.º 44
0
 public static short ToInt16(CefV8Value value)
 {
     return ToInt16(value.NativePointer);
 }
Exemplo n.º 45
0
 public static char ToChar(CefV8Value value)
 {
     return ToChar(value.NativePointer);
 }
Exemplo n.º 46
0
 public static DateTime ToDateTime(CefV8Value value)
 {
     return(ToDateTime(value.NativePointer));
 }
Exemplo n.º 47
0
 public static double ToDouble(CefV8Value value)
 {
     return ToDouble(value.NativePointer);
 }
Exemplo n.º 48
0
 /// <summary>
 /// Create a new CefV8Value object of type undefined.
 /// </summary>
 public static CefV8Value CreateUndefined()
 {
     return(CefV8Value.From(
                NativeMethods.cef_v8value_create_undefined()
                ));
 }
Exemplo n.º 49
0
 public static int ToInt32(CefV8Value value)
 {
     return ToInt32(value.NativePointer);
 }
Exemplo n.º 50
0
 /// <summary>
 /// Create a new CefV8Value object of type object with accessors.
 /// </summary>
 public static CefV8Value CreateObject(CefV8Accessor accessor)
 {
     return(CefV8Value.From(NativeMethods.cef_v8value_create_object(
                                accessor != null ? accessor.GetNativePointerAndAddRef() : null
                                )));
 }
Exemplo n.º 51
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>
 protected virtual bool Get(string name, CefV8Value obj, out CefV8Value returnValue, out string exception)
 {
     returnValue = null;
     exception = null;
     return false;
 }
Exemplo n.º 52
0
 /// <summary>
 /// Create a new CefV8Value object of type array.
 /// </summary>
 public static CefV8Value CreateArray(int length)
 {
     return(CefV8Value.From(
                NativeMethods.cef_v8value_create_array(length)
                ));
 }
Exemplo n.º 53
0
        /// <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 CefV8Value ExecuteFunctionWithContext(CefV8Context context, CefV8Value obj, CefV8Value[] arguments)
        {
            ThrowIfObjectIsInvalid();
            var n_arguments = CreateArgumentsArray(arguments);

            fixed (cef_v8value_t** n_arguments_ptr = n_arguments)
            {
                return CefV8Value.FromOrDefault(
                    cef_v8value_t.invoke_execute_function_with_context(
                        this.ptr,
                        context.GetNativePointerAndAddRef(),
                        obj.GetNativePointerAndAddRef(),
                        n_arguments != null ? n_arguments.Length : 0,
                        n_arguments_ptr
                    )
                );
            }
        }
Exemplo n.º 54
0
 /// <summary>
 /// Create a new CefV8Value object of type null.
 /// </summary>
 public static CefV8Value CreateNull()
 {
     return(CefV8Value.From(
                NativeMethods.cef_v8value_create_null()
                ));
 }
Exemplo n.º 55
0
        /// <summary>
        /// Associates a value with the specified identifier and returns true on
        /// success. Returns false if this method is called incorrectly or an exception
        /// is thrown. For read-only values this method will return true even though
        /// assignment failed.
        /// </summary>
        public bool SetValue(string key, CefV8Value value, CefV8PropertyAttribute attribute = CefV8PropertyAttribute.None)
        {
            ThrowIfObjectIsInvalid();
            fixed (char* key_str = key)
            {
                var n_key = new cef_string_t(key_str, key != null ? key.Length : 0);

                return cef_v8value_t.invoke_set_value_bykey(this.ptr, &n_key, value.GetNativePointerAndAddRef(), (cef_v8_propertyattribute_t)attribute) != 0;
            }
        }
Exemplo n.º 56
0
 /// <summary>
 /// Create a new CefV8Value object of type bool.
 /// </summary>
 public static CefV8Value CreateBool(bool value)
 {
     return(CefV8Value.From(
                NativeMethods.cef_v8value_create_bool(value ? 1 : 0)
                ));
 }
Exemplo n.º 57
0
        private static cef_v8value_t*[] CreateArgumentsArray(CefV8Value[] arguments)
        {
            if (arguments == null) return null;

            var length = arguments.Length;
            if (length == 0) return null;

            var result = new cef_v8value_t*[arguments.Length];

            for (var i = 0; i < length; i++)
            {
                result[i] = arguments[i].GetNativePointerAndAddRef();
            }

            return result;
        }
Exemplo n.º 58
0
 /// <summary>
 /// Returns true if this object is pointing to the same handle as |that| object.
 /// </summary>
 public bool IsSame(CefV8Value that)
 {
     ThrowIfObjectIsInvalid();
     return(cef_v8value_t.invoke_is_same(this.ptr, that.GetNativePointerAndAddRef()) != 0);
 }