Exemple #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));
            }
        }
Exemple #2
0
 /// <summary>
 /// Initializes new instance of the <see cref="CefNetJSExcepton"/> class.
 /// </summary>
 /// <param name="exception">
 /// The CEF V8 exception that is the cause of the current exception.
 /// </param>
 public CefNetJSExcepton(CefV8Exception exception)
     : base(exception.Message)
 {
     this.SourceLine = exception.SourceLine;
     this.ScriptName = exception.ScriptResourceName;
     this.Line       = exception.LineNumber;
     this.Column     = exception.StartColumn;
 }
Exemple #3
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);
            }
        }
Exemple #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CefUncaughtExceptionEventArgs"/> class.
 /// </summary>
 /// <param name="browser">The <see cref="CefBrowser"/> that triggered the event.</param>
 /// <param name="frame">The <see cref="CefFrame"/> that triggered the event.</param>
 /// <param name="context">The <see cref="CefV8Context"/> in which the exception occurred.</param>
 /// <param name="exception">The unhandled V8 exception object.</param>
 /// <param name="stackTrace">The V8 stack trace.</param>
 public CefUncaughtExceptionEventArgs(CefBrowser browser, CefFrame frame, CefV8Context context, CefV8Exception exception, CefV8StackTrace stackTrace)
 {
     this.Browser    = browser;
     this.Frame      = frame;
     this.Context    = context;
     this.Exception  = exception;
     this.StackTrace = stackTrace;
 }
Exemple #5
0
 /// <summary>
 /// Returns the exception resulting from the last function call. This attribute
 /// exists only in the scope of the current CEF value object.
 /// </summary>
 public unsafe virtual CefV8Exception GetException()
 {
     return(SafeCall(CefV8Exception.Wrap(CefV8Exception.Create, NativeInstance->GetException())));
 }