From 2685d35c496f7e5516ee200212b3fe008caea57c Mon Sep 17 00:00:00 2001 From: Stanca Serban Date: Wed, 8 Nov 2023 17:12:40 +0200 Subject: [PATCH] Backed out 3 changesets (bug 1849037) for causing mochitests failures in test_gamepad_extensions.html. Backed out changeset 27fd9f6f57ea (bug 1849037) Backed out changeset 89aa49de2473 (bug 1849037) Backed out changeset c336a8c78928 (bug 1849037) --- dom/base/ChromeUtils.cpp | 6 +- dom/base/Pose.cpp | 6 +- dom/bindings/TypedArray.h | 110 +++++++----------- dom/canvas/CanvasRenderingContext2D.cpp | 7 +- dom/canvas/ClientWebGLContext.cpp | 92 +++++++++------ dom/canvas/ImageData.cpp | 6 +- dom/crypto/CryptoBuffer.cpp | 10 +- dom/crypto/CryptoBuffer.h | 4 +- dom/crypto/CryptoKey.cpp | 2 +- dom/crypto/KeyAlgorithmProxy.h | 8 +- dom/encoding/TextEncoder.cpp | 7 +- dom/encoding/TextEncoder.h | 2 +- dom/gamepad/GamepadTouch.cpp | 20 ++-- dom/media/eme/MediaEncryptedEvent.cpp | 6 +- dom/media/eme/MediaKeyMessageEvent.cpp | 6 +- dom/media/webaudio/WaveShaperNode.cpp | 10 +- dom/media/webaudio/WaveShaperNode.h | 3 +- dom/midi/MIDIMessageEvent.cpp | 6 +- dom/network/UDPSocket.cpp | 8 +- dom/push/PushUtil.cpp | 6 +- dom/serviceworkers/ServiceWorkerOp.cpp | 6 +- dom/vr/VRDisplay.cpp | 10 +- .../AuthenticatorAssertionResponse.cpp | 19 +-- .../AuthenticatorAttestationResponse.cpp | 19 +-- dom/webauthn/AuthenticatorResponse.cpp | 5 +- dom/webauthn/PublicKeyCredential.cpp | 6 +- dom/webidl/TextEncoder.webidl | 2 +- dom/webidl/WaveShaperNode.webidl | 2 +- .../api/WebTransportDatagramDuplexStream.cpp | 6 +- netwerk/base/nsUDPSocket.cpp | 7 +- .../extensions/webrequest/StreamFilter.cpp | 6 +- tools/profiler/gecko/nsProfiler.cpp | 56 ++++----- 32 files changed, 236 insertions(+), 233 deletions(-) diff --git a/dom/base/ChromeUtils.cpp b/dom/base/ChromeUtils.cpp index 31fc0ef9d3b3..e76ce3a7ddd1 100644 --- a/dom/base/ChromeUtils.cpp +++ b/dom/base/ChromeUtils.cpp @@ -162,8 +162,10 @@ void ChromeUtils::Base64URLDecode(GlobalObject& aGlobal, } JS::Rooted buffer( - aGlobal.Context(), ArrayBuffer::Create(aGlobal.Context(), data, aRv)); - if (aRv.Failed()) { + aGlobal.Context(), + ArrayBuffer::Create(aGlobal.Context(), data.Length(), data.Elements())); + if (NS_WARN_IF(!buffer)) { + aRv.Throw(NS_ERROR_OUT_OF_MEMORY); return; } aRetval.set(buffer); diff --git a/dom/base/Pose.cpp b/dom/base/Pose.cpp index 83a6756c56c5..ddccd476ef87 100644 --- a/dom/base/Pose.cpp +++ b/dom/base/Pose.cpp @@ -42,9 +42,9 @@ void Pose::SetFloat32Array(JSContext* aJSContext, nsWrapperCache* creator, } if (!aObj) { - aObj = - Float32Array::Create(aJSContext, creator, Span(aVal, aValLength), aRv); - if (aRv.Failed()) { + aObj = Float32Array::Create(aJSContext, creator, aValLength, aVal); + if (!aObj) { + aRv.NoteJSContextException(aJSContext); return; } } else { diff --git a/dom/bindings/TypedArray.h b/dom/bindings/TypedArray.h index 9b041cac8b3a..9c50298110b1 100644 --- a/dom/bindings/TypedArray.h +++ b/dom/bindings/TypedArray.h @@ -693,74 +693,58 @@ struct TypedArray : public TypedArray_base { TypedArray(TypedArray&& aOther) = default; static inline JSObject* Create(JSContext* cx, nsWrapperCache* creator, - size_t length, ErrorResult& error) { - return CreateCommon(cx, creator, length, error).asObject(); - } - - static inline JSObject* Create(JSContext* cx, size_t length, - ErrorResult& error) { - return CreateCommon(cx, length, error).asObject(); - } - - static inline JSObject* Create(JSContext* cx, nsWrapperCache* creator, - Span data, - ErrorResult& error) { - ArrayT array = CreateCommon(cx, creator, data.Length(), error); - if (!error.Failed()) { - CopyFrom(cx, data, array); - } - return array.asObject(); - } - - static inline JSObject* Create(JSContext* cx, Span data, - ErrorResult& error) { - ArrayT array = CreateCommon(cx, data.Length(), error); - if (!error.Failed()) { - CopyFrom(cx, data, array); - } - return array.asObject(); - } - - private: - template - friend class TypedArrayCreator; - - static inline ArrayT CreateCommon(JSContext* cx, nsWrapperCache* creator, - size_t length, ErrorResult& error) { + uint32_t length, + const element_type* data = nullptr) { JS::Rooted creatorWrapper(cx); Maybe ar; if (creator && (creatorWrapper = creator->GetWrapperPreserveColor())) { ar.emplace(cx, creatorWrapper); } - return CreateCommon(cx, length, error); + return CreateCommon(cx, length, data); } - static inline ArrayT CreateCommon(JSContext* cx, size_t length, - ErrorResult& error) { - ArrayT array = CreateCommon(cx, length); - if (!array) { - error.StealExceptionFromJSContext(cx); + + static inline JSObject* Create(JSContext* cx, uint32_t length, + const element_type* data = nullptr) { + return CreateCommon(cx, length, data); + } + + static inline JSObject* Create(JSContext* cx, nsWrapperCache* creator, + Span data) { + // Span<> uses size_t as a length, and we use uint32_t instead. + if (MOZ_UNLIKELY(data.Length() > UINT32_MAX)) { + JS_ReportOutOfMemory(cx); + return nullptr; } - return array; + return Create(cx, creator, data.Length(), data.Elements()); } - // NOTE: this leaves any exceptions on the JSContext, and the caller is - // required to deal with them. - static inline ArrayT CreateCommon(JSContext* cx, size_t length) { - return ArrayT::create(cx, length); + + static inline JSObject* Create(JSContext* cx, Span data) { + // Span<> uses size_t as a length, and we use uint32_t instead. + if (MOZ_UNLIKELY(data.Length() > UINT32_MAX)) { + JS_ReportOutOfMemory(cx); + return nullptr; + } + return CreateCommon(cx, data.Length(), data.Elements()); } - static inline void CopyFrom(JSContext* cx, - const Span& data, - ArrayT& dest) { - JS::AutoCheckCannotGC nogc; - size_t length; - bool isShared; - element_type* buf = dest.getLengthAndData(&length, &isShared, nogc); - MOZ_ASSERT(length == data.Length(), - "Didn't create a large enough typed array object?"); - // Data will not be shared, until a construction protocol exists - // for constructing shared data. - MOZ_ASSERT(!isShared); - memcpy(buf, data.Elements(), data.LengthBytes()); + + private: + static inline JSObject* CreateCommon(JSContext* cx, uint32_t length, + const element_type* data) { + auto array = ArrayT::create(cx, length); + if (!array) { + return nullptr; + } + if (data) { + JS::AutoCheckCannotGC nogc; + bool isShared; + element_type* buf = array.getData(&isShared, nogc); + // Data will not be shared, until a construction protocol exists + // for constructing shared data. + MOZ_ASSERT(!isShared); + memcpy(buf, data, length * sizeof(element_type)); + } + return array.asObject(); } TypedArray(const TypedArray&) = delete; @@ -815,20 +799,14 @@ using ArrayBuffer = TypedArray; // So this is best used to pass from things that understand nsTArray to // things that understand TypedArray, as with ToJSValue. template -class MOZ_STACK_CLASS TypedArrayCreator { +class TypedArrayCreator { typedef nsTArray ArrayType; public: explicit TypedArrayCreator(const ArrayType& aArray) : mArray(aArray) {} - // NOTE: this leaves any exceptions on the JSContext, and the caller is - // required to deal with them. JSObject* Create(JSContext* aCx) const { - auto array = TypedArrayType::CreateCommon(aCx, mArray.Length()); - if (array) { - TypedArrayType::CopyFrom(aCx, mArray, array); - } - return array.asObject(); + return TypedArrayType::Create(aCx, mArray.Length(), mArray.Elements()); } private: diff --git a/dom/canvas/CanvasRenderingContext2D.cpp b/dom/canvas/CanvasRenderingContext2D.cpp index 0da990a06471..4b46e2f552f0 100644 --- a/dom/canvas/CanvasRenderingContext2D.cpp +++ b/dom/canvas/CanvasRenderingContext2D.cpp @@ -6231,9 +6231,10 @@ static already_AddRefed CreateImageData( } // Create the fast typed array; it's initialized to 0 by default. - JSObject* darray = - Uint8ClampedArray::Create(aCx, aContext, len.value(), aError); - if (aError.Failed()) { + JSObject* darray = Uint8ClampedArray::Create(aCx, aContext, len.value()); + if (!darray) { + // TODO: Should use OOMReporter. + aError.Throw(NS_ERROR_OUT_OF_MEMORY); return nullptr; } diff --git a/dom/canvas/ClientWebGLContext.cpp b/dom/canvas/ClientWebGLContext.cpp index ade57e4ad1af..e10b30e949a7 100644 --- a/dom/canvas/ClientWebGLContext.cpp +++ b/dom/canvas/ClientWebGLContext.cpp @@ -1935,12 +1935,6 @@ bool ClientWebGLContext::IsEnabled(GLenum cap) const { return ret; } -template -static JS::Value Create(JSContext* cx, nsWrapperCache* creator, const S& src, - ErrorResult& rv) { - return JS::ObjectOrNullValue(T::Create(cx, creator, src, rv)); -} - void ClientWebGLContext::GetInternalformatParameter( JSContext* cx, GLenum target, GLenum internalformat, GLenum pname, JS::MutableHandle retval, ErrorResult& rv) { @@ -1967,8 +1961,13 @@ void ClientWebGLContext::GetInternalformatParameter( if (!maybe) { return; } - - retval.set(Create(cx, this, *maybe, rv)); + // zero-length array indicates out-of-memory + JSObject* obj = + dom::Int32Array::Create(cx, this, maybe->size(), maybe->data()); + if (!obj) { + rv = NS_ERROR_OUT_OF_MEMORY; + } + retval.setObjectOrNull(obj); } static JS::Value StringValue(JSContext* cx, const std::string& str, @@ -1992,6 +1991,23 @@ bool ToJSValueOrNull(JSContext* const cx, const RefPtr& ptr, return dom::ToJSValue(cx, ptr, retval); } +template +static JS::Value CreateAs(JSContext* cx, nsWrapperCache* creator, const S& src, + ErrorResult& rv) { + const auto obj = + T::Create(cx, creator, src.size(), reinterpret_cast(src.data())); + if (!obj) { + rv = NS_ERROR_OUT_OF_MEMORY; + } + return JS::ObjectOrNullValue(obj); +} + +template +static JS::Value Create(JSContext* cx, nsWrapperCache* creator, const S& src, + ErrorResult& rv) { + return CreateAs(cx, creator, src, rv); +} + Maybe ClientWebGLContext::GetNumber(const GLenum pname) { MOZ_ASSERT(!IsContextLost()); @@ -2162,9 +2178,9 @@ void ClientWebGLContext::GetParameter(JSContext* cx, GLenum pname, // 2 ints case LOCAL_GL_MAX_VIEWPORT_DIMS: { - auto maxViewportDim = BitwiseCast(limits.maxViewportDim); - const auto dims = std::array{maxViewportDim, maxViewportDim}; - retval.set(Create(cx, this, dims, rv)); + const auto dims = + std::array{limits.maxViewportDim, limits.maxViewportDim}; + retval.set(CreateAs(cx, this, dims, rv)); return; } @@ -2791,9 +2807,7 @@ void ClientWebGLContext::GetUniform(JSContext* const cx, case LOCAL_GL_FLOAT_MAT4x2: case LOCAL_GL_FLOAT_MAT4x3: { const auto ptr = reinterpret_cast(res.data); - IgnoredErrorResult error; - JSObject* obj = - dom::Float32Array::Create(cx, this, Span(ptr, elemCount), error); + JSObject* obj = dom::Float32Array::Create(cx, this, elemCount, ptr); MOZ_ASSERT(obj); retval.set(JS::ObjectOrNullValue(obj)); return; @@ -2803,9 +2817,7 @@ void ClientWebGLContext::GetUniform(JSContext* const cx, case LOCAL_GL_INT_VEC3: case LOCAL_GL_INT_VEC4: { const auto ptr = reinterpret_cast(res.data); - IgnoredErrorResult error; - JSObject* obj = - dom::Int32Array::Create(cx, this, Span(ptr, elemCount), error); + JSObject* obj = dom::Int32Array::Create(cx, this, elemCount, ptr); MOZ_ASSERT(obj); retval.set(JS::ObjectOrNullValue(obj)); return; @@ -2815,9 +2827,7 @@ void ClientWebGLContext::GetUniform(JSContext* const cx, case LOCAL_GL_UNSIGNED_INT_VEC3: case LOCAL_GL_UNSIGNED_INT_VEC4: { const auto ptr = reinterpret_cast(res.data); - IgnoredErrorResult error; - JSObject* obj = - dom::Uint32Array::Create(cx, this, Span(ptr, elemCount), error); + JSObject* obj = dom::Uint32Array::Create(cx, this, elemCount, ptr); MOZ_ASSERT(obj); retval.set(JS::ObjectOrNullValue(obj)); return; @@ -4742,31 +4752,33 @@ void ClientWebGLContext::GetVertexAttrib(JSContext* cx, GLuint index, switch (pname) { case LOCAL_GL_CURRENT_VERTEX_ATTRIB: { + JS::Rooted obj(cx); + const auto& attrib = genericAttribs[index]; switch (attrib.type) { - case webgl::AttribBaseType::Float: { - const auto ptr = reinterpret_cast(attrib.data.data()); - retval.setObjectOrNull( - dom::Float32Array::Create(cx, this, Span(ptr, 4), rv)); + case webgl::AttribBaseType::Float: + obj = dom::Float32Array::Create( + cx, this, 4, reinterpret_cast(attrib.data.data())); break; - } - case webgl::AttribBaseType::Int: { - const auto ptr = reinterpret_cast(attrib.data.data()); - retval.setObjectOrNull( - dom::Int32Array::Create(cx, this, Span(ptr, 4), rv)); + case webgl::AttribBaseType::Int: + obj = dom::Int32Array::Create( + cx, this, 4, + reinterpret_cast(attrib.data.data())); break; - } - case webgl::AttribBaseType::Uint: { - const auto ptr = - reinterpret_cast(attrib.data.data()); - retval.setObjectOrNull( - dom::Uint32Array::Create(cx, this, Span(ptr, 4), rv)); + case webgl::AttribBaseType::Uint: + obj = dom::Uint32Array::Create( + cx, this, 4, + reinterpret_cast(attrib.data.data())); break; - } case webgl::AttribBaseType::Boolean: MOZ_CRASH("impossible"); } + if (!obj) { + rv.Throw(NS_ERROR_OUT_OF_MEMORY); + return; + } + retval.set(JS::ObjectValue(*obj)); return; } @@ -6100,7 +6112,13 @@ void ClientWebGLContext::GetActiveUniformBlockParameter( case LOCAL_GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES: { const auto& indices = block.activeUniformIndices; - return Create(cx, this, indices, rv); + JS::Rooted obj( + cx, + dom::Uint32Array::Create(cx, this, indices.size(), indices.data())); + if (!obj) { + rv = NS_ERROR_OUT_OF_MEMORY; + } + return JS::ObjectOrNullValue(obj); } case LOCAL_GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER: diff --git a/dom/canvas/ImageData.cpp b/dom/canvas/ImageData.cpp index b826c7cdf0a0..df38da517d80 100644 --- a/dom/canvas/ImageData.cpp +++ b/dom/canvas/ImageData.cpp @@ -58,9 +58,9 @@ already_AddRefed ImageData::Constructor(const GlobalObject& aGlobal, return nullptr; } js::AssertSameCompartment(aGlobal.Context(), aGlobal.Get()); - JSObject* data = - Uint8ClampedArray::Create(aGlobal.Context(), length.value(), aRv); - if (aRv.Failed()) { + JSObject* data = Uint8ClampedArray::Create(aGlobal.Context(), length.value()); + if (!data) { + aRv.Throw(NS_ERROR_OUT_OF_MEMORY); return nullptr; } RefPtr imageData = new ImageData(aWidth, aHeight, *data); diff --git a/dom/crypto/CryptoBuffer.cpp b/dom/crypto/CryptoBuffer.cpp index 67e1a8e56a0d..1c5c9bd0352f 100644 --- a/dom/crypto/CryptoBuffer.cpp +++ b/dom/crypto/CryptoBuffer.cpp @@ -122,14 +122,12 @@ bool CryptoBuffer::ToSECItem(PLArenaPool* aArena, SECItem* aItem) const { return true; } -JSObject* CryptoBuffer::ToUint8Array(JSContext* aCx, - ErrorResult& aError) const { - return Uint8Array::Create(aCx, *this, aError); +JSObject* CryptoBuffer::ToUint8Array(JSContext* aCx) const { + return Uint8Array::Create(aCx, Length(), Elements()); } -JSObject* CryptoBuffer::ToArrayBuffer(JSContext* aCx, - ErrorResult& aError) const { - return ArrayBuffer::Create(aCx, *this, aError); +JSObject* CryptoBuffer::ToArrayBuffer(JSContext* aCx) const { + return ArrayBuffer::Create(aCx, Length(), Elements()); } // "BigInt" comes from the WebCrypto spec diff --git a/dom/crypto/CryptoBuffer.h b/dom/crypto/CryptoBuffer.h index 53c42ac670ec..494d89120617 100644 --- a/dom/crypto/CryptoBuffer.h +++ b/dom/crypto/CryptoBuffer.h @@ -35,8 +35,8 @@ class CryptoBuffer : public FallibleTArray { nsresult FromJwkBase64(const nsString& aBase64); nsresult ToJwkBase64(nsString& aBase64) const; bool ToSECItem(PLArenaPool* aArena, SECItem* aItem) const; - JSObject* ToUint8Array(JSContext* aCx, ErrorResult& aError) const; - JSObject* ToArrayBuffer(JSContext* aCx, ErrorResult& aError) const; + JSObject* ToUint8Array(JSContext* aCx) const; + JSObject* ToArrayBuffer(JSContext* aCx) const; bool GetBigIntValue(unsigned long& aRetVal); diff --git a/dom/crypto/CryptoKey.cpp b/dom/crypto/CryptoKey.cpp index 10a60961886e..cc83816380f7 100644 --- a/dom/crypto/CryptoKey.cpp +++ b/dom/crypto/CryptoKey.cpp @@ -200,7 +200,7 @@ void CryptoKey::GetAlgorithm(JSContext* cx, break; case KeyAlgorithmProxy::RSA: { RootedDictionary rsa(cx); - converted = mAlgorithm.mRsa.ToKeyAlgorithm(cx, rsa, aRv); + converted = mAlgorithm.mRsa.ToKeyAlgorithm(cx, rsa); if (converted) { converted = ToJSValue(cx, rsa, &val); } diff --git a/dom/crypto/KeyAlgorithmProxy.h b/dom/crypto/KeyAlgorithmProxy.h index eaaf40892973..505f808d1c2f 100644 --- a/dom/crypto/KeyAlgorithmProxy.h +++ b/dom/crypto/KeyAlgorithmProxy.h @@ -35,11 +35,9 @@ struct RsaHashedKeyAlgorithmStorage { uint16_t mModulusLength; CryptoBuffer mPublicExponent; - bool ToKeyAlgorithm(JSContext* aCx, RsaHashedKeyAlgorithm& aRsa, - ErrorResult& aError) const { - JS::Rooted exponent(aCx, - mPublicExponent.ToUint8Array(aCx, aError)); - if (aError.Failed()) { + bool ToKeyAlgorithm(JSContext* aCx, RsaHashedKeyAlgorithm& aRsa) const { + JS::Rooted exponent(aCx, mPublicExponent.ToUint8Array(aCx)); + if (!exponent) { return false; } diff --git a/dom/encoding/TextEncoder.cpp b/dom/encoding/TextEncoder.cpp index 68ee4aa02d50..9c2e1091d116 100644 --- a/dom/encoding/TextEncoder.cpp +++ b/dom/encoding/TextEncoder.cpp @@ -15,10 +15,11 @@ namespace mozilla::dom { void TextEncoder::Encode(JSContext* aCx, JS::Handle aObj, const nsACString& aUtf8String, JS::MutableHandle aRetval, - ErrorResult& aRv) { + OOMReporter& aRv) { JSAutoRealm ar(aCx, aObj); - JSObject* outView = Uint8Array::Create(aCx, aUtf8String, aRv); - if (aRv.Failed()) { + JSObject* outView = Uint8Array::Create(aCx, aUtf8String); + if (!outView) { + aRv.ReportOOM(); return; } diff --git a/dom/encoding/TextEncoder.h b/dom/encoding/TextEncoder.h index f582b7722b7d..c89c48d4f965 100644 --- a/dom/encoding/TextEncoder.h +++ b/dom/encoding/TextEncoder.h @@ -54,7 +54,7 @@ class TextEncoder final : public NonRefcountedDOMObject { */ void Encode(JSContext* aCx, JS::Handle aObj, const nsACString& aUtf8String, - JS::MutableHandle aRetval, ErrorResult& aRv); + JS::MutableHandle aRetval, OOMReporter& aRv); void EncodeInto(JSContext* aCx, JS::Handle aSrc, const Uint8Array& aDst, TextEncoderEncodeIntoResult& aResult, diff --git a/dom/gamepad/GamepadTouch.cpp b/dom/gamepad/GamepadTouch.cpp index f589312452ff..2fdef5b12cd5 100644 --- a/dom/gamepad/GamepadTouch.cpp +++ b/dom/gamepad/GamepadTouch.cpp @@ -33,8 +33,9 @@ GamepadTouch::~GamepadTouch() { mozilla::DropJSObjects(this); } void GamepadTouch::GetPosition(JSContext* aCx, JS::MutableHandle aRetval, ErrorResult& aRv) { - mPosition = Float32Array::Create(aCx, this, mTouchState.position, aRv); - if (aRv.Failed()) { + mPosition = Float32Array::Create(aCx, this, 2, mTouchState.position); + if (!mPosition) { + aRv.NoteJSContextException(aCx); return; } @@ -44,16 +45,13 @@ void GamepadTouch::GetPosition(JSContext* aCx, void GamepadTouch::GetSurfaceDimensions(JSContext* aCx, JS::MutableHandle aRetval, ErrorResult& aRv) { - if (mTouchState.isSurfaceDimensionsValid) { - mSurfaceDimensions = Uint32Array::Create( - aCx, this, std::size(mTouchState.surfaceDimensions), aRv); + mSurfaceDimensions = Uint32Array::Create(aCx, this, 2, + mTouchState.isSurfaceDimensionsValid + ? mTouchState.surfaceDimensions + : nullptr); - } else { - mSurfaceDimensions = - Uint32Array::Create(aCx, this, mTouchState.surfaceDimensions, aRv); - } - - if (aRv.Failed()) { + if (!mSurfaceDimensions) { + aRv.NoteJSContextException(aCx); return; } diff --git a/dom/media/eme/MediaEncryptedEvent.cpp b/dom/media/eme/MediaEncryptedEvent.cpp index bef98bcd5549..b01171529553 100644 --- a/dom/media/eme/MediaEncryptedEvent.cpp +++ b/dom/media/eme/MediaEncryptedEvent.cpp @@ -94,8 +94,10 @@ void MediaEncryptedEvent::GetInitData(JSContext* cx, JS::MutableHandle aData, ErrorResult& aRv) { if (mRawInitData.Length()) { - mInitData = ArrayBuffer::Create(cx, this, mRawInitData, aRv); - if (aRv.Failed()) { + mInitData = ArrayBuffer::Create(cx, this, mRawInitData.Length(), + mRawInitData.Elements()); + if (!mInitData) { + aRv.NoteJSContextException(cx); return; } mRawInitData.Clear(); diff --git a/dom/media/eme/MediaKeyMessageEvent.cpp b/dom/media/eme/MediaKeyMessageEvent.cpp index 0884e3b0e057..69ce5499f4d5 100644 --- a/dom/media/eme/MediaKeyMessageEvent.cpp +++ b/dom/media/eme/MediaKeyMessageEvent.cpp @@ -89,8 +89,10 @@ void MediaKeyMessageEvent::GetMessage(JSContext* cx, JS::MutableHandle aMessage, ErrorResult& aRv) { if (!mMessage) { - mMessage = ArrayBuffer::Create(cx, this, mRawMessage, aRv); - if (aRv.Failed()) { + mMessage = ArrayBuffer::Create(cx, this, mRawMessage.Length(), + mRawMessage.Elements()); + if (!mMessage) { + aRv.NoteJSContextException(cx); return; } mRawMessage.Clear(); diff --git a/dom/media/webaudio/WaveShaperNode.cpp b/dom/media/webaudio/WaveShaperNode.cpp index f01b61303989..0a5eaa90dc54 100644 --- a/dom/media/webaudio/WaveShaperNode.cpp +++ b/dom/media/webaudio/WaveShaperNode.cpp @@ -364,8 +364,7 @@ void WaveShaperNode::SendCurveToTrack() { } void WaveShaperNode::GetCurve(JSContext* aCx, - JS::MutableHandle aRetval, - ErrorResult& aError) { + JS::MutableHandle aRetval) { // Let's return a null value if the list is empty. if (mCurve.IsEmpty()) { aRetval.set(nullptr); @@ -373,11 +372,8 @@ void WaveShaperNode::GetCurve(JSContext* aCx, } MOZ_ASSERT(mCurve.Length() >= 2); - JSObject* curve = Float32Array::Create(aCx, this, mCurve, aError); - if (aError.Failed()) { - return; - } - aRetval.set(curve); + aRetval.set( + Float32Array::Create(aCx, this, mCurve.Length(), mCurve.Elements())); } void WaveShaperNode::SetOversample(OverSampleType aType) { diff --git a/dom/media/webaudio/WaveShaperNode.h b/dom/media/webaudio/WaveShaperNode.h index 5c91960af9d3..3c5d8c8ef4d3 100644 --- a/dom/media/webaudio/WaveShaperNode.h +++ b/dom/media/webaudio/WaveShaperNode.h @@ -35,8 +35,7 @@ class WaveShaperNode final : public AudioNode { JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; - void GetCurve(JSContext* aCx, JS::MutableHandle aRetval, - ErrorResult& aRv); + void GetCurve(JSContext* aCx, JS::MutableHandle aRetval); void SetCurve(const Nullable& aData, ErrorResult& aRv); OverSampleType Oversample() const { return mType; } diff --git a/dom/midi/MIDIMessageEvent.cpp b/dom/midi/MIDIMessageEvent.cpp index 793cb4eeca05..975d57ed4d63 100644 --- a/dom/midi/MIDIMessageEvent.cpp +++ b/dom/midi/MIDIMessageEvent.cpp @@ -83,8 +83,10 @@ void MIDIMessageEvent::GetData(JSContext* cx, JS::MutableHandle aData, ErrorResult& aRv) { if (!mData) { - mData = Uint8Array::Create(cx, this, mRawData, aRv); - if (aRv.Failed()) { + mData = + Uint8Array::Create(cx, this, mRawData.Length(), mRawData.Elements()); + if (!mData) { + aRv.Throw(NS_ERROR_OUT_OF_MEMORY); return; } mRawData.Clear(); diff --git a/dom/network/UDPSocket.cpp b/dom/network/UDPSocket.cpp index 7dfcae36526f..7719defb555e 100644 --- a/dom/network/UDPSocket.cpp +++ b/dom/network/UDPSocket.cpp @@ -578,11 +578,11 @@ nsresult UDPSocket::DispatchReceivedData(const nsACString& aRemoteAddress, JSContext* cx = jsapi.cx(); // Copy packet data to ArrayBuffer - ErrorResult error; - JS::Rooted arrayBuf(cx, ArrayBuffer::Create(cx, aData, error)); + JS::Rooted arrayBuf( + cx, ArrayBuffer::Create(cx, aData.Length(), aData.Elements())); - if (NS_WARN_IF(error.Failed())) { - return error.StealNSResult(); + if (NS_WARN_IF(!arrayBuf)) { + return NS_ERROR_FAILURE; } JS::Rooted jsData(cx, JS::ObjectValue(*arrayBuf)); diff --git a/dom/push/PushUtil.cpp b/dom/push/PushUtil.cpp index b1373391ea84..eac3a7ed6fdb 100644 --- a/dom/push/PushUtil.cpp +++ b/dom/push/PushUtil.cpp @@ -26,8 +26,10 @@ void PushUtil::CopyArrayToArrayBuffer(JSContext* aCx, aValue.set(nullptr); return; } - JS::Rooted buffer(aCx, ArrayBuffer::Create(aCx, aArray, aRv)); - if (NS_WARN_IF(aRv.Failed())) { + JS::Rooted buffer( + aCx, ArrayBuffer::Create(aCx, aArray.Length(), aArray.Elements())); + if (NS_WARN_IF(!buffer)) { + aRv.Throw(NS_ERROR_OUT_OF_MEMORY); return; } aValue.set(buffer); diff --git a/dom/serviceworkers/ServiceWorkerOp.cpp b/dom/serviceworkers/ServiceWorkerOp.cpp index 168da58ff621..18db1e298883 100644 --- a/dom/serviceworkers/ServiceWorkerOp.cpp +++ b/dom/serviceworkers/ServiceWorkerOp.cpp @@ -670,9 +670,11 @@ class PushEventOp final : public ExtendableEventOp { if (args.data().type() != OptionalPushData::Tvoid_t) { auto& bytes = args.data().get_ArrayOfuint8_t(); - JSObject* data = Uint8Array::Create(aCx, bytes, result); + JSObject* data = + Uint8Array::Create(aCx, bytes.Length(), bytes.Elements()); - if (result.Failed()) { + if (!data) { + result = ErrorResult(NS_ERROR_FAILURE); return false; } diff --git a/dom/vr/VRDisplay.cpp b/dom/vr/VRDisplay.cpp index a79fb7b7d2d1..7c788a4c5781 100644 --- a/dom/vr/VRDisplay.cpp +++ b/dom/vr/VRDisplay.cpp @@ -147,8 +147,9 @@ void VREyeParameters::GetOffset(JSContext* aCx, if (!mOffset) { // Lazily create the Float32Array mOffset = - dom::Float32Array::Create(aCx, this, mEyeTranslation.components, aRv); - if (aRv.Failed()) { + dom::Float32Array::Create(aCx, this, 3, mEyeTranslation.components); + if (!mOffset) { + aRv.NoteJSContextException(aCx); return; } } @@ -200,8 +201,9 @@ void VRStageParameters::GetSittingToStandingTransform( if (!mSittingToStandingTransformArray) { // Lazily create the Float32Array mSittingToStandingTransformArray = dom::Float32Array::Create( - aCx, this, mSittingToStandingTransform.components, aRv); - if (aRv.Failed()) { + aCx, this, 16, mSittingToStandingTransform.components); + if (!mSittingToStandingTransformArray) { + aRv.NoteJSContextException(aCx); return; } } diff --git a/dom/webauthn/AuthenticatorAssertionResponse.cpp b/dom/webauthn/AuthenticatorAssertionResponse.cpp index 9824edc30bff..ff0c445e4061 100644 --- a/dom/webauthn/AuthenticatorAssertionResponse.cpp +++ b/dom/webauthn/AuthenticatorAssertionResponse.cpp @@ -58,9 +58,10 @@ JSObject* AuthenticatorAssertionResponse::WrapObject( void AuthenticatorAssertionResponse::GetAuthenticatorData( JSContext* aCx, JS::MutableHandle aValue, ErrorResult& aRv) { if (!mAuthenticatorDataCachedObj) { - mAuthenticatorDataCachedObj = - ArrayBuffer::Create(aCx, mAuthenticatorData, aRv); - if (aRv.Failed()) { + mAuthenticatorDataCachedObj = ArrayBuffer::Create( + aCx, mAuthenticatorData.Length(), mAuthenticatorData.Elements()); + if (!mAuthenticatorDataCachedObj) { + aRv.NoteJSContextException(aCx); return; } } @@ -75,8 +76,10 @@ void AuthenticatorAssertionResponse::SetAuthenticatorData( void AuthenticatorAssertionResponse::GetSignature( JSContext* aCx, JS::MutableHandle aValue, ErrorResult& aRv) { if (!mSignatureCachedObj) { - mSignatureCachedObj = ArrayBuffer::Create(aCx, mSignature, aRv); - if (aRv.Failed()) { + mSignatureCachedObj = + ArrayBuffer::Create(aCx, mSignature.Length(), mSignature.Elements()); + if (!mSignatureCachedObj) { + aRv.NoteJSContextException(aCx); return; } } @@ -97,8 +100,10 @@ void AuthenticatorAssertionResponse::GetUserHandle( aValue.set(nullptr); } else { if (!mUserHandleCachedObj) { - mUserHandleCachedObj = ArrayBuffer::Create(aCx, mUserHandle, aRv); - if (aRv.Failed()) { + mUserHandleCachedObj = ArrayBuffer::Create(aCx, mUserHandle.Length(), + mUserHandle.Elements()); + if (!mUserHandleCachedObj) { + aRv.NoteJSContextException(aCx); return; } } diff --git a/dom/webauthn/AuthenticatorAttestationResponse.cpp b/dom/webauthn/AuthenticatorAttestationResponse.cpp index 7fe493dae32a..43f928f6566e 100644 --- a/dom/webauthn/AuthenticatorAttestationResponse.cpp +++ b/dom/webauthn/AuthenticatorAttestationResponse.cpp @@ -54,9 +54,10 @@ JSObject* AuthenticatorAttestationResponse::WrapObject( void AuthenticatorAttestationResponse::GetAttestationObject( JSContext* aCx, JS::MutableHandle aValue, ErrorResult& aRv) { if (!mAttestationObjectCachedObj) { - mAttestationObjectCachedObj = - ArrayBuffer::Create(aCx, mAttestationObject, aRv); - if (aRv.Failed()) { + mAttestationObjectCachedObj = ArrayBuffer::Create( + aCx, mAttestationObject.Length(), mAttestationObject.Elements()); + if (!mAttestationObjectCachedObj) { + aRv.NoteJSContextException(aCx); return; } } @@ -105,8 +106,10 @@ void AuthenticatorAttestationResponse::GetAuthenticatorData( return; } - JS::Heap buffer(ArrayBuffer::Create(aCx, authenticatorData, aRv)); - if (aRv.Failed()) { + JS::Heap buffer(ArrayBuffer::Create( + aCx, authenticatorData.Length(), authenticatorData.Elements())); + if (!buffer) { + aRv.NoteJSContextException(aCx); return; } aValue.set(buffer); @@ -142,8 +145,10 @@ void AuthenticatorAttestationResponse::GetPublicKey( return; } - JS::Heap buffer(ArrayBuffer::Create(aCx, publicKey, aRv)); - if (aRv.Failed()) { + JS::Heap buffer( + ArrayBuffer::Create(aCx, publicKey.Length(), publicKey.Elements())); + if (!buffer) { + aRv.NoteJSContextException(aCx); return; } aValue.set(buffer); diff --git a/dom/webauthn/AuthenticatorResponse.cpp b/dom/webauthn/AuthenticatorResponse.cpp index f0c3888fa830..ba291ae4cdf4 100644 --- a/dom/webauthn/AuthenticatorResponse.cpp +++ b/dom/webauthn/AuthenticatorResponse.cpp @@ -37,8 +37,9 @@ nsISupports* AuthenticatorResponse::GetParentObject() const { return mParent; } void AuthenticatorResponse::GetClientDataJSON( JSContext* aCx, JS::MutableHandle aValue, ErrorResult& aRv) { if (!mClientDataJSONCachedObj) { - mClientDataJSONCachedObj = ArrayBuffer::Create(aCx, mClientDataJSON, aRv); - if (aRv.Failed()) { + mClientDataJSONCachedObj = ArrayBuffer::Create(aCx, mClientDataJSON); + if (!mClientDataJSONCachedObj) { + aRv.NoteJSContextException(aCx); return; } } diff --git a/dom/webauthn/PublicKeyCredential.cpp b/dom/webauthn/PublicKeyCredential.cpp index 8ef063118fbc..4b8109d7b80c 100644 --- a/dom/webauthn/PublicKeyCredential.cpp +++ b/dom/webauthn/PublicKeyCredential.cpp @@ -65,8 +65,10 @@ void PublicKeyCredential::GetRawId(JSContext* aCx, JS::MutableHandle aValue, ErrorResult& aRv) { if (!mRawIdCachedObj) { - mRawIdCachedObj = ArrayBuffer::Create(aCx, mRawId, aRv); - if (aRv.Failed()) { + mRawIdCachedObj = + ArrayBuffer::Create(aCx, mRawId.Length(), mRawId.Elements()); + if (!mRawIdCachedObj) { + aRv.NoteJSContextException(aCx); return; } } diff --git a/dom/webidl/TextEncoder.webidl b/dom/webidl/TextEncoder.webidl index 120d4693d125..84a2998c9118 100644 --- a/dom/webidl/TextEncoder.webidl +++ b/dom/webidl/TextEncoder.webidl @@ -33,7 +33,7 @@ interface TextEncoder { * replacing lone surrogates with the REPLACEMENT CHARACTER, so the * observable behavior of USVString is matched.) */ - [NewObject, Throws] + [NewObject] Uint8Array encode(optional UTF8String input = ""); /* diff --git a/dom/webidl/WaveShaperNode.webidl b/dom/webidl/WaveShaperNode.webidl index 22a198e7e3b5..7a3374a7085f 100644 --- a/dom/webidl/WaveShaperNode.webidl +++ b/dom/webidl/WaveShaperNode.webidl @@ -28,7 +28,7 @@ interface WaveShaperNode : AudioNode { constructor(BaseAudioContext context, optional WaveShaperOptions options = {}); - [Cached, Pure, Throws] + [Cached, Pure, SetterThrows] attribute Float32Array? curve; attribute OverSampleType oversample; diff --git a/dom/webtransport/api/WebTransportDatagramDuplexStream.cpp b/dom/webtransport/api/WebTransportDatagramDuplexStream.cpp index 30d7451414dd..e2776e8429a6 100644 --- a/dom/webtransport/api/WebTransportDatagramDuplexStream.cpp +++ b/dom/webtransport/api/WebTransportDatagramDuplexStream.cpp @@ -224,8 +224,10 @@ void IncomingDatagramStreamAlgorithms::ReturnDatagram(JSContext* aCx, UniquePtr entry = mDatagrams->mIncomingDatagramsQueue.Pop(); // Pull Step 6: Let chunk be a new Uint8Array object representing bytes. - JSObject* outView = Uint8Array::Create(aCx, entry->mBuffer, aRv); - if (aRv.Failed()) { + JSObject* outView = Uint8Array::Create(aCx, entry->mBuffer.Length(), + entry->mBuffer.Elements()); + if (!outView) { + aRv.Throw(NS_ERROR_OUT_OF_MEMORY); return; } JS::Rooted chunk(aCx, outView); diff --git a/netwerk/base/nsUDPSocket.cpp b/netwerk/base/nsUDPSocket.cpp index 16b65f826e22..3c8518f10bff 100644 --- a/netwerk/base/nsUDPSocket.cpp +++ b/netwerk/base/nsUDPSocket.cpp @@ -223,11 +223,8 @@ nsUDPMessage::GetOutputStream(nsIOutputStream** aOutputStream) { NS_IMETHODIMP nsUDPMessage::GetRawData(JSContext* cx, JS::MutableHandle aRawData) { if (!mJsobj) { - ErrorResult error; - mJsobj = dom::Uint8Array::Create(cx, nullptr, mData, error); - if (error.Failed()) { - return error.StealNSResult(); - } + mJsobj = + dom::Uint8Array::Create(cx, nullptr, mData.Length(), mData.Elements()); HoldJSObjects(this); } aRawData.setObject(*mJsobj); diff --git a/toolkit/components/extensions/webrequest/StreamFilter.cpp b/toolkit/components/extensions/webrequest/StreamFilter.cpp index abfdabb3d507..e65062d1e415 100644 --- a/toolkit/components/extensions/webrequest/StreamFilter.cpp +++ b/toolkit/components/extensions/webrequest/StreamFilter.cpp @@ -201,11 +201,9 @@ void StreamFilter::FireDataEvent(const nsTArray& aData) { init.mBubbles = false; init.mCancelable = false; - ErrorResult error; - auto buffer = ArrayBuffer::Create(cx, aData, error); - if (error.Failed()) { + auto buffer = ArrayBuffer::Create(cx, aData.Length(), aData.Elements()); + if (!buffer) { // TODO: There is no way to recover from this. This chunk of data is lost. - error.SuppressException(); FireErrorEvent(u"Out of memory"_ns); return; } diff --git a/tools/profiler/gecko/nsProfiler.cpp b/tools/profiler/gecko/nsProfiler.cpp index 0d989d1befcd..35cf838a0fb4 100644 --- a/tools/profiler/gecko/nsProfiler.cpp +++ b/tools/profiler/gecko/nsProfiler.cpp @@ -478,14 +478,14 @@ nsProfiler::GetProfileDataAsArrayBuffer(double aSinceTime, JSContext* aCx, } JSContext* cx = jsapi.cx(); - ErrorResult error; - JSObject* typedArray = - dom::ArrayBuffer::Create(cx, aResult.mProfile, error); - if (!error.Failed()) { + JSObject* typedArray = dom::ArrayBuffer::Create( + cx, aResult.mProfile.Length(), + reinterpret_cast(aResult.mProfile.Data())); + if (typedArray) { JS::Rooted val(cx, JS::ObjectValue(*typedArray)); promise->MaybeResolve(val); } else { - promise->MaybeReject(std::move(error)); + promise->MaybeReject(NS_ERROR_OUT_OF_MEMORY); } }, [promise](nsresult aRv) { promise->MaybeReject(aRv); }); @@ -582,10 +582,10 @@ nsProfiler::GetProfileDataAsGzippedArrayBuffer(double aSinceTime, JSContext* cx = jsapi.cx(); // Get the profile typedArray. - ErrorResult error; - JSObject* typedArray = dom::ArrayBuffer::Create(cx, outBuff, error); - if (error.Failed()) { - promise->MaybeReject(std::move(error)); + JSObject* typedArray = dom::ArrayBuffer::Create( + cx, outBuff.Length(), outBuff.Elements()); + if (!typedArray) { + promise->MaybeReject(NS_ERROR_OUT_OF_MEMORY); return; } JS::Rooted typedArrayValue(cx, @@ -705,33 +705,25 @@ nsProfiler::GetSymbolTable(const nsACString& aDebugPath, JSContext* cx = jsapi.cx(); - ErrorResult error; JS::Rooted addrsArray( - cx, dom::Uint32Array::Create(cx, aSymbolTable.mAddrs, error)); - if (error.Failed()) { - promise->MaybeReject(std::move(error)); - return; - } - + cx, dom::Uint32Array::Create(cx, aSymbolTable.mAddrs.Length(), + aSymbolTable.mAddrs.Elements())); JS::Rooted indexArray( - cx, dom::Uint32Array::Create(cx, aSymbolTable.mIndex, error)); - if (error.Failed()) { - promise->MaybeReject(std::move(error)); - return; - } - + cx, dom::Uint32Array::Create(cx, aSymbolTable.mIndex.Length(), + aSymbolTable.mIndex.Elements())); JS::Rooted bufferArray( - cx, dom::Uint8Array::Create(cx, aSymbolTable.mBuffer, error)); - if (error.Failed()) { - promise->MaybeReject(std::move(error)); - return; - } + cx, dom::Uint8Array::Create(cx, aSymbolTable.mBuffer.Length(), + aSymbolTable.mBuffer.Elements())); - JS::Rooted tuple(cx, JS::NewArrayObject(cx, 3)); - JS_SetElement(cx, tuple, 0, addrsArray); - JS_SetElement(cx, tuple, 1, indexArray); - JS_SetElement(cx, tuple, 2, bufferArray); - promise->MaybeResolve(tuple); + if (addrsArray && indexArray && bufferArray) { + JS::Rooted tuple(cx, JS::NewArrayObject(cx, 3)); + JS_SetElement(cx, tuple, 0, addrsArray); + JS_SetElement(cx, tuple, 1, indexArray); + JS_SetElement(cx, tuple, 2, bufferArray); + promise->MaybeResolve(tuple); + } else { + promise->MaybeReject(NS_ERROR_FAILURE); + } }, [promise](nsresult aRv) { promise->MaybeReject(aRv); });