Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Unified Diff: src/api.cc

Issue 2589113002: [api] add API for Promise status and result. (Closed)
Patch Set: addressed comments Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/v8.h ('k') | src/builtins/builtins-promise.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 04e7c894d4584e3d4cce1ad50b73b22885acfff4..b872ec500d1d2dadf92f3ec0cbe69468096dc9b2 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -7289,6 +7289,24 @@ bool Promise::HasHandler() {
return false;
}
+Local<Value> Promise::Result() {
+ i::Handle<i::JSReceiver> promise = Utils::OpenHandle(this);
+ i::Isolate* isolate = promise->GetIsolate();
+ LOG_API(isolate, Promise, Result);
+ i::Handle<i::JSPromise> js_promise = i::Handle<i::JSPromise>::cast(promise);
+ Utils::ApiCheck(js_promise->status() != kPending, "v8_Promise_Result",
+ "Promise is still pending");
+ i::Handle<i::Object> result(js_promise->result(), isolate);
+ return Utils::ToLocal(result);
+}
+
+Promise::PromiseState Promise::State() {
+ i::Handle<i::JSReceiver> promise = Utils::OpenHandle(this);
+ i::Isolate* isolate = promise->GetIsolate();
+ LOG_API(isolate, Promise, Status);
+ i::Handle<i::JSPromise> js_promise = i::Handle<i::JSPromise>::cast(promise);
+ return static_cast<PromiseState>(js_promise->status());
+}
Local<Object> Proxy::GetTarget() {
i::Handle<i::JSProxy> self = Utils::OpenHandle(this);
« no previous file with comments | « include/v8.h ('k') | src/builtins/builtins-promise.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698