/// <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; } } }
/// <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; }
/// <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) )); }
/// <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; }
/// <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) )); }
public static sbyte ToSByte(CefV8Value value) { return(ToSByte(value.NativePointer)); }
/// <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; }
public static float? ToNullableSingle(CefV8Value value) { return ToNullableSingle(value.NativePointer); }
public static string ToString(CefV8Value value) { return ToString(value.NativePointer); }
public static bool?ToNullableBoolean(CefV8Value value) { return(ToNullableBoolean(value.NativePointer)); }
public static int?ToNullableInt32(CefV8Value value) { return(ToNullableInt32(value.NativePointer)); }
public static char ToChar(CefV8Value value) { return(ToChar(value.NativePointer)); }
public static float ToSingle(CefV8Value value) { return(ToSingle(value.NativePointer)); }
public static CefV8Value ToV8Value(ushort value) { return(CefV8Value.From(ToNativeV8Value(value))); }
public static ushort ToUInt16(CefV8Value value) { return(ToUInt16(value.NativePointer)); }
public static CefV8Value ToV8Value(sbyte value) { return(CefV8Value.From(ToNativeV8Value(value))); }
public static DateTime? ToNullableDateTime(CefV8Value value) { return ToNullableDateTime(value.NativePointer); }
public static int ToInt32(CefV8Value value) { return(ToInt32(value.NativePointer)); }
public static int? ToNullableInt32(CefV8Value value) { return ToNullableInt32(value.NativePointer); }
public static double?ToNullableDouble(CefV8Value value) { return(ToNullableDouble(value.NativePointer)); }
public static object ToObject(CefV8Value value) { return ToObject(value.NativePointer); }
public static DateTime?ToNullableDateTime(CefV8Value value) { return(ToNullableDateTime(value.NativePointer)); }
public static byte ToByte(CefV8Value value) { return ToByte(value.NativePointer); }
public static CefV8Value ToV8Value(DateTime?value) { return(CefV8Value.From(ToNativeV8Value(value))); }
public static bool? ToNullableBoolean(CefV8Value value) { return ToNullableBoolean(value.NativePointer); }
public static sbyte?ToNullableSByte(CefV8Value value) { return(ToNullableSByte(value.NativePointer)); }
/// <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; }
public static ushort?ToNullableUInt16(CefV8Value value) { return(ToNullableUInt16(value.NativePointer)); }
/// <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; }
public static char?ToNullableChar(CefV8Value value) { return(ToNullableChar(value.NativePointer)); }
/// <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); }
public static double ToDouble(CefV8Value value) { return(ToDouble(value.NativePointer)); }
public static char? ToNullableChar(CefV8Value value) { return ToNullableChar(value.NativePointer); }
public static float?ToNullableSingle(CefV8Value value) { return(ToNullableSingle(value.NativePointer)); }
public static double? ToNullableDouble(CefV8Value value) { return ToNullableDouble(value.NativePointer); }
public static CefV8Value ToV8Value(float?value) { return(CefV8Value.From(ToNativeV8Value(value))); }
public static sbyte? ToNullableSByte(CefV8Value value) { return ToNullableSByte(value.NativePointer); }
/// <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) )); }
public static ushort? ToNullableUInt16(CefV8Value value) { return ToNullableUInt16(value.NativePointer); }
/// <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); }
public static float ToSingle(CefV8Value value) { return ToSingle(value.NativePointer); }
public static DateTime ToDateTime(CefV8Value value) { return ToDateTime(value.NativePointer); }
public static bool ToBoolean(CefV8Value value) { return ToBoolean(value.NativePointer); }
public static short ToInt16(CefV8Value value) { return ToInt16(value.NativePointer); }
public static char ToChar(CefV8Value value) { return ToChar(value.NativePointer); }
public static DateTime ToDateTime(CefV8Value value) { return(ToDateTime(value.NativePointer)); }
public static double ToDouble(CefV8Value value) { return ToDouble(value.NativePointer); }
/// <summary> /// Create a new CefV8Value object of type undefined. /// </summary> public static CefV8Value CreateUndefined() { return(CefV8Value.From( NativeMethods.cef_v8value_create_undefined() )); }
public static int ToInt32(CefV8Value value) { return ToInt32(value.NativePointer); }
/// <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 ))); }
/// <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; }
/// <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) )); }
/// <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 ) ); } }
/// <summary> /// Create a new CefV8Value object of type null. /// </summary> public static CefV8Value CreateNull() { return(CefV8Value.From( NativeMethods.cef_v8value_create_null() )); }
/// <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; } }
/// <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) )); }
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; }
/// <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); }