Bug 1849037 - Add ErrorResult to TypedArray::Create. r=necko-reviewers,extension-reviewers,media-playback-reviewers,webidl,profiler-reviewers,farre,padenot,smaug,robwu,jesup,aabh

Differential Revision: https://phabricator.services.mozilla.com/D191418
This commit is contained in:
Peter Van der Beken 2023-11-11 08:24:05 +00:00
parent 124d3d1698
commit 44a577eec3
32 changed files with 175 additions and 141 deletions

View File

@ -161,10 +161,9 @@ void ChromeUtils::Base64URLDecode(GlobalObject& aGlobal,
return;
}
JS::Rooted<JSObject*> buffer(aGlobal.Context(),
ArrayBuffer::Create(aGlobal.Context(), data));
if (NS_WARN_IF(!buffer)) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
JS::Rooted<JSObject*> buffer(
aGlobal.Context(), ArrayBuffer::Create(aGlobal.Context(), data, aRv));
if (aRv.Failed()) {
return;
}
aRetval.set(buffer);

View File

@ -42,9 +42,9 @@ void Pose::SetFloat32Array(JSContext* aJSContext, nsWrapperCache* creator,
}
if (!aObj) {
aObj = Float32Array::Create(aJSContext, creator, Span(aVal, aValLength));
if (!aObj) {
aRv.NoteJSContextException(aJSContext);
aObj =
Float32Array::Create(aJSContext, creator, Span(aVal, aValLength), aRv);
if (aRv.Failed()) {
return;
}
} else {

View File

@ -692,42 +692,59 @@ struct TypedArray : public TypedArray_base<ArrayT> {
TypedArray(TypedArray&& aOther) = default;
static inline JSObject* Create(JSContext* cx, nsWrapperCache* creator,
size_t length) {
return CreateCommon(cx, creator, length).asObject();
size_t length, ErrorResult& error) {
return CreateCommon(cx, creator, length, error).asObject();
}
static inline JSObject* Create(JSContext* cx, size_t length) {
return CreateCommon(cx, length).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<const element_type> data) {
ArrayT array = CreateCommon(cx, creator, data.Length());
if (array) {
Span<const element_type> 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<const element_type> data) {
ArrayT array = CreateCommon(cx, data.Length());
if (array) {
static inline JSObject* Create(JSContext* cx, Span<const element_type> data,
ErrorResult& error) {
ArrayT array = CreateCommon(cx, data.Length(), error);
if (!error.Failed()) {
CopyFrom(cx, data, array);
}
return array.asObject();
}
private:
template <typename>
friend class TypedArrayCreator;
static inline ArrayT CreateCommon(JSContext* cx, nsWrapperCache* creator,
size_t length) {
size_t length, ErrorResult& error) {
JS::Rooted<JSObject*> creatorWrapper(cx);
Maybe<JSAutoRealm> ar;
if (creator && (creatorWrapper = creator->GetWrapperPreserveColor())) {
ar.emplace(cx, creatorWrapper);
}
return CreateCommon(cx, length);
return CreateCommon(cx, length, error);
}
static inline ArrayT CreateCommon(JSContext* cx, size_t length,
ErrorResult& error) {
ArrayT array = CreateCommon(cx, length);
if (array) {
return array;
}
error.StealExceptionFromJSContext(cx);
return ArrayT::fromObject(nullptr);
}
// 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);
}
@ -803,8 +820,14 @@ class MOZ_STACK_CLASS TypedArrayCreator {
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 {
return TypedArrayType::Create(aCx, mArray);
auto array = TypedArrayType::CreateCommon(aCx, mArray.Length());
if (array) {
TypedArrayType::CopyFrom(aCx, mArray, array);
}
return array.asObject();
}
private:

View File

@ -6231,10 +6231,9 @@ static already_AddRefed<ImageData> CreateImageData(
}
// Create the fast typed array; it's initialized to 0 by default.
JSObject* darray = Uint8ClampedArray::Create(aCx, aContext, len.value());
if (!darray) {
// TODO: Should use OOMReporter.
aError.Throw(NS_ERROR_OUT_OF_MEMORY);
JSObject* darray =
Uint8ClampedArray::Create(aCx, aContext, len.value(), aError);
if (aError.Failed()) {
return nullptr;
}

View File

@ -1938,11 +1938,7 @@ bool ClientWebGLContext::IsEnabled(GLenum cap) const {
template <typename T, typename S>
static JS::Value Create(JSContext* cx, nsWrapperCache* creator, const S& src,
ErrorResult& rv) {
const auto obj = T::Create(cx, creator, src);
if (!obj) {
rv = NS_ERROR_OUT_OF_MEMORY;
}
return JS::ObjectOrNullValue(obj);
return JS::ObjectOrNullValue(T::Create(cx, creator, src, rv));
}
void ClientWebGLContext::GetInternalformatParameter(
@ -2795,7 +2791,9 @@ void ClientWebGLContext::GetUniform(JSContext* const cx,
case LOCAL_GL_FLOAT_MAT4x2:
case LOCAL_GL_FLOAT_MAT4x3: {
const auto ptr = reinterpret_cast<const float*>(res.data);
JSObject* obj = dom::Float32Array::Create(cx, this, Span(ptr, elemCount));
IgnoredErrorResult error;
JSObject* obj =
dom::Float32Array::Create(cx, this, Span(ptr, elemCount), error);
MOZ_ASSERT(obj);
retval.set(JS::ObjectOrNullValue(obj));
return;
@ -2805,7 +2803,9 @@ void ClientWebGLContext::GetUniform(JSContext* const cx,
case LOCAL_GL_INT_VEC3:
case LOCAL_GL_INT_VEC4: {
const auto ptr = reinterpret_cast<const int32_t*>(res.data);
JSObject* obj = dom::Int32Array::Create(cx, this, Span(ptr, elemCount));
IgnoredErrorResult error;
JSObject* obj =
dom::Int32Array::Create(cx, this, Span(ptr, elemCount), error);
MOZ_ASSERT(obj);
retval.set(JS::ObjectOrNullValue(obj));
return;
@ -2815,7 +2815,9 @@ void ClientWebGLContext::GetUniform(JSContext* const cx,
case LOCAL_GL_UNSIGNED_INT_VEC3:
case LOCAL_GL_UNSIGNED_INT_VEC4: {
const auto ptr = reinterpret_cast<const uint32_t*>(res.data);
JSObject* obj = dom::Uint32Array::Create(cx, this, Span(ptr, elemCount));
IgnoredErrorResult error;
JSObject* obj =
dom::Uint32Array::Create(cx, this, Span(ptr, elemCount), error);
MOZ_ASSERT(obj);
retval.set(JS::ObjectOrNullValue(obj));
return;
@ -4745,30 +4747,26 @@ void ClientWebGLContext::GetVertexAttrib(JSContext* cx, GLuint index,
case webgl::AttribBaseType::Float: {
const auto ptr = reinterpret_cast<const float*>(attrib.data.data());
retval.setObjectOrNull(
dom::Float32Array::Create(cx, this, Span(ptr, 4)));
dom::Float32Array::Create(cx, this, Span(ptr, 4), rv));
break;
}
case webgl::AttribBaseType::Int: {
const auto ptr = reinterpret_cast<const int32_t*>(attrib.data.data());
retval.setObjectOrNull(
dom::Int32Array::Create(cx, this, Span(ptr, 4)));
dom::Int32Array::Create(cx, this, Span(ptr, 4), rv));
break;
}
case webgl::AttribBaseType::Uint: {
const auto ptr =
reinterpret_cast<const uint32_t*>(attrib.data.data());
retval.setObjectOrNull(
dom::Uint32Array::Create(cx, this, Span(ptr, 4)));
dom::Uint32Array::Create(cx, this, Span(ptr, 4), rv));
break;
}
case webgl::AttribBaseType::Boolean:
MOZ_CRASH("impossible");
}
if (retval.isNull()) {
rv.Throw(NS_ERROR_OUT_OF_MEMORY);
return;
}
return;
}

View File

@ -58,9 +58,9 @@ already_AddRefed<ImageData> ImageData::Constructor(const GlobalObject& aGlobal,
return nullptr;
}
js::AssertSameCompartment(aGlobal.Context(), aGlobal.Get());
JSObject* data = Uint8ClampedArray::Create(aGlobal.Context(), length.value());
if (!data) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
JSObject* data =
Uint8ClampedArray::Create(aGlobal.Context(), length.value(), aRv);
if (aRv.Failed()) {
return nullptr;
}
RefPtr<ImageData> imageData = new ImageData(aWidth, aHeight, *data);

View File

@ -122,12 +122,14 @@ bool CryptoBuffer::ToSECItem(PLArenaPool* aArena, SECItem* aItem) const {
return true;
}
JSObject* CryptoBuffer::ToUint8Array(JSContext* aCx) const {
return Uint8Array::Create(aCx, *this);
JSObject* CryptoBuffer::ToUint8Array(JSContext* aCx,
ErrorResult& aError) const {
return Uint8Array::Create(aCx, *this, aError);
}
JSObject* CryptoBuffer::ToArrayBuffer(JSContext* aCx) const {
return ArrayBuffer::Create(aCx, *this);
JSObject* CryptoBuffer::ToArrayBuffer(JSContext* aCx,
ErrorResult& aError) const {
return ArrayBuffer::Create(aCx, *this, aError);
}
// "BigInt" comes from the WebCrypto spec

View File

@ -35,8 +35,8 @@ class CryptoBuffer : public FallibleTArray<uint8_t> {
nsresult FromJwkBase64(const nsString& aBase64);
nsresult ToJwkBase64(nsString& aBase64) const;
bool ToSECItem(PLArenaPool* aArena, SECItem* aItem) const;
JSObject* ToUint8Array(JSContext* aCx) const;
JSObject* ToArrayBuffer(JSContext* aCx) const;
JSObject* ToUint8Array(JSContext* aCx, ErrorResult& aError) const;
JSObject* ToArrayBuffer(JSContext* aCx, ErrorResult& aError) const;
bool GetBigIntValue(unsigned long& aRetVal);

View File

@ -200,7 +200,7 @@ void CryptoKey::GetAlgorithm(JSContext* cx,
break;
case KeyAlgorithmProxy::RSA: {
RootedDictionary<RsaHashedKeyAlgorithm> rsa(cx);
converted = mAlgorithm.mRsa.ToKeyAlgorithm(cx, rsa);
converted = mAlgorithm.mRsa.ToKeyAlgorithm(cx, rsa, aRv);
if (converted) {
converted = ToJSValue(cx, rsa, &val);
}

View File

@ -35,9 +35,11 @@ struct RsaHashedKeyAlgorithmStorage {
uint16_t mModulusLength;
CryptoBuffer mPublicExponent;
bool ToKeyAlgorithm(JSContext* aCx, RsaHashedKeyAlgorithm& aRsa) const {
JS::Rooted<JSObject*> exponent(aCx, mPublicExponent.ToUint8Array(aCx));
if (!exponent) {
bool ToKeyAlgorithm(JSContext* aCx, RsaHashedKeyAlgorithm& aRsa,
ErrorResult& aError) const {
JS::Rooted<JSObject*> exponent(aCx,
mPublicExponent.ToUint8Array(aCx, aError));
if (aError.Failed()) {
return false;
}

View File

@ -15,11 +15,10 @@ namespace mozilla::dom {
void TextEncoder::Encode(JSContext* aCx, JS::Handle<JSObject*> aObj,
const nsACString& aUtf8String,
JS::MutableHandle<JSObject*> aRetval,
OOMReporter& aRv) {
ErrorResult& aRv) {
JSAutoRealm ar(aCx, aObj);
JSObject* outView = Uint8Array::Create(aCx, aUtf8String);
if (!outView) {
aRv.ReportOOM();
JSObject* outView = Uint8Array::Create(aCx, aUtf8String, aRv);
if (aRv.Failed()) {
return;
}

View File

@ -54,7 +54,7 @@ class TextEncoder final : public NonRefcountedDOMObject {
*/
void Encode(JSContext* aCx, JS::Handle<JSObject*> aObj,
const nsACString& aUtf8String,
JS::MutableHandle<JSObject*> aRetval, OOMReporter& aRv);
JS::MutableHandle<JSObject*> aRetval, ErrorResult& aRv);
void EncodeInto(JSContext* aCx, JS::Handle<JSString*> aSrc,
const Uint8Array& aDst, TextEncoderEncodeIntoResult& aResult,

View File

@ -33,9 +33,8 @@ GamepadTouch::~GamepadTouch() { mozilla::DropJSObjects(this); }
void GamepadTouch::GetPosition(JSContext* aCx,
JS::MutableHandle<JSObject*> aRetval,
ErrorResult& aRv) {
mPosition = Float32Array::Create(aCx, this, mTouchState.position);
if (!mPosition) {
aRv.NoteJSContextException(aCx);
mPosition = Float32Array::Create(aCx, this, mTouchState.position, aRv);
if (aRv.Failed()) {
return;
}
@ -47,10 +46,10 @@ void GamepadTouch::GetSurfaceDimensions(JSContext* aCx,
ErrorResult& aRv) {
if (mTouchState.isSurfaceDimensionsValid) {
mSurfaceDimensions =
Uint32Array::Create(aCx, this, mTouchState.surfaceDimensions);
Uint32Array::Create(aCx, this, mTouchState.surfaceDimensions, aRv);
} else {
mSurfaceDimensions = Uint32Array::Create(
aCx, this, std::size(mTouchState.surfaceDimensions));
aCx, this, std::size(mTouchState.surfaceDimensions), aRv);
}
if (!mSurfaceDimensions) {

View File

@ -94,9 +94,8 @@ void MediaEncryptedEvent::GetInitData(JSContext* cx,
JS::MutableHandle<JSObject*> aData,
ErrorResult& aRv) {
if (mRawInitData.Length()) {
mInitData = ArrayBuffer::Create(cx, this, mRawInitData);
if (!mInitData) {
aRv.NoteJSContextException(cx);
mInitData = ArrayBuffer::Create(cx, this, mRawInitData, aRv);
if (aRv.Failed()) {
return;
}
mRawInitData.Clear();

View File

@ -89,9 +89,8 @@ void MediaKeyMessageEvent::GetMessage(JSContext* cx,
JS::MutableHandle<JSObject*> aMessage,
ErrorResult& aRv) {
if (!mMessage) {
mMessage = ArrayBuffer::Create(cx, this, mRawMessage);
if (!mMessage) {
aRv.NoteJSContextException(cx);
mMessage = ArrayBuffer::Create(cx, this, mRawMessage, aRv);
if (aRv.Failed()) {
return;
}
mRawMessage.Clear();

View File

@ -364,7 +364,8 @@ void WaveShaperNode::SendCurveToTrack() {
}
void WaveShaperNode::GetCurve(JSContext* aCx,
JS::MutableHandle<JSObject*> aRetval) {
JS::MutableHandle<JSObject*> aRetval,
ErrorResult& aError) {
// Let's return a null value if the list is empty.
if (mCurve.IsEmpty()) {
aRetval.set(nullptr);
@ -372,7 +373,11 @@ void WaveShaperNode::GetCurve(JSContext* aCx,
}
MOZ_ASSERT(mCurve.Length() >= 2);
aRetval.set(Float32Array::Create(aCx, this, mCurve));
JSObject* curve = Float32Array::Create(aCx, this, mCurve, aError);
if (aError.Failed()) {
return;
}
aRetval.set(curve);
}
void WaveShaperNode::SetOversample(OverSampleType aType) {

View File

@ -35,7 +35,8 @@ class WaveShaperNode final : public AudioNode {
JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
void GetCurve(JSContext* aCx, JS::MutableHandle<JSObject*> aRetval);
void GetCurve(JSContext* aCx, JS::MutableHandle<JSObject*> aRetval,
ErrorResult& aRv);
void SetCurve(const Nullable<Float32Array>& aData, ErrorResult& aRv);
OverSampleType Oversample() const { return mType; }

View File

@ -83,9 +83,8 @@ void MIDIMessageEvent::GetData(JSContext* cx,
JS::MutableHandle<JSObject*> aData,
ErrorResult& aRv) {
if (!mData) {
mData = Uint8Array::Create(cx, this, mRawData);
if (!mData) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
mData = Uint8Array::Create(cx, this, mRawData, aRv);
if (aRv.Failed()) {
return;
}
mRawData.Clear();

View File

@ -578,10 +578,11 @@ nsresult UDPSocket::DispatchReceivedData(const nsACString& aRemoteAddress,
JSContext* cx = jsapi.cx();
// Copy packet data to ArrayBuffer
JS::Rooted<JSObject*> arrayBuf(cx, ArrayBuffer::Create(cx, aData));
ErrorResult error;
JS::Rooted<JSObject*> arrayBuf(cx, ArrayBuffer::Create(cx, aData, error));
if (NS_WARN_IF(!arrayBuf)) {
return NS_ERROR_FAILURE;
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
JS::Rooted<JS::Value> jsData(cx, JS::ObjectValue(*arrayBuf));

View File

@ -26,9 +26,8 @@ void PushUtil::CopyArrayToArrayBuffer(JSContext* aCx,
aValue.set(nullptr);
return;
}
JS::Rooted<JSObject*> buffer(aCx, ArrayBuffer::Create(aCx, aArray));
if (NS_WARN_IF(!buffer)) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
JS::Rooted<JSObject*> buffer(aCx, ArrayBuffer::Create(aCx, aArray, aRv));
if (NS_WARN_IF(aRv.Failed())) {
return;
}
aValue.set(buffer);

View File

@ -670,10 +670,9 @@ 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);
JSObject* data = Uint8Array::Create(aCx, bytes, result);
if (!data) {
result = ErrorResult(NS_ERROR_FAILURE);
if (result.Failed()) {
return false;
}

View File

@ -146,9 +146,9 @@ void VREyeParameters::GetOffset(JSContext* aCx,
ErrorResult& aRv) {
if (!mOffset) {
// Lazily create the Float32Array
mOffset = dom::Float32Array::Create(aCx, this, mEyeTranslation.components);
if (!mOffset) {
aRv.NoteJSContextException(aCx);
mOffset =
dom::Float32Array::Create(aCx, this, mEyeTranslation.components, aRv);
if (aRv.Failed()) {
return;
}
}
@ -200,9 +200,8 @@ void VRStageParameters::GetSittingToStandingTransform(
if (!mSittingToStandingTransformArray) {
// Lazily create the Float32Array
mSittingToStandingTransformArray = dom::Float32Array::Create(
aCx, this, mSittingToStandingTransform.components);
if (!mSittingToStandingTransformArray) {
aRv.NoteJSContextException(aCx);
aCx, this, mSittingToStandingTransform.components, aRv);
if (aRv.Failed()) {
return;
}
}

View File

@ -58,9 +58,9 @@ JSObject* AuthenticatorAssertionResponse::WrapObject(
void AuthenticatorAssertionResponse::GetAuthenticatorData(
JSContext* aCx, JS::MutableHandle<JSObject*> aValue, ErrorResult& aRv) {
if (!mAuthenticatorDataCachedObj) {
mAuthenticatorDataCachedObj = ArrayBuffer::Create(aCx, mAuthenticatorData);
if (!mAuthenticatorDataCachedObj) {
aRv.NoteJSContextException(aCx);
mAuthenticatorDataCachedObj =
ArrayBuffer::Create(aCx, mAuthenticatorData, aRv);
if (aRv.Failed()) {
return;
}
}
@ -75,9 +75,8 @@ void AuthenticatorAssertionResponse::SetAuthenticatorData(
void AuthenticatorAssertionResponse::GetSignature(
JSContext* aCx, JS::MutableHandle<JSObject*> aValue, ErrorResult& aRv) {
if (!mSignatureCachedObj) {
mSignatureCachedObj = ArrayBuffer::Create(aCx, mSignature);
if (!mSignatureCachedObj) {
aRv.NoteJSContextException(aCx);
mSignatureCachedObj = ArrayBuffer::Create(aCx, mSignature, aRv);
if (aRv.Failed()) {
return;
}
}
@ -98,9 +97,8 @@ void AuthenticatorAssertionResponse::GetUserHandle(
aValue.set(nullptr);
} else {
if (!mUserHandleCachedObj) {
mUserHandleCachedObj = ArrayBuffer::Create(aCx, mUserHandle);
if (!mUserHandleCachedObj) {
aRv.NoteJSContextException(aCx);
mUserHandleCachedObj = ArrayBuffer::Create(aCx, mUserHandle, aRv);
if (aRv.Failed()) {
return;
}
}

View File

@ -54,9 +54,9 @@ JSObject* AuthenticatorAttestationResponse::WrapObject(
void AuthenticatorAttestationResponse::GetAttestationObject(
JSContext* aCx, JS::MutableHandle<JSObject*> aValue, ErrorResult& aRv) {
if (!mAttestationObjectCachedObj) {
mAttestationObjectCachedObj = ArrayBuffer::Create(aCx, mAttestationObject);
if (!mAttestationObjectCachedObj) {
aRv.NoteJSContextException(aCx);
mAttestationObjectCachedObj =
ArrayBuffer::Create(aCx, mAttestationObject, aRv);
if (aRv.Failed()) {
return;
}
}
@ -105,9 +105,8 @@ void AuthenticatorAttestationResponse::GetAuthenticatorData(
return;
}
JS::Heap<JSObject*> buffer(ArrayBuffer::Create(aCx, authenticatorData));
if (!buffer) {
aRv.NoteJSContextException(aCx);
JS::Heap<JSObject*> buffer(ArrayBuffer::Create(aCx, authenticatorData, aRv));
if (aRv.Failed()) {
return;
}
aValue.set(buffer);
@ -143,9 +142,8 @@ void AuthenticatorAttestationResponse::GetPublicKey(
return;
}
JS::Heap<JSObject*> buffer(ArrayBuffer::Create(aCx, publicKey));
if (!buffer) {
aRv.NoteJSContextException(aCx);
JS::Heap<JSObject*> buffer(ArrayBuffer::Create(aCx, publicKey, aRv));
if (aRv.Failed()) {
return;
}
aValue.set(buffer);

View File

@ -37,9 +37,8 @@ nsISupports* AuthenticatorResponse::GetParentObject() const { return mParent; }
void AuthenticatorResponse::GetClientDataJSON(
JSContext* aCx, JS::MutableHandle<JSObject*> aValue, ErrorResult& aRv) {
if (!mClientDataJSONCachedObj) {
mClientDataJSONCachedObj = ArrayBuffer::Create(aCx, mClientDataJSON);
if (!mClientDataJSONCachedObj) {
aRv.NoteJSContextException(aCx);
mClientDataJSONCachedObj = ArrayBuffer::Create(aCx, mClientDataJSON, aRv);
if (aRv.Failed()) {
return;
}
}

View File

@ -68,9 +68,8 @@ void PublicKeyCredential::GetRawId(JSContext* aCx,
JS::MutableHandle<JSObject*> aValue,
ErrorResult& aRv) {
if (!mRawIdCachedObj) {
mRawIdCachedObj = ArrayBuffer::Create(aCx, mRawId);
if (!mRawIdCachedObj) {
aRv.NoteJSContextException(aCx);
mRawIdCachedObj = ArrayBuffer::Create(aCx, mRawId, aRv);
if (aRv.Failed()) {
return;
}
}

View File

@ -33,7 +33,7 @@ interface TextEncoder {
* replacing lone surrogates with the REPLACEMENT CHARACTER, so the
* observable behavior of USVString is matched.)
*/
[NewObject]
[NewObject, Throws]
Uint8Array encode(optional UTF8String input = "");
/*

View File

@ -28,7 +28,7 @@ interface WaveShaperNode : AudioNode {
constructor(BaseAudioContext context,
optional WaveShaperOptions options = {});
[Cached, Pure, SetterThrows]
[Cached, Pure, Throws]
attribute Float32Array? curve;
attribute OverSampleType oversample;

View File

@ -224,9 +224,8 @@ void IncomingDatagramStreamAlgorithms::ReturnDatagram(JSContext* aCx,
UniquePtr<DatagramEntry> entry = mDatagrams->mIncomingDatagramsQueue.Pop();
// Pull Step 6: Let chunk be a new Uint8Array object representing bytes.
JSObject* outView = Uint8Array::Create(aCx, entry->mBuffer);
if (!outView) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
JSObject* outView = Uint8Array::Create(aCx, entry->mBuffer, aRv);
if (aRv.Failed()) {
return;
}
JS::Rooted<JSObject*> chunk(aCx, outView);

View File

@ -223,7 +223,11 @@ nsUDPMessage::GetOutputStream(nsIOutputStream** aOutputStream) {
NS_IMETHODIMP
nsUDPMessage::GetRawData(JSContext* cx, JS::MutableHandle<JS::Value> aRawData) {
if (!mJsobj) {
mJsobj = dom::Uint8Array::Create(cx, nullptr, mData);
ErrorResult error;
mJsobj = dom::Uint8Array::Create(cx, nullptr, mData, error);
if (error.Failed()) {
return error.StealNSResult();
}
HoldJSObjects(this);
}
aRawData.setObject(*mJsobj);

View File

@ -201,9 +201,11 @@ void StreamFilter::FireDataEvent(const nsTArray<uint8_t>& aData) {
init.mBubbles = false;
init.mCancelable = false;
auto buffer = ArrayBuffer::Create(cx, aData);
if (!buffer) {
ErrorResult error;
auto buffer = ArrayBuffer::Create(cx, aData, error);
if (error.Failed()) {
// TODO: There is no way to recover from this. This chunk of data is lost.
error.SuppressException();
FireErrorEvent(u"Out of memory"_ns);
return;
}

View File

@ -478,13 +478,14 @@ nsProfiler::GetProfileDataAsArrayBuffer(double aSinceTime, JSContext* aCx,
}
JSContext* cx = jsapi.cx();
ErrorResult error;
JSObject* typedArray =
dom::ArrayBuffer::Create(cx, aResult.mProfile);
if (typedArray) {
dom::ArrayBuffer::Create(cx, aResult.mProfile, error);
if (!error.Failed()) {
JS::Rooted<JS::Value> val(cx, JS::ObjectValue(*typedArray));
promise->MaybeResolve(val);
} else {
promise->MaybeReject(NS_ERROR_OUT_OF_MEMORY);
promise->MaybeReject(std::move(error));
}
},
[promise](nsresult aRv) { promise->MaybeReject(aRv); });
@ -581,9 +582,10 @@ nsProfiler::GetProfileDataAsGzippedArrayBuffer(double aSinceTime,
JSContext* cx = jsapi.cx();
// Get the profile typedArray.
JSObject* typedArray = dom::ArrayBuffer::Create(cx, outBuff);
if (!typedArray) {
promise->MaybeReject(NS_ERROR_OUT_OF_MEMORY);
ErrorResult error;
JSObject* typedArray = dom::ArrayBuffer::Create(cx, outBuff, error);
if (error.Failed()) {
promise->MaybeReject(std::move(error));
return;
}
JS::Rooted<JS::Value> typedArrayValue(cx,
@ -703,22 +705,33 @@ nsProfiler::GetSymbolTable(const nsACString& aDebugPath,
JSContext* cx = jsapi.cx();
ErrorResult error;
JS::Rooted<JSObject*> addrsArray(
cx, dom::Uint32Array::Create(cx, aSymbolTable.mAddrs));
JS::Rooted<JSObject*> indexArray(
cx, dom::Uint32Array::Create(cx, aSymbolTable.mIndex));
JS::Rooted<JSObject*> bufferArray(
cx, dom::Uint8Array::Create(cx, aSymbolTable.mBuffer));
if (addrsArray && indexArray && bufferArray) {
JS::Rooted<JSObject*> 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);
cx, dom::Uint32Array::Create(cx, aSymbolTable.mAddrs, error));
if (error.Failed()) {
promise->MaybeReject(std::move(error));
return;
}
JS::Rooted<JSObject*> indexArray(
cx, dom::Uint32Array::Create(cx, aSymbolTable.mIndex, error));
if (error.Failed()) {
promise->MaybeReject(std::move(error));
return;
}
JS::Rooted<JSObject*> bufferArray(
cx, dom::Uint8Array::Create(cx, aSymbolTable.mBuffer, error));
if (error.Failed()) {
promise->MaybeReject(std::move(error));
return;
}
JS::Rooted<JSObject*> 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);
},
[promise](nsresult aRv) { promise->MaybeReject(aRv); });