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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « include/v8.h ('k') | src/builtins/builtins-promise.cc » ('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 Local<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 i::Handle<i::JSPromise> js_promise = i::Handle<i::JSPromise>::cast(promise);
7297 Utils::ApiCheck(js_promise->status() != kPending, "v8_Promise_Result",
7298 "Promise is still pending");
7299 i::Handle<i::Object> result(js_promise->result(), isolate);
7300 return Utils::ToLocal(result);
7301 }
7302
7303 Promise::PromiseState Promise::State() {
7304 i::Handle<i::JSReceiver> promise = Utils::OpenHandle(this);
7305 i::Isolate* isolate = promise->GetIsolate();
7306 LOG_API(isolate, Promise, Status);
7307 i::Handle<i::JSPromise> js_promise = i::Handle<i::JSPromise>::cast(promise);
7308 return static_cast<PromiseState>(js_promise->status());
7309 }
7292 7310
7293 Local<Object> Proxy::GetTarget() { 7311 Local<Object> Proxy::GetTarget() {
7294 i::Handle<i::JSProxy> self = Utils::OpenHandle(this); 7312 i::Handle<i::JSProxy> self = Utils::OpenHandle(this);
7295 i::Handle<i::JSReceiver> target(self->target()); 7313 i::Handle<i::JSReceiver> target(self->target());
7296 return Utils::ToLocal(target); 7314 return Utils::ToLocal(target);
7297 } 7315 }
7298 7316
7299 7317
7300 Local<Value> Proxy::GetHandler() { 7318 Local<Value> Proxy::GetHandler() {
7301 i::Handle<i::JSProxy> self = Utils::OpenHandle(this); 7319 i::Handle<i::JSProxy> self = Utils::OpenHandle(this);
(...skipping 2602 matching lines...) Expand 10 before | Expand all | Expand 10 after
9904 Address callback_address = 9922 Address callback_address =
9905 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 9923 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
9906 VMState<EXTERNAL> state(isolate); 9924 VMState<EXTERNAL> state(isolate);
9907 ExternalCallbackScope call_scope(isolate, callback_address); 9925 ExternalCallbackScope call_scope(isolate, callback_address);
9908 callback(info); 9926 callback(info);
9909 } 9927 }
9910 9928
9911 9929
9912 } // namespace internal 9930 } // namespace internal
9913 } // namespace v8 9931 } // namespace v8
OLDNEW
« 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