Commit 2f060955 authored by domenic's avatar domenic Committed by Commit bot

Add markPromiseAsHandled V8 extra util

This will allow V8 extra consumers to mark a promise as handled without
adding redundant empty onRejected handlers. This is needed by streams as
discussed in https://github.com/whatwg/streams/issues/547.

BUG=chromium:654701

Review-Url: https://codereview.chromium.org/2498143002
Cr-Commit-Position: refs/heads/master@{#41012}
parent 6e643f04
......@@ -587,6 +587,10 @@ function PromiseHasUserDefinedRejectHandler() {
return PromiseHasUserDefinedRejectHandlerRecursive(this);
};
function MarkPromiseAsHandled(promise) {
SET_PRIVATE(promise, promiseHasHandlerSymbol, true);
}
function PromiseSpecies() {
return this;
......@@ -632,7 +636,8 @@ utils.InstallFunctions(GlobalPromise.prototype, DONT_ENUM, [
utils.InstallFunctions(extrasUtils, 0, [
"createPromise", PromiseCreate,
"resolvePromise", ResolvePromise,
"rejectPromise", DoRejectPromise
"rejectPromise", DoRejectPromise,
"markPromiseAsHandled", MarkPromiseAsHandled
]);
utils.Export(function(to) {
......
......@@ -25396,6 +25396,12 @@ TEST(ExtrasUtilsObject) {
rejected_promise->Catch(env.local(), store).ToLocalChecked();
isolate->RunMicrotasks();
CHECK_EQ(3, CompileRun("result")->Int32Value(env.local()).FromJust());
auto rejected_but_handled_promise =
result->Get(env.local(), v8_str("rejectedButHandledPromise"))
.ToLocalChecked()
.As<v8::Promise>();
CHECK_EQ(true, rejected_but_handled_promise->HasHandler());
}
......
......@@ -65,11 +65,16 @@
return (arg1 === arg2 && arg2 === 'x') ? 3 : -1;
}, null, new v8.InternalPackedArray('x', 'x')));
const rejectedButHandledPromise = v8.createPromise();
v8.rejectPromise(rejectedButHandledPromise, 4);
v8.markPromiseAsHandled(rejectedButHandledPromise);
return {
privateSymbol: v8.createPrivateSymbol('sym'),
fulfilledPromise, // should be fulfilled with 1
fulfilledPromise2, // should be fulfilled with 2
rejectedPromise // should be rejected with 3
rejectedPromise, // should be rejected with 3
rejectedButHandledPromise // should be rejected but have a handler
};
};
})
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