Bug 900898 part 2. Move to using Nullable<TypedArray> to represent possibly-null TypedArray structs. r=smaug

This commit is contained in:
Boris Zbarsky 2013-08-05 13:40:01 -04:00
parent 1e4bd71b64
commit bcd1523d40
23 changed files with 179 additions and 176 deletions

View File

@ -1218,7 +1218,7 @@ WebSocket::Send(nsIDOMBlob* aData,
} }
void void
WebSocket::Send(ArrayBuffer& aData, WebSocket::Send(const ArrayBuffer& aData,
ErrorResult& aRv) ErrorResult& aRv)
{ {
NS_ABORT_IF_FALSE(NS_IsMainThread(), "Not running on main thread"); NS_ABORT_IF_FALSE(NS_IsMainThread(), "Not running on main thread");
@ -1232,7 +1232,7 @@ WebSocket::Send(ArrayBuffer& aData,
} }
void void
WebSocket::Send(ArrayBufferView& aData, WebSocket::Send(const ArrayBufferView& aData,
ErrorResult& aRv) ErrorResult& aRv)
{ {
NS_ABORT_IF_FALSE(NS_IsMainThread(), "Not running on main thread"); NS_ABORT_IF_FALSE(NS_IsMainThread(), "Not running on main thread");

View File

@ -150,9 +150,9 @@ public: // WebIDL interface:
ErrorResult& aRv); ErrorResult& aRv);
void Send(nsIDOMBlob* aData, void Send(nsIDOMBlob* aData,
ErrorResult& aRv); ErrorResult& aRv);
void Send(ArrayBuffer& aData, void Send(const ArrayBuffer& aData,
ErrorResult& aRv); ErrorResult& aRv);
void Send(ArrayBufferView& aData, void Send(const ArrayBufferView& aData,
ErrorResult& aRv); ErrorResult& aRv);
private: // constructor && distructor private: // constructor && distructor

View File

@ -290,7 +290,7 @@ nsDOMDataChannel::Send(nsIDOMBlob* aData, ErrorResult& aRv)
} }
void 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"); NS_ABORT_IF_FALSE(NS_IsMainThread(), "Not running on main thread");
@ -303,7 +303,7 @@ nsDOMDataChannel::Send(ArrayBuffer& aData, ErrorResult& aRv)
} }
void 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"); NS_ABORT_IF_FALSE(NS_IsMainThread(), "Not running on main thread");

View File

@ -67,8 +67,9 @@ public:
} }
void Send(const nsAString& aData, mozilla::ErrorResult& aRv); void Send(const nsAString& aData, mozilla::ErrorResult& aRv);
void Send(nsIDOMBlob* aData, mozilla::ErrorResult& aRv); void Send(nsIDOMBlob* aData, mozilla::ErrorResult& aRv);
void Send(mozilla::dom::ArrayBuffer& aData, mozilla::ErrorResult& aRv); void Send(const mozilla::dom::ArrayBuffer& aData, mozilla::ErrorResult& aRv);
void Send(mozilla::dom::ArrayBufferView& aData, mozilla::ErrorResult& aRv); void Send(const mozilla::dom::ArrayBufferView& aData,
mozilla::ErrorResult& aRv);
// Uses XPIDL GetProtocol. // Uses XPIDL GetProtocol.
bool Ordered() const; bool Ordered() const;

View File

@ -272,11 +272,11 @@ private:
RequestBody() : mType(Uninitialized) RequestBody() : mType(Uninitialized)
{ {
} }
RequestBody(mozilla::dom::ArrayBuffer* aArrayBuffer) : mType(ArrayBuffer) RequestBody(const mozilla::dom::ArrayBuffer* aArrayBuffer) : mType(ArrayBuffer)
{ {
mValue.mArrayBuffer = aArrayBuffer; mValue.mArrayBuffer = aArrayBuffer;
} }
RequestBody(mozilla::dom::ArrayBufferView* aArrayBufferView) : mType(ArrayBufferView) RequestBody(const mozilla::dom::ArrayBufferView* aArrayBufferView) : mType(ArrayBufferView)
{ {
mValue.mArrayBufferView = aArrayBufferView; mValue.mArrayBufferView = aArrayBufferView;
} }
@ -312,8 +312,8 @@ private:
InputStream InputStream
}; };
union Value { union Value {
mozilla::dom::ArrayBuffer* mArrayBuffer; const mozilla::dom::ArrayBuffer* mArrayBuffer;
mozilla::dom::ArrayBufferView* mArrayBufferView; const mozilla::dom::ArrayBufferView* mArrayBufferView;
nsIDOMBlob* mBlob; nsIDOMBlob* mBlob;
nsIDocument* mDocument; nsIDocument* mDocument;
const nsAString* mString; const nsAString* mString;
@ -359,11 +359,12 @@ public:
{ {
aRv = Send(Nullable<RequestBody>()); aRv = Send(Nullable<RequestBody>());
} }
void Send(mozilla::dom::ArrayBuffer& aArrayBuffer, ErrorResult& aRv) void Send(const mozilla::dom::ArrayBuffer& aArrayBuffer, ErrorResult& aRv)
{ {
aRv = Send(RequestBody(&aArrayBuffer)); 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)); aRv = Send(RequestBody(&aArrayBufferView));
} }

View File

@ -338,13 +338,15 @@ public:
void BlendFuncSeparate(WebGLenum srcRGB, WebGLenum dstRGB, void BlendFuncSeparate(WebGLenum srcRGB, WebGLenum dstRGB,
WebGLenum srcAlpha, WebGLenum dstAlpha); WebGLenum srcAlpha, WebGLenum dstAlpha);
void BufferData(WebGLenum target, WebGLsizeiptr size, WebGLenum usage); 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<dom::ArrayBuffer> &maybeData,
WebGLenum usage); WebGLenum usage);
void BufferData(WebGLenum target, dom::ArrayBuffer *data, WebGLenum usage);
void BufferSubData(WebGLenum target, WebGLsizeiptr byteOffset, void BufferSubData(WebGLenum target, WebGLsizeiptr byteOffset,
dom::ArrayBufferView &data); const dom::ArrayBufferView &data);
void BufferSubData(WebGLenum target, WebGLsizeiptr byteOffset, void BufferSubData(WebGLenum target, WebGLsizeiptr byteOffset,
dom::ArrayBuffer *data); const Nullable<dom::ArrayBuffer> &maybeData);
WebGLenum CheckFramebufferStatus(WebGLenum target); WebGLenum CheckFramebufferStatus(WebGLenum target);
void Clear(WebGLbitfield mask); void Clear(WebGLbitfield mask);
void ClearColor(WebGLclampf r, WebGLclampf g, WebGLclampf b, WebGLclampf a); void ClearColor(WebGLclampf r, WebGLclampf g, WebGLclampf b, WebGLclampf a);
@ -355,11 +357,12 @@ public:
void CompressedTexImage2D(WebGLenum target, WebGLint level, void CompressedTexImage2D(WebGLenum target, WebGLint level,
WebGLenum internalformat, WebGLsizei width, WebGLenum internalformat, WebGLsizei width,
WebGLsizei height, WebGLint border, WebGLsizei height, WebGLint border,
dom::ArrayBufferView& view); const dom::ArrayBufferView& view);
void CompressedTexSubImage2D(WebGLenum target, WebGLint level, void CompressedTexSubImage2D(WebGLenum target, WebGLint level,
WebGLint xoffset, WebGLint yoffset, WebGLint xoffset, WebGLint yoffset,
WebGLsizei width, WebGLsizei height, WebGLsizei width, WebGLsizei height,
WebGLenum format, dom::ArrayBufferView& view); WebGLenum format,
const dom::ArrayBufferView& view);
void CopyTexImage2D(WebGLenum target, WebGLint level, void CopyTexImage2D(WebGLenum target, WebGLint level,
WebGLenum internalformat, WebGLint x, WebGLint y, WebGLenum internalformat, WebGLint x, WebGLint y,
WebGLsizei width, WebGLsizei height, WebGLint border); WebGLsizei width, WebGLsizei height, WebGLint border);
@ -487,7 +490,8 @@ public:
} }
void ReadPixels(WebGLint x, WebGLint y, WebGLsizei width, WebGLsizei height, void ReadPixels(WebGLint x, WebGLint y, WebGLsizei width, WebGLsizei height,
WebGLenum format, WebGLenum type, WebGLenum format, WebGLenum type,
dom::ArrayBufferView* pixels, ErrorResult& rv); const Nullable<dom::ArrayBufferView> &pixels,
ErrorResult& rv);
void RenderbufferStorage(WebGLenum target, WebGLenum internalformat, void RenderbufferStorage(WebGLenum target, WebGLenum internalformat,
WebGLsizei width, WebGLsizei height); WebGLsizei width, WebGLsizei height);
void SampleCoverage(WebGLclampf value, WebGLboolean invert) { void SampleCoverage(WebGLclampf value, WebGLboolean invert) {
@ -509,7 +513,8 @@ public:
void TexImage2D(WebGLenum target, WebGLint level, void TexImage2D(WebGLenum target, WebGLint level,
WebGLenum internalformat, WebGLsizei width, WebGLenum internalformat, WebGLsizei width,
WebGLsizei height, WebGLint border, WebGLenum format, WebGLsizei height, WebGLint border, WebGLenum format,
WebGLenum type, dom::ArrayBufferView *pixels, WebGLenum type,
const Nullable<dom::ArrayBufferView> &pixels,
ErrorResult& rv); ErrorResult& rv);
void TexImage2D(WebGLenum target, WebGLint level, void TexImage2D(WebGLenum target, WebGLint level,
WebGLenum internalformat, WebGLenum format, WebGLenum type, WebGLenum internalformat, WebGLenum format, WebGLenum type,
@ -547,7 +552,8 @@ public:
void TexSubImage2D(WebGLenum target, WebGLint level, void TexSubImage2D(WebGLenum target, WebGLint level,
WebGLint xoffset, WebGLint yoffset, WebGLint xoffset, WebGLint yoffset,
WebGLsizei width, WebGLsizei height, WebGLenum format, WebGLsizei width, WebGLsizei height, WebGLenum format,
WebGLenum type, dom::ArrayBufferView* pixels, WebGLenum type,
const Nullable<dom::ArrayBufferView> &pixels,
ErrorResult& rv); ErrorResult& rv);
void TexSubImage2D(WebGLenum target, WebGLint level, void TexSubImage2D(WebGLenum target, WebGLint level,
WebGLint xoffset, WebGLint yoffset, WebGLenum format, WebGLint xoffset, WebGLint yoffset, WebGLenum format,
@ -592,7 +598,8 @@ public:
void Uniform4f(WebGLUniformLocation* location, WebGLfloat x, WebGLfloat y, void Uniform4f(WebGLUniformLocation* location, WebGLfloat x, WebGLfloat y,
WebGLfloat z, WebGLfloat w); 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()); Uniform1iv_base(location, arr.Length(), arr.Data());
} }
void Uniform1iv(WebGLUniformLocation* location, void Uniform1iv(WebGLUniformLocation* location,
@ -602,7 +609,8 @@ public:
void Uniform1iv_base(WebGLUniformLocation* location, uint32_t arrayLength, void Uniform1iv_base(WebGLUniformLocation* location, uint32_t arrayLength,
const WebGLint* data); 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()); Uniform2iv_base(location, arr.Length(), arr.Data());
} }
void Uniform2iv(WebGLUniformLocation* location, void Uniform2iv(WebGLUniformLocation* location,
@ -612,7 +620,8 @@ public:
void Uniform2iv_base(WebGLUniformLocation* location, uint32_t arrayLength, void Uniform2iv_base(WebGLUniformLocation* location, uint32_t arrayLength,
const WebGLint* data); 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()); Uniform3iv_base(location, arr.Length(), arr.Data());
} }
void Uniform3iv(WebGLUniformLocation* location, void Uniform3iv(WebGLUniformLocation* location,
@ -622,7 +631,8 @@ public:
void Uniform3iv_base(WebGLUniformLocation* location, uint32_t arrayLength, void Uniform3iv_base(WebGLUniformLocation* location, uint32_t arrayLength,
const WebGLint* data); 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()); Uniform4iv_base(location, arr.Length(), arr.Data());
} }
void Uniform4iv(WebGLUniformLocation* location, void Uniform4iv(WebGLUniformLocation* location,
@ -632,7 +642,8 @@ public:
void Uniform4iv_base(WebGLUniformLocation* location, uint32_t arrayLength, void Uniform4iv_base(WebGLUniformLocation* location, uint32_t arrayLength,
const WebGLint* data); 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()); Uniform1fv_base(location, arr.Length(), arr.Data());
} }
void Uniform1fv(WebGLUniformLocation* location, void Uniform1fv(WebGLUniformLocation* location,
@ -642,7 +653,8 @@ public:
void Uniform1fv_base(WebGLUniformLocation* location, uint32_t arrayLength, void Uniform1fv_base(WebGLUniformLocation* location, uint32_t arrayLength,
const WebGLfloat* data); 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()); Uniform2fv_base(location, arr.Length(), arr.Data());
} }
void Uniform2fv(WebGLUniformLocation* location, void Uniform2fv(WebGLUniformLocation* location,
@ -652,7 +664,8 @@ public:
void Uniform2fv_base(WebGLUniformLocation* location, uint32_t arrayLength, void Uniform2fv_base(WebGLUniformLocation* location, uint32_t arrayLength,
const WebGLfloat* data); 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()); Uniform3fv_base(location, arr.Length(), arr.Data());
} }
void Uniform3fv(WebGLUniformLocation* location, void Uniform3fv(WebGLUniformLocation* location,
@ -662,7 +675,8 @@ public:
void Uniform3fv_base(WebGLUniformLocation* location, uint32_t arrayLength, void Uniform3fv_base(WebGLUniformLocation* location, uint32_t arrayLength,
const WebGLfloat* data); 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()); Uniform4fv_base(location, arr.Length(), arr.Data());
} }
void Uniform4fv(WebGLUniformLocation* location, void Uniform4fv(WebGLUniformLocation* location,
@ -674,7 +688,7 @@ public:
void UniformMatrix2fv(WebGLUniformLocation* location, void UniformMatrix2fv(WebGLUniformLocation* location,
WebGLboolean transpose, WebGLboolean transpose,
dom::Float32Array &value) { const dom::Float32Array &value) {
UniformMatrix2fv_base(location, transpose, value.Length(), value.Data()); UniformMatrix2fv_base(location, transpose, value.Length(), value.Data());
} }
void UniformMatrix2fv(WebGLUniformLocation* location, void UniformMatrix2fv(WebGLUniformLocation* location,
@ -689,7 +703,7 @@ public:
void UniformMatrix3fv(WebGLUniformLocation* location, void UniformMatrix3fv(WebGLUniformLocation* location,
WebGLboolean transpose, WebGLboolean transpose,
dom::Float32Array &value) { const dom::Float32Array &value) {
UniformMatrix3fv_base(location, transpose, value.Length(), value.Data()); UniformMatrix3fv_base(location, transpose, value.Length(), value.Data());
} }
void UniformMatrix3fv(WebGLUniformLocation* location, void UniformMatrix3fv(WebGLUniformLocation* location,
@ -704,7 +718,7 @@ public:
void UniformMatrix4fv(WebGLUniformLocation* location, void UniformMatrix4fv(WebGLUniformLocation* location,
WebGLboolean transpose, WebGLboolean transpose,
dom::Float32Array &value) { const dom::Float32Array &value) {
UniformMatrix4fv_base(location, transpose, value.Length(), value.Data()); UniformMatrix4fv_base(location, transpose, value.Length(), value.Data());
} }
void UniformMatrix4fv(WebGLUniformLocation* location, void UniformMatrix4fv(WebGLUniformLocation* location,
@ -738,7 +752,7 @@ public:
void VertexAttrib4f(WebGLuint index, WebGLfloat x0, WebGLfloat x1, void VertexAttrib4f(WebGLuint index, WebGLfloat x0, WebGLfloat x1,
WebGLfloat x2, WebGLfloat x3); 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()); VertexAttrib1fv_base(idx, arr.Length(), arr.Data());
} }
void VertexAttrib1fv(WebGLuint idx, const dom::Sequence<WebGLfloat>& arr) { void VertexAttrib1fv(WebGLuint idx, const dom::Sequence<WebGLfloat>& arr) {
@ -747,7 +761,7 @@ public:
void VertexAttrib1fv_base(WebGLuint idx, uint32_t arrayLength, void VertexAttrib1fv_base(WebGLuint idx, uint32_t arrayLength,
const WebGLfloat* ptr); 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()); VertexAttrib2fv_base(idx, arr.Length(), arr.Data());
} }
void VertexAttrib2fv(WebGLuint idx, const dom::Sequence<WebGLfloat>& arr) { void VertexAttrib2fv(WebGLuint idx, const dom::Sequence<WebGLfloat>& arr) {
@ -756,7 +770,7 @@ public:
void VertexAttrib2fv_base(WebGLuint idx, uint32_t arrayLength, void VertexAttrib2fv_base(WebGLuint idx, uint32_t arrayLength,
const WebGLfloat* ptr); 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()); VertexAttrib3fv_base(idx, arr.Length(), arr.Data());
} }
void VertexAttrib3fv(WebGLuint idx, const dom::Sequence<WebGLfloat>& arr) { void VertexAttrib3fv(WebGLuint idx, const dom::Sequence<WebGLfloat>& arr) {
@ -765,7 +779,7 @@ public:
void VertexAttrib3fv_base(WebGLuint idx, uint32_t arrayLength, void VertexAttrib3fv_base(WebGLuint idx, uint32_t arrayLength,
const WebGLfloat* ptr); 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()); VertexAttrib4fv_base(idx, arr.Length(), arr.Data());
} }
void VertexAttrib4fv(WebGLuint idx, const dom::Sequence<WebGLfloat>& arr) { void VertexAttrib4fv(WebGLuint idx, const dom::Sequence<WebGLfloat>& arr) {

View File

@ -400,16 +400,20 @@ WebGLContext::BufferData(WebGLenum target, WebGLsizeiptr size,
} }
void void
WebGLContext::BufferData(WebGLenum target, ArrayBuffer *data, WebGLenum usage) WebGLContext::BufferData(WebGLenum target,
const Nullable<ArrayBuffer> &maybeData,
WebGLenum usage)
{ {
if (!IsContextStable()) if (!IsContextStable())
return; return;
if (!data) { if (maybeData.IsNull()) {
// see http://www.khronos.org/bugzilla/show_bug.cgi?id=386 // see http://www.khronos.org/bugzilla/show_bug.cgi?id=386
return ErrorInvalidValue("bufferData: null object passed"); return ErrorInvalidValue("bufferData: null object passed");
} }
const ArrayBuffer& data = maybeData.Value();
WebGLBuffer *boundBuffer = nullptr; WebGLBuffer *boundBuffer = nullptr;
if (target == LOCAL_GL_ARRAY_BUFFER) { if (target == LOCAL_GL_ARRAY_BUFFER) {
@ -429,21 +433,22 @@ WebGLContext::BufferData(WebGLenum target, ArrayBuffer *data, WebGLenum usage)
MakeContextCurrent(); MakeContextCurrent();
InvalidateCachedMinInUseAttribArrayLength(); InvalidateCachedMinInUseAttribArrayLength();
GLenum error = CheckedBufferData(target, data->Length(), data->Data(), usage); GLenum error = CheckedBufferData(target, data.Length(), data.Data(), usage);
if (error) { if (error) {
GenerateWarning("bufferData generated error %s", ErrorName(error)); GenerateWarning("bufferData generated error %s", ErrorName(error));
return; return;
} }
boundBuffer->SetByteLength(data->Length()); boundBuffer->SetByteLength(data.Length());
if (!boundBuffer->ElementArrayCacheBufferData(data->Data(), data->Length())) { if (!boundBuffer->ElementArrayCacheBufferData(data.Data(), data.Length())) {
return ErrorOutOfMemory("bufferData: out of memory"); return ErrorOutOfMemory("bufferData: out of memory");
} }
} }
void void
WebGLContext::BufferData(WebGLenum target, ArrayBufferView& data, WebGLenum usage) WebGLContext::BufferData(WebGLenum target, const ArrayBufferView& data,
WebGLenum usage)
{ {
if (!IsContextStable()) if (!IsContextStable())
return; return;
@ -481,16 +486,18 @@ WebGLContext::BufferData(WebGLenum target, ArrayBufferView& data, WebGLenum usag
void void
WebGLContext::BufferSubData(GLenum target, WebGLsizeiptr byteOffset, WebGLContext::BufferSubData(GLenum target, WebGLsizeiptr byteOffset,
ArrayBuffer *data) const Nullable<ArrayBuffer> &maybeData)
{ {
if (!IsContextStable()) if (!IsContextStable())
return; return;
if (!data) { if (maybeData.IsNull()) {
// see http://www.khronos.org/bugzilla/show_bug.cgi?id=386 // see http://www.khronos.org/bugzilla/show_bug.cgi?id=386
return; return;
} }
const ArrayBuffer& data = maybeData.Value();
WebGLBuffer *boundBuffer = nullptr; WebGLBuffer *boundBuffer = nullptr;
if (target == LOCAL_GL_ARRAY_BUFFER) { if (target == LOCAL_GL_ARRAY_BUFFER) {
@ -507,7 +514,7 @@ WebGLContext::BufferSubData(GLenum target, WebGLsizeiptr byteOffset,
if (!boundBuffer) if (!boundBuffer)
return ErrorInvalidOperation("bufferData: no buffer bound!"); return ErrorInvalidOperation("bufferData: no buffer bound!");
CheckedUint32 checked_neededByteLength = CheckedUint32(byteOffset) + data->Length(); CheckedUint32 checked_neededByteLength = CheckedUint32(byteOffset) + data.Length();
if (!checked_neededByteLength.isValid()) if (!checked_neededByteLength.isValid())
return ErrorInvalidValue("bufferSubData: integer overflow computing the needed byte length"); return ErrorInvalidValue("bufferSubData: integer overflow computing the needed byte length");
@ -517,14 +524,14 @@ WebGLContext::BufferSubData(GLenum target, WebGLsizeiptr byteOffset,
MakeContextCurrent(); 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 void
WebGLContext::BufferSubData(WebGLenum target, WebGLsizeiptr byteOffset, WebGLContext::BufferSubData(WebGLenum target, WebGLsizeiptr byteOffset,
ArrayBufferView& data) const ArrayBufferView& data)
{ {
if (!IsContextStable()) if (!IsContextStable())
return; return;
@ -3014,7 +3021,7 @@ WebGLContext::PixelStorei(WebGLenum pname, WebGLint param)
void void
WebGLContext::ReadPixels(WebGLint x, WebGLint y, WebGLsizei width, WebGLContext::ReadPixels(WebGLint x, WebGLint y, WebGLsizei width,
WebGLsizei height, WebGLenum format, WebGLsizei height, WebGLenum format,
WebGLenum type, ArrayBufferView* pixels, WebGLenum type, const Nullable<ArrayBufferView> &pixels,
ErrorResult& rv) ErrorResult& rv)
{ {
if (!IsContextStable()) { if (!IsContextStable()) {
@ -3029,7 +3036,7 @@ WebGLContext::ReadPixels(WebGLint x, WebGLint y, WebGLsizei width,
if (width < 0 || height < 0) if (width < 0 || height < 0)
return ErrorInvalidValue("readPixels: negative size passed"); return ErrorInvalidValue("readPixels: negative size passed");
if (!pixels) if (pixels.IsNull())
return ErrorInvalidValue("readPixels: null destination buffer"); return ErrorInvalidValue("readPixels: null destination buffer");
const WebGLRectangleObject *framebufferRect = FramebufferRectangleObject(); const WebGLRectangleObject *framebufferRect = FramebufferRectangleObject();
@ -3072,7 +3079,7 @@ WebGLContext::ReadPixels(WebGLint x, WebGLint y, WebGLsizei width,
return ErrorInvalidEnum("readPixels: Bad type"); return ErrorInvalidEnum("readPixels: Bad type");
} }
int dataType = JS_GetArrayBufferViewType(pixels->Obj()); int dataType = JS_GetArrayBufferViewType(pixels.Value().Obj());
// Check the pixels param type // Check the pixels param type
if (dataType != requiredDataType) if (dataType != requiredDataType)
@ -3090,11 +3097,11 @@ WebGLContext::ReadPixels(WebGLint x, WebGLint y, WebGLsizei width,
if (!checked_neededByteLength.isValid()) if (!checked_neededByteLength.isValid())
return ErrorInvalidOperation("readPixels: integer overflow computing the needed buffer size"); 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) if (checked_neededByteLength.value() > dataByteLen)
return ErrorInvalidOperation("readPixels: buffer too small"); return ErrorInvalidOperation("readPixels: buffer too small");
void* data = pixels->Data(); void* data = pixels.Value().Data();
if (!data) { if (!data) {
ErrorOutOfMemory("readPixels: buffer storage is null. Did we run out of memory?"); ErrorOutOfMemory("readPixels: buffer storage is null. Did we run out of memory?");
return rv.Throw(NS_ERROR_OUT_OF_MEMORY); return rv.Throw(NS_ERROR_OUT_OF_MEMORY);
@ -4289,7 +4296,7 @@ WebGLContext::CompileShader(WebGLShader *shader)
void void
WebGLContext::CompressedTexImage2D(WebGLenum target, WebGLint level, WebGLenum internalformat, WebGLContext::CompressedTexImage2D(WebGLenum target, WebGLint level, WebGLenum internalformat,
WebGLsizei width, WebGLsizei height, WebGLint border, WebGLsizei width, WebGLsizei height, WebGLint border,
ArrayBufferView& view) const ArrayBufferView& view)
{ {
if (!IsContextStable()) { if (!IsContextStable()) {
return; return;
@ -4329,7 +4336,7 @@ WebGLContext::CompressedTexImage2D(WebGLenum target, WebGLint level, WebGLenum i
void void
WebGLContext::CompressedTexSubImage2D(WebGLenum target, WebGLint level, WebGLint xoffset, WebGLContext::CompressedTexSubImage2D(WebGLenum target, WebGLint level, WebGLint xoffset,
WebGLint yoffset, WebGLsizei width, WebGLsizei height, WebGLint yoffset, WebGLsizei width, WebGLsizei height,
WebGLenum format, ArrayBufferView& view) WebGLenum format, const ArrayBufferView& view)
{ {
if (!IsContextStable()) { if (!IsContextStable()) {
return; return;
@ -4861,15 +4868,15 @@ void
WebGLContext::TexImage2D(WebGLenum target, WebGLint level, WebGLContext::TexImage2D(WebGLenum target, WebGLint level,
WebGLenum internalformat, WebGLsizei width, WebGLenum internalformat, WebGLsizei width,
WebGLsizei height, WebGLint border, WebGLenum format, WebGLsizei height, WebGLint border, WebGLenum format,
WebGLenum type, ArrayBufferView *pixels, ErrorResult& rv) WebGLenum type, const Nullable<ArrayBufferView> &pixels, ErrorResult& rv)
{ {
if (!IsContextStable()) if (!IsContextStable())
return; return;
return TexImage2D_base(target, level, internalformat, width, height, 0, border, format, type, return TexImage2D_base(target, level, internalformat, width, height, 0, border, format, type,
pixels ? pixels->Data() : 0, pixels.IsNull() ? 0 : pixels.Value().Data(),
pixels ? pixels->Length() : 0, pixels.IsNull() ? 0 : pixels.Value().Length(),
pixels ? (int)JS_GetArrayBufferViewType(pixels->Obj()) : -1, pixels.IsNull() ? -1 : (int)JS_GetArrayBufferViewType(pixels.Value().Obj()),
WebGLTexelConversions::Auto, false); WebGLTexelConversions::Auto, false);
} }
@ -5011,19 +5018,19 @@ WebGLContext::TexSubImage2D(WebGLenum target, WebGLint level,
WebGLint xoffset, WebGLint yoffset, WebGLint xoffset, WebGLint yoffset,
WebGLsizei width, WebGLsizei height, WebGLsizei width, WebGLsizei height,
WebGLenum format, WebGLenum type, WebGLenum format, WebGLenum type,
ArrayBufferView* pixels, const Nullable<ArrayBufferView> &pixels,
ErrorResult& rv) ErrorResult& rv)
{ {
if (!IsContextStable()) if (!IsContextStable())
return; return;
if (!pixels) if (pixels.IsNull())
return ErrorInvalidValue("texSubImage2D: pixels must not be null!"); return ErrorInvalidValue("texSubImage2D: pixels must not be null!");
return TexSubImage2D_base(target, level, xoffset, yoffset, return TexSubImage2D_base(target, level, xoffset, yoffset,
width, height, 0, format, type, width, height, 0, format, type,
pixels->Data(), pixels->Length(), pixels.Value().Data(), pixels.Value().Length(),
JS_GetArrayBufferViewType(pixels->Obj()), JS_GetArrayBufferViewType(pixels.Value().Obj()),
WebGLTexelConversions::Auto, false); WebGLTexelConversions::Auto, false);
} }

View File

@ -89,13 +89,13 @@ SourceBuffer::SetAppendWindowEnd(double aAppendWindowEnd, ErrorResult& aRv)
} }
void void
SourceBuffer::AppendBuffer(ArrayBuffer& aData, ErrorResult& aRv) SourceBuffer::AppendBuffer(const ArrayBuffer& aData, ErrorResult& aRv)
{ {
AppendData(aData.Data(), aData.Length(), aRv); AppendData(aData.Data(), aData.Length(), aRv);
} }
void void
SourceBuffer::AppendBuffer(ArrayBufferView& aData, ErrorResult& aRv) SourceBuffer::AppendBuffer(const ArrayBufferView& aData, ErrorResult& aRv)
{ {
AppendData(aData.Data(), aData.Length(), aRv); AppendData(aData.Data(), aData.Length(), aRv);
} }

View File

@ -62,8 +62,8 @@ public:
void SetAppendWindowEnd(double aAppendWindowEnd, ErrorResult& aRv); void SetAppendWindowEnd(double aAppendWindowEnd, ErrorResult& aRv);
void AppendBuffer(ArrayBuffer& aData, ErrorResult& aRv); void AppendBuffer(const ArrayBuffer& aData, ErrorResult& aRv);
void AppendBuffer(ArrayBufferView& aData, ErrorResult& aRv); void AppendBuffer(const ArrayBufferView& aData, ErrorResult& aRv);
void Abort(ErrorResult& aRv); void Abort(ErrorResult& aRv);

View File

@ -143,7 +143,7 @@ AnalyserNode::SetSmoothingTimeConstant(double aValue, ErrorResult& aRv)
} }
void void
AnalyserNode::GetFloatFrequencyData(Float32Array& aArray) AnalyserNode::GetFloatFrequencyData(const Float32Array& aArray)
{ {
if (!FFTAnalysis()) { if (!FFTAnalysis()) {
// Might fail to allocate memory // Might fail to allocate memory
@ -159,7 +159,7 @@ AnalyserNode::GetFloatFrequencyData(Float32Array& aArray)
} }
void void
AnalyserNode::GetByteFrequencyData(Uint8Array& aArray) AnalyserNode::GetByteFrequencyData(const Uint8Array& aArray)
{ {
if (!FFTAnalysis()) { if (!FFTAnalysis()) {
// Might fail to allocate memory // Might fail to allocate memory
@ -181,7 +181,7 @@ AnalyserNode::GetByteFrequencyData(Uint8Array& aArray)
} }
void void
AnalyserNode::GetByteTimeDomainData(Uint8Array& aArray) AnalyserNode::GetByteTimeDomainData(const Uint8Array& aArray)
{ {
unsigned char* buffer = aArray.Data(); unsigned char* buffer = aArray.Data();
uint32_t length = std::min(aArray.Length(), mBuffer.Length()); uint32_t length = std::min(aArray.Length(), mBuffer.Length());

View File

@ -25,9 +25,9 @@ public:
virtual JSObject* WrapObject(JSContext* aCx, virtual JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aScope) MOZ_OVERRIDE; JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
void GetFloatFrequencyData(Float32Array& aArray); void GetFloatFrequencyData(const Float32Array& aArray);
void GetByteFrequencyData(Uint8Array& aArray); void GetByteFrequencyData(const Uint8Array& aArray);
void GetByteTimeDomainData(Uint8Array& aArray); void GetByteTimeDomainData(const Uint8Array& aArray);
uint32_t FftSize() const uint32_t FftSize() const
{ {
return mAnalysisBlock.FFTSize(); return mAnalysisBlock.FFTSize();

View File

@ -160,7 +160,7 @@ AudioContext::CreateBuffer(JSContext* aJSContext, uint32_t aNumberOfChannels,
} }
already_AddRefed<AudioBuffer> already_AddRefed<AudioBuffer>
AudioContext::CreateBuffer(JSContext* aJSContext, ArrayBuffer& aBuffer, AudioContext::CreateBuffer(JSContext* aJSContext, const ArrayBuffer& aBuffer,
bool aMixToMono, ErrorResult& aRv) bool aMixToMono, ErrorResult& aRv)
{ {
// Do not accept this method unless the legacy pref has been set. // Do not accept this method unless the legacy pref has been set.

View File

@ -124,7 +124,7 @@ public:
ErrorResult& aRv); ErrorResult& aRv);
already_AddRefed<AudioBuffer> already_AddRefed<AudioBuffer>
CreateBuffer(JSContext* aJSContext, ArrayBuffer& aBuffer, CreateBuffer(JSContext* aJSContext, const ArrayBuffer& aBuffer,
bool aMixToMono, ErrorResult& aRv); bool aMixToMono, ErrorResult& aRv);
already_AddRefed<MediaStreamAudioDestinationNode> already_AddRefed<MediaStreamAudioDestinationNode>

View File

@ -248,8 +248,8 @@ BiquadFilterNode::SetType(BiquadFilterType aType)
void void
BiquadFilterNode::GetFrequencyResponse(const Float32Array& aFrequencyHz, BiquadFilterNode::GetFrequencyResponse(const Float32Array& aFrequencyHz,
Float32Array& aMagResponse, const Float32Array& aMagResponse,
Float32Array& aPhaseResponse) const Float32Array& aPhaseResponse)
{ {
uint32_t length = std::min(std::min(aFrequencyHz.Length(), aMagResponse.Length()), uint32_t length = std::min(std::min(aFrequencyHz.Length(), aMagResponse.Length()),
aPhaseResponse.Length()); aPhaseResponse.Length());

View File

@ -54,8 +54,8 @@ public:
} }
void GetFrequencyResponse(const Float32Array& aFrequencyHz, void GetFrequencyResponse(const Float32Array& aFrequencyHz,
Float32Array& aMagResponse, const Float32Array& aMagResponse,
Float32Array& aPhaseResponse); const Float32Array& aPhaseResponse);
private: private:
static void SendFrequencyToStream(AudioNode* aNode); static void SendFrequencyToStream(AudioNode* aNode);

View File

@ -121,14 +121,14 @@ WaveShaperNode::WrapObject(JSContext *aCx, JS::Handle<JSObject*> aScope)
} }
void void
WaveShaperNode::SetCurve(const Float32Array* aCurve) WaveShaperNode::SetCurve(const Nullable<Float32Array>& aCurve)
{ {
nsTArray<float> curve; nsTArray<float> curve;
if (aCurve) { if (!aCurve.IsNull()) {
mCurve = aCurve->Obj(); mCurve = aCurve.Value().Obj();
curve.SetLength(aCurve->Length()); curve.SetLength(aCurve.Value().Length());
PodCopy(curve.Elements(), aCurve->Data(), aCurve->Length()); PodCopy(curve.Elements(), aCurve.Value().Data(), aCurve.Value().Length());
} else { } else {
mCurve = nullptr; mCurve = nullptr;
} }

View File

@ -31,7 +31,7 @@ public:
{ {
return mCurve; return mCurve;
} }
void SetCurve(const Float32Array* aData); void SetCurve(const Nullable<Float32Array>& aData);
private: private:
void ClearCurve(); void ClearCurve();

View File

@ -55,7 +55,8 @@ Crypto::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
} }
JSObject * 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"); NS_ABORT_IF_FALSE(NS_IsMainThread(), "Called on the wrong thread");

View File

@ -34,7 +34,8 @@ public:
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Crypto) NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Crypto)
JSObject * JSObject *
GetRandomValues(JSContext* aCx, ArrayBufferView& aArray, ErrorResult& aRv); GetRandomValues(JSContext* aCx, const ArrayBufferView& aArray,
ErrorResult& aRv);
#ifndef MOZ_DISABLE_CRYPTOLEGACY #ifndef MOZ_DISABLE_CRYPTOLEGACY
virtual bool EnableSmartCardEvents() = 0; virtual bool EnableSmartCardEvents() = 0;

View File

@ -3205,55 +3205,24 @@ for (uint32_t i = 0; i < length; ++i) {
"arraybuffer views because making sure all the " "arraybuffer views because making sure all the "
"objects are properly rooted is hard") "objects are properly rooted is hard")
name = type.name name = type.name
# By default, we use a Maybe<> to hold our typed array. And in the optional declType = CGGeneric(name)
# non-nullable case we want to pass Optional<TypedArray> to consumers, not
# Optional<NonNull<TypedArray> >, so jump though some hoops to do that.
holderType = "Maybe<%s>" % name
constructLoc = "${holderName}"
constructMethod = "construct"
constructInternal = "ref"
if type.nullable(): if type.nullable():
if isOptional: declType = CGTemplatedType("Nullable", declType)
declType = "Optional<" + name + "*>" objRef = "${declName}.SetValue()"
else:
declType = name + "*"
else: else:
if isOptional: objRef = "${declName}"
declType = "Optional<" + name + ">"
# We don't need a holder in this case
holderType = None
constructLoc = "${declName}"
constructMethod = "Construct"
constructInternal = "Value"
else:
declType = "NonNull<" + name + ">"
template = ( template = (
"%s.%s(&${val}.toObject());\n" "if (!%s.Init(&${val}.toObject())) {\n"
"if (!%s.%s().inited()) {\n"
"%s" # No newline here because onFailureBadType() handles that "%s" # No newline here because onFailureBadType() handles that
"}\n" % "}\n" %
(constructLoc, constructMethod, constructLoc, constructInternal, (objRef,
CGIndenter(onFailureBadType(failureCode, type.name)).define())) CGIndenter(onFailureBadType(failureCode, type.name)).define()))
nullableTarget = "" template = wrapObjectTemplate(template, type, "${declName}.SetNull()",
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,
failureCode) 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, return JSToNativeConversionInfo(template,
declType=CGGeneric(declType), declType=declType,
holderType=holderType) dealWithOptional=isOptional)
if type.isDOMString(): if type.isDOMString():
assert not isEnforceRange and not isClamp assert not isEnforceRange and not isClamp
@ -3886,7 +3855,7 @@ class CGArgumentConverter(CGThing):
sequenceWrapLevel = 0 sequenceWrapLevel = 0
def getWrapTemplateForType(type, descriptorProvider, result, successCode, 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 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 "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 doing a 'break' if the entire conversion template is inside a block that
the 'break' will exit). 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 The resulting string should be used with string.Template. It
needs the following keys when substituting: needs the following keys when substituting:
@ -3970,7 +3942,8 @@ def getWrapTemplateForType(type, descriptorProvider, result, successCode,
# Nullable sequences are Nullable< nsTArray<T> > # Nullable sequences are Nullable< nsTArray<T> >
(recTemplate, recInfall) = getWrapTemplateForType(type.inner, descriptorProvider, (recTemplate, recInfall) = getWrapTemplateForType(type.inner, descriptorProvider,
"%s.Value()" % result, successCode, "%s.Value()" % result, successCode,
isCreator, exceptionCode) isCreator, exceptionCode,
typedArraysAreStructs)
return (""" return ("""
if (%s.IsNull()) { if (%s.IsNull()) {
%s %s
@ -4135,7 +4108,8 @@ if (!returnArray) {
# NB: setValue(..., True) calls JS_WrapValue(), so is fallible # NB: setValue(..., True) calls JS_WrapValue(), so is fallible
return (setValue(result, "value"), False) 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 # See comments in WrapNewBindingObject explaining why we need
# to wrap here. # to wrap here.
if type.nullable(): if type.nullable():
@ -4153,17 +4127,28 @@ if (!returnArray) {
# NB: setValue(..., True) calls JS_WrapValue(), so is fallible # NB: setValue(..., True) calls JS_WrapValue(), so is fallible
return (setValue(toValue % result, wrapType), False) 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) raise TypeError("Need to learn to wrap %s" % type)
if type.nullable(): if type.nullable():
(recTemplate, recInfal) = getWrapTemplateForType(type.inner, descriptorProvider, (recTemplate, recInfal) = getWrapTemplateForType(type.inner, descriptorProvider,
"%s.Value()" % result, successCode, "%s.Value()" % result, successCode,
isCreator, exceptionCode) isCreator, exceptionCode,
typedArraysAreStructs)
return ("if (%s.IsNull()) {\n" % result + return ("if (%s.IsNull()) {\n" % result +
CGIndenter(CGGeneric(setValue("JSVAL_NULL"))).define() + "\n" + CGIndenter(CGGeneric(setValue("JSVAL_NULL"))).define() + "\n" +
"}\n" + recTemplate, recInfal) "}\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(): if type.isUnion():
return (wrapAndSetPtr("%s.ToJSVal(cx, ${obj}, ${jsvalHandle})" % result), return (wrapAndSetPtr("%s.ToJSVal(cx, ${obj}, ${jsvalHandle})" % result),
False) False)
@ -4234,7 +4219,9 @@ def wrapForType(type, descriptorProvider, templateValues):
templateValues.get('successCode', None), templateValues.get('successCode', None),
templateValues.get('isCreator', False), templateValues.get('isCreator', False),
templateValues.get('exceptionCode', templateValues.get('exceptionCode',
"return false;"))[0] "return false;"),
templateValues.get('typedArraysAreStructs',
False))[0]
defaultValues = {'obj': 'obj'} defaultValues = {'obj': 'obj'}
return string.Template(wrap).substitute(defaultValues, **templateValues) return string.Template(wrap).substitute(defaultValues, **templateValues)
@ -4251,7 +4238,8 @@ def infallibleForMember(member, type, descriptorProvider):
failure conditions. failure conditions.
""" """
return getWrapTemplateForType(type, descriptorProvider, 'result', None,\ return getWrapTemplateForType(type, descriptorProvider, 'result', None,\
memberIsCreator(member), "return false;")[1] memberIsCreator(member), "return false;",
False)[1]
def typeNeedsCx(type, descriptorProvider, retVal=False): def typeNeedsCx(type, descriptorProvider, retVal=False):
if type is None: if type is None:
@ -4442,11 +4430,13 @@ class CGCallGenerator(CGThing):
return True return True
if a.type.isUnion(): if a.type.isUnion():
return True return True
if a.type.isSpiderMonkeyInterface():
return True
return False return False
if needsConst(a): if needsConst(a):
arg = CGWrapper(arg, pre="Constify(", post=")") arg = CGWrapper(arg, pre="Constify(", post=")")
# And convert NonNull<T> to T& # And convert NonNull<T> 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 not a.type.nullable()) or
a.type.isDOMString()): a.type.isDOMString()):
arg = CGWrapper(arg, pre="NonNullHelper(", post=")") arg = CGWrapper(arg, pre="NonNullHelper(", post=")")
@ -5893,10 +5883,8 @@ def getUnionAccessorSignatureType(type, descriptorProvider):
if type.isSpiderMonkeyInterface(): if type.isSpiderMonkeyInterface():
typeName = CGGeneric(type.name) typeName = CGGeneric(type.name)
if type.nullable(): if type.nullable():
typeName = CGWrapper(typeName, post="*") typeName = CGTemplatedType("Nullable", typeName)
else: return CGWrapper(typeName, post="&")
typeName = CGWrapper(typeName, post="&")
return typeName
if type.isDOMString(): if type.isDOMString():
return CGGeneric("const nsAString&") return CGGeneric("const nsAString&")
@ -6146,11 +6134,6 @@ ${doConversionsToJS}
(templateVars, type) = arg (templateVars, type) = arg
assert not type.nullable() # flatMemberTypes never has nullable types assert not type.nullable() # flatMemberTypes never has nullable types
val = "mValue.m%(name)s.Value()" % templateVars val = "mValue.m%(name)s.Value()" % templateVars
if type.isSpiderMonkeyInterface():
# We have a NonNull<TypedArray> 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( wrapCode = wrapForType(
type, self.descriptorProvider, type, self.descriptorProvider,
{ {
@ -6158,6 +6141,7 @@ ${doConversionsToJS}
"jsvalHandle": "rval", "jsvalHandle": "rval",
"obj": "scopeObj", "obj": "scopeObj",
"result": val, "result": val,
"typedArraysAreStructs": True
}) })
return CGIndenter(CGList([CGGeneric("case e%(name)s:" % templateVars), return CGIndenter(CGList([CGGeneric("case e%(name)s:" % templateVars),
CGWrapper(CGIndenter(CGGeneric(wrapCode)), CGWrapper(CGIndenter(CGGeneric(wrapCode)),
@ -8988,9 +8972,9 @@ class CGNativeMember(ClassMethod):
return "JSObject*", "nullptr", "return ${declName};" return "JSObject*", "nullptr", "return ${declName};"
if type.isSpiderMonkeyInterface(): if type.isSpiderMonkeyInterface():
if type.nullable(): if type.nullable():
returnCode = "return ${declName} ? ${declName}->Obj() : nullptr;" returnCode = "return ${declName}.IsNull() ? nullptr : ${declName}.Value().Obj();"
else: else:
returnCode = ("return static_cast<%s&>(${declName}).Obj();" % type.name) returnCode = "return ${declName}.Obj();"
return "JSObject*", "nullptr", returnCode return "JSObject*", "nullptr", returnCode
if type.isSequence(): if type.isSequence():
# If we want to handle sequence-of-sequences return values, we're # If we want to handle sequence-of-sequences return values, we're
@ -9105,16 +9089,9 @@ class CGNativeMember(ClassMethod):
if type.isSpiderMonkeyInterface(): if type.isSpiderMonkeyInterface():
assert not isMember assert not isMember
if self.jsObjectsArePtr: if self.jsObjectsArePtr:
typeDecl = "JSObject*" return "JSObject*", False, False
else:
if type.nullable(): return type.name, True, True
typeDecl = "%s*"
else:
typeDecl = "%s"
if not optional:
typeDecl += "&"
typeDecl = typeDecl % type.name
return typeDecl, False, False
if type.isDOMString(): if type.isDOMString():
if isMember: if isMember:

View File

@ -38,10 +38,11 @@ private:
JSObject* mObj; JSObject* mObj;
public: public:
inline void Init(JSObject* obj) inline bool Init(JSObject* obj)
{ {
MOZ_ASSERT(!inited()); MOZ_ASSERT(!inited());
DoInit(obj); DoInit(obj);
return inited();
} }
inline bool inited() const { inline bool inited() const {

View File

@ -384,21 +384,21 @@ public:
void ReceiveSequenceOfSequences(nsTArray< nsTArray<int32_t> >&); void ReceiveSequenceOfSequences(nsTArray< nsTArray<int32_t> >&);
// Typed array types // Typed array types
void PassArrayBuffer(ArrayBuffer&); void PassArrayBuffer(const ArrayBuffer&);
void PassNullableArrayBuffer(ArrayBuffer*); void PassNullableArrayBuffer(const Nullable<ArrayBuffer>&);
void PassOptionalArrayBuffer(const Optional<ArrayBuffer>&); void PassOptionalArrayBuffer(const Optional<ArrayBuffer>&);
void PassOptionalNullableArrayBuffer(const Optional<ArrayBuffer*>&); void PassOptionalNullableArrayBuffer(const Optional<Nullable<ArrayBuffer> >&);
void PassOptionalNullableArrayBufferWithDefaultValue(ArrayBuffer*); void PassOptionalNullableArrayBufferWithDefaultValue(const Nullable<ArrayBuffer>&);
void PassArrayBufferView(ArrayBufferView&); void PassArrayBufferView(const ArrayBufferView&);
void PassInt8Array(Int8Array&); void PassInt8Array(const Int8Array&);
void PassInt16Array(Int16Array&); void PassInt16Array(const Int16Array&);
void PassInt32Array(Int32Array&); void PassInt32Array(const Int32Array&);
void PassUint8Array(Uint8Array&); void PassUint8Array(const Uint8Array&);
void PassUint16Array(Uint16Array&); void PassUint16Array(const Uint16Array&);
void PassUint32Array(Uint32Array&); void PassUint32Array(const Uint32Array&);
void PassUint8ClampedArray(Uint8ClampedArray&); void PassUint8ClampedArray(const Uint8ClampedArray&);
void PassFloat32Array(Float32Array&); void PassFloat32Array(const Float32Array&);
void PassFloat64Array(Float64Array&); void PassFloat64Array(const Float64Array&);
JSObject* ReceiveUint8Array(JSContext*); JSObject* ReceiveUint8Array(JSContext*);
// DOMString types // DOMString types

View File

@ -176,12 +176,12 @@ public:
} }
void void
Send(ArrayBuffer& aBody, ErrorResult& aRv) { Send(const ArrayBuffer& aBody, ErrorResult& aRv) {
return Send(aBody.Obj(), aRv); return Send(aBody.Obj(), aRv);
} }
void void
Send(ArrayBufferView& aBody, ErrorResult& aRv) { Send(const ArrayBufferView& aBody, ErrorResult& aRv) {
return Send(aBody.Obj(), aRv); return Send(aBody.Obj(), aRv);
} }