diff --git a/atom/common/promise_util.h b/atom/common/promise_util.h index c133423cfd..d36ba82daa 100644 --- a/atom/common/promise_util.h +++ b/atom/common/promise_util.h @@ -8,6 +8,7 @@ #include #include "atom/common/api/locker.h" +#include "atom/common/native_mate_converters/callback.h" #include "content/public/browser/browser_thread.h" #include "native_mate/converter.h" @@ -46,6 +47,17 @@ class Promise : public base::RefCounted { return GetInner()->Reject(GetContext(), v8::Undefined(isolate())); } + v8::MaybeLocal Then(base::Closure cb) { + v8::HandleScope handle_scope(isolate()); + v8::Context::Scope context_scope( + v8::Local::New(isolate(), GetContext())); + + v8::Local value = mate::ConvertToV8(isolate(), cb); + v8::Local handler = v8::Local::Cast(value); + + return GetHandle()->Then(GetContext(), handler); + } + // Promise resolution is a microtask // We use the MicrotasksRunner to trigger the running of pending microtasks template