diff --git a/content/base/src/WebSocket.cpp b/content/base/src/WebSocket.cpp index 2f96fdd1408f..87d7fba6cee3 100644 --- a/content/base/src/WebSocket.cpp +++ b/content/base/src/WebSocket.cpp @@ -1218,7 +1218,7 @@ WebSocket::Send(nsIDOMBlob* aData, } void -WebSocket::Send(ArrayBuffer& aData, +WebSocket::Send(const ArrayBuffer& aData, ErrorResult& aRv) { NS_ABORT_IF_FALSE(NS_IsMainThread(), "Not running on main thread"); @@ -1232,7 +1232,7 @@ WebSocket::Send(ArrayBuffer& aData, } void -WebSocket::Send(ArrayBufferView& aData, +WebSocket::Send(const ArrayBufferView& aData, ErrorResult& aRv) { NS_ABORT_IF_FALSE(NS_IsMainThread(), "Not running on main thread"); diff --git a/content/base/src/WebSocket.h b/content/base/src/WebSocket.h index 358ac4da8beb..40ffe94508cc 100644 --- a/content/base/src/WebSocket.h +++ b/content/base/src/WebSocket.h @@ -150,9 +150,9 @@ public: // WebIDL interface: ErrorResult& aRv); void Send(nsIDOMBlob* aData, ErrorResult& aRv); - void Send(ArrayBuffer& aData, + void Send(const ArrayBuffer& aData, ErrorResult& aRv); - void Send(ArrayBufferView& aData, + void Send(const ArrayBufferView& aData, ErrorResult& aRv); private: // constructor && distructor diff --git a/content/base/src/nsDOMDataChannel.cpp b/content/base/src/nsDOMDataChannel.cpp index 6163c1faa1a0..be3ed71f890d 100644 --- a/content/base/src/nsDOMDataChannel.cpp +++ b/content/base/src/nsDOMDataChannel.cpp @@ -290,7 +290,7 @@ nsDOMDataChannel::Send(nsIDOMBlob* aData, ErrorResult& aRv) } void -nsDOMDataChannel::Send(ArrayBuffer& aData, ErrorResult& aRv) +nsDOMDataChannel::Send(const ArrayBuffer& aData, ErrorResult& aRv) { NS_ABORT_IF_FALSE(NS_IsMainThread(), "Not running on main thread"); @@ -303,7 +303,7 @@ nsDOMDataChannel::Send(ArrayBuffer& aData, ErrorResult& aRv) } void -nsDOMDataChannel::Send(ArrayBufferView& aData, ErrorResult& aRv) +nsDOMDataChannel::Send(const ArrayBufferView& aData, ErrorResult& aRv) { NS_ABORT_IF_FALSE(NS_IsMainThread(), "Not running on main thread"); diff --git a/content/base/src/nsDOMDataChannel.h b/content/base/src/nsDOMDataChannel.h index 584f4a610fc0..59c3dd31617c 100644 --- a/content/base/src/nsDOMDataChannel.h +++ b/content/base/src/nsDOMDataChannel.h @@ -67,8 +67,9 @@ public: } void Send(const nsAString& aData, mozilla::ErrorResult& aRv); void Send(nsIDOMBlob* aData, mozilla::ErrorResult& aRv); - void Send(mozilla::dom::ArrayBuffer& aData, mozilla::ErrorResult& aRv); - void Send(mozilla::dom::ArrayBufferView& aData, mozilla::ErrorResult& aRv); + void Send(const mozilla::dom::ArrayBuffer& aData, mozilla::ErrorResult& aRv); + void Send(const mozilla::dom::ArrayBufferView& aData, + mozilla::ErrorResult& aRv); // Uses XPIDL GetProtocol. bool Ordered() const; diff --git a/content/base/src/nsXMLHttpRequest.h b/content/base/src/nsXMLHttpRequest.h index f318eb42242a..781979ad1f1a 100644 --- a/content/base/src/nsXMLHttpRequest.h +++ b/content/base/src/nsXMLHttpRequest.h @@ -272,11 +272,11 @@ private: RequestBody() : mType(Uninitialized) { } - RequestBody(mozilla::dom::ArrayBuffer* aArrayBuffer) : mType(ArrayBuffer) + RequestBody(const mozilla::dom::ArrayBuffer* aArrayBuffer) : mType(ArrayBuffer) { mValue.mArrayBuffer = aArrayBuffer; } - RequestBody(mozilla::dom::ArrayBufferView* aArrayBufferView) : mType(ArrayBufferView) + RequestBody(const mozilla::dom::ArrayBufferView* aArrayBufferView) : mType(ArrayBufferView) { mValue.mArrayBufferView = aArrayBufferView; } @@ -312,8 +312,8 @@ private: InputStream }; union Value { - mozilla::dom::ArrayBuffer* mArrayBuffer; - mozilla::dom::ArrayBufferView* mArrayBufferView; + const mozilla::dom::ArrayBuffer* mArrayBuffer; + const mozilla::dom::ArrayBufferView* mArrayBufferView; nsIDOMBlob* mBlob; nsIDocument* mDocument; const nsAString* mString; @@ -359,11 +359,12 @@ public: { aRv = Send(Nullable()); } - void Send(mozilla::dom::ArrayBuffer& aArrayBuffer, ErrorResult& aRv) + void Send(const mozilla::dom::ArrayBuffer& aArrayBuffer, ErrorResult& aRv) { aRv = Send(RequestBody(&aArrayBuffer)); } - void Send(mozilla::dom::ArrayBufferView& aArrayBufferView, ErrorResult& aRv) + void Send(const mozilla::dom::ArrayBufferView& aArrayBufferView, + ErrorResult& aRv) { aRv = Send(RequestBody(&aArrayBufferView)); } diff --git a/content/canvas/src/WebGLContext.h b/content/canvas/src/WebGLContext.h index 3c8f7937e93c..8d1c9f69cde4 100644 --- a/content/canvas/src/WebGLContext.h +++ b/content/canvas/src/WebGLContext.h @@ -338,13 +338,15 @@ public: void BlendFuncSeparate(WebGLenum srcRGB, WebGLenum dstRGB, WebGLenum srcAlpha, WebGLenum dstAlpha); void BufferData(WebGLenum target, WebGLsizeiptr size, WebGLenum usage); - void BufferData(WebGLenum target, dom::ArrayBufferView &data, + void BufferData(WebGLenum target, const dom::ArrayBufferView &data, + WebGLenum usage); + void BufferData(WebGLenum target, + const Nullable &maybeData, WebGLenum usage); - void BufferData(WebGLenum target, dom::ArrayBuffer *data, WebGLenum usage); void BufferSubData(WebGLenum target, WebGLsizeiptr byteOffset, - dom::ArrayBufferView &data); + const dom::ArrayBufferView &data); void BufferSubData(WebGLenum target, WebGLsizeiptr byteOffset, - dom::ArrayBuffer *data); + const Nullable &maybeData); WebGLenum CheckFramebufferStatus(WebGLenum target); void Clear(WebGLbitfield mask); void ClearColor(WebGLclampf r, WebGLclampf g, WebGLclampf b, WebGLclampf a); @@ -355,11 +357,12 @@ public: void CompressedTexImage2D(WebGLenum target, WebGLint level, WebGLenum internalformat, WebGLsizei width, WebGLsizei height, WebGLint border, - dom::ArrayBufferView& view); + const dom::ArrayBufferView& view); void CompressedTexSubImage2D(WebGLenum target, WebGLint level, WebGLint xoffset, WebGLint yoffset, WebGLsizei width, WebGLsizei height, - WebGLenum format, dom::ArrayBufferView& view); + WebGLenum format, + const dom::ArrayBufferView& view); void CopyTexImage2D(WebGLenum target, WebGLint level, WebGLenum internalformat, WebGLint x, WebGLint y, WebGLsizei width, WebGLsizei height, WebGLint border); @@ -487,7 +490,8 @@ public: } void ReadPixels(WebGLint x, WebGLint y, WebGLsizei width, WebGLsizei height, WebGLenum format, WebGLenum type, - dom::ArrayBufferView* pixels, ErrorResult& rv); + const Nullable &pixels, + ErrorResult& rv); void RenderbufferStorage(WebGLenum target, WebGLenum internalformat, WebGLsizei width, WebGLsizei height); void SampleCoverage(WebGLclampf value, WebGLboolean invert) { @@ -509,7 +513,8 @@ public: void TexImage2D(WebGLenum target, WebGLint level, WebGLenum internalformat, WebGLsizei width, WebGLsizei height, WebGLint border, WebGLenum format, - WebGLenum type, dom::ArrayBufferView *pixels, + WebGLenum type, + const Nullable &pixels, ErrorResult& rv); void TexImage2D(WebGLenum target, WebGLint level, WebGLenum internalformat, WebGLenum format, WebGLenum type, @@ -547,7 +552,8 @@ public: void TexSubImage2D(WebGLenum target, WebGLint level, WebGLint xoffset, WebGLint yoffset, WebGLsizei width, WebGLsizei height, WebGLenum format, - WebGLenum type, dom::ArrayBufferView* pixels, + WebGLenum type, + const Nullable &pixels, ErrorResult& rv); void TexSubImage2D(WebGLenum target, WebGLint level, WebGLint xoffset, WebGLint yoffset, WebGLenum format, @@ -592,7 +598,8 @@ public: void Uniform4f(WebGLUniformLocation* location, WebGLfloat x, WebGLfloat y, WebGLfloat z, WebGLfloat w); - void Uniform1iv(WebGLUniformLocation* location, dom::Int32Array& arr) { + void Uniform1iv(WebGLUniformLocation* location, + const dom::Int32Array& arr) { Uniform1iv_base(location, arr.Length(), arr.Data()); } void Uniform1iv(WebGLUniformLocation* location, @@ -602,7 +609,8 @@ public: void Uniform1iv_base(WebGLUniformLocation* location, uint32_t arrayLength, const WebGLint* data); - void Uniform2iv(WebGLUniformLocation* location, dom::Int32Array& arr) { + void Uniform2iv(WebGLUniformLocation* location, + const dom::Int32Array& arr) { Uniform2iv_base(location, arr.Length(), arr.Data()); } void Uniform2iv(WebGLUniformLocation* location, @@ -612,7 +620,8 @@ public: void Uniform2iv_base(WebGLUniformLocation* location, uint32_t arrayLength, const WebGLint* data); - void Uniform3iv(WebGLUniformLocation* location, dom::Int32Array& arr) { + void Uniform3iv(WebGLUniformLocation* location, + const dom::Int32Array& arr) { Uniform3iv_base(location, arr.Length(), arr.Data()); } void Uniform3iv(WebGLUniformLocation* location, @@ -622,7 +631,8 @@ public: void Uniform3iv_base(WebGLUniformLocation* location, uint32_t arrayLength, const WebGLint* data); - void Uniform4iv(WebGLUniformLocation* location, dom::Int32Array& arr) { + void Uniform4iv(WebGLUniformLocation* location, + const dom::Int32Array& arr) { Uniform4iv_base(location, arr.Length(), arr.Data()); } void Uniform4iv(WebGLUniformLocation* location, @@ -632,7 +642,8 @@ public: void Uniform4iv_base(WebGLUniformLocation* location, uint32_t arrayLength, const WebGLint* data); - void Uniform1fv(WebGLUniformLocation* location, dom::Float32Array& arr) { + void Uniform1fv(WebGLUniformLocation* location, + const dom::Float32Array& arr) { Uniform1fv_base(location, arr.Length(), arr.Data()); } void Uniform1fv(WebGLUniformLocation* location, @@ -642,7 +653,8 @@ public: void Uniform1fv_base(WebGLUniformLocation* location, uint32_t arrayLength, const WebGLfloat* data); - void Uniform2fv(WebGLUniformLocation* location, dom::Float32Array& arr) { + void Uniform2fv(WebGLUniformLocation* location, + const dom::Float32Array& arr) { Uniform2fv_base(location, arr.Length(), arr.Data()); } void Uniform2fv(WebGLUniformLocation* location, @@ -652,7 +664,8 @@ public: void Uniform2fv_base(WebGLUniformLocation* location, uint32_t arrayLength, const WebGLfloat* data); - void Uniform3fv(WebGLUniformLocation* location, dom::Float32Array& arr) { + void Uniform3fv(WebGLUniformLocation* location, + const dom::Float32Array& arr) { Uniform3fv_base(location, arr.Length(), arr.Data()); } void Uniform3fv(WebGLUniformLocation* location, @@ -662,7 +675,8 @@ public: void Uniform3fv_base(WebGLUniformLocation* location, uint32_t arrayLength, const WebGLfloat* data); - void Uniform4fv(WebGLUniformLocation* location, dom::Float32Array& arr) { + void Uniform4fv(WebGLUniformLocation* location, + const dom::Float32Array& arr) { Uniform4fv_base(location, arr.Length(), arr.Data()); } void Uniform4fv(WebGLUniformLocation* location, @@ -674,7 +688,7 @@ public: void UniformMatrix2fv(WebGLUniformLocation* location, WebGLboolean transpose, - dom::Float32Array &value) { + const dom::Float32Array &value) { UniformMatrix2fv_base(location, transpose, value.Length(), value.Data()); } void UniformMatrix2fv(WebGLUniformLocation* location, @@ -689,7 +703,7 @@ public: void UniformMatrix3fv(WebGLUniformLocation* location, WebGLboolean transpose, - dom::Float32Array &value) { + const dom::Float32Array &value) { UniformMatrix3fv_base(location, transpose, value.Length(), value.Data()); } void UniformMatrix3fv(WebGLUniformLocation* location, @@ -704,7 +718,7 @@ public: void UniformMatrix4fv(WebGLUniformLocation* location, WebGLboolean transpose, - dom::Float32Array &value) { + const dom::Float32Array &value) { UniformMatrix4fv_base(location, transpose, value.Length(), value.Data()); } void UniformMatrix4fv(WebGLUniformLocation* location, @@ -738,7 +752,7 @@ public: void VertexAttrib4f(WebGLuint index, WebGLfloat x0, WebGLfloat x1, WebGLfloat x2, WebGLfloat x3); - void VertexAttrib1fv(WebGLuint idx, dom::Float32Array &arr) { + void VertexAttrib1fv(WebGLuint idx, const dom::Float32Array &arr) { VertexAttrib1fv_base(idx, arr.Length(), arr.Data()); } void VertexAttrib1fv(WebGLuint idx, const dom::Sequence& arr) { @@ -747,7 +761,7 @@ public: void VertexAttrib1fv_base(WebGLuint idx, uint32_t arrayLength, const WebGLfloat* ptr); - void VertexAttrib2fv(WebGLuint idx, dom::Float32Array &arr) { + void VertexAttrib2fv(WebGLuint idx, const dom::Float32Array &arr) { VertexAttrib2fv_base(idx, arr.Length(), arr.Data()); } void VertexAttrib2fv(WebGLuint idx, const dom::Sequence& arr) { @@ -756,7 +770,7 @@ public: void VertexAttrib2fv_base(WebGLuint idx, uint32_t arrayLength, const WebGLfloat* ptr); - void VertexAttrib3fv(WebGLuint idx, dom::Float32Array &arr) { + void VertexAttrib3fv(WebGLuint idx, const dom::Float32Array &arr) { VertexAttrib3fv_base(idx, arr.Length(), arr.Data()); } void VertexAttrib3fv(WebGLuint idx, const dom::Sequence& arr) { @@ -765,7 +779,7 @@ public: void VertexAttrib3fv_base(WebGLuint idx, uint32_t arrayLength, const WebGLfloat* ptr); - void VertexAttrib4fv(WebGLuint idx, dom::Float32Array &arr) { + void VertexAttrib4fv(WebGLuint idx, const dom::Float32Array &arr) { VertexAttrib4fv_base(idx, arr.Length(), arr.Data()); } void VertexAttrib4fv(WebGLuint idx, const dom::Sequence& arr) { diff --git a/content/canvas/src/WebGLContextGL.cpp b/content/canvas/src/WebGLContextGL.cpp index 70c89a6ba2e5..8af12d824cef 100644 --- a/content/canvas/src/WebGLContextGL.cpp +++ b/content/canvas/src/WebGLContextGL.cpp @@ -400,16 +400,20 @@ WebGLContext::BufferData(WebGLenum target, WebGLsizeiptr size, } void -WebGLContext::BufferData(WebGLenum target, ArrayBuffer *data, WebGLenum usage) +WebGLContext::BufferData(WebGLenum target, + const Nullable &maybeData, + WebGLenum usage) { if (!IsContextStable()) return; - if (!data) { + if (maybeData.IsNull()) { // see http://www.khronos.org/bugzilla/show_bug.cgi?id=386 return ErrorInvalidValue("bufferData: null object passed"); } + const ArrayBuffer& data = maybeData.Value(); + WebGLBuffer *boundBuffer = nullptr; if (target == LOCAL_GL_ARRAY_BUFFER) { @@ -429,21 +433,22 @@ WebGLContext::BufferData(WebGLenum target, ArrayBuffer *data, WebGLenum usage) MakeContextCurrent(); InvalidateCachedMinInUseAttribArrayLength(); - GLenum error = CheckedBufferData(target, data->Length(), data->Data(), usage); + GLenum error = CheckedBufferData(target, data.Length(), data.Data(), usage); if (error) { GenerateWarning("bufferData generated error %s", ErrorName(error)); return; } - boundBuffer->SetByteLength(data->Length()); - if (!boundBuffer->ElementArrayCacheBufferData(data->Data(), data->Length())) { + boundBuffer->SetByteLength(data.Length()); + if (!boundBuffer->ElementArrayCacheBufferData(data.Data(), data.Length())) { return ErrorOutOfMemory("bufferData: out of memory"); } } void -WebGLContext::BufferData(WebGLenum target, ArrayBufferView& data, WebGLenum usage) +WebGLContext::BufferData(WebGLenum target, const ArrayBufferView& data, + WebGLenum usage) { if (!IsContextStable()) return; @@ -481,16 +486,18 @@ WebGLContext::BufferData(WebGLenum target, ArrayBufferView& data, WebGLenum usag void WebGLContext::BufferSubData(GLenum target, WebGLsizeiptr byteOffset, - ArrayBuffer *data) + const Nullable &maybeData) { if (!IsContextStable()) return; - if (!data) { + if (maybeData.IsNull()) { // see http://www.khronos.org/bugzilla/show_bug.cgi?id=386 return; } + const ArrayBuffer& data = maybeData.Value(); + WebGLBuffer *boundBuffer = nullptr; if (target == LOCAL_GL_ARRAY_BUFFER) { @@ -507,7 +514,7 @@ WebGLContext::BufferSubData(GLenum target, WebGLsizeiptr byteOffset, if (!boundBuffer) return ErrorInvalidOperation("bufferData: no buffer bound!"); - CheckedUint32 checked_neededByteLength = CheckedUint32(byteOffset) + data->Length(); + CheckedUint32 checked_neededByteLength = CheckedUint32(byteOffset) + data.Length(); if (!checked_neededByteLength.isValid()) return ErrorInvalidValue("bufferSubData: integer overflow computing the needed byte length"); @@ -517,14 +524,14 @@ WebGLContext::BufferSubData(GLenum target, WebGLsizeiptr byteOffset, MakeContextCurrent(); - boundBuffer->ElementArrayCacheBufferSubData(byteOffset, data->Data(), data->Length()); + boundBuffer->ElementArrayCacheBufferSubData(byteOffset, data.Data(), data.Length()); - gl->fBufferSubData(target, byteOffset, data->Length(), data->Data()); + gl->fBufferSubData(target, byteOffset, data.Length(), data.Data()); } void WebGLContext::BufferSubData(WebGLenum target, WebGLsizeiptr byteOffset, - ArrayBufferView& data) + const ArrayBufferView& data) { if (!IsContextStable()) return; @@ -3014,7 +3021,7 @@ WebGLContext::PixelStorei(WebGLenum pname, WebGLint param) void WebGLContext::ReadPixels(WebGLint x, WebGLint y, WebGLsizei width, WebGLsizei height, WebGLenum format, - WebGLenum type, ArrayBufferView* pixels, + WebGLenum type, const Nullable &pixels, ErrorResult& rv) { if (!IsContextStable()) { @@ -3029,7 +3036,7 @@ WebGLContext::ReadPixels(WebGLint x, WebGLint y, WebGLsizei width, if (width < 0 || height < 0) return ErrorInvalidValue("readPixels: negative size passed"); - if (!pixels) + if (pixels.IsNull()) return ErrorInvalidValue("readPixels: null destination buffer"); const WebGLRectangleObject *framebufferRect = FramebufferRectangleObject(); @@ -3072,7 +3079,7 @@ WebGLContext::ReadPixels(WebGLint x, WebGLint y, WebGLsizei width, return ErrorInvalidEnum("readPixels: Bad type"); } - int dataType = JS_GetArrayBufferViewType(pixels->Obj()); + int dataType = JS_GetArrayBufferViewType(pixels.Value().Obj()); // Check the pixels param type if (dataType != requiredDataType) @@ -3090,11 +3097,11 @@ WebGLContext::ReadPixels(WebGLint x, WebGLint y, WebGLsizei width, if (!checked_neededByteLength.isValid()) return ErrorInvalidOperation("readPixels: integer overflow computing the needed buffer size"); - uint32_t dataByteLen = JS_GetTypedArrayByteLength(pixels->Obj()); + uint32_t dataByteLen = JS_GetTypedArrayByteLength(pixels.Value().Obj()); if (checked_neededByteLength.value() > dataByteLen) return ErrorInvalidOperation("readPixels: buffer too small"); - void* data = pixels->Data(); + void* data = pixels.Value().Data(); if (!data) { ErrorOutOfMemory("readPixels: buffer storage is null. Did we run out of memory?"); return rv.Throw(NS_ERROR_OUT_OF_MEMORY); @@ -4289,7 +4296,7 @@ WebGLContext::CompileShader(WebGLShader *shader) void WebGLContext::CompressedTexImage2D(WebGLenum target, WebGLint level, WebGLenum internalformat, WebGLsizei width, WebGLsizei height, WebGLint border, - ArrayBufferView& view) + const ArrayBufferView& view) { if (!IsContextStable()) { return; @@ -4329,7 +4336,7 @@ WebGLContext::CompressedTexImage2D(WebGLenum target, WebGLint level, WebGLenum i void WebGLContext::CompressedTexSubImage2D(WebGLenum target, WebGLint level, WebGLint xoffset, WebGLint yoffset, WebGLsizei width, WebGLsizei height, - WebGLenum format, ArrayBufferView& view) + WebGLenum format, const ArrayBufferView& view) { if (!IsContextStable()) { return; @@ -4861,15 +4868,15 @@ void WebGLContext::TexImage2D(WebGLenum target, WebGLint level, WebGLenum internalformat, WebGLsizei width, WebGLsizei height, WebGLint border, WebGLenum format, - WebGLenum type, ArrayBufferView *pixels, ErrorResult& rv) + WebGLenum type, const Nullable &pixels, ErrorResult& rv) { if (!IsContextStable()) return; return TexImage2D_base(target, level, internalformat, width, height, 0, border, format, type, - pixels ? pixels->Data() : 0, - pixels ? pixels->Length() : 0, - pixels ? (int)JS_GetArrayBufferViewType(pixels->Obj()) : -1, + pixels.IsNull() ? 0 : pixels.Value().Data(), + pixels.IsNull() ? 0 : pixels.Value().Length(), + pixels.IsNull() ? -1 : (int)JS_GetArrayBufferViewType(pixels.Value().Obj()), WebGLTexelConversions::Auto, false); } @@ -5011,19 +5018,19 @@ WebGLContext::TexSubImage2D(WebGLenum target, WebGLint level, WebGLint xoffset, WebGLint yoffset, WebGLsizei width, WebGLsizei height, WebGLenum format, WebGLenum type, - ArrayBufferView* pixels, + const Nullable &pixels, ErrorResult& rv) { if (!IsContextStable()) return; - if (!pixels) + if (pixels.IsNull()) return ErrorInvalidValue("texSubImage2D: pixels must not be null!"); return TexSubImage2D_base(target, level, xoffset, yoffset, width, height, 0, format, type, - pixels->Data(), pixels->Length(), - JS_GetArrayBufferViewType(pixels->Obj()), + pixels.Value().Data(), pixels.Value().Length(), + JS_GetArrayBufferViewType(pixels.Value().Obj()), WebGLTexelConversions::Auto, false); } diff --git a/content/media/mediasource/SourceBuffer.cpp b/content/media/mediasource/SourceBuffer.cpp index 9a9c3c57d290..9673a62e4506 100644 --- a/content/media/mediasource/SourceBuffer.cpp +++ b/content/media/mediasource/SourceBuffer.cpp @@ -89,13 +89,13 @@ SourceBuffer::SetAppendWindowEnd(double aAppendWindowEnd, ErrorResult& aRv) } void -SourceBuffer::AppendBuffer(ArrayBuffer& aData, ErrorResult& aRv) +SourceBuffer::AppendBuffer(const ArrayBuffer& aData, ErrorResult& aRv) { AppendData(aData.Data(), aData.Length(), aRv); } void -SourceBuffer::AppendBuffer(ArrayBufferView& aData, ErrorResult& aRv) +SourceBuffer::AppendBuffer(const ArrayBufferView& aData, ErrorResult& aRv) { AppendData(aData.Data(), aData.Length(), aRv); } diff --git a/content/media/mediasource/SourceBuffer.h b/content/media/mediasource/SourceBuffer.h index f7664b8b92c9..9ca4e6d7737b 100644 --- a/content/media/mediasource/SourceBuffer.h +++ b/content/media/mediasource/SourceBuffer.h @@ -62,8 +62,8 @@ public: void SetAppendWindowEnd(double aAppendWindowEnd, ErrorResult& aRv); - void AppendBuffer(ArrayBuffer& aData, ErrorResult& aRv); - void AppendBuffer(ArrayBufferView& aData, ErrorResult& aRv); + void AppendBuffer(const ArrayBuffer& aData, ErrorResult& aRv); + void AppendBuffer(const ArrayBufferView& aData, ErrorResult& aRv); void Abort(ErrorResult& aRv); diff --git a/content/media/webaudio/AnalyserNode.cpp b/content/media/webaudio/AnalyserNode.cpp index d5fbe9cd0fdd..a86847bb688d 100644 --- a/content/media/webaudio/AnalyserNode.cpp +++ b/content/media/webaudio/AnalyserNode.cpp @@ -143,7 +143,7 @@ AnalyserNode::SetSmoothingTimeConstant(double aValue, ErrorResult& aRv) } void -AnalyserNode::GetFloatFrequencyData(Float32Array& aArray) +AnalyserNode::GetFloatFrequencyData(const Float32Array& aArray) { if (!FFTAnalysis()) { // Might fail to allocate memory @@ -159,7 +159,7 @@ AnalyserNode::GetFloatFrequencyData(Float32Array& aArray) } void -AnalyserNode::GetByteFrequencyData(Uint8Array& aArray) +AnalyserNode::GetByteFrequencyData(const Uint8Array& aArray) { if (!FFTAnalysis()) { // Might fail to allocate memory @@ -181,7 +181,7 @@ AnalyserNode::GetByteFrequencyData(Uint8Array& aArray) } void -AnalyserNode::GetByteTimeDomainData(Uint8Array& aArray) +AnalyserNode::GetByteTimeDomainData(const Uint8Array& aArray) { unsigned char* buffer = aArray.Data(); uint32_t length = std::min(aArray.Length(), mBuffer.Length()); diff --git a/content/media/webaudio/AnalyserNode.h b/content/media/webaudio/AnalyserNode.h index 0bf8f020d967..e0c6c927e0fc 100644 --- a/content/media/webaudio/AnalyserNode.h +++ b/content/media/webaudio/AnalyserNode.h @@ -25,9 +25,9 @@ public: virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aScope) MOZ_OVERRIDE; - void GetFloatFrequencyData(Float32Array& aArray); - void GetByteFrequencyData(Uint8Array& aArray); - void GetByteTimeDomainData(Uint8Array& aArray); + void GetFloatFrequencyData(const Float32Array& aArray); + void GetByteFrequencyData(const Uint8Array& aArray); + void GetByteTimeDomainData(const Uint8Array& aArray); uint32_t FftSize() const { return mAnalysisBlock.FFTSize(); diff --git a/content/media/webaudio/AudioContext.cpp b/content/media/webaudio/AudioContext.cpp index 0ce02007da1b..2e455948daf1 100644 --- a/content/media/webaudio/AudioContext.cpp +++ b/content/media/webaudio/AudioContext.cpp @@ -160,7 +160,7 @@ AudioContext::CreateBuffer(JSContext* aJSContext, uint32_t aNumberOfChannels, } already_AddRefed -AudioContext::CreateBuffer(JSContext* aJSContext, ArrayBuffer& aBuffer, +AudioContext::CreateBuffer(JSContext* aJSContext, const ArrayBuffer& aBuffer, bool aMixToMono, ErrorResult& aRv) { // Do not accept this method unless the legacy pref has been set. diff --git a/content/media/webaudio/AudioContext.h b/content/media/webaudio/AudioContext.h index 9835c3d884bc..5ce721f343f5 100644 --- a/content/media/webaudio/AudioContext.h +++ b/content/media/webaudio/AudioContext.h @@ -124,7 +124,7 @@ public: ErrorResult& aRv); already_AddRefed - CreateBuffer(JSContext* aJSContext, ArrayBuffer& aBuffer, + CreateBuffer(JSContext* aJSContext, const ArrayBuffer& aBuffer, bool aMixToMono, ErrorResult& aRv); already_AddRefed diff --git a/content/media/webaudio/BiquadFilterNode.cpp b/content/media/webaudio/BiquadFilterNode.cpp index acbd4082d164..8f571004e2d9 100644 --- a/content/media/webaudio/BiquadFilterNode.cpp +++ b/content/media/webaudio/BiquadFilterNode.cpp @@ -248,8 +248,8 @@ BiquadFilterNode::SetType(BiquadFilterType aType) void BiquadFilterNode::GetFrequencyResponse(const Float32Array& aFrequencyHz, - Float32Array& aMagResponse, - Float32Array& aPhaseResponse) + const Float32Array& aMagResponse, + const Float32Array& aPhaseResponse) { uint32_t length = std::min(std::min(aFrequencyHz.Length(), aMagResponse.Length()), aPhaseResponse.Length()); diff --git a/content/media/webaudio/BiquadFilterNode.h b/content/media/webaudio/BiquadFilterNode.h index 77d09dc55c66..9ae967b9e7cb 100644 --- a/content/media/webaudio/BiquadFilterNode.h +++ b/content/media/webaudio/BiquadFilterNode.h @@ -54,8 +54,8 @@ public: } void GetFrequencyResponse(const Float32Array& aFrequencyHz, - Float32Array& aMagResponse, - Float32Array& aPhaseResponse); + const Float32Array& aMagResponse, + const Float32Array& aPhaseResponse); private: static void SendFrequencyToStream(AudioNode* aNode); diff --git a/content/media/webaudio/WaveShaperNode.cpp b/content/media/webaudio/WaveShaperNode.cpp index 92ec2271f180..4ebdfdfe1a60 100644 --- a/content/media/webaudio/WaveShaperNode.cpp +++ b/content/media/webaudio/WaveShaperNode.cpp @@ -121,14 +121,14 @@ WaveShaperNode::WrapObject(JSContext *aCx, JS::Handle aScope) } void -WaveShaperNode::SetCurve(const Float32Array* aCurve) +WaveShaperNode::SetCurve(const Nullable& aCurve) { nsTArray curve; - if (aCurve) { - mCurve = aCurve->Obj(); + if (!aCurve.IsNull()) { + mCurve = aCurve.Value().Obj(); - curve.SetLength(aCurve->Length()); - PodCopy(curve.Elements(), aCurve->Data(), aCurve->Length()); + curve.SetLength(aCurve.Value().Length()); + PodCopy(curve.Elements(), aCurve.Value().Data(), aCurve.Value().Length()); } else { mCurve = nullptr; } diff --git a/content/media/webaudio/WaveShaperNode.h b/content/media/webaudio/WaveShaperNode.h index f6d73a82f84f..a9c90ef928a3 100644 --- a/content/media/webaudio/WaveShaperNode.h +++ b/content/media/webaudio/WaveShaperNode.h @@ -31,7 +31,7 @@ public: { return mCurve; } - void SetCurve(const Float32Array* aData); + void SetCurve(const Nullable& aData); private: void ClearCurve(); diff --git a/dom/base/Crypto.cpp b/dom/base/Crypto.cpp index 4227de8a6909..99cbf1d1cdcc 100644 --- a/dom/base/Crypto.cpp +++ b/dom/base/Crypto.cpp @@ -55,7 +55,8 @@ Crypto::WrapObject(JSContext* aCx, JS::Handle aScope) } JSObject * -Crypto::GetRandomValues(JSContext* aCx, ArrayBufferView& aArray, ErrorResult& aRv) +Crypto::GetRandomValues(JSContext* aCx, const ArrayBufferView& aArray, + ErrorResult& aRv) { NS_ABORT_IF_FALSE(NS_IsMainThread(), "Called on the wrong thread"); diff --git a/dom/base/Crypto.h b/dom/base/Crypto.h index 4e5da69b288c..6c5a7eaa5bc9 100644 --- a/dom/base/Crypto.h +++ b/dom/base/Crypto.h @@ -34,7 +34,8 @@ public: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Crypto) JSObject * - GetRandomValues(JSContext* aCx, ArrayBufferView& aArray, ErrorResult& aRv); + GetRandomValues(JSContext* aCx, const ArrayBufferView& aArray, + ErrorResult& aRv); #ifndef MOZ_DISABLE_CRYPTOLEGACY virtual bool EnableSmartCardEvents() = 0; diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index 3bb02cb1ff15..3f5c63f205df 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -3205,55 +3205,24 @@ for (uint32_t i = 0; i < length; ++i) { "arraybuffer views because making sure all the " "objects are properly rooted is hard") name = type.name - # By default, we use a Maybe<> to hold our typed array. And in the optional - # non-nullable case we want to pass Optional to consumers, not - # Optional >, so jump though some hoops to do that. - holderType = "Maybe<%s>" % name - constructLoc = "${holderName}" - constructMethod = "construct" - constructInternal = "ref" + declType = CGGeneric(name) if type.nullable(): - if isOptional: - declType = "Optional<" + name + "*>" - else: - declType = name + "*" + declType = CGTemplatedType("Nullable", declType) + objRef = "${declName}.SetValue()" else: - if isOptional: - declType = "Optional<" + name + ">" - # We don't need a holder in this case - holderType = None - constructLoc = "${declName}" - constructMethod = "Construct" - constructInternal = "Value" - else: - declType = "NonNull<" + name + ">" + objRef = "${declName}" + template = ( - "%s.%s(&${val}.toObject());\n" - "if (!%s.%s().inited()) {\n" + "if (!%s.Init(&${val}.toObject())) {\n" "%s" # No newline here because onFailureBadType() handles that "}\n" % - (constructLoc, constructMethod, constructLoc, constructInternal, + (objRef, CGIndenter(onFailureBadType(failureCode, type.name)).define())) - nullableTarget = "" - if type.nullable(): - if isOptional: - template += "${declName}.Construct();\n" - nullableTarget = "${declName}.Value()" - else: - nullableTarget = "${declName}" - template += "%s = ${holderName}.addr();" % nullableTarget - elif not isOptional: - template += "${declName} = ${holderName}.addr();" - template = wrapObjectTemplate(template, type, - "%s = nullptr" % nullableTarget, + template = wrapObjectTemplate(template, type, "${declName}.SetNull()", failureCode) - - if holderType is not None: - holderType = CGGeneric(holderType) - # We handle all the optional stuff ourselves; no need for caller to do it. return JSToNativeConversionInfo(template, - declType=CGGeneric(declType), - holderType=holderType) + declType=declType, + dealWithOptional=isOptional) if type.isDOMString(): assert not isEnforceRange and not isClamp @@ -3886,7 +3855,7 @@ class CGArgumentConverter(CGThing): sequenceWrapLevel = 0 def getWrapTemplateForType(type, descriptorProvider, result, successCode, - isCreator, exceptionCode): + isCreator, exceptionCode, typedArraysAreStructs): """ Reflect a C++ value stored in "result", of IDL type "type" into JS. The "successCode" is the code to run once we have successfully done the @@ -3895,6 +3864,9 @@ def getWrapTemplateForType(type, descriptorProvider, result, successCode, doing a 'break' if the entire conversion template is inside a block that the 'break' will exit). + If typedArraysAreStructs is true, then if the type is a typed array, + "result" is one of the dom::TypedArray subclasses, not a JSObject*. + The resulting string should be used with string.Template. It needs the following keys when substituting: @@ -3970,7 +3942,8 @@ def getWrapTemplateForType(type, descriptorProvider, result, successCode, # Nullable sequences are Nullable< nsTArray > (recTemplate, recInfall) = getWrapTemplateForType(type.inner, descriptorProvider, "%s.Value()" % result, successCode, - isCreator, exceptionCode) + isCreator, exceptionCode, + typedArraysAreStructs) return (""" if (%s.IsNull()) { %s @@ -4135,7 +4108,8 @@ if (!returnArray) { # NB: setValue(..., True) calls JS_WrapValue(), so is fallible return (setValue(result, "value"), False) - if type.isObject() or type.isSpiderMonkeyInterface(): + if (type.isObject() or (type.isSpiderMonkeyInterface() and + not typedArraysAreStructs)): # See comments in WrapNewBindingObject explaining why we need # to wrap here. if type.nullable(): @@ -4153,17 +4127,28 @@ if (!returnArray) { # NB: setValue(..., True) calls JS_WrapValue(), so is fallible return (setValue(toValue % result, wrapType), False) - if not (type.isUnion() or type.isPrimitive() or type.isDictionary() or type.isDate()): + if not (type.isUnion() or type.isPrimitive() or type.isDictionary() or + type.isDate() or + (type.isSpiderMonkeyInterface() and typedArraysAreStructs)): raise TypeError("Need to learn to wrap %s" % type) if type.nullable(): (recTemplate, recInfal) = getWrapTemplateForType(type.inner, descriptorProvider, "%s.Value()" % result, successCode, - isCreator, exceptionCode) + isCreator, exceptionCode, + typedArraysAreStructs) return ("if (%s.IsNull()) {\n" % result + CGIndenter(CGGeneric(setValue("JSVAL_NULL"))).define() + "\n" + "}\n" + recTemplate, recInfal) + if type.isSpiderMonkeyInterface(): + assert typedArraysAreStructs + # See comments in WrapNewBindingObject explaining why we need + # to wrap here. + # NB: setValue(..., True) calls JS_WrapValue(), so is fallible + return (setValue("JS::ObjectValue(*%s.Obj())" % result, + "nonDOMObject"), False) + if type.isUnion(): return (wrapAndSetPtr("%s.ToJSVal(cx, ${obj}, ${jsvalHandle})" % result), False) @@ -4234,7 +4219,9 @@ def wrapForType(type, descriptorProvider, templateValues): templateValues.get('successCode', None), templateValues.get('isCreator', False), templateValues.get('exceptionCode', - "return false;"))[0] + "return false;"), + templateValues.get('typedArraysAreStructs', + False))[0] defaultValues = {'obj': 'obj'} return string.Template(wrap).substitute(defaultValues, **templateValues) @@ -4251,7 +4238,8 @@ def infallibleForMember(member, type, descriptorProvider): failure conditions. """ return getWrapTemplateForType(type, descriptorProvider, 'result', None,\ - memberIsCreator(member), "return false;")[1] + memberIsCreator(member), "return false;", + False)[1] def typeNeedsCx(type, descriptorProvider, retVal=False): if type is None: @@ -4442,11 +4430,13 @@ class CGCallGenerator(CGThing): return True if a.type.isUnion(): return True + if a.type.isSpiderMonkeyInterface(): + return True return False if needsConst(a): arg = CGWrapper(arg, pre="Constify(", post=")") # And convert NonNull to T& - if (((a.type.isInterface() or a.type.isCallback()) and + if (((a.type.isGeckoInterface() or a.type.isCallback()) and not a.type.nullable()) or a.type.isDOMString()): arg = CGWrapper(arg, pre="NonNullHelper(", post=")") @@ -5893,10 +5883,8 @@ def getUnionAccessorSignatureType(type, descriptorProvider): if type.isSpiderMonkeyInterface(): typeName = CGGeneric(type.name) if type.nullable(): - typeName = CGWrapper(typeName, post="*") - else: - typeName = CGWrapper(typeName, post="&") - return typeName + typeName = CGTemplatedType("Nullable", typeName) + return CGWrapper(typeName, post="&") if type.isDOMString(): return CGGeneric("const nsAString&") @@ -6146,11 +6134,6 @@ ${doConversionsToJS} (templateVars, type) = arg assert not type.nullable() # flatMemberTypes never has nullable types val = "mValue.m%(name)s.Value()" % templateVars - if type.isSpiderMonkeyInterface(): - # We have a NonNull object while the wrapping code - # wants a JSObject*. Cheat with .get() so we don't have to - # figure out the right reference type to cast to. - val = "%s.get()->Obj()" % val wrapCode = wrapForType( type, self.descriptorProvider, { @@ -6158,6 +6141,7 @@ ${doConversionsToJS} "jsvalHandle": "rval", "obj": "scopeObj", "result": val, + "typedArraysAreStructs": True }) return CGIndenter(CGList([CGGeneric("case e%(name)s:" % templateVars), CGWrapper(CGIndenter(CGGeneric(wrapCode)), @@ -8988,9 +8972,9 @@ class CGNativeMember(ClassMethod): return "JSObject*", "nullptr", "return ${declName};" if type.isSpiderMonkeyInterface(): if type.nullable(): - returnCode = "return ${declName} ? ${declName}->Obj() : nullptr;" + returnCode = "return ${declName}.IsNull() ? nullptr : ${declName}.Value().Obj();" else: - returnCode = ("return static_cast<%s&>(${declName}).Obj();" % type.name) + returnCode = "return ${declName}.Obj();" return "JSObject*", "nullptr", returnCode if type.isSequence(): # If we want to handle sequence-of-sequences return values, we're @@ -9105,16 +9089,9 @@ class CGNativeMember(ClassMethod): if type.isSpiderMonkeyInterface(): assert not isMember if self.jsObjectsArePtr: - typeDecl = "JSObject*" - else: - if type.nullable(): - typeDecl = "%s*" - else: - typeDecl = "%s" - if not optional: - typeDecl += "&" - typeDecl = typeDecl % type.name - return typeDecl, False, False + return "JSObject*", False, False + + return type.name, True, True if type.isDOMString(): if isMember: diff --git a/dom/bindings/TypedArray.h b/dom/bindings/TypedArray.h index d76d26a43c44..f64ae53de263 100644 --- a/dom/bindings/TypedArray.h +++ b/dom/bindings/TypedArray.h @@ -38,10 +38,11 @@ private: JSObject* mObj; public: - inline void Init(JSObject* obj) + inline bool Init(JSObject* obj) { MOZ_ASSERT(!inited()); DoInit(obj); + return inited(); } inline bool inited() const { diff --git a/dom/bindings/test/TestBindingHeader.h b/dom/bindings/test/TestBindingHeader.h index 888f12eab1bb..66a07db0f839 100644 --- a/dom/bindings/test/TestBindingHeader.h +++ b/dom/bindings/test/TestBindingHeader.h @@ -384,21 +384,21 @@ public: void ReceiveSequenceOfSequences(nsTArray< nsTArray >&); // Typed array types - void PassArrayBuffer(ArrayBuffer&); - void PassNullableArrayBuffer(ArrayBuffer*); + void PassArrayBuffer(const ArrayBuffer&); + void PassNullableArrayBuffer(const Nullable&); void PassOptionalArrayBuffer(const Optional&); - void PassOptionalNullableArrayBuffer(const Optional&); - void PassOptionalNullableArrayBufferWithDefaultValue(ArrayBuffer*); - void PassArrayBufferView(ArrayBufferView&); - void PassInt8Array(Int8Array&); - void PassInt16Array(Int16Array&); - void PassInt32Array(Int32Array&); - void PassUint8Array(Uint8Array&); - void PassUint16Array(Uint16Array&); - void PassUint32Array(Uint32Array&); - void PassUint8ClampedArray(Uint8ClampedArray&); - void PassFloat32Array(Float32Array&); - void PassFloat64Array(Float64Array&); + void PassOptionalNullableArrayBuffer(const Optional >&); + void PassOptionalNullableArrayBufferWithDefaultValue(const Nullable&); + void PassArrayBufferView(const ArrayBufferView&); + void PassInt8Array(const Int8Array&); + void PassInt16Array(const Int16Array&); + void PassInt32Array(const Int32Array&); + void PassUint8Array(const Uint8Array&); + void PassUint16Array(const Uint16Array&); + void PassUint32Array(const Uint32Array&); + void PassUint8ClampedArray(const Uint8ClampedArray&); + void PassFloat32Array(const Float32Array&); + void PassFloat64Array(const Float64Array&); JSObject* ReceiveUint8Array(JSContext*); // DOMString types diff --git a/dom/workers/XMLHttpRequest.h b/dom/workers/XMLHttpRequest.h index 462967908168..458813570ecc 100644 --- a/dom/workers/XMLHttpRequest.h +++ b/dom/workers/XMLHttpRequest.h @@ -176,12 +176,12 @@ public: } void - Send(ArrayBuffer& aBody, ErrorResult& aRv) { + Send(const ArrayBuffer& aBody, ErrorResult& aRv) { return Send(aBody.Obj(), aRv); } void - Send(ArrayBufferView& aBody, ErrorResult& aRv) { + Send(const ArrayBufferView& aBody, ErrorResult& aRv) { return Send(aBody.Obj(), aRv); }