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}
This commit is contained in:
parent
6e643f045c
commit
2f060955e8
@ -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
|
||||
};
|
||||
};
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user