public virtual void Invoke(IV8PluginRouter router, CefV8Context context, object result, int errorCode, string error) { if (CallbackFunction == null) { throw new ObjectDisposedException("_callback"); } // Have to enter the context in order to be able to create object/array/function/date V8 instances context.Enter(); try { var args = new List <CefV8Value>(); switch (_callbackType) { case V8CallbackType.ParameterCallback: case V8CallbackType.EventListener: { var remoteResult = result as ResultData; var localArray = result as object[]; if (remoteResult != null) { if (remoteResult.Items != null) { args.AddRange(remoteResult.Items.Select(item => ToCefV8Value(router, item))); } } else if (localArray != null) { args.AddRange(localArray.Select(item => ToCefV8Value(router, item))); } break; } case V8CallbackType.FunctionCallback: { args.Add(ToCefV8Value(router, result)); args.Add(CefV8Value.CreateInt(errorCode)); args.Add(CefV8Value.CreateString(error)); break; } } var functionResult = CallbackFunction.ExecuteFunction(null, args.ToArray()); if (functionResult == null && CallbackFunction.HasException) { var exception = CallbackFunction.GetException(); Logger.Error("Error executing callback: ", exception.Message); } } finally { context.Exit(); } }