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

Unified Diff: test/cctest/test-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:
Download patch
« src/api.cc ('K') | « src/counters.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index ca2c8dea063c4fca55ad398b7e1c8897f15900b6..f17859e2e47b9d0a02bd71b0345077528fd80255 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -24347,6 +24347,26 @@ TEST(PromiseThen) {
.FromJust());
}
+TEST(PromiseStatusAndValue) {
+ LocalContext context;
+ v8::Isolate* isolate = context->GetIsolate();
+ v8::HandleScope scope(isolate);
+ v8::Local<v8::Value> result = CompileRun(
+ "var resolver;"
+ "new Promise((res, rej) => { resolver = res; })");
+ v8::Local<v8::Promise> promise = v8::Local<v8::Promise>::Cast(result);
+ CHECK_EQ(v8::Promise::kPending, promise->Status());
+ CHECK(promise->Result().IsEmpty());
+
+ CompileRun("resolver('fulfilled')");
+ CHECK_EQ(v8::Promise::kFulfilled, promise->Status());
+ CHECK(v8_str("fulfilled")->SameValue(promise->Result().ToLocalChecked()));
+
+ result = CompileRun("Promise.reject('rejected')");
+ promise = v8::Local<v8::Promise>::Cast(result);
+ CHECK_EQ(v8::Promise::kRejected, promise->Status());
+ CHECK(v8_str("rejected")->SameValue(promise->Result().ToLocalChecked()));
+}
TEST(DisallowJavascriptExecutionScope) {
LocalContext context;
« src/api.cc ('K') | « src/counters.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698