From bc10b96605d7fcb96289d80ba1bcda849104f74c Mon Sep 17 00:00:00 2001 From: Matthew Gaudet Date: Thu, 20 Jan 2022 19:11:39 +0000 Subject: [PATCH] Bug 1748888 - Add ErrorResult parameter to PromiseNativeHandler callbacks r=smaug Differential Revision: https://phabricator.services.mozilla.com/D136423 --- dom/base/BodyConsumer.cpp | 6 +- dom/base/Document.cpp | 6 +- dom/cache/Cache.cpp | 8 +-- dom/events/Clipboard.cpp | 6 +- dom/fetch/FetchStreamReader.cpp | 6 +- dom/fetch/FetchStreamReader.h | 6 +- dom/filesystem/compat/CallbackRunnables.cpp | 6 +- dom/filesystem/compat/CallbackRunnables.h | 8 +-- .../compat/FileSystemDirectoryReader.cpp | 8 +-- dom/ipc/WindowGlobalParent.cpp | 14 ++-- dom/ipc/jsactor/JSActor.cpp | 8 ++- dom/ipc/jsactor/JSActor.h | 8 +-- dom/l10n/DOMLocalization.cpp | 15 +++-- dom/l10n/DocumentL10n.cpp | 6 +- dom/l10n/L10nMutations.cpp | 7 +- dom/locks/Lock.cpp | 6 +- dom/locks/Lock.h | 8 +-- .../video_engine/tab_capturer.cc | 6 +- dom/payments/MerchantValidationEvent.cpp | 6 +- dom/payments/MerchantValidationEvent.h | 8 +-- dom/payments/PaymentRequest.cpp | 6 +- dom/payments/PaymentRequest.h | 6 +- dom/payments/PaymentRequestUpdateEvent.cpp | 6 +- dom/payments/PaymentRequestUpdateEvent.h | 8 +-- dom/promise/Promise-inl.h | 6 +- dom/promise/Promise.cpp | 27 ++++---- dom/promise/PromiseNativeHandler.cpp | 6 +- dom/promise/PromiseNativeHandler.h | 15 +++-- dom/promise/PromiseWorkerProxy.h | 8 +-- dom/reporting/ReportDeliver.cpp | 6 +- dom/serviceworkers/ServiceWorkerEvents.cpp | 18 +++-- dom/serviceworkers/ServiceWorkerOp.cpp | 12 ++-- dom/serviceworkers/ServiceWorkerOp.h | 6 +- dom/serviceworkers/ServiceWorkerPrivate.cpp | 6 +- .../ServiceWorkerScriptCache.cpp | 34 ++++++---- dom/streams/ReadableByteStreamController.cpp | 29 ++++---- dom/streams/ReadableStream.cpp | 19 +++--- .../ReadableStreamDefaultController.cpp | 31 ++++----- dom/streams/ReadableStreamTee.cpp | 18 +++-- dom/streams/WritableStream.cpp | 6 +- .../WritableStreamDefaultController.cpp | 66 ++++++++----------- dom/workers/ScriptLoader.cpp | 42 +++++++----- dom/worklet/Worklet.cpp | 8 +-- dom/xhr/XMLHttpRequestMainThread.cpp | 6 +- intl/l10n/Localization.cpp | 12 ++-- .../webidl-api/ExtensionAPIBase.cpp | 10 +-- .../extensions/webidl-api/ExtensionAPIBase.h | 10 +-- .../webidl-api/ExtensionEventListener.cpp | 4 +- .../webidl-api/ExtensionEventListener.h | 6 +- .../extensions/webidl-api/ExtensionTest.cpp | 10 +-- xpfe/appshell/AppWindow.cpp | 6 +- 51 files changed, 337 insertions(+), 268 deletions(-) diff --git a/dom/base/BodyConsumer.cpp b/dom/base/BodyConsumer.cpp index 9c9cba4baa05..4e02c7624ffa 100644 --- a/dom/base/BodyConsumer.cpp +++ b/dom/base/BodyConsumer.cpp @@ -400,7 +400,8 @@ class FileCreationHandler final : public PromiseNativeHandler { aPromise->AppendNativeHandler(handler); } - void ResolvedCallback(JSContext* aCx, JS::Handle aValue) override { + void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { AssertIsOnMainThread(); if (NS_WARN_IF(!aValue.isObject())) { @@ -417,7 +418,8 @@ class FileCreationHandler final : public PromiseNativeHandler { mConsumer->OnBlobResult(blob->Impl(), mWorkerRef); } - void RejectedCallback(JSContext* aCx, JS::Handle aValue) override { + void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { AssertIsOnMainThread(); mConsumer->OnBlobResult(nullptr, mWorkerRef); diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp index a9ada9c2003a..c1848c87cdfc 100644 --- a/dom/base/Document.cpp +++ b/dom/base/Document.cpp @@ -13564,13 +13564,15 @@ class UnblockParsingPromiseHandler final : public PromiseNativeHandler { } } - void ResolvedCallback(JSContext* aCx, JS::Handle aValue) override { + void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { MaybeUnblockParser(); mPromise->MaybeResolve(aValue); } - void RejectedCallback(JSContext* aCx, JS::Handle aValue) override { + void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { MaybeUnblockParser(); mPromise->MaybeReject(aValue); diff --git a/dom/cache/Cache.cpp b/dom/cache/Cache.cpp index 600413900b89..8a6ef0542d63 100644 --- a/dom/cache/Cache.cpp +++ b/dom/cache/Cache.cpp @@ -114,8 +114,8 @@ class Cache::FetchHandler final : public PromiseNativeHandler { MOZ_DIAGNOSTIC_ASSERT(mPromise); } - virtual void ResolvedCallback(JSContext* aCx, - JS::Handle aValue) override { + virtual void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { NS_ASSERT_OWNINGTHREAD(FetchHandler); // Stop holding the worker alive when we leave this method. @@ -190,8 +190,8 @@ class Cache::FetchHandler final : public PromiseNativeHandler { mPromise->MaybeResolve(put); } - virtual void RejectedCallback(JSContext* aCx, - JS::Handle aValue) override { + virtual void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { NS_ASSERT_OWNINGTHREAD(FetchHandler); Fail(); } diff --git a/dom/events/Clipboard.cpp b/dom/events/Clipboard.cpp index 57a089b146af..7e5d6a74015d 100644 --- a/dom/events/Clipboard.cpp +++ b/dom/events/Clipboard.cpp @@ -187,7 +187,8 @@ class BlobTextHandler final : public PromiseNativeHandler { mHolder.Reject(rv, __func__); } - void ResolvedCallback(JSContext* aCx, JS::Handle aValue) override { + void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { AssertIsOnMainThread(); nsString text; @@ -203,7 +204,8 @@ class BlobTextHandler final : public PromiseNativeHandler { mHolder.Resolve(std::move(native), __func__); } - void RejectedCallback(JSContext* aCx, JS::Handle aValue) override { + void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { Reject(); } diff --git a/dom/fetch/FetchStreamReader.cpp b/dom/fetch/FetchStreamReader.cpp index 0b55d19b452e..57fa4e3c4570 100644 --- a/dom/fetch/FetchStreamReader.cpp +++ b/dom/fetch/FetchStreamReader.cpp @@ -320,7 +320,8 @@ FetchStreamReader::OnOutputStreamReady(nsIAsyncOutputStream* aStream) { } void FetchStreamReader::ResolvedCallback(JSContext* aCx, - JS::Handle aValue) { + JS::Handle aValue, + ErrorResult& aRv) { if (mStreamClosed) { return; } @@ -418,7 +419,8 @@ nsresult FetchStreamReader::WriteBuffer() { } void FetchStreamReader::RejectedCallback(JSContext* aCx, - JS::Handle aValue) { + JS::Handle aValue, + ErrorResult& aRv) { ReportErrorToConsole(aCx, aValue); CloseAndRelease(aCx, NS_ERROR_FAILURE); } diff --git a/dom/fetch/FetchStreamReader.h b/dom/fetch/FetchStreamReader.h index 14d826d22ff4..85c1efef8274 100644 --- a/dom/fetch/FetchStreamReader.h +++ b/dom/fetch/FetchStreamReader.h @@ -36,9 +36,11 @@ class FetchStreamReader final : public nsIOutputStreamCallback, FetchStreamReader** aStreamReader, nsIInputStream** aInputStream); - void ResolvedCallback(JSContext* aCx, JS::Handle aValue) override; + void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override; - void RejectedCallback(JSContext* aCx, JS::Handle aValue) override; + void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override; // Idempotently close the output stream and null out all state. If aCx is // provided, the reader will also be canceled. aStatus must be a DOM error diff --git a/dom/filesystem/compat/CallbackRunnables.cpp b/dom/filesystem/compat/CallbackRunnables.cpp index 7231c079baa6..cbdd2f2f562b 100644 --- a/dom/filesystem/compat/CallbackRunnables.cpp +++ b/dom/filesystem/compat/CallbackRunnables.cpp @@ -160,7 +160,8 @@ void GetEntryHelper::Run() { } void GetEntryHelper::ResolvedCallback(JSContext* aCx, - JS::Handle aValue) { + JS::Handle aValue, + ErrorResult& aRv) { if (NS_WARN_IF(!aValue.isObject())) { return; } @@ -225,7 +226,8 @@ void GetEntryHelper::ContinueRunning(JSObject* aObj) { } void GetEntryHelper::RejectedCallback(JSContext* aCx, - JS::Handle aValue) { + JS::Handle aValue, + ErrorResult& aRv) { Error(NS_ERROR_DOM_NOT_FOUND_ERR); } diff --git a/dom/filesystem/compat/CallbackRunnables.h b/dom/filesystem/compat/CallbackRunnables.h index 4c5ce1f67e04..3e6732c7b5ec 100644 --- a/dom/filesystem/compat/CallbackRunnables.h +++ b/dom/filesystem/compat/CallbackRunnables.h @@ -73,11 +73,11 @@ class GetEntryHelper final : public PromiseNativeHandler { void Run(); MOZ_CAN_RUN_SCRIPT - virtual void ResolvedCallback(JSContext* aCx, - JS::Handle aValue) override; + virtual void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override; - virtual void RejectedCallback(JSContext* aCx, - JS::Handle aValue) override; + virtual void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override; private: ~GetEntryHelper(); diff --git a/dom/filesystem/compat/FileSystemDirectoryReader.cpp b/dom/filesystem/compat/FileSystemDirectoryReader.cpp index 3ed9ff8a82fb..533faae41300 100644 --- a/dom/filesystem/compat/FileSystemDirectoryReader.cpp +++ b/dom/filesystem/compat/FileSystemDirectoryReader.cpp @@ -40,8 +40,8 @@ class PromiseHandler final : public PromiseNativeHandler { } MOZ_CAN_RUN_SCRIPT - virtual void ResolvedCallback(JSContext* aCx, - JS::Handle aValue) override { + virtual void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { if (NS_WARN_IF(!aValue.isObject())) { return; } @@ -93,8 +93,8 @@ class PromiseHandler final : public PromiseNativeHandler { mSuccessCallback->Call(sequence); } - virtual void RejectedCallback(JSContext* aCx, - JS::Handle aValue) override { + virtual void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { if (mErrorCallback) { RefPtr runnable = new ErrorCallbackRunnable( mParentEntry->GetParentObject(), mErrorCallback, diff --git a/dom/ipc/WindowGlobalParent.cpp b/dom/ipc/WindowGlobalParent.cpp index 22714ad85a1f..c008e10b2267 100644 --- a/dom/ipc/WindowGlobalParent.cpp +++ b/dom/ipc/WindowGlobalParent.cpp @@ -627,13 +627,13 @@ class ShareHandler final : public PromiseNativeHandler { NS_DECL_ISUPPORTS public: - virtual void ResolvedCallback(JSContext* aCx, - JS::Handle aValue) override { + virtual void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { mResolver(NS_OK); } - virtual void RejectedCallback(JSContext* aCx, - JS::Handle aValue) override { + virtual void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { if (NS_WARN_IF(!aValue.isObject())) { mResolver(NS_ERROR_FAILURE); return; @@ -844,13 +844,15 @@ class CheckPermitUnloadRequest final : public PromiseNativeHandler, mState = State::REPLIED; } - void ResolvedCallback(JSContext* aCx, JS::Handle aValue) override { + void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { MOZ_ASSERT(mState == State::PROMPTING); SendReply(JS::ToBoolean(aValue)); } - void RejectedCallback(JSContext* aCx, JS::Handle aValue) override { + void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { MOZ_ASSERT(mState == State::PROMPTING); SendReply(false); diff --git a/dom/ipc/jsactor/JSActor.cpp b/dom/ipc/jsactor/JSActor.cpp index 8b7f0a33f144..6a3ddeea47d1 100644 --- a/dom/ipc/jsactor/JSActor.cpp +++ b/dom/ipc/jsactor/JSActor.cpp @@ -372,7 +372,8 @@ JSActor::QueryHandler::QueryHandler(JSActor* aActor, mQueryId(aMetadata.queryId()) {} void JSActor::QueryHandler::RejectedCallback(JSContext* aCx, - JS::Handle aValue) { + JS::Handle aValue, + ErrorResult& aRv) { if (!mActor) { // Make sure that this rejection is reported. See comment below. if (!JS::CallOriginalPromiseReject(aCx, aValue)) { @@ -414,7 +415,8 @@ void JSActor::QueryHandler::RejectedCallback(JSContext* aCx, } void JSActor::QueryHandler::ResolvedCallback(JSContext* aCx, - JS::Handle aValue) { + JS::Handle aValue, + ErrorResult& aRv) { if (!mActor) { return; } @@ -438,7 +440,7 @@ void JSActor::QueryHandler::ResolvedCallback(JSContext* aCx, JS::Rooted val(aCx); if (ToJSValue(aCx, exc, &val)) { - RejectedCallback(aCx, val); + RejectedCallback(aCx, val, aRv); } else { JS_ClearPendingException(aCx); } diff --git a/dom/ipc/jsactor/JSActor.h b/dom/ipc/jsactor/JSActor.h index 515d2c312cc3..d7b0e1563bce 100644 --- a/dom/ipc/jsactor/JSActor.h +++ b/dom/ipc/jsactor/JSActor.h @@ -128,11 +128,11 @@ class JSActor : public nsISupports, public nsWrapperCache { QueryHandler(JSActor* aActor, const JSActorMessageMeta& aMetadata, Promise* aPromise); - void RejectedCallback(JSContext* aCx, - JS::Handle aValue) override; + void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override; - void ResolvedCallback(JSContext* aCx, - JS::Handle aValue) override; + void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override; private: ~QueryHandler() = default; diff --git a/dom/l10n/DOMLocalization.cpp b/dom/l10n/DOMLocalization.cpp index 73d816089bf6..dd53d56e9e48 100644 --- a/dom/l10n/DOMLocalization.cpp +++ b/dom/l10n/DOMLocalization.cpp @@ -203,8 +203,8 @@ class ElementTranslationHandler : public PromiseNativeHandler { mReturnValuePromise = aReturnValuePromise; } - virtual void ResolvedCallback(JSContext* aCx, - JS::Handle aValue) override { + virtual void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { ErrorResult rv; nsTArray> l10nData; @@ -257,8 +257,8 @@ class ElementTranslationHandler : public PromiseNativeHandler { mReturnValuePromise->MaybeResolveWithUndefined(); } - virtual void RejectedCallback(JSContext* aCx, - JS::Handle aValue) override { + virtual void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { mReturnValuePromise->MaybeRejectWithClone(aCx, aValue); } @@ -377,12 +377,13 @@ class L10nRootTranslationHandler final : public PromiseNativeHandler { explicit L10nRootTranslationHandler(Element* aRoot) : mRoot(aRoot) {} - void ResolvedCallback(JSContext* aCx, JS::Handle aValue) override { + void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { DOMLocalization::SetRootInfo(mRoot); } - void RejectedCallback(JSContext* aCx, JS::Handle aValue) override { - } + void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override {} private: ~L10nRootTranslationHandler() = default; diff --git a/dom/l10n/DocumentL10n.cpp b/dom/l10n/DocumentL10n.cpp index c65f53c73aed..5f9a3379f63c 100644 --- a/dom/l10n/DocumentL10n.cpp +++ b/dom/l10n/DocumentL10n.cpp @@ -69,12 +69,14 @@ class L10nReadyHandler final : public PromiseNativeHandler { explicit L10nReadyHandler(Promise* aPromise, DocumentL10n* aDocumentL10n) : mPromise(aPromise), mDocumentL10n(aDocumentL10n) {} - void ResolvedCallback(JSContext* aCx, JS::Handle aValue) override { + void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { mDocumentL10n->InitialTranslationCompleted(true); mPromise->MaybeResolveWithUndefined(); } - void RejectedCallback(JSContext* aCx, JS::Handle aValue) override { + void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { mDocumentL10n->InitialTranslationCompleted(false); nsTArray errors{ diff --git a/dom/l10n/L10nMutations.cpp b/dom/l10n/L10nMutations.cpp index f0eff146f044..e8de9932ef48 100644 --- a/dom/l10n/L10nMutations.cpp +++ b/dom/l10n/L10nMutations.cpp @@ -165,10 +165,11 @@ class L10nMutationFinalizationHandler final : public PromiseNativeHandler { explicit L10nMutationFinalizationHandler(nsIGlobalObject* aGlobal) : mGlobal(aGlobal) {} - void ResolvedCallback(JSContext* aCx, JS::Handle aValue) override { - } + void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override {} - void RejectedCallback(JSContext* aCx, JS::Handle aValue) override { + void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { nsTArray errors{ "[dom/l10n] Errors during l10n mutation frame."_ns, }; diff --git a/dom/locks/Lock.cpp b/dom/locks/Lock.cpp index ab29c7d8b207..24d5456c5415 100644 --- a/dom/locks/Lock.cpp +++ b/dom/locks/Lock.cpp @@ -48,7 +48,8 @@ Promise& Lock::GetWaitingPromise() { return *mWaitingPromise; } -void Lock::ResolvedCallback(JSContext* aCx, JS::Handle aValue) { +void Lock::ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) { if (mLockRequestChild) { locks::PLockRequestChild::Send__delete__(mLockRequestChild, false); mLockRequestChild = nullptr; @@ -56,7 +57,8 @@ void Lock::ResolvedCallback(JSContext* aCx, JS::Handle aValue) { mReleasedPromise->MaybeResolve(aValue); } -void Lock::RejectedCallback(JSContext* aCx, JS::Handle aValue) { +void Lock::RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) { if (mLockRequestChild) { locks::PLockRequestChild::Send__delete__(mLockRequestChild, false); mLockRequestChild = nullptr; diff --git a/dom/locks/Lock.h b/dom/locks/Lock.h index 9f4f1e6c8b23..87ceaf550fca 100644 --- a/dom/locks/Lock.h +++ b/dom/locks/Lock.h @@ -52,10 +52,10 @@ class Lock final : public PromiseNativeHandler, public nsWrapperCache { Promise& GetWaitingPromise(); // PromiseNativeHandler - virtual void ResolvedCallback(JSContext* aCx, - JS::Handle aValue) override; - virtual void RejectedCallback(JSContext* aCx, - JS::Handle aValue) override; + virtual void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override; + virtual void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override; private: nsCOMPtr mOwner; diff --git a/dom/media/systemservices/video_engine/tab_capturer.cc b/dom/media/systemservices/video_engine/tab_capturer.cc index a7786e0bca4e..352c0d1b47c5 100644 --- a/dom/media/systemservices/video_engine/tab_capturer.cc +++ b/dom/media/systemservices/video_engine/tab_capturer.cc @@ -110,7 +110,8 @@ class TabCapturedHandler final : public dom::PromiseNativeHandler { aPromise->AppendNativeHandler(handler); } - void ResolvedCallback(JSContext* aCx, JS::Handle aValue) override { + void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { MOZ_ASSERT(NS_IsMainThread()); MonitorAutoLock monitor(mEngine->mMonitor); if (NS_WARN_IF(!aValue.isObject())) { @@ -131,7 +132,8 @@ class TabCapturedHandler final : public dom::PromiseNativeHandler { monitor.Notify(); } - void RejectedCallback(JSContext* aCx, JS::Handle aValue) override { + void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { MOZ_ASSERT(NS_IsMainThread()); MonitorAutoLock monitor(mEngine->mMonitor); mEngine->mCapturing = false; diff --git a/dom/payments/MerchantValidationEvent.cpp b/dom/payments/MerchantValidationEvent.cpp index 9153d13a3bb9..cd1c8f1800b7 100644 --- a/dom/payments/MerchantValidationEvent.cpp +++ b/dom/payments/MerchantValidationEvent.cpp @@ -87,7 +87,8 @@ MerchantValidationEvent::MerchantValidationEvent(EventTarget* aOwner) } void MerchantValidationEvent::ResolvedCallback(JSContext* aCx, - JS::Handle aValue) { + JS::Handle aValue, + ErrorResult& aRv) { MOZ_ASSERT(aCx); MOZ_ASSERT(mRequest); @@ -112,7 +113,8 @@ void MerchantValidationEvent::ResolvedCallback(JSContext* aCx, } void MerchantValidationEvent::RejectedCallback(JSContext* aCx, - JS::Handle aValue) { + JS::Handle aValue, + ErrorResult& aRv) { MOZ_ASSERT(mRequest); if (!mWaitForUpdate) { return; diff --git a/dom/payments/MerchantValidationEvent.h b/dom/payments/MerchantValidationEvent.h index b7de875ea173..e4ace4c6b824 100644 --- a/dom/payments/MerchantValidationEvent.h +++ b/dom/payments/MerchantValidationEvent.h @@ -33,10 +33,10 @@ class MerchantValidationEvent : public Event, public PromiseNativeHandler { virtual JSObject* WrapObjectInternal( JSContext* aCx, JS::Handle aGivenProto) override; - virtual void ResolvedCallback(JSContext* aCx, - JS::Handle aValue) override; - virtual void RejectedCallback(JSContext* aCx, - JS::Handle aValue) override; + virtual void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override; + virtual void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override; static already_AddRefed Constructor( EventTarget* aOwner, const nsAString& aType, diff --git a/dom/payments/PaymentRequest.cpp b/dom/payments/PaymentRequest.cpp index 22c8f17378ee..1afe9e7777e7 100644 --- a/dom/payments/PaymentRequest.cpp +++ b/dom/payments/PaymentRequest.cpp @@ -1112,7 +1112,8 @@ void PaymentRequest::SetOptions(const PaymentOptions& aOptions) { } void PaymentRequest::ResolvedCallback(JSContext* aCx, - JS::Handle aValue) { + JS::Handle aValue, + ErrorResult& aRv) { if (!InFullyActiveDocument()) { return; } @@ -1147,7 +1148,8 @@ void PaymentRequest::ResolvedCallback(JSContext* aCx, } void PaymentRequest::RejectedCallback(JSContext* aCx, - JS::Handle aValue) { + JS::Handle aValue, + ErrorResult& aRv) { if (!InFullyActiveDocument()) { return; } diff --git a/dom/payments/PaymentRequest.h b/dom/payments/PaymentRequest.h index 995a99dfb301..6bece3f3d8a9 100644 --- a/dom/payments/PaymentRequest.h +++ b/dom/payments/PaymentRequest.h @@ -201,8 +201,10 @@ class PaymentRequest final : public DOMEventTargetHelper, nsresult UpdatePaymentMethod(const nsAString& aMethodName, const ChangeDetails& aMethodDetails); - void ResolvedCallback(JSContext* aCx, JS::Handle aValue) override; - void RejectedCallback(JSContext* aCx, JS::Handle aValue) override; + void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override; + void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override; bool InFullyActiveDocument(); diff --git a/dom/payments/PaymentRequestUpdateEvent.cpp b/dom/payments/PaymentRequestUpdateEvent.cpp index 5997f37a6fd8..12c4a8c287a1 100644 --- a/dom/payments/PaymentRequestUpdateEvent.cpp +++ b/dom/payments/PaymentRequestUpdateEvent.cpp @@ -50,7 +50,8 @@ PaymentRequestUpdateEvent::PaymentRequestUpdateEvent(EventTarget* aOwner) } void PaymentRequestUpdateEvent::ResolvedCallback(JSContext* aCx, - JS::Handle aValue) { + JS::Handle aValue, + ErrorResult& aRv) { MOZ_ASSERT(aCx); MOZ_ASSERT(mRequest); if (!mRequest->InFullyActiveDocument()) { @@ -93,7 +94,8 @@ void PaymentRequestUpdateEvent::ResolvedCallback(JSContext* aCx, } void PaymentRequestUpdateEvent::RejectedCallback(JSContext* aCx, - JS::Handle aValue) { + JS::Handle aValue, + ErrorResult& aRv) { MOZ_ASSERT(mRequest); if (!mRequest->InFullyActiveDocument()) { return; diff --git a/dom/payments/PaymentRequestUpdateEvent.h b/dom/payments/PaymentRequestUpdateEvent.h index cd5afb8ae9fc..5ed0dd295ab3 100644 --- a/dom/payments/PaymentRequestUpdateEvent.h +++ b/dom/payments/PaymentRequestUpdateEvent.h @@ -30,10 +30,10 @@ class PaymentRequestUpdateEvent : public Event, public PromiseNativeHandler { virtual JSObject* WrapObjectInternal( JSContext* aCx, JS::Handle aGivenProto) override; - virtual void ResolvedCallback(JSContext* aCx, - JS::Handle aValue) override; - virtual void RejectedCallback(JSContext* aCx, - JS::Handle aValue) override; + virtual void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override; + virtual void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override; static already_AddRefed Constructor( EventTarget* aOwner, const nsAString& aType, diff --git a/dom/promise/Promise-inl.h b/dom/promise/Promise-inl.h index 4ff32585babb..0acc13d0f057 100644 --- a/dom/promise/Promise-inl.h +++ b/dom/promise/Promise-inl.h @@ -23,9 +23,11 @@ class PromiseNativeThenHandlerBase : public PromiseNativeHandler { PromiseNativeThenHandlerBase(Promise& aPromise) : mPromise(&aPromise) {} - void ResolvedCallback(JSContext* aCx, JS::Handle aValue) override; + void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override; - void RejectedCallback(JSContext* aCx, JS::Handle aValue) override; + void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override; protected: virtual ~PromiseNativeThenHandlerBase() = default; diff --git a/dom/promise/Promise.cpp b/dom/promise/Promise.cpp index 17a03f17cd5a..83632a3cdc0c 100644 --- a/dom/promise/Promise.cpp +++ b/dom/promise/Promise.cpp @@ -232,7 +232,7 @@ void Promise::Then(JSContext* aCx, } void PromiseNativeThenHandlerBase::ResolvedCallback( - JSContext* aCx, JS::Handle aValue) { + JSContext* aCx, JS::Handle aValue, ErrorResult& aRv) { RefPtr promise = CallResolveCallback(aCx, aValue); if (promise) { mPromise->MaybeResolve(promise); @@ -242,7 +242,7 @@ void PromiseNativeThenHandlerBase::ResolvedCallback( } void PromiseNativeThenHandlerBase::RejectedCallback( - JSContext* aCx, JS::Handle aValue) { + JSContext* aCx, JS::Handle aValue, ErrorResult& aRv) { mPromise->MaybeReject(aValue); } @@ -333,16 +333,17 @@ static bool NativeHandlerCallback(JSContext* aCx, unsigned aArgc, v = js::GetFunctionNativeReserved(&args.callee(), SLOT_NATIVEHANDLER_TASK); NativeHandlerTask task = static_cast(v.toInt32()); + ErrorResult rv; if (task == NativeHandlerTask::Resolve) { // handler is kept alive by "obj" on the stack. - MOZ_KnownLive(handler)->ResolvedCallback(aCx, args.get(0)); + MOZ_KnownLive(handler)->ResolvedCallback(aCx, args.get(0), rv); } else { MOZ_ASSERT(task == NativeHandlerTask::Reject); // handler is kept alive by "obj" on the stack. - MOZ_KnownLive(handler)->RejectedCallback(aCx, args.get(0)); + MOZ_KnownLive(handler)->RejectedCallback(aCx, args.get(0), rv); } - return true; + return !rv.MaybeSetPendingException(aCx); } static JSObject* CreateNativeHandlerFunction(JSContext* aCx, @@ -380,16 +381,18 @@ class PromiseNativeHandlerShim final : public PromiseNativeHandler { } MOZ_CAN_RUN_SCRIPT - void ResolvedCallback(JSContext* aCx, JS::Handle aValue) override { + void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { RefPtr inner = std::move(mInner); - inner->ResolvedCallback(aCx, aValue); + inner->ResolvedCallback(aCx, aValue, aRv); MOZ_ASSERT(!mInner); } MOZ_CAN_RUN_SCRIPT - void RejectedCallback(JSContext* aCx, JS::Handle aValue) override { + void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { RefPtr inner = std::move(mInner); - inner->RejectedCallback(aCx, aValue); + inner->RejectedCallback(aCx, aValue, aRv); MOZ_ASSERT(!mInner); } @@ -770,12 +773,14 @@ void PromiseWorkerProxy::RunCallback(JSContext* aCx, } void PromiseWorkerProxy::ResolvedCallback(JSContext* aCx, - JS::Handle aValue) { + JS::Handle aValue, + ErrorResult& aRv) { RunCallback(aCx, aValue, &Promise::MaybeResolve); } void PromiseWorkerProxy::RejectedCallback(JSContext* aCx, - JS::Handle aValue) { + JS::Handle aValue, + ErrorResult& aRv) { RunCallback(aCx, aValue, &Promise::MaybeReject); } diff --git a/dom/promise/PromiseNativeHandler.cpp b/dom/promise/PromiseNativeHandler.cpp index 5bbdaf2f8229..57d6030c40b6 100644 --- a/dom/promise/PromiseNativeHandler.cpp +++ b/dom/promise/PromiseNativeHandler.cpp @@ -24,7 +24,8 @@ DomPromiseListener::~DomPromiseListener() { } void DomPromiseListener::ResolvedCallback(JSContext* aCx, - JS::Handle aValue) { + JS::Handle aValue, + ErrorResult& aRv) { if (mResolve) { mResolve(aCx, aValue); } @@ -33,7 +34,8 @@ void DomPromiseListener::ResolvedCallback(JSContext* aCx, } void DomPromiseListener::RejectedCallback(JSContext* aCx, - JS::Handle aValue) { + JS::Handle aValue, + ErrorResult& aRv) { if (mReject) { nsresult errorCode; if (!aValue.isInt32()) { diff --git a/dom/promise/PromiseNativeHandler.h b/dom/promise/PromiseNativeHandler.h index 9a26332a6f51..96308f81b3f5 100644 --- a/dom/promise/PromiseNativeHandler.h +++ b/dom/promise/PromiseNativeHandler.h @@ -10,6 +10,7 @@ #include #include "js/TypeDecls.h" #include "js/Value.h" +#include "mozilla/ErrorResult.h" #include "mozilla/Maybe.h" #include "nsISupports.h" @@ -27,12 +28,12 @@ class PromiseNativeHandler : public nsISupports { public: MOZ_CAN_RUN_SCRIPT - virtual void ResolvedCallback(JSContext* aCx, - JS::Handle aValue) = 0; + virtual void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) = 0; MOZ_CAN_RUN_SCRIPT - virtual void RejectedCallback(JSContext* aCx, - JS::Handle aValue) = 0; + virtual void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) = 0; }; // This class is used to set C++ callbacks once a dom Promise a resolved or @@ -50,8 +51,10 @@ class DomPromiseListener final : public PromiseNativeHandler { void Clear(); - void ResolvedCallback(JSContext* aCx, JS::Handle aValue) override; - void RejectedCallback(JSContext* aCx, JS::Handle aValue) override; + void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override; + void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override; private: ~DomPromiseListener(); diff --git a/dom/promise/PromiseWorkerProxy.h b/dom/promise/PromiseWorkerProxy.h index aba1f0cf8ce3..0e93bbc9e021 100644 --- a/dom/promise/PromiseWorkerProxy.h +++ b/dom/promise/PromiseWorkerProxy.h @@ -174,11 +174,11 @@ class PromiseWorkerProxy : public PromiseNativeHandler, bool* aSameProcessScopeRequired) override; protected: - virtual void ResolvedCallback(JSContext* aCx, - JS::Handle aValue) override; + virtual void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override; - virtual void RejectedCallback(JSContext* aCx, - JS::Handle aValue) override; + virtual void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override; private: explicit PromiseWorkerProxy( diff --git a/dom/reporting/ReportDeliver.cpp b/dom/reporting/ReportDeliver.cpp index 59acc06d7cce..ce9463450f5b 100644 --- a/dom/reporting/ReportDeliver.cpp +++ b/dom/reporting/ReportDeliver.cpp @@ -39,7 +39,8 @@ class ReportFetchHandler final : public PromiseNativeHandler { const nsTArray& aReportData) : mReports(aReportData.Clone()) {} - void ResolvedCallback(JSContext* aCx, JS::Handle aValue) override { + void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { if (!gReportDeliver) { return; } @@ -76,7 +77,8 @@ class ReportFetchHandler final : public PromiseNativeHandler { } } - void RejectedCallback(JSContext* aCx, JS::Handle aValue) override { + void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { if (gReportDeliver) { for (auto& report : mReports) { ++report.mFailures; diff --git a/dom/serviceworkers/ServiceWorkerEvents.cpp b/dom/serviceworkers/ServiceWorkerEvents.cpp index a9a788dd8860..da1f1f9922fa 100644 --- a/dom/serviceworkers/ServiceWorkerEvents.cpp +++ b/dom/serviceworkers/ServiceWorkerEvents.cpp @@ -432,9 +432,11 @@ class RespondWithHandler final : public PromiseNativeHandler { mRequestWasHandled(false) { } - void ResolvedCallback(JSContext* aCx, JS::Handle aValue) override; + void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override; - void RejectedCallback(JSContext* aCx, JS::Handle aValue) override; + void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override; void CancelRequest(nsresult aStatus); @@ -561,7 +563,8 @@ class MOZ_STACK_CLASS AutoCancel { NS_IMPL_ISUPPORTS0(RespondWithHandler) void RespondWithHandler::ResolvedCallback(JSContext* aCx, - JS::Handle aValue) { + JS::Handle aValue, + ErrorResult& aRv) { AutoCancel autoCancel(this, mRequestURL); if (!aValue.isObject()) { @@ -735,7 +738,8 @@ void RespondWithHandler::ResolvedCallback(JSContext* aCx, } void RespondWithHandler::RejectedCallback(JSContext* aCx, - JS::Handle aValue) { + JS::Handle aValue, + ErrorResult& aRv) { nsCString sourceSpec = mRespondWithScriptSpec; uint32_t line = mRespondWithLineNumber; uint32_t column = mRespondWithColumnNumber; @@ -879,11 +883,13 @@ class WaitUntilHandler final : public PromiseNativeHandler { nsJSUtils::GetCallingLocation(aCx, mSourceSpec, &mLine, &mColumn); } - void ResolvedCallback(JSContext* aCx, JS::Handle aValue) override { + void ResolvedCallback(JSContext* aCx, JS::Handle aValu, + ErrorResult& aRve) override { // do nothing, we are only here to report errors } - void RejectedCallback(JSContext* aCx, JS::Handle aValue) override { + void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { mWorkerPrivate->AssertIsOnWorkerThread(); nsString spec; diff --git a/dom/serviceworkers/ServiceWorkerOp.cpp b/dom/serviceworkers/ServiceWorkerOp.cpp index b9df982f7c1b..4288f097ee56 100644 --- a/dom/serviceworkers/ServiceWorkerOp.cpp +++ b/dom/serviceworkers/ServiceWorkerOp.cpp @@ -117,11 +117,13 @@ class ExtendableEventKeepAliveHandler final /** * PromiseNativeHandler interface */ - void ResolvedCallback(JSContext* aCx, JS::Handle aValue) override { + void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { RemovePromise(Resolved); } - void RejectedCallback(JSContext* aCx, JS::Handle aValue) override { + void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { RemovePromise(Rejected); } @@ -1344,7 +1346,8 @@ void FetchEventOp::GetRequestURL(nsAString& aOutRequestURL) { } void FetchEventOp::ResolvedCallback(JSContext* aCx, - JS::Handle aValue) { + JS::Handle aValue, + ErrorResult& aRv) { MOZ_ASSERT(IsCurrentThreadRunningWorker()); MOZ_ASSERT(mRespondWithClosure); MOZ_ASSERT(!mRespondWithPromiseHolder.IsEmpty()); @@ -1523,7 +1526,8 @@ void FetchEventOp::ResolvedCallback(JSContext* aCx, } void FetchEventOp::RejectedCallback(JSContext* aCx, - JS::Handle aValue) { + JS::Handle aValue, + ErrorResult& aRv) { MOZ_ASSERT(IsCurrentThreadRunningWorker()); MOZ_ASSERT(mRespondWithClosure); MOZ_ASSERT(!mRespondWithPromiseHolder.IsEmpty()); diff --git a/dom/serviceworkers/ServiceWorkerOp.h b/dom/serviceworkers/ServiceWorkerOp.h index c868e03bfc12..3f7bedf13526 100644 --- a/dom/serviceworkers/ServiceWorkerOp.h +++ b/dom/serviceworkers/ServiceWorkerOp.h @@ -136,9 +136,11 @@ class FetchEventOp final : public ExtendableEventOp, * `{Resolved,Reject}Callback()` are use to handle the * `FetchEvent::RespondWith()` promise. */ - void ResolvedCallback(JSContext* aCx, JS::Handle aValue) override; + void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override; - void RejectedCallback(JSContext* aCx, JS::Handle aValue) override; + void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override; void MaybeFinished(); diff --git a/dom/serviceworkers/ServiceWorkerPrivate.cpp b/dom/serviceworkers/ServiceWorkerPrivate.cpp index 6115166c88eb..1e68078ca471 100644 --- a/dom/serviceworkers/ServiceWorkerPrivate.cpp +++ b/dom/serviceworkers/ServiceWorkerPrivate.cpp @@ -301,11 +301,13 @@ class KeepAliveHandler final : public ExtendableEvent::ExtensionsHandler, return true; } - void ResolvedCallback(JSContext* aCx, JS::Handle aValue) override { + void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { RemovePromise(Resolved); } - void RejectedCallback(JSContext* aCx, JS::Handle aValue) override { + void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { RemovePromise(Rejected); } diff --git a/dom/serviceworkers/ServiceWorkerScriptCache.cpp b/dom/serviceworkers/ServiceWorkerScriptCache.cpp index d34ed77e6584..1c40c35edce1 100644 --- a/dom/serviceworkers/ServiceWorkerScriptCache.cpp +++ b/dom/serviceworkers/ServiceWorkerScriptCache.cpp @@ -210,11 +210,11 @@ class CompareCache final : public PromiseNativeHandler, void Abort(); - virtual void ResolvedCallback(JSContext* aCx, - JS::Handle aValue) override; + virtual void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override; - virtual void RejectedCallback(JSContext* aCx, - JS::Handle aValue) override; + virtual void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override; const nsString& Buffer() const { MOZ_ASSERT(NS_IsMainThread()); @@ -265,9 +265,11 @@ class CompareManager final : public PromiseNativeHandler { nsresult Initialize(nsIPrincipal* aPrincipal, const nsAString& aURL, const nsAString& aCacheName); - void ResolvedCallback(JSContext* aCx, JS::Handle aValue) override; + void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override; - void RejectedCallback(JSContext* aCx, JS::Handle aValue) override; + void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override; CacheStorage* CacheStorage_() { MOZ_ASSERT(NS_IsMainThread()); @@ -1193,7 +1195,8 @@ CompareCache::OnStreamComplete(nsIStreamLoader* aLoader, nsISupports* aContext, } void CompareCache::ResolvedCallback(JSContext* aCx, - JS::Handle aValue) { + JS::Handle aValue, + ErrorResult& aRv) { MOZ_ASSERT(NS_IsMainThread()); switch (mState) { @@ -1208,7 +1211,8 @@ void CompareCache::ResolvedCallback(JSContext* aCx, } void CompareCache::RejectedCallback(JSContext* aCx, - JS::Handle aValue) { + JS::Handle aValue, + ErrorResult& aRv) { MOZ_ASSERT(NS_IsMainThread()); if (mState != Finished) { @@ -1344,7 +1348,8 @@ nsresult CompareManager::Initialize(nsIPrincipal* aPrincipal, // 4. Put the value in the cache. // For this reason we have mState to know what callback we are handling. void CompareManager::ResolvedCallback(JSContext* aCx, - JS::Handle aValue) { + JS::Handle aValue, + ErrorResult& aRv) { MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(mCallback); @@ -1374,7 +1379,8 @@ void CompareManager::ResolvedCallback(JSContext* aCx, } void CompareManager::RejectedCallback(JSContext* aCx, - JS::Handle aValue) { + JS::Handle aValue, + ErrorResult& aRv) { MOZ_ASSERT(NS_IsMainThread()); switch (mState) { case Finished: @@ -1428,10 +1434,10 @@ class NoopPromiseHandler final : public PromiseNativeHandler { NoopPromiseHandler() { AssertIsOnMainThread(); } - void ResolvedCallback(JSContext* aCx, JS::Handle aValue) override { - } - void RejectedCallback(JSContext* aCx, JS::Handle aValue) override { - } + void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override {} + void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override {} private: ~NoopPromiseHandler() { AssertIsOnMainThread(); } diff --git a/dom/streams/ReadableByteStreamController.cpp b/dom/streams/ReadableByteStreamController.cpp index 8deea7411e5c..07f964beefc3 100644 --- a/dom/streams/ReadableByteStreamController.cpp +++ b/dom/streams/ReadableByteStreamController.cpp @@ -424,7 +424,8 @@ class ByteStreamPullIfNeededPromiseHandler final : public PromiseNativeHandler { : PromiseNativeHandler(), mController(aController) {} MOZ_CAN_RUN_SCRIPT - void ResolvedCallback(JSContext* aCx, JS::Handle aValue) override { + void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { // https://streams.spec.whatwg.org/#readable-byte-stream-controller-call-pull-if-needed // Step 7.1 mController->SetPulling(false); @@ -434,19 +435,16 @@ class ByteStreamPullIfNeededPromiseHandler final : public PromiseNativeHandler { mController->SetPullAgain(false); // Step 7.2.2 - ErrorResult rv; ReadableByteStreamControllerCallPullIfNeeded( - aCx, MOZ_KnownLive(mController), rv); - (void)rv.MaybeSetPendingException(aCx, "PullIfNeeded Resolved Error"); + aCx, MOZ_KnownLive(mController), aRv); } } - void RejectedCallback(JSContext* aCx, JS::Handle aValue) override { + void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { // https://streams.spec.whatwg.org/#readable-byte-stream-controller-call-pull-if-needed // Step 8.1 - ErrorResult rv; - ReadableByteStreamControllerError(mController, aValue, rv); - (void)rv.MaybeSetPendingException(aCx, "PullIfNeeded Rejected Error"); + ReadableByteStreamControllerError(mController, aValue, aRv); } }; @@ -1661,7 +1659,8 @@ class ByteStreamStartPromiseNativeHandler final : public PromiseNativeHandler { : PromiseNativeHandler(), mController(aController) {} MOZ_CAN_RUN_SCRIPT - void ResolvedCallback(JSContext* aCx, JS::Handle aValue) override { + void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { MOZ_ASSERT(mController); // https://streams.spec.whatwg.org/#set-up-readable-byte-stream-controller @@ -1676,18 +1675,16 @@ class ByteStreamStartPromiseNativeHandler final : public PromiseNativeHandler { mController->SetPullAgain(false); // Step 16.4: - ErrorResult rv; + RefPtr stackController = mController; - ReadableByteStreamControllerCallPullIfNeeded(aCx, stackController, rv); - (void)rv.MaybeSetPendingException(aCx, "StartPromise Resolve Error"); + ReadableByteStreamControllerCallPullIfNeeded(aCx, stackController, aRv); } - void RejectedCallback(JSContext* aCx, JS::Handle aValue) override { + void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { // https://streams.spec.whatwg.org/#set-up-readable-byte-stream-controller // Step 17.1 - ErrorResult rv; - ReadableByteStreamControllerError(mController, aValue, rv); - (void)rv.MaybeSetPendingException(aCx, "StartPromise Rejected Error"); + ReadableByteStreamControllerError(mController, aValue, aRv); } }; diff --git a/dom/streams/ReadableStream.cpp b/dom/streams/ReadableStream.cpp index f3a17b4450d9..c2f2232f0cc3 100644 --- a/dom/streams/ReadableStream.cpp +++ b/dom/streams/ReadableStream.cpp @@ -759,24 +759,21 @@ class ReadableStreamTeeClosePromiseHandler final : public PromiseNativeHandler { explicit ReadableStreamTeeClosePromiseHandler(TeeState* aTeeState) : mTeeState(aTeeState) {} - void ResolvedCallback(JSContext* aCx, JS::Handle aValue) override { - } - void RejectedCallback(JSContext* aCx, - JS::Handle aReason) override { + void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override {} + void RejectedCallback(JSContext* aCx, JS::Handle aReason, + ErrorResult& aRv) override { // Step 19.1. - ErrorResult rv; ReadableStreamDefaultControllerError( - aCx, mTeeState->Branch1()->DefaultController(), aReason, rv); - if (rv.MaybeSetPendingException( - aCx, "ReadableStreamDefaultTee Error During Promise Rejection")) { + aCx, mTeeState->Branch1()->DefaultController(), aReason, aRv); + if (aRv.Failed()) { return; } // Step 19.2 ReadableStreamDefaultControllerError( - aCx, mTeeState->Branch2()->DefaultController(), aReason, rv); - if (rv.MaybeSetPendingException( - aCx, "ReadableStreamDefaultTee Error During Promise Rejection")) { + aCx, mTeeState->Branch2()->DefaultController(), aReason, aRv); + if (aRv.Failed()) { return; } diff --git a/dom/streams/ReadableStreamDefaultController.cpp b/dom/streams/ReadableStreamDefaultController.cpp index bf1eb0dd8fcd..21605004922d 100644 --- a/dom/streams/ReadableStreamDefaultController.cpp +++ b/dom/streams/ReadableStreamDefaultController.cpp @@ -420,8 +420,9 @@ class PullIfNeededNativePromiseHandler final : public PromiseNativeHandler { ReadableStreamDefaultController* aController) : PromiseNativeHandler(), mController(aController) {} - MOZ_CAN_RUN_SCRIPT void ResolvedCallback( - JSContext* aCx, JS::Handle aValue) override { + MOZ_CAN_RUN_SCRIPT void ResolvedCallback(JSContext* aCx, + JS::Handle aValue, + ErrorResult& aRv) override { // https://streams.spec.whatwg.org/#readable-stream-default-controller-call-pull-if-needed // Step 7.1 mController->SetPulling(false); @@ -433,18 +434,15 @@ class PullIfNeededNativePromiseHandler final : public PromiseNativeHandler { // Step 7.2.2 ErrorResult rv; ReadableStreamDefaultControllerCallPullIfNeeded( - aCx, MOZ_KnownLive(mController), rv); - - (void)rv.MaybeSetPendingException(aCx); + aCx, MOZ_KnownLive(mController), aRv); } } - void RejectedCallback(JSContext* aCx, JS::Handle aValue) override { + void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { // https://streams.spec.whatwg.org/#readable-stream-default-controller-call-pull-if-needed // Step 8.1 - ErrorResult rv; - ReadableStreamDefaultControllerError(aCx, mController, aValue, rv); - (void)rv.MaybeSetPendingException(aCx, "PullIfNeeded Rejected Error"); + ReadableStreamDefaultControllerError(aCx, mController, aValue, aRv); } }; @@ -513,7 +511,8 @@ class StartPromiseNativeHandler final : public PromiseNativeHandler { : PromiseNativeHandler(), mController(aController) {} MOZ_CAN_RUN_SCRIPT - void ResolvedCallback(JSContext* aCx, JS::Handle aValue) override { + void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { MOZ_ASSERT(mController); // https://streams.spec.whatwg.org/#set-up-readable-stream-default-controller @@ -528,18 +527,16 @@ class StartPromiseNativeHandler final : public PromiseNativeHandler { mController->SetPullAgain(false); // Step 11.4: - ErrorResult rv; + RefPtr stackController = mController; - ReadableStreamDefaultControllerCallPullIfNeeded(aCx, stackController, rv); - (void)rv.MaybeSetPendingException(aCx, "StartPromise Resolved Error"); + ReadableStreamDefaultControllerCallPullIfNeeded(aCx, stackController, aRv); } - void RejectedCallback(JSContext* aCx, JS::Handle aValue) override { + void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { // https://streams.spec.whatwg.org/#set-up-readable-stream-default-controller // Step 12.1 - ErrorResult rv; - ReadableStreamDefaultControllerError(aCx, mController, aValue, rv); - (void)rv.MaybeSetPendingException(aCx, "StartPromise Rejected Error"); + ReadableStreamDefaultControllerError(aCx, mController, aValue, aRv); } }; diff --git a/dom/streams/ReadableStreamTee.cpp b/dom/streams/ReadableStreamTee.cpp index 7fcd48ed759d..dee9954c066b 100644 --- a/dom/streams/ReadableStreamTee.cpp +++ b/dom/streams/ReadableStreamTee.cpp @@ -927,12 +927,12 @@ class ForwardReaderErrorPromiseHandler final : public PromiseNativeHandler { : mTeeState(aTeeState), mReader(aReader) {} MOZ_CAN_RUN_SCRIPT - void ResolvedCallback(JSContext* aCx, JS::Handle aValue) override { - } + void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override {} MOZ_CAN_RUN_SCRIPT - virtual void RejectedCallback(JSContext* aCx, - JS::Handle aValue) override { + virtual void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { // Step 14.1.1 if (mTeeState->GetReader() != mReader) { return; @@ -943,9 +943,8 @@ class ForwardReaderErrorPromiseHandler final : public PromiseNativeHandler { // !ReadableByteStreamControllerError(branch1.[[controller]], r). MOZ_ASSERT(mTeeState->Branch1()->Controller()->IsByte()); ReadableByteStreamControllerError( - mTeeState->Branch1()->Controller()->AsByte(), aValue, rv); - if (rv.MaybeSetPendingException( - aCx, "ReadableByteStreamTee: Error during forwardReaderError")) { + mTeeState->Branch1()->Controller()->AsByte(), aValue, aRv); + if (aRv.Failed()) { return; } @@ -953,9 +952,8 @@ class ForwardReaderErrorPromiseHandler final : public PromiseNativeHandler { // !ReadableByteStreamControllerError(branch2.[[controller]], r). MOZ_ASSERT(mTeeState->Branch2()->Controller()->IsByte()); ReadableByteStreamControllerError( - mTeeState->Branch2()->Controller()->AsByte(), aValue, rv); - if (rv.MaybeSetPendingException( - aCx, "ReadableByteStreamTee: Error during forwardReaderError")) { + mTeeState->Branch2()->Controller()->AsByte(), aValue, aRv); + if (aRv.Failed()) { return; } diff --git a/dom/streams/WritableStream.cpp b/dom/streams/WritableStream.cpp index 605522adb226..6f100bc33219 100644 --- a/dom/streams/WritableStream.cpp +++ b/dom/streams/WritableStream.cpp @@ -116,7 +116,8 @@ class AbortStepsNativePromiseHandler final : public PromiseNativeHandler { mStream(aStream), mAbortRequestPromise(aAbortRequestPromise) {} - void ResolvedCallback(JSContext* aCx, JS::Handle aValue) override { + void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { // https://streams.spec.whatwg.org/#writable-stream-finish-erroring // Step 13. Upon fulfillment of promise, @@ -128,7 +129,8 @@ class AbortStepsNativePromiseHandler final : public PromiseNativeHandler { mStream->RejectCloseAndClosedPromiseIfNeeded(); } - void RejectedCallback(JSContext* aCx, JS::Handle aValue) override { + void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { // https://streams.spec.whatwg.org/#writable-stream-finish-erroring // Step 14. Upon rejection of promise with reason reason, diff --git a/dom/streams/WritableStreamDefaultController.cpp b/dom/streams/WritableStreamDefaultController.cpp index 52e713404178..da6166cec003 100644 --- a/dom/streams/WritableStreamDefaultController.cpp +++ b/dom/streams/WritableStreamDefaultController.cpp @@ -139,8 +139,9 @@ class WritableStartPromiseNativeHandler final : public PromiseNativeHandler { WritableStreamDefaultController* aController) : PromiseNativeHandler(), mController(aController) {} - MOZ_CAN_RUN_SCRIPT void ResolvedCallback( - JSContext* aCx, JS::Handle aValue) override { + MOZ_CAN_RUN_SCRIPT void ResolvedCallback(JSContext* aCx, + JS::Handle aValue, + ErrorResult& aRv) override { // https://streams.spec.whatwg.org/#set-up-writable-stream-default-controller // Step 17. Upon fulfillment of startPromise, // Step 17.1. Assert: stream.[[state]] is "writable" or "erroring". @@ -152,16 +153,13 @@ class WritableStartPromiseNativeHandler final : public PromiseNativeHandler { mController->SetStarted(true); // Step 17.3 Perform // ! WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller). - IgnoredErrorResult rv; WritableStreamDefaultControllerAdvanceQueueIfNeeded( - aCx, MOZ_KnownLive(mController), rv); - if (rv.MaybeSetPendingException(aCx)) { - return; - } + aCx, MOZ_KnownLive(mController), aRv); } - MOZ_CAN_RUN_SCRIPT void RejectedCallback( - JSContext* aCx, JS::Handle aValue) override { + MOZ_CAN_RUN_SCRIPT void RejectedCallback(JSContext* aCx, + JS::Handle aValue, + ErrorResult& aRv) override { // https://streams.spec.whatwg.org/#set-up-writable-stream-default-controller RefPtr stream = mController->Stream(); // Step 18. Upon rejection of startPromise with reason r, @@ -171,11 +169,7 @@ class WritableStartPromiseNativeHandler final : public PromiseNativeHandler { // Step 18.2. Set controller.[[started]] to true. mController->SetStarted(true); // Step 18.3. Perform ! WritableStreamDealWithRejection(stream, r). - IgnoredErrorResult rv; - stream->DealWithRejection(aCx, aValue, rv); - if (rv.MaybeSetPendingException(aCx)) { - return; - } + stream->DealWithRejection(aCx, aValue, aRv); } }; @@ -326,7 +320,8 @@ class SinkCloseNativePromiseHandler final : public PromiseNativeHandler { WritableStreamDefaultController* aController) : PromiseNativeHandler(), mController(aController) {} - void ResolvedCallback(JSContext* aCx, JS::Handle aValue) override { + void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { // https://streams.spec.whatwg.org/#writable-stream-default-controller-process-close RefPtr stream = mController->Stream(); // Step 7. Upon fulfillment of sinkClosePromise, @@ -334,16 +329,16 @@ class SinkCloseNativePromiseHandler final : public PromiseNativeHandler { stream->FinishInFlightClose(); } - MOZ_CAN_RUN_SCRIPT void RejectedCallback( - JSContext* aCx, JS::Handle aValue) override { + MOZ_CAN_RUN_SCRIPT void RejectedCallback(JSContext* aCx, + JS::Handle aValue, + ErrorResult& aRv) override { // https://streams.spec.whatwg.org/#writable-stream-default-controller-process-close RefPtr stream = mController->Stream(); // Step 8. Upon rejection of sinkClosePromise with reason reason, // Step 8.1. Perform ! WritableStreamFinishInFlightCloseWithError(stream, // reason). - IgnoredErrorResult rv; - stream->FinishInFlightCloseWithError(aCx, aValue, rv); - NS_WARNING_ASSERTION(!rv.Failed(), "FinishInFlightCloseWithError failed"); + + stream->FinishInFlightCloseWithError(aCx, aValue, aRv); } private: @@ -410,8 +405,9 @@ class SinkWriteNativePromiseHandler final : public PromiseNativeHandler { WritableStreamDefaultController* aController) : PromiseNativeHandler(), mController(aController) {} - MOZ_CAN_RUN_SCRIPT void ResolvedCallback( - JSContext* aCx, JS::Handle aValue) override { + MOZ_CAN_RUN_SCRIPT void ResolvedCallback(JSContext* aCx, + JS::Handle aValue, + ErrorResult& aRv) override { // https://streams.spec.whatwg.org/#writable-stream-default-controller-process-write RefPtr stream = mController->Stream(); @@ -438,25 +434,21 @@ class SinkWriteNativePromiseHandler final : public PromiseNativeHandler { bool backpressure = mController->GetBackpressure(); // Step 4.5.2. Perform ! WritableStreamUpdateBackpressure(stream, // backpressure). - IgnoredErrorResult rv; - stream->UpdateBackpressure(backpressure, rv); - // XXX Not Sure How To Handle Errors Inside Native Callbacks, - NS_WARNING_ASSERTION(!rv.Failed(), "UpdateBackpressure failed"); + stream->UpdateBackpressure(backpressure, aRv); + if (aRv.Failed()) { + return; + } } // Step 4.6. Perform ! // WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller). - IgnoredErrorResult rv; WritableStreamDefaultControllerAdvanceQueueIfNeeded( - aCx, MOZ_KnownLive(mController), rv); - // XXX Not Sure How To Handle Errors Inside Native Callbacks, - NS_WARNING_ASSERTION( - !rv.Failed(), - "WritableStreamDefaultControllerAdvanceQueueIfNeeded failed"); + aCx, MOZ_KnownLive(mController), aRv); } - MOZ_CAN_RUN_SCRIPT void RejectedCallback( - JSContext* aCx, JS::Handle aValue) override { + MOZ_CAN_RUN_SCRIPT void RejectedCallback(JSContext* aCx, + JS::Handle aValue, + ErrorResult& aRv) override { // https://streams.spec.whatwg.org/#writable-stream-default-controller-process-write RefPtr stream = mController->Stream(); @@ -468,10 +460,8 @@ class SinkWriteNativePromiseHandler final : public PromiseNativeHandler { // Step 5.2. Perform ! WritableStreamFinishInFlightWriteWithError(stream, // reason) - IgnoredErrorResult rv; - stream->FinishInFlightWriteWithError(aCx, aValue, rv); - // XXX Not Sure How To Handle Errors Inside Native Callbacks, - NS_WARNING_ASSERTION(!rv.Failed(), "FinishInFlightWriteWithError failed"); + + stream->FinishInFlightWriteWithError(aCx, aValue, aRv); } }; diff --git a/dom/workers/ScriptLoader.cpp b/dom/workers/ScriptLoader.cpp index 24150dc74473..ff55dbe73dc4 100644 --- a/dom/workers/ScriptLoader.cpp +++ b/dom/workers/ScriptLoader.cpp @@ -426,11 +426,11 @@ class CacheCreator final : public PromiseNativeHandler { mLoaders.AppendElement(std::move(aLoader)); } - virtual void ResolvedCallback(JSContext* aCx, - JS::Handle aValue) override; + virtual void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override; - virtual void RejectedCallback(JSContext* aCx, - JS::Handle aValue) override; + virtual void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override; // Try to load from cache with aPrincipal used for cache access. nsresult Load(nsIPrincipal* aPrincipal); @@ -492,11 +492,11 @@ class CacheScriptLoader final : public PromiseNativeHandler, void Load(Cache* aCache); - virtual void ResolvedCallback(JSContext* aCx, - JS::Handle aValue) override; + virtual void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override; - virtual void RejectedCallback(JSContext* aCx, - JS::Handle aValue) override; + virtual void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override; private: ~CacheScriptLoader() { AssertIsOnMainThread(); } @@ -529,11 +529,11 @@ class CachePromiseHandler final : public PromiseNativeHandler { MOZ_ASSERT(mRunnable); } - virtual void ResolvedCallback(JSContext* aCx, - JS::Handle aValue) override; + virtual void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override; - virtual void RejectedCallback(JSContext* aCx, - JS::Handle aValue) override; + virtual void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override; private: ~CachePromiseHandler() { AssertIsOnMainThread(); } @@ -1565,7 +1565,8 @@ LoaderListener::OnStartRequest(nsIRequest* aRequest) { } void CachePromiseHandler::ResolvedCallback(JSContext* aCx, - JS::Handle aValue) { + JS::Handle aValue, + ErrorResult& aRv) { AssertIsOnMainThread(); // May already have been canceled by CacheScriptLoader::Fail from // CancelMainThread. @@ -1582,7 +1583,8 @@ void CachePromiseHandler::ResolvedCallback(JSContext* aCx, } void CachePromiseHandler::RejectedCallback(JSContext* aCx, - JS::Handle aValue) { + JS::Handle aValue, + ErrorResult& aRv) { AssertIsOnMainThread(); // May already have been canceled by CacheScriptLoader::Fail from // CancelMainThread. @@ -1679,13 +1681,15 @@ void CacheCreator::FailLoaders(nsresult aRv) { } void CacheCreator::RejectedCallback(JSContext* aCx, - JS::Handle aValue) { + JS::Handle aValue, + ErrorResult& aRv) { AssertIsOnMainThread(); FailLoaders(NS_ERROR_FAILURE); } void CacheCreator::ResolvedCallback(JSContext* aCx, - JS::Handle aValue) { + JS::Handle aValue, + ErrorResult& aRv) { AssertIsOnMainThread(); if (!aValue.isObject()) { @@ -1802,14 +1806,16 @@ void CacheScriptLoader::Load(Cache* aCache) { } void CacheScriptLoader::RejectedCallback(JSContext* aCx, - JS::Handle aValue) { + JS::Handle aValue, + ErrorResult& aRv) { AssertIsOnMainThread(); MOZ_ASSERT(mLoadInfo.mCacheStatus == ScriptLoadInfo::Uncached); Fail(NS_ERROR_FAILURE); } void CacheScriptLoader::ResolvedCallback(JSContext* aCx, - JS::Handle aValue) { + JS::Handle aValue, + ErrorResult& aRv) { AssertIsOnMainThread(); // If we have already called 'Fail', we should not proceed. if (mFailed) { diff --git a/dom/worklet/Worklet.cpp b/dom/worklet/Worklet.cpp index ddf2aafb8cc4..6fcb854ca88b 100644 --- a/dom/worklet/Worklet.cpp +++ b/dom/worklet/Worklet.cpp @@ -164,8 +164,8 @@ class WorkletFetchHandler final : public PromiseNativeHandler, return promise.forget(); } - virtual void ResolvedCallback(JSContext* aCx, - JS::Handle aValue) override { + virtual void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { MOZ_ASSERT(NS_IsMainThread()); if (!aValue.isObject()) { @@ -256,8 +256,8 @@ class WorkletFetchHandler final : public PromiseNativeHandler, return NS_OK; } - virtual void RejectedCallback(JSContext* aCx, - JS::Handle aValue) override { + virtual void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { MOZ_ASSERT(NS_IsMainThread()); RejectPromises(NS_ERROR_DOM_NETWORK_ERR); } diff --git a/dom/xhr/XMLHttpRequestMainThread.cpp b/dom/xhr/XMLHttpRequestMainThread.cpp index 685970933602..4009b8247569 100644 --- a/dom/xhr/XMLHttpRequestMainThread.cpp +++ b/dom/xhr/XMLHttpRequestMainThread.cpp @@ -1700,7 +1700,8 @@ class FileCreationHandler final : public PromiseNativeHandler { aPromise->AppendNativeHandler(handler); } - void ResolvedCallback(JSContext* aCx, JS::Handle aValue) override { + void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { if (NS_WARN_IF(!aValue.isObject())) { mXHR->LocalFileToBlobCompleted(nullptr); return; @@ -1715,7 +1716,8 @@ class FileCreationHandler final : public PromiseNativeHandler { mXHR->LocalFileToBlobCompleted(blob->Impl()); } - void RejectedCallback(JSContext* aCx, JS::Handle aValue) override { + void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { mXHR->LocalFileToBlobCompleted(nullptr); } diff --git a/intl/l10n/Localization.cpp b/intl/l10n/Localization.cpp index 030074142261..b0a7abc07554 100644 --- a/intl/l10n/Localization.cpp +++ b/intl/l10n/Localization.cpp @@ -458,8 +458,10 @@ class PromiseResolver final : public PromiseNativeHandler { NS_DECL_ISUPPORTS explicit PromiseResolver(Promise* aPromise); - void ResolvedCallback(JSContext* aCx, JS::Handle aValue) override; - void RejectedCallback(JSContext* aCx, JS::Handle aValue) override; + void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override; + void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override; protected: virtual ~PromiseResolver(); @@ -477,12 +479,14 @@ NS_IMPL_RELEASE(PromiseResolver) PromiseResolver::PromiseResolver(Promise* aPromise) { mPromise = aPromise; } void PromiseResolver::ResolvedCallback(JSContext* aCx, - JS::Handle aValue) { + JS::Handle aValue, + ErrorResult& aRv) { mPromise->MaybeResolveWithClone(aCx, aValue); } void PromiseResolver::RejectedCallback(JSContext* aCx, - JS::Handle aValue) { + JS::Handle aValue, + ErrorResult& aRv) { mPromise->MaybeRejectWithClone(aCx, aValue); } diff --git a/toolkit/components/extensions/webidl-api/ExtensionAPIBase.cpp b/toolkit/components/extensions/webidl-api/ExtensionAPIBase.cpp index 1ff861fc6e1a..c0520ba83dce 100644 --- a/toolkit/components/extensions/webidl-api/ExtensionAPIBase.cpp +++ b/toolkit/components/extensions/webidl-api/ExtensionAPIBase.cpp @@ -43,15 +43,17 @@ void ChromeCompatCallbackHandler::Create( aPromise->AppendNativeHandler(handler); } -void ChromeCompatCallbackHandler::ResolvedCallback( - JSContext* aCx, JS::Handle aValue) { +void ChromeCompatCallbackHandler::ResolvedCallback(JSContext* aCx, + JS::Handle aValue, + ErrorResult& aRv) { JS::RootedValue retval(aCx); IgnoredErrorResult rv; MOZ_KnownLive(mCallback)->Call({aValue}, &retval, rv); } -void ChromeCompatCallbackHandler::RejectedCallback( - JSContext* aCx, JS::Handle aValue) { +void ChromeCompatCallbackHandler::RejectedCallback(JSContext* aCx, + JS::Handle aValue, + ErrorResult& aRv) { JS::RootedValue retval(aCx); IgnoredErrorResult rv; // Call the chrome-compatible callback without any parameter, the errors diff --git a/toolkit/components/extensions/webidl-api/ExtensionAPIBase.h b/toolkit/components/extensions/webidl-api/ExtensionAPIBase.h index 6c9b945330c6..a13070695189 100644 --- a/toolkit/components/extensions/webidl-api/ExtensionAPIBase.h +++ b/toolkit/components/extensions/webidl-api/ExtensionAPIBase.h @@ -139,10 +139,12 @@ class ChromeCompatCallbackHandler final : public dom::PromiseNativeHandler { dom::Promise* aPromise, const RefPtr& aCallback); - MOZ_CAN_RUN_SCRIPT void ResolvedCallback( - JSContext* aCx, JS::Handle aValue) override; - MOZ_CAN_RUN_SCRIPT void RejectedCallback( - JSContext* aCx, JS::Handle aValue) override; + MOZ_CAN_RUN_SCRIPT void ResolvedCallback(JSContext* aCx, + JS::Handle aValue, + ErrorResult& aRv) override; + MOZ_CAN_RUN_SCRIPT void RejectedCallback(JSContext* aCx, + JS::Handle aValue, + ErrorResult& aRv) override; private: ChromeCompatCallbackHandler(ExtensionBrowser* aExtensionBrowser, diff --git a/toolkit/components/extensions/webidl-api/ExtensionEventListener.cpp b/toolkit/components/extensions/webidl-api/ExtensionEventListener.cpp index 72ba93a534b5..5aeae930546b 100644 --- a/toolkit/components/extensions/webidl-api/ExtensionEventListener.cpp +++ b/toolkit/components/extensions/webidl-api/ExtensionEventListener.cpp @@ -678,12 +678,12 @@ void ExtensionListenerCallPromiseResultHandler::WorkerRunCallback( } void ExtensionListenerCallPromiseResultHandler::ResolvedCallback( - JSContext* aCx, JS::Handle aValue) { + JSContext* aCx, JS::Handle aValue, ErrorResult& aRv) { WorkerRunCallback(aCx, aValue, PromiseCallbackType::Resolve); } void ExtensionListenerCallPromiseResultHandler::RejectedCallback( - JSContext* aCx, JS::Handle aValue) { + JSContext* aCx, JS::Handle aValue, ErrorResult& aRv) { WorkerRunCallback(aCx, aValue, PromiseCallbackType::Reject); } diff --git a/toolkit/components/extensions/webidl-api/ExtensionEventListener.h b/toolkit/components/extensions/webidl-api/ExtensionEventListener.h index 4cc95777bce9..8fc46a3dfcda 100644 --- a/toolkit/components/extensions/webidl-api/ExtensionEventListener.h +++ b/toolkit/components/extensions/webidl-api/ExtensionEventListener.h @@ -200,8 +200,10 @@ class ExtensionListenerCallPromiseResultHandler dom::ThreadSafeWorkerRef* aWorkerRef); // PromiseNativeHandler - void ResolvedCallback(JSContext* aCx, JS::Handle aValue) override; - void RejectedCallback(JSContext* aCx, JS::Handle aValue) override; + void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override; + void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override; enum class PromiseCallbackType { Resolve, Reject }; diff --git a/toolkit/components/extensions/webidl-api/ExtensionTest.cpp b/toolkit/components/extensions/webidl-api/ExtensionTest.cpp index 919d4aa76cad..bdcb8e697d4c 100644 --- a/toolkit/components/extensions/webidl-api/ExtensionTest.cpp +++ b/toolkit/components/extensions/webidl-api/ExtensionTest.cpp @@ -359,8 +359,9 @@ class AssertRejectsHandler final : public dom::PromiseNativeHandler { aPromise->AppendNativeHandler(handler); } - MOZ_CAN_RUN_SCRIPT void ResolvedCallback( - JSContext* aCx, JS::Handle aValue) override { + MOZ_CAN_RUN_SCRIPT void ResolvedCallback(JSContext* aCx, + JS::Handle aValue, + ErrorResult& aRv) override { nsAutoJSString expectedErrorSource; JS::Rooted rootedExpectedMatchValue(aCx, mExpectedMatchValue); JS::Rooted expectedErrorToSource( @@ -402,8 +403,9 @@ class AssertRejectsHandler final : public dom::PromiseNativeHandler { mOutPromise->MaybeResolve(JS::UndefinedValue()); } - MOZ_CAN_RUN_SCRIPT void RejectedCallback( - JSContext* aCx, JS::Handle aValue) override { + MOZ_CAN_RUN_SCRIPT void RejectedCallback(JSContext* aCx, + JS::Handle aValue, + ErrorResult& aRv) override { JS::Rooted expectedMatchRooted(aCx, mExpectedMatchValue); ErrorResult erv; diff --git a/xpfe/appshell/AppWindow.cpp b/xpfe/appshell/AppWindow.cpp index 30a82ce77a6f..0caa36ea69dc 100644 --- a/xpfe/appshell/AppWindow.cpp +++ b/xpfe/appshell/AppWindow.cpp @@ -3057,11 +3057,13 @@ class L10nReadyPromiseHandler final : public dom::PromiseNativeHandler { L10nReadyPromiseHandler(Document* aDoc, nsIWidget* aParentWindow) : mDocument(aDoc), mWindow(aParentWindow) {} - void ResolvedCallback(JSContext* aCx, JS::Handle aValue) override { + void ResolvedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { LoadNativeMenus(mDocument, mWindow); } - void RejectedCallback(JSContext* aCx, JS::Handle aValue) override { + void RejectedCallback(JSContext* aCx, JS::Handle aValue, + ErrorResult& aRv) override { // Again, this shouldn't happen, but fallback to loading the menus as is. NS_WARNING( "L10nReadyPromiseHandler rejected - loading fallback native "