From 7039b5a95d14c2a2343a26f5b4cc794996fb6996 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Wed, 5 Feb 2025 19:56:46 +0100 Subject: [PATCH] Issue #2690 - Replace SyntaxError with TypeError for derive_bits_keys. --- dom/crypto/WebCryptoTask.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/dom/crypto/WebCryptoTask.cpp b/dom/crypto/WebCryptoTask.cpp index e004ab6fc8..cbb95f966b 100644 --- a/dom/crypto/WebCryptoTask.cpp +++ b/dom/crypto/WebCryptoTask.cpp @@ -170,7 +170,7 @@ Coerce(JSContext* aCx, T& aTarget, const OOS& aAlgorithm) JS::RootedValue value(aCx, JS::ObjectValue(*aAlgorithm.GetAsObject())); if (!aTarget.Init(aCx, value)) { - return NS_ERROR_DOM_SYNTAX_ERR; + return NS_ERROR_DOM_TYPE_MISMATCH_ERR; } return NS_OK; @@ -401,9 +401,14 @@ WebCryptoTask::FailWithError(nsresult aRv) { MOZ_ASSERT(IsOnOriginalThread()); - // Blindly convert nsresult to DOMException - // Individual tasks must ensure they pass the right values - mResultPromise->MaybeReject(aRv); + if (aRv == NS_ERROR_DOM_TYPE_MISMATCH_ERR) { + mResultPromise->MaybeRejectWithTypeError( + "The operation could not be performed."); + } else { + // Blindly convert nsresult to DOMException + // Individual tasks must ensure they pass the right values + mResultPromise->MaybeReject(aRv); + } // Manually release mResultPromise while we're on the main thread mResultPromise = nullptr; mWorkerHolder = nullptr; @@ -2927,7 +2932,7 @@ public: RootedDictionary params(aCx); mEarlyRv = Coerce(aCx, params, aAlgorithm); if (NS_FAILED(mEarlyRv)) { - mEarlyRv = NS_ERROR_DOM_SYNTAX_ERR; + /* The returned code is installed by Coerce function. */ return; }