/// <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> /// 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)); } }
private CefV8Exception(cef_v8exception_t *ptr) { if (ptr == null) { throw new ArgumentNullException("ptr"); } _self = ptr; }
internal static CefV8Exception FromNativeOrNull(cef_v8exception_t *ptr) { if (ptr == null) { return(null); } return(new CefV8Exception(ptr)); }
public void Dispose() { if (_self != null) { Release(); _self = null; } GC.SuppressFinalize(this); }
/// <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 TryEval(string code, out CefV8Value returnValue, out CefV8Exception exception) { bool result; 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); result = cef_v8context_t.eval(_self, &n_code, &n_retval, &n_exception) != 0; } returnValue = n_retval != null ? CefV8Value.FromNative(n_retval) : null; exception = n_exception != null ? CefV8Exception.FromNative(n_exception) : null; return result; }
public static void add_ref(cef_v8exception_t *self) { add_ref_delegate d; var p = self->_base._add_ref; if (p == _p0) { d = _d0; } else { d = (add_ref_delegate)Marshal.GetDelegateForFunctionPointer(p, typeof(add_ref_delegate)); if (_p0 == IntPtr.Zero) { _d0 = d; _p0 = p; } } d(self); }
public static int has_one_ref(cef_v8exception_t *self) { has_one_ref_delegate d; var p = self->_base._has_one_ref; if (p == _p2) { d = _d2; } else { d = (has_one_ref_delegate)Marshal.GetDelegateForFunctionPointer(p, typeof(has_one_ref_delegate)); if (_p2 == IntPtr.Zero) { _d2 = d; _p2 = p; } } return(d(self)); }
public static int release(cef_v8exception_t *self) { release_delegate d; var p = self->_base._release; if (p == _p1) { d = _d1; } else { d = (release_delegate)Marshal.GetDelegateForFunctionPointer(p, typeof(release_delegate)); if (_p1 == IntPtr.Zero) { _d1 = d; _p1 = p; } } return(d(self)); }
public static cef_string_userfree *get_script_resource_name(cef_v8exception_t *self) { get_script_resource_name_delegate d; var p = self->_get_script_resource_name; if (p == _p5) { d = _d5; } else { d = (get_script_resource_name_delegate)Marshal.GetDelegateForFunctionPointer(p, typeof(get_script_resource_name_delegate)); if (_p5 == IntPtr.Zero) { _d5 = d; _p5 = p; } } return(d(self)); }
public static cef_string_userfree *get_message(cef_v8exception_t *self) { get_message_delegate d; var p = self->_get_message; if (p == _p3) { d = _d3; } else { d = (get_message_delegate)Marshal.GetDelegateForFunctionPointer(p, typeof(get_message_delegate)); if (_p3 == IntPtr.Zero) { _d3 = d; _p3 = p; } } return(d(self)); }
public static int get_line_number(cef_v8exception_t *self) { get_line_number_delegate d; var p = self->_get_line_number; if (p == _p6) { d = _d6; } else { d = (get_line_number_delegate)Marshal.GetDelegateForFunctionPointer(p, typeof(get_line_number_delegate)); if (_p6 == IntPtr.Zero) { _d6 = d; _p6 = p; } } return(d(self)); }
public static int get_end_column(cef_v8exception_t *self) { get_end_column_delegate d; var p = self->_get_end_column; if (p == _pa) { d = _da; } else { d = (get_end_column_delegate)Marshal.GetDelegateForFunctionPointer(p, typeof(get_end_column_delegate)); if (_pa == IntPtr.Zero) { _da = d; _pa = p; } } return(d(self)); }
public static int get_start_position(cef_v8exception_t *self) { get_start_position_delegate d; var p = self->_get_start_position; if (p == _p7) { d = _d7; } else { d = (get_start_position_delegate)Marshal.GetDelegateForFunctionPointer(p, typeof(get_start_position_delegate)); if (_p7 == IntPtr.Zero) { _d7 = d; _p7 = p; } } return(d(self)); }
/// <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. On failure |exception| will be set to the /// exception, if any, and the function will return false. /// </summary> public bool TryEval(string code, string scriptUrl, int startLine, out CefV8Value returnValue, out CefV8Exception exception) { bool result; cef_v8value_t * n_retval = null; cef_v8exception_t *n_exception = null; fixed(char *code_str = code) fixed(char *scriptUrl_str = scriptUrl) { var n_code = new cef_string_t(code_str, code != null ? code.Length : 0); var n_scriptUrl = new cef_string_t(scriptUrl_str, scriptUrl != null ? scriptUrl.Length : 0); result = cef_v8context_t.eval(_self, &n_code, &n_scriptUrl, startLine, &n_retval, &n_exception) != 0; } returnValue = n_retval != null?CefV8Value.FromNative(n_retval) : null; exception = n_exception != null?CefV8Exception.FromNative(n_exception) : null; return(result); }
/// <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); } }
public CefV8Value Eval(string code) { if (_cache_eval == null) { _cache_eval = Marshal.GetDelegateForFunctionPointer <delegate_eval>(FixedPtr->eval); } CefString strcode = code ?? throw new ArgumentNullException(nameof(code)); cef_v8value_t * result = null; cef_v8exception_t *exception = null; int r = _cache_eval(FixedPtr, strcode, null, 0, ref result, ref exception); CefV8Value res = CefV8Value.FromOutVal(result); CefV8Exception err = CefV8Exception.FromOutVal(exception); Console.WriteLine("Eval result : " + r + ":" + (IntPtr)result + ":" + (IntPtr)exception); if (err != null) { throw new Exception("JSERROR:" + err.Message); } if (r == 0) { throw new Exception("JSFAILED"); } return(res); }
/// <summary> /// Called immediately before the V8 context for a frame is released. No /// references to the context should be kept after this method is called. /// </summary> // protected abstract void OnContextReleased(cef_browser_t* browser, cef_frame_t* frame, cef_v8context_t* context); private void on_uncaught_exception(cef_render_process_handler_t *self, cef_browser_t *browser, cef_frame_t *frame, cef_v8context_t *context, cef_v8exception_t *exception, cef_v8stack_trace_t *stackTrace) { CheckSelf(self); throw new NotImplementedException(); // TODO: CefRenderProcessHandler.OnUncaughtException }
internal static CefV8Exception FromNative(cef_v8exception_t *ptr) { return(new CefV8Exception(ptr)); }
private CefV8Exception(cef_v8exception_t* ptr) { if (ptr == null) throw new ArgumentNullException("ptr"); _self = ptr; }
public unsafe void OnUncaughtException(cef_browser_t *browser, cef_frame_t *frame, cef_v8context_t *context, cef_v8exception_t *exception, cef_v8stack_trace_t *stackTrace) { fixed(cef_render_process_handler_t *self = &this) { ((delegate * unmanaged[Stdcall] < cef_render_process_handler_t *, cef_browser_t *, cef_frame_t *, cef_v8context_t *, cef_v8exception_t *, cef_v8stack_trace_t *, void >)on_uncaught_exception)(self, browser, frame, context, exception, stackTrace); } }
static public CefV8Exception FromOutVal(cef_v8exception_t *ptr) => FromOutVal((IntPtr)ptr, (p2) => new CefV8Exception(p2, false));
static public CefV8Exception FromInArg(cef_v8exception_t *ptr) => FromInArg((IntPtr)ptr, (p2) => new CefV8Exception(p2));
public unsafe extern void OnUncaughtException(cef_browser_t *browser, cef_frame_t *frame, cef_v8context_t *context, cef_v8exception_t *exception, cef_v8stack_trace_t *stackTrace);
public CefV8Exception(cef_v8exception_t *instance) : base((cef_base_ref_counted_t *)instance) { }
/// <summary> /// Called for global uncaught exceptions. Execution of this callback is /// disabled by default. To enable set /// CefSettings.uncaught_exception_stack_size > 0. /// </summary> private void on_uncaught_exception(cef_v8context_handler_t *self, cef_browser_t *browser, cef_frame_t *frame, cef_v8context_t *context, cef_v8exception_t *exception, cef_v8stack_trace_t *stackTrace) { ThrowIfObjectDisposed(); var m_browser = CefBrowser.From(browser); var m_frame = CefFrame.From(frame); var m_context = CefV8Context.From(context); var m_exception = CefV8Exception.From(exception); var m_stackTrace = CefV8StackTrace.From(stackTrace); this.OnUncaughtException(m_browser, m_frame, m_context, m_exception, m_stackTrace); }
private void on_uncaught_exception(cef_render_process_handler_t *self, cef_browser_t *browser, cef_frame_t *frame, cef_v8context_t *context, cef_v8exception_t *exception, cef_v8stack_trace_t *stackTrace) { CheckSelf(self); var mBrowser = CefBrowser.FromNative(browser); var mFrame = CefFrame.FromNative(frame); var mContext = CefV8Context.FromNative(context); var mException = CefV8Exception.FromNative(exception); var mStackTrace = CefV8StackTrace.FromNative(stackTrace); OnUncaughtException(mBrowser, mFrame, mContext, mException, mStackTrace); }