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

Side by Side Diff: src/api.cc

Issue 2589113002: [api] add API for Promise status and result. (Closed)
Patch Set: 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 unified diff | Download patch
« include/v8.h ('K') | « include/v8.h ('k') | src/counters.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/api.h" 5 #include "src/api.h"
6 6
7 #include <string.h> // For memcpy, strlen. 7 #include <string.h> // For memcpy, strlen.
8 #ifdef V8_USE_ADDRESS_SANITIZER 8 #ifdef V8_USE_ADDRESS_SANITIZER
9 #include <sanitizer/asan_interface.h> 9 #include <sanitizer/asan_interface.h>
10 #endif // V8_USE_ADDRESS_SANITIZER 10 #endif // V8_USE_ADDRESS_SANITIZER
(...skipping 7271 matching lines...) Expand 10 before | Expand all | Expand 10 after
7282 i::Isolate* isolate = promise->GetIsolate(); 7282 i::Isolate* isolate = promise->GetIsolate();
7283 LOG_API(isolate, Promise, HasRejectHandler); 7283 LOG_API(isolate, Promise, HasRejectHandler);
7284 ENTER_V8(isolate); 7284 ENTER_V8(isolate);
7285 if (promise->IsJSPromise()) { 7285 if (promise->IsJSPromise()) {
7286 i::Handle<i::JSPromise> js_promise = i::Handle<i::JSPromise>::cast(promise); 7286 i::Handle<i::JSPromise> js_promise = i::Handle<i::JSPromise>::cast(promise);
7287 return js_promise->has_handler(); 7287 return js_promise->has_handler();
7288 } 7288 }
7289 return false; 7289 return false;
7290 } 7290 }
7291 7291
7292 MaybeLocal<Value> Promise::Result() {
7293 i::Handle<i::JSReceiver> promise = Utils::OpenHandle(this);
7294 i::Isolate* isolate = promise->GetIsolate();
7295 LOG_API(isolate, Promise, Result);
7296 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.
7297 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.
7298 i::Handle<i::JSPromise> js_promise = i::Handle<i::JSPromise>::cast(promise);
7299 if (js_promise->status() != i::kPromisePending) {
7300 i::Handle<i::Object> result(js_promise->result(), isolate);
7301 return Utils::ToLocal(result);
7302 }
7303 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
7304 }
7305
7306 Promise::PromiseStatus Promise::Status() {
7307 i::Handle<i::JSReceiver> promise = Utils::OpenHandle(this);
7308 i::Isolate* isolate = promise->GetIsolate();
7309 LOG_API(isolate, Promise, Status);
7310 ENTER_V8(isolate);
7311 Utils::ApiCheck(promise->IsJSPromise(), "v8_Promise_Status", "Not a Promise");
7312 i::Handle<i::JSPromise> js_promise = i::Handle<i::JSPromise>::cast(promise);
7313 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.
7314 STATIC_ASSERT(static_cast<int>(i::kPromiseFulfilled) == kFulfilled);
7315 STATIC_ASSERT(static_cast<int>(i::kPromiseRejected) == kRejected);
7316 return static_cast<PromiseStatus>(js_promise->status());
7317 }
7292 7318
7293 Local<Object> Proxy::GetTarget() { 7319 Local<Object> Proxy::GetTarget() {
7294 i::Handle<i::JSProxy> self = Utils::OpenHandle(this); 7320 i::Handle<i::JSProxy> self = Utils::OpenHandle(this);
7295 i::Handle<i::JSReceiver> target(self->target()); 7321 i::Handle<i::JSReceiver> target(self->target());
7296 return Utils::ToLocal(target); 7322 return Utils::ToLocal(target);
7297 } 7323 }
7298 7324
7299 7325
7300 Local<Value> Proxy::GetHandler() { 7326 Local<Value> Proxy::GetHandler() {
7301 i::Handle<i::JSProxy> self = Utils::OpenHandle(this); 7327 i::Handle<i::JSProxy> self = Utils::OpenHandle(this);
(...skipping 2602 matching lines...) Expand 10 before | Expand all | Expand 10 after
9904 Address callback_address = 9930 Address callback_address =
9905 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 9931 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
9906 VMState<EXTERNAL> state(isolate); 9932 VMState<EXTERNAL> state(isolate);
9907 ExternalCallbackScope call_scope(isolate, callback_address); 9933 ExternalCallbackScope call_scope(isolate, callback_address);
9908 callback(info); 9934 callback(info);
9909 } 9935 }
9910 9936
9911 9937
9912 } // namespace internal 9938 } // namespace internal
9913 } // namespace v8 9939 } // namespace v8
OLDNEW
« include/v8.h ('K') | « include/v8.h ('k') | src/counters.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698