Commit e2f0a90e authored by Yutaka Hirano's avatar Yutaka Hirano Committed by Commit Bot

Introduce Promise::MarkAsHandled

We are migrating streams implementation from JavaScript (v8Extra) to
C++. One of missing features is an ability to set
promise.[[PromiseIsHandled]] to true, used for example in
https://streams.spec.whatwg.org/#rs-pipe-through. This CL introduces
the feature.

Bug: chromium:894357, chromium:888154, chromium:902633
Change-Id: If6487b29a74a212761e6d2ef04ef3ca0e6957dce
Reviewed-on: https://chromium-review.googlesource.com/c/1322296Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Commit-Queue: Yutaka Hirano <yhirano@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57370}
parent a6ab4e00
...@@ -4153,6 +4153,11 @@ class V8_EXPORT Promise : public Object { ...@@ -4153,6 +4153,11 @@ class V8_EXPORT Promise : public Object {
*/ */
PromiseState State(); PromiseState State();
/**
* Marks this promise as handled to avoid reporting unhandled rejections.
*/
void MarkAsHandled();
V8_INLINE static Promise* Cast(Value* obj); V8_INLINE static Promise* Cast(Value* obj);
static const int kEmbedderFieldCount = V8_PROMISE_INTERNAL_FIELD_COUNT; static const int kEmbedderFieldCount = V8_PROMISE_INTERNAL_FIELD_COUNT;
......
...@@ -7272,6 +7272,11 @@ Promise::PromiseState Promise::State() { ...@@ -7272,6 +7272,11 @@ Promise::PromiseState Promise::State() {
return static_cast<PromiseState>(js_promise->status()); return static_cast<PromiseState>(js_promise->status());
} }
void Promise::MarkAsHandled() {
i::Handle<i::JSPromise> js_promise = Utils::OpenHandle(this);
js_promise->set_has_handler(true);
}
Local<Value> Proxy::GetTarget() { Local<Value> Proxy::GetTarget() {
i::Handle<i::JSProxy> self = Utils::OpenHandle(this); i::Handle<i::JSProxy> self = Utils::OpenHandle(this);
i::Handle<i::Object> target(self->target(), self->GetIsolate()); i::Handle<i::Object> target(self->target(), self->GetIsolate());
......
...@@ -18507,6 +18507,34 @@ TEST(PromiseRejectIsSharedCrossOrigin) { ...@@ -18507,6 +18507,34 @@ TEST(PromiseRejectIsSharedCrossOrigin) {
CHECK(promise_reject_is_shared_cross_origin); CHECK(promise_reject_is_shared_cross_origin);
} }
TEST(PromiseRejectMarkAsHandled) {
LocalContext env;
v8::Isolate* isolate = env->GetIsolate();
v8::HandleScope scope(isolate);
isolate->SetPromiseRejectCallback(PromiseRejectCallback);
ResetPromiseStates();
// Create promise p0.
CompileRun(
"var reject; \n"
"var p0 = new Promise( \n"
" function(res, rej) { \n"
" reject = rej; \n"
" } \n"
"); \n");
CHECK(!GetPromise("p0")->HasHandler());
CHECK_EQ(0, promise_reject_counter);
CHECK_EQ(0, promise_revoke_counter);
GetPromise("p0")->MarkAsHandled();
// Reject p0. promise_reject_counter shouldn't be incremented because
// it's marked as handled.
CompileRun("reject('ppp');");
CHECK_EQ(0, promise_reject_counter);
CHECK_EQ(0, promise_revoke_counter);
}
void PromiseRejectCallbackConstructError( void PromiseRejectCallbackConstructError(
v8::PromiseRejectMessage reject_message) { v8::PromiseRejectMessage reject_message) {
v8::Local<v8::Context> context = CcTest::isolate()->GetCurrentContext(); v8::Local<v8::Context> context = CcTest::isolate()->GetCurrentContext();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment