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

Unified Diff: test/cctest/test-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:
Download patch
« no previous file with comments | « src/runtime/runtime-promise.cc ('k') | test/cctest/test-code-stub-assembler.cc » ('j') | 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..25fb1508fab0c1f48cb49da02c07a82ba5d6bedc 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -24347,6 +24347,25 @@ TEST(PromiseThen) {
.FromJust());
}
+TEST(PromiseStateAndValue) {
+ 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(promise->State() == v8::Promise::PromiseState::kPending);
+
+ CompileRun("resolver('fulfilled')");
+ CHECK(promise->State() == v8::Promise::PromiseState::kFulfilled);
+ CHECK(v8_str("fulfilled")->SameValue(promise->Result()));
+
+ result = CompileRun("Promise.reject('rejected')");
+ promise = v8::Local<v8::Promise>::Cast(result);
+ CHECK(promise->State() == v8::Promise::PromiseState::kRejected);
+ CHECK(v8_str("rejected")->SameValue(promise->Result()));
+}
TEST(DisallowJavascriptExecutionScope) {
LocalContext context;
« no previous file with comments | « src/runtime/runtime-promise.cc ('k') | test/cctest/test-code-stub-assembler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698