Chromium Code Reviews| Index: src/api.cc |
| diff --git a/src/api.cc b/src/api.cc |
| index 04e7c894d4584e3d4cce1ad50b73b22885acfff4..20108439e985d26e6f2c9d1484f49916198a4fd6 100644 |
| --- a/src/api.cc |
| +++ b/src/api.cc |
| @@ -7289,6 +7289,32 @@ bool Promise::HasHandler() { |
| return false; |
| } |
| +MaybeLocal<Value> Promise::Result() { |
| + i::Handle<i::JSReceiver> promise = Utils::OpenHandle(this); |
| + i::Isolate* isolate = promise->GetIsolate(); |
| + LOG_API(isolate, Promise, Result); |
| + ENTER_V8(isolate); |
|
jochen (gone - plz use gerrit)
2016/12/20 07:49:52
this method (and Status) don't execute script, so
Yang
2016/12/20 11:38:27
Done.
|
| + Utils::ApiCheck(promise->IsJSPromise(), "v8_Promise_Result", "Not a Promise"); |
|
jochen (gone - plz use gerrit)
2016/12/20 07:49:52
that check should never trigger, so I'd suggest to
Yang
2016/12/20 11:38:27
Done.
|
| + i::Handle<i::JSPromise> js_promise = i::Handle<i::JSPromise>::cast(promise); |
| + if (js_promise->status() != i::kPromisePending) { |
| + i::Handle<i::Object> result(js_promise->result(), isolate); |
| + return Utils::ToLocal(result); |
| + } |
| + return MaybeLocal<Value>(); |
|
jochen (gone - plz use gerrit)
2016/12/20 07:49:52
APIs should return empty handles iff an exception
Yang
2016/12/20 11:38:27
Done. Now requiring status not to be pending guard
|
| +} |
| + |
| +Promise::PromiseStatus Promise::Status() { |
| + i::Handle<i::JSReceiver> promise = Utils::OpenHandle(this); |
| + i::Isolate* isolate = promise->GetIsolate(); |
| + LOG_API(isolate, Promise, Status); |
| + ENTER_V8(isolate); |
| + Utils::ApiCheck(promise->IsJSPromise(), "v8_Promise_Status", "Not a Promise"); |
| + i::Handle<i::JSPromise> js_promise = i::Handle<i::JSPromise>::cast(promise); |
| + STATIC_ASSERT(static_cast<int>(i::kPromisePending) == kPending); |
|
jochen (gone - plz use gerrit)
2016/12/20 07:49:52
an alternative approach was to use the external en
Yang
2016/12/20 11:38:27
Done.
|
| + STATIC_ASSERT(static_cast<int>(i::kPromiseFulfilled) == kFulfilled); |
| + STATIC_ASSERT(static_cast<int>(i::kPromiseRejected) == kRejected); |
| + return static_cast<PromiseStatus>(js_promise->status()); |
| +} |
| Local<Object> Proxy::GetTarget() { |
| i::Handle<i::JSProxy> self = Utils::OpenHandle(this); |