Commit d3c34e80 authored by Makoto Shimazu's avatar Makoto Shimazu Committed by Commit Bot

Allow throwing an exception in fulfilled function in WaitUntilObserver

Previously, when an exception happens in an internal callback to fulfill a
promise passed to waitUntil or respondWith, it invokes rejected callback too,
though we expect that either of those is called. This CL correct it by using
ScriptPromise::Then() twice.
Previously, we used ScriptPromise::Then() as like Then(f, g), and it means
calling a promise.then(f).catch(g); in the JavaScript world. I changed it to
Then(f, _), Then(_, g), which is equivalent to promise.then(f);
promise.catch(g);.

Bug: 889567
Change-Id: Id2e2848762b50df633293571c01c5f60d106de7c
Reviewed-on: https://chromium-review.googlesource.com/c/1312141Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Commit-Queue: Makoto Shimazu <shimazu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604535}
parent ac25f032
......@@ -182,10 +182,16 @@ void WaitUntilObserver::WaitUntil(ScriptState* script_state,
}
IncrementPendingPromiseCount();
// Call Then() separately for fulfilled and rejected cases. This ensures
// throwing an exception in |on_promise_fulfilled| doesn't invoke
// |on_promise_rejected|.
script_promise.Then(
ThenFunction::CreateFunction(script_state, this, ThenFunction::kFulfilled,
std::move(on_promise_fulfilled)),
ThenFunction::CreateFunction(script_state, this, ThenFunction::kRejected,
{});
script_promise.Then({}, ThenFunction::CreateFunction(
script_state, this, ThenFunction::kRejected,
std::move(on_promise_rejected)));
}
......
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