2018-06-27 21:06:08 +00:00
|
|
|
// 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 {
|
|
|
|
|
2018-06-28 21:20:11 +00:00
|
|
|
Promise::Promise(v8::Isolate* isolate) {
|
|
|
|
isolate_ = isolate;
|
|
|
|
resolver_.Reset(isolate, v8::Promise::Resolver::New(isolate));
|
|
|
|
}
|
|
|
|
|
|
|
|
Promise::~Promise() = default;
|
|
|
|
|
2018-06-27 21:06:08 +00:00
|
|
|
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);
|
2018-10-15 15:26:47 +00:00
|
|
|
return Reject(error);
|
2018-06-27 21:06:08 +00:00
|
|
|
}
|
|
|
|
|
2018-09-27 14:59:23 +00:00
|
|
|
v8::Local<v8::Promise> Promise::GetHandle() const {
|
2018-06-27 21:06:08 +00:00
|
|
|
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
|