refactor: add promise helper and change whenReady to be native impl (#13115)

* Add promise helper and change whenReady to be native impl

* remove commented code

* add GetInner helper to dedupe promise code

* add Promise.reject helper to be consistent with JS

* fix linting

* update promise impl per feedback

* remove param name from unused isolate

* Use non-depreceated resolvers for promises

* Add thread dchecks for promise helper, intiialize promise pointer to nullptr
This commit is contained in:
Samuel Attard 2018-06-28 07:06:08 +10:00 committed by Charles Kerr
parent e9971173d4
commit 92588be2bd
8 changed files with 145 additions and 18 deletions

View file

@ -0,0 +1,37 @@
// Copyright (c) 2018 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "atom/common/promise_util.h"
#include <string>
namespace atom {
namespace util {
v8::Maybe<bool> Promise::RejectWithErrorMessage(const std::string& string) {
v8::Local<v8::String> error_message =
v8::String::NewFromUtf8(isolate(), string.c_str());
v8::Local<v8::Value> error = v8::Exception::Error(error_message);
return GetInner()->Reject(isolate()->GetCurrentContext(),
mate::ConvertToV8(isolate(), error));
}
v8::Local<v8::Object> Promise::GetHandle() const {
return GetInner()->GetPromise();
}
} // namespace util
} // namespace atom
namespace mate {
v8::Local<v8::Value> mate::Converter<atom::util::Promise*>::ToV8(
v8::Isolate*,
atom::util::Promise* val) {
return val->GetHandle();
}
} // namespace mate