From 2f060955e881aad0e6d5124c533403d3b172bb3b Mon Sep 17 00:00:00 2001 From: domenic Date: Tue, 15 Nov 2016 13:24:58 -0800 Subject: [PATCH] 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} --- src/js/promise.js | 7 ++++++- test/cctest/test-api.cc | 6 ++++++ test/cctest/test-extra.js | 7 ++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/js/promise.js b/src/js/promise.js index d7e2512470..0b37c643d1 100644 --- a/src/js/promise.js +++ b/src/js/promise.js @@ -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) { diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc index 354db4344f..437848b8c0 100644 --- a/test/cctest/test-api.cc +++ b/test/cctest/test-api.cc @@ -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(); + CHECK_EQ(true, rejected_but_handled_promise->HasHandler()); } diff --git a/test/cctest/test-extra.js b/test/cctest/test-extra.js index b3752d97b2..0cc4df4cc4 100644 --- a/test/cctest/test-extra.js +++ b/test/cctest/test-extra.js @@ -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 }; }; })