Ejemplo 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 (1). On failure |exception| will be set to the
        /// exception, if any, and the function will return false (0).
        /// </summary>
        /// <remarks>
        /// See also the original CEF documentation in
        /// <see href="https://bitbucket.org/chromiumfx/chromiumfx/src/tip/cef/include/capi/cef_v8_capi.h">cef/include/capi/cef_v8_capi.h</see>.
        /// </remarks>
        public bool Eval(string code, out CfxV8Value retval, out CfxV8Exception exception)
        {
            var    code_pinned = new PinnedString(code);
            IntPtr retval_ptr;
            IntPtr exception_ptr;
            var    __retval = CfxApi.cfx_v8context_eval(NativePtr, code_pinned.Obj.PinnedPtr, code_pinned.Length, out retval_ptr, out exception_ptr);

            code_pinned.Obj.Free();
            retval    = CfxV8Value.Wrap(retval_ptr);
            exception = CfxV8Exception.Wrap(exception_ptr);
            return(0 != __retval);
        }
Ejemplo n.º 2
0
 internal static CfxV8Exception Wrap(IntPtr nativePtr)
 {
     if (nativePtr == IntPtr.Zero)
     {
         return(null);
     }
     lock (weakCache) {
         var wrapper = (CfxV8Exception)weakCache.Get(nativePtr);
         if (wrapper == null)
         {
             wrapper = new CfxV8Exception(nativePtr);
             weakCache.Add(wrapper);
         }
         else
         {
             CfxApi.cfx_release(nativePtr);
         }
         return(wrapper);
     }
 }