From fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:14:29 +0200 Subject: Merging upstream version 125.0.1. Signed-off-by: Daniel Baumann --- dom/promise/Promise.cpp | 53 ------------- dom/promise/Promise.h | 7 -- dom/promise/tests/promise_uncatchable_exception.js | 4 +- dom/promise/tests/test_bug883683.html | 4 +- .../tests/test_on_promise_settled_duplicates.html | 2 +- dom/promise/tests/test_promise.html | 92 +++++++++++----------- .../tests/test_promise_uncatchable_exception.html | 2 +- dom/promise/tests/test_promise_utils.html | 12 +-- dom/promise/tests/test_promise_xrays.html | 26 +++--- dom/promise/tests/test_resolve.html | 2 +- dom/promise/tests/test_webassembly_compile.html | 2 +- dom/promise/tests/unit/test_monitor_uncaught.js | 8 +- .../tests/unit/test_promise_job_across_sandbox.js | 5 +- 13 files changed, 80 insertions(+), 139 deletions(-) (limited to 'dom/promise') diff --git a/dom/promise/Promise.cpp b/dom/promise/Promise.cpp index fb4989c43d..3abb517ac7 100644 --- a/dom/promise/Promise.cpp +++ b/dom/promise/Promise.cpp @@ -213,59 +213,6 @@ already_AddRefed Promise::All( return CreateFromExisting(global, result, aPropagateUserInteraction); } -void Promise::Then(JSContext* aCx, - // aCalleeGlobal may not be in the compartment of aCx, when - // called over Xrays. - JS::Handle aCalleeGlobal, - AnyCallback* aResolveCallback, AnyCallback* aRejectCallback, - JS::MutableHandle aRetval, ErrorResult& aRv) { - NS_ASSERT_OWNINGTHREAD(Promise); - - // Let's hope this does the right thing with Xrays... Ensure everything is - // just in the caller compartment; that ought to do the trick. In theory we - // should consider aCalleeGlobal, but in practice our only caller is - // DOMRequest::Then, which is not working with a Promise subclass, so things - // should be OK. - JS::Rooted promise(aCx, PromiseObj()); - if (!promise) { - // This promise is no-op, so do nothing. - return; - } - - if (!JS_WrapObject(aCx, &promise)) { - aRv.NoteJSContextException(aCx); - return; - } - - JS::Rooted resolveCallback(aCx); - if (aResolveCallback) { - resolveCallback = aResolveCallback->CallbackOrNull(); - if (!JS_WrapObject(aCx, &resolveCallback)) { - aRv.NoteJSContextException(aCx); - return; - } - } - - JS::Rooted rejectCallback(aCx); - if (aRejectCallback) { - rejectCallback = aRejectCallback->CallbackOrNull(); - if (!JS_WrapObject(aCx, &rejectCallback)) { - aRv.NoteJSContextException(aCx); - return; - } - } - - JS::Rooted retval(aCx); - retval = JS::CallOriginalPromiseThen(aCx, promise, resolveCallback, - rejectCallback); - if (!retval) { - aRv.NoteJSContextException(aCx); - return; - } - - aRetval.setObject(*retval); -} - static void SettlePromise(Promise* aSettlingPromise, Promise* aCallbackPromise, ErrorResult& aRv) { if (!aSettlingPromise) { diff --git a/dom/promise/Promise.h b/dom/promise/Promise.h index 76c657d5a6..f2b70a95cd 100644 --- a/dom/promise/Promise.h +++ b/dom/promise/Promise.h @@ -255,13 +255,6 @@ class Promise : public SupportsWeakPtr { PropagateUserInteraction aPropagateUserInteraction = eDontPropagateUserInteraction); - void Then(JSContext* aCx, - // aCalleeGlobal may not be in the compartment of aCx, when called - // over Xrays. - JS::Handle aCalleeGlobal, AnyCallback* aResolveCallback, - AnyCallback* aRejectCallback, JS::MutableHandle aRetval, - ErrorResult& aRv); - template using IsHandlerCallback = std::is_same, diff --git a/dom/promise/tests/promise_uncatchable_exception.js b/dom/promise/tests/promise_uncatchable_exception.js index eafc9e5448..1b1f62e774 100644 --- a/dom/promise/tests/promise_uncatchable_exception.js +++ b/dom/promise/tests/promise_uncatchable_exception.js @@ -2,10 +2,10 @@ postMessage("Done", "*"); -var p = new Promise(function (resolve, reject) { +var p = new Promise(function () { TestFunctions.throwUncatchableException(); ok(false, "Shouldn't get here!"); -}).catch(function (exception) { +}).catch(function () { ok(false, "Shouldn't get here!"); }); ok(false, "Shouldn't get here!"); diff --git a/dom/promise/tests/test_bug883683.html b/dom/promise/tests/test_bug883683.html index 1b31e32330..b2f776fe53 100644 --- a/dom/promise/tests/test_bug883683.html +++ b/dom/promise/tests/test_bug883683.html @@ -23,10 +23,10 @@ function runTest() { [{}, {}, {}, {}, {}].reduce(Promise.resolve.bind(Promise)); ok(true, "No leaks with resolve?"); - [{}, {}, {}, {}, {}].reduce(function(a, b, c, d) { return new Promise(function(r1, r2) { throw a; }); }); + [{}, {}, {}, {}, {}].reduce(function(a) { return new Promise(function() { throw a; }); }); ok(true, "No leaks with exception?"); - [{}, {}, {}, {}, {}].reduce(function(a, b, c, d) { return new Promise(function(r1, r2) { }); }); + [{}, {}, {}, {}, {}].reduce(function() { return new Promise(function() { }); }); ok(true, "No leaks with empty promise?"); SimpleTest.finish(); diff --git a/dom/promise/tests/test_on_promise_settled_duplicates.html b/dom/promise/tests/test_on_promise_settled_duplicates.html index e11f4eaa60..324c63b74f 100644 --- a/dom/promise/tests/test_on_promise_settled_duplicates.html +++ b/dom/promise/tests/test_on_promise_settled_duplicates.html @@ -38,7 +38,7 @@ Bug 1084065 - Test that Debugger.prototype.onPromiseResolved doesn't get dupes. seen.add(wp); }; - var promise = new Promise(function(fulfill, reject) { + var promise = new Promise(function(fulfill) { fulfill(1); fulfill(2); fulfill(3); diff --git a/dom/promise/tests/test_promise.html b/dom/promise/tests/test_promise.html index 7c724daf51..95126bd6ba 100644 --- a/dom/promise/tests/test_promise.html +++ b/dom/promise/tests/test_promise.html @@ -56,7 +56,7 @@ function promiseReject() { var promise = new Promise(function(resolve, reject) { reject(42); }); - promise.then(function(what) { + promise.then(function() { ok(false, "Then - resolveCb has been called"); runTest(); }, function(what) { @@ -70,7 +70,7 @@ function promiseRejectNoHandler() { // This test only checks that the code that reports unhandled errors in the // Promises implementation does not crash or leak. - new Promise(function(res, rej) { + new Promise(function() { // eslint-disable-next-line no-undef noSuchMethod(); }); @@ -81,7 +81,7 @@ function promiseRejectNoArg() { var promise = new Promise(function(resolve, reject) { reject(); }); - promise.then(function(what) { + promise.then(function() { ok(false, "Then - resolveCb has been called"); runTest(); }, function(what) { @@ -92,11 +92,11 @@ function promiseRejectNoArg() { } function promiseException() { - var promise = new Promise(function(resolve, reject) { + var promise = new Promise(function() { // eslint-disable-next-line no-throw-literal throw 42; }); - promise.then(function(what) { + promise.then(function() { ok(false, "Then - resolveCb has been called"); runTest(); }, function(what) { @@ -108,10 +108,10 @@ function promiseException() { function promiseGC() { var resolve; - var promise = new Promise(function(r1, r2) { + var promise = new Promise(function(r1) { resolve = r1; }); - promise.then(function(what) { + promise.then(function() { ok(true, "Then - promise is still alive"); runTest(); }); @@ -199,7 +199,7 @@ function promiseAsync_SyncXHR() { function promiseDoubleThen() { var steps = 0; - var promise = new Promise(function(r1, r2) { + var promise = new Promise(function(r1) { r1(42); }); @@ -207,7 +207,7 @@ function promiseDoubleThen() { ok(true, "Then.resolve has been called"); is(what, 42, "Value == 42"); steps++; - }, function(what) { + }, function() { ok(false, "Then.reject has been called"); }); @@ -216,28 +216,28 @@ function promiseDoubleThen() { is(steps, 1, "Then.resolve - step == 1"); is(what, 42, "Value == 42"); runTest(); - }, function(what) { + }, function() { ok(false, "Then.reject has been called"); }); } function promiseThenException() { - var promise = new Promise(function(resolve, reject) { + var promise = new Promise(function(resolve) { resolve(42); }); - promise.then(function(what) { + promise.then(function() { ok(true, "Then.resolve has been called"); // eslint-disable-next-line no-throw-literal throw "booh"; - }).catch(function(e) { + }).catch(function() { ok(true, "window.onerror has been called!"); runTest(); }); } function promiseThenCatchThen() { - var promise = new Promise(function(resolve, reject) { + var promise = new Promise(function(resolve) { resolve(42); }); @@ -245,7 +245,7 @@ function promiseThenCatchThen() { ok(true, "Then.resolve has been called"); is(what, 42, "Value == 42"); return what + 1; - }, function(what) { + }, function() { ok(false, "Then.reject has been called"); }); @@ -255,7 +255,7 @@ function promiseThenCatchThen() { ok(true, "Then.resolve has been called"); is(what, 43, "Value == 43"); return what + 1; - }, function(what) { + }, function() { ok(false, "Then.reject has been called"); }).catch(function() { ok(false, "Catch has been called"); @@ -263,13 +263,13 @@ function promiseThenCatchThen() { ok(true, "Then.resolve has been called"); is(what, 44, "Value == 44"); runTest(); - }, function(what) { + }, function() { ok(false, "Then.reject has been called"); }); } function promiseThenNoArg() { - var promise = new Promise(function(resolve, reject) { + var promise = new Promise(function(resolve) { resolve(42); }); @@ -318,7 +318,7 @@ function promiseRejectThenCatchThen() { reject(42); }); - var promise2 = promise.then(function(what) { + var promise2 = promise.then(function() { ok(false, "Then.resolve has been called"); }, function(what) { ok(true, "Then.reject has been called"); @@ -332,7 +332,7 @@ function promiseRejectThenCatchThen() { ok(true, "Then.resolve has been called"); is(what, 43, "Value == 43"); return what + 1; - }).catch(function(what) { + }).catch(function() { ok(false, "Catch has been called"); }).then(function(what) { ok(true, "Then.resolve has been called"); @@ -366,7 +366,7 @@ function promiseRejectThenCatchExceptionThen() { reject(42); }); - promise.then(function(what) { + promise.then(function() { ok(false, "Then.resolve has been called"); }, function(what) { ok(true, "Then.reject has been called"); @@ -386,7 +386,7 @@ function promiseRejectThenCatchExceptionThen() { function promiseThenCatchOrderingResolve() { var global = 0; - var f = new Promise(function(r1, r2) { + var f = new Promise(function(r1) { r1(42); }); @@ -446,8 +446,8 @@ function promiseCatchNoArg() { } function promiseNestedPromise() { - new Promise(function(resolve, reject) { - resolve(new Promise(function(res, rej) { + new Promise(function(resolve) { + resolve(new Promise(function(res) { ok(true, "Nested promise is executed"); res(42); })); @@ -458,8 +458,8 @@ function promiseNestedPromise() { } function promiseNestedNestedPromise() { - new Promise(function(resolve, reject) { - resolve(new Promise(function(res, rej) { + new Promise(function(resolve) { + resolve(new Promise(function(res) { ok(true, "Nested promise is executed"); res(42); }).then(function(what) { return what + 1; })); @@ -471,7 +471,7 @@ function promiseNestedNestedPromise() { function promiseWrongNestedPromise() { new Promise(function(resolve, reject) { - resolve(new Promise(function(r, r2) { + resolve(new Promise(function(r) { ok(true, "Nested promise is executed"); r(42); })); @@ -479,16 +479,16 @@ function promiseWrongNestedPromise() { }).then(function(value) { is(value, 42, "Nested promise is executed and then == 42"); runTest(); - }, function(value) { + }, function() { ok(false, "This is wrong"); }); } function promiseLoop() { - new Promise(function(resolve, reject) { - resolve(new Promise(function(res, rej) { + new Promise(function(resolve) { + resolve(new Promise(function(res) { ok(true, "Nested promise is executed"); - res(new Promise(function(resInner, rejInner) { + res(new Promise(function(resInner) { ok(true, "Nested nested promise is executed"); resInner(42); })); @@ -496,14 +496,14 @@ function promiseLoop() { }).then(function(value) { is(value, 42, "Nested nested promise is executed and then == 42"); runTest(); - }, function(value) { + }, function() { ok(false, "This is wrong"); }); } function promiseStaticReject() { var promise = Promise.reject(42); - promise.then(function(what) { + promise.then(function() { ok(false, "This should not be called"); }, function(what) { is(what, 42, "Value == 42"); @@ -522,7 +522,7 @@ function promiseStaticResolve() { } function promiseResolveNestedPromise() { - var promise = Promise.resolve(new Promise(function(r, r2) { + var promise = Promise.resolve(new Promise(function(r) { ok(true, "Nested promise is executed"); r(42); }, function() { @@ -538,21 +538,21 @@ function promiseResolveNestedPromise() { function promiseSimpleThenableResolve() { var thenable = { then(resolve) { resolve(5); } }; - var promise = new Promise(function(resolve, reject) { + var promise = new Promise(function(resolve) { resolve(thenable); }); promise.then(function(v) { ok(v === 5, "promiseSimpleThenableResolve"); runTest(); - }, function(e) { + }, function() { ok(false, "promiseSimpleThenableResolve: Should not reject"); }); } function promiseSimpleThenableReject() { var thenable = { then(resolve, reject) { reject(5); } }; - var promise = new Promise(function(resolve, reject) { + var promise = new Promise(function(resolve) { resolve(thenable); }); @@ -574,7 +574,7 @@ function promiseThenableThrowsBeforeCallback() { }}; var promise = Promise.resolve(thenable); - promise.then(function(v) { + promise.then(function() { ok(false, "promiseThenableThrowsBeforeCallback: Should've rejected"); runTest(); }, function(e) { @@ -593,7 +593,7 @@ function promiseThenableThrowsAfterCallback() { promise.then(function(v) { ok(v === 5, "promiseThenableThrowsAfterCallback"); runTest(); - }, function(e) { + }, function() { ok(false, "promiseThenableThrowsAfterCallback: Should've resolved"); runTest(); }); @@ -606,7 +606,7 @@ function promiseThenableRejectThenResolve() { }}; var promise = Promise.resolve(thenable); - promise.then(function(v) { + promise.then(function() { ok(false, "promiseThenableRejectThenResolve should have rejected"); runTest(); }, function(e) { @@ -617,7 +617,7 @@ function promiseThenableRejectThenResolve() { function promiseWithThenReplaced() { // Ensure that we call the 'then' on the promise and not the internal then. - var promise = new Promise(function(resolve, reject) { + var promise = new Promise(function(resolve) { resolve(5); }); @@ -627,7 +627,7 @@ function promiseWithThenReplaced() { }; var promise2 = Promise.resolve(promise); - promise2.then(function(v) { + promise2.then(function() { ok(false, "promiseWithThenReplaced: Should've rejected"); runTest(); }, function(e) { @@ -646,7 +646,7 @@ function promiseStrictHandlers() { } function promiseStrictExecutorThisArg() { - new Promise(function(resolve, reject) { + new Promise(function() { "use strict"; ok(this === undefined, "thisArg should be undefined."); runTest(); @@ -667,12 +667,12 @@ function promiseResolveArray() { } function promiseResolveThenable() { - var p = Promise.resolve({ then(onFulfill, onReject) { onFulfill(2); } }); + var p = Promise.resolve({ then(onFulfill) { onFulfill(2); } }); ok(p instanceof Promise, "Should cast to a Promise."); p.then(function(v) { is(v, 2, "Should resolve to 2."); runTest(); - }, function(e) { + }, function() { ok(false, "promiseResolveThenable should've resolved"); runTest(); }); @@ -748,7 +748,7 @@ function promiseTestAsyncThenableResolution() { // Bug 1062323 function promiseWrapperAsyncResolution() { - var p = new Promise(function(resolve, reject) { + var p = new Promise(function(resolve) { resolve(); }); diff --git a/dom/promise/tests/test_promise_uncatchable_exception.html b/dom/promise/tests/test_promise_uncatchable_exception.html index 2bb6f1fe17..b8e4bdb103 100644 --- a/dom/promise/tests/test_promise_uncatchable_exception.html +++ b/dom/promise/tests/test_promise_uncatchable_exception.html @@ -16,7 +16,7 @@