Bug 656519 - Fix consumers outside SpiderMonkey to use new ArrayBuffer APIs. r=mrbkap

--HG--
extra : rebase_source : f359987831611155029114b5f85080155c6a12d5
This commit is contained in:
Nikhil Marathe 2011-06-14 15:37:21 -04:00
Родитель b8cff7804c
Коммит e8a2d9bc3e
8 изменённых файлов: 45 добавлений и 41 удалений

Просмотреть файл

@ -5538,17 +5538,17 @@ CloneSimpleValues(JSContext* cx,
// ArrayBuffer objects.
if (js_IsArrayBuffer(obj)) {
js::ArrayBuffer* src = js::ArrayBuffer::fromJSObject(obj);
JSObject* src = js::ArrayBuffer::getArrayBuffer(src);
if (!src) {
return NS_ERROR_FAILURE;
}
JSObject* newBuffer = js_CreateArrayBuffer(cx, src->byteLength);
JSObject* newBuffer = js_CreateArrayBuffer(cx, js::ArrayBuffer::getByteLength(src));
if (!newBuffer) {
return NS_ERROR_FAILURE;
}
memcpy(js::ArrayBuffer::fromJSObject(newBuffer)->data, src->data,
src->byteLength);
memcpy(js::ArrayBuffer::getDataOffset(newBuffer), js::ArrayBuffer::getDataOffset(src),
js::ArrayBuffer::getByteLength(src));
return SetPropertyOnValueOrObject(cx, OBJECT_TO_JSVAL(newBuffer), rval,
robj, rid);
}

Просмотреть файл

@ -35,6 +35,7 @@
*
* ***** END LICENSE BLOCK ***** */
#include "jsobj.h"
#include "jstypedarray.h"
#include "nsAutoPtr.h"
#include "nsDOMClassInfo.h"
@ -234,7 +235,7 @@ protected:
nsresult AppendVoidPtr(void* aData, PRUint32 aLength);
nsresult AppendString(JSString* aString, JSContext* aCx);
nsresult AppendBlob(nsIDOMBlob* aBlob);
nsresult AppendArrayBuffer(js::ArrayBuffer* aBuffer);
nsresult AppendArrayBuffer(JSObject* aBuffer);
bool ExpandBufferSize(PRUint64 aSize)
{
@ -332,9 +333,9 @@ nsDOMBlobBuilder::AppendBlob(nsIDOMBlob* aBlob)
}
nsresult
nsDOMBlobBuilder::AppendArrayBuffer(js::ArrayBuffer* aBuffer)
nsDOMBlobBuilder::AppendArrayBuffer(JSObject* aBuffer)
{
return AppendVoidPtr(aBuffer->data, aBuffer->byteLength);
return AppendVoidPtr(js::ArrayBuffer::getDataOffset(aBuffer), js::ArrayBuffer::getByteLength(aBuffer));
}
/* nsIDOMBlob getBlob ([optional] in DOMString contentType); */
@ -379,7 +380,7 @@ nsDOMBlobBuilder::Append(const jsval& aData, JSContext* aCx)
// Is it an array buffer?
if (js_IsArrayBuffer(obj)) {
js::ArrayBuffer* buffer = js::ArrayBuffer::fromJSObject(obj);
JSObject* buffer = js::ArrayBuffer::getArrayBuffer(obj);
if (buffer)
return AppendArrayBuffer(buffer);
}

Просмотреть файл

@ -867,9 +867,9 @@ nsresult nsXMLHttpRequest::CreateResponseArrayBuffer(JSContext *aCx)
}
if (dataLen > 0) {
js::ArrayBuffer *abuf = js::ArrayBuffer::fromJSObject(mResultArrayBuffer);
JSObject *abuf = js::ArrayBuffer::getArrayBuffer(mResultArrayBuffer);
NS_ASSERTION(abuf, "What happened?");
memcpy(abuf->data, mResponseBody.BeginReading(), dataLen);
memcpy(js::ArrayBuffer::getDataOffset(abuf), mResponseBody.BeginReading(), dataLen);
}
return NS_OK;

Просмотреть файл

@ -102,7 +102,7 @@ nsIDOMWebGLRenderingContext_BufferData(JSContext *cx, uintN argc, jsval *vp)
int32 target;
js::TypedArray *wa = 0;
js::ArrayBuffer *wb = 0;
JSObject *wb = 0;
int32 size;
int32 usage;
@ -118,7 +118,7 @@ nsIDOMWebGLRenderingContext_BufferData(JSContext *cx, uintN argc, jsval *vp)
JSObject *arg2 = JSVAL_TO_OBJECT(argv[1]);
if (js_IsArrayBuffer(arg2)) {
wb = js::ArrayBuffer::fromJSObject(arg2);
wb = js::ArrayBuffer::getArrayBuffer(arg2);
} else if (js_IsTypedArray(arg2)) {
wa = js::TypedArray::fromJSObject(arg2);
}
@ -176,7 +176,7 @@ nsIDOMWebGLRenderingContext_BufferSubData(JSContext *cx, uintN argc, jsval *vp)
int32 target;
int32 offset;
js::TypedArray *wa = 0;
js::ArrayBuffer *wb = 0;
JSObject *wb = 0;
if (!JS_ValueToECMAInt32(cx, argv[0], &target))
return JS_FALSE;
@ -193,7 +193,7 @@ nsIDOMWebGLRenderingContext_BufferSubData(JSContext *cx, uintN argc, jsval *vp)
if (!nullobject) {
JSObject *arg3 = JSVAL_TO_OBJECT(argv[2]);
if (js_IsArrayBuffer(arg3)) {
wb = js::ArrayBuffer::fromJSObject(arg3);
wb = js::ArrayBuffer::getArrayBuffer(arg3);
} else if (js_IsTypedArray(arg3)) {
wa = js::TypedArray::fromJSObject(arg3);
} else {
@ -261,7 +261,7 @@ nsIDOMWebGLRenderingContext_ReadPixels(JSContext *cx, uintN argc, jsval *vp)
JSObject *argv6 = JSVAL_TO_OBJECT(argv[6]);
if (js_IsArrayBuffer(argv6)) {
rv = self->ReadPixels_buf(argv0, argv1, argv2, argv3,
argv4, argv5, js::ArrayBuffer::fromJSObject(argv6));
argv4, argv5, js::ArrayBuffer::getArrayBuffer(argv6));
} else if (js_IsTypedArray(argv6)) {
rv = self->ReadPixels_array(argv0, argv1, argv2, argv3,
argv4, argv5,
@ -381,7 +381,7 @@ nsIDOMWebGLRenderingContext_TexImage2D(JSContext *cx, uintN argc, jsval *vp)
} else if (js_IsArrayBuffer(argv8)) {
rv = self->TexImage2D_buf(argv0, argv1, argv2, argv3,
argv4, argv5, argv6, argv7,
js::ArrayBuffer::fromJSObject(argv8));
js::ArrayBuffer::getArrayBuffer(argv8));
} else if (js_IsTypedArray(argv8)) {
rv = self->TexImage2D_array(argv0, argv1, argv2, argv3,
argv4, argv5, argv6, argv7,
@ -493,7 +493,7 @@ nsIDOMWebGLRenderingContext_TexSubImage2D(JSContext *cx, uintN argc, jsval *vp)
if (js_IsArrayBuffer(argv8)) {
rv = self->TexSubImage2D_buf(argv0, argv1, argv2, argv3,
argv4, argv5, argv6, argv7,
js::ArrayBuffer::fromJSObject(argv8));
js::ArrayBuffer::getArrayBuffer(argv8));
} else if (js_IsTypedArray(argv8)) {
rv = self->TexSubImage2D_array(argv0, argv1, argv2, argv3,
argv4, argv5, argv6, argv7,

Просмотреть файл

@ -53,6 +53,7 @@
#include "CanvasUtils.h"
#include "jsobj.h"
#include "jstypedarray.h"
#if defined(USE_ANGLE)
@ -418,7 +419,7 @@ WebGLContext::BufferData_size(WebGLenum target, WebGLsizei size, WebGLenum usage
}
NS_IMETHODIMP
WebGLContext::BufferData_buf(WebGLenum target, js::ArrayBuffer *wb, WebGLenum usage)
WebGLContext::BufferData_buf(WebGLenum target, JSObject *wb, WebGLenum usage)
{
WebGLBuffer *boundBuffer = NULL;
@ -438,12 +439,12 @@ WebGLContext::BufferData_buf(WebGLenum target, js::ArrayBuffer *wb, WebGLenum us
MakeContextCurrent();
boundBuffer->SetByteLength(wb->byteLength);
if (!boundBuffer->CopyDataIfElementArray(wb->data))
boundBuffer->SetByteLength(js::ArrayBuffer::getByteLength(wb));
if (!boundBuffer->CopyDataIfElementArray(js::ArrayBuffer::getDataOffset(wb)))
return ErrorOutOfMemory("bufferData: out of memory");
boundBuffer->InvalidateCachedMaxElements();
gl->fBufferData(target, wb->byteLength, wb->data, usage);
gl->fBufferData(target, js::ArrayBuffer::getByteLength(wb), js::ArrayBuffer::getDataOffset(wb), usage);
return NS_OK;
}
@ -492,7 +493,7 @@ WebGLContext::BufferSubData_null()
}
NS_IMETHODIMP
WebGLContext::BufferSubData_buf(GLenum target, WebGLsizei byteOffset, js::ArrayBuffer *wb)
WebGLContext::BufferSubData_buf(GLenum target, WebGLsizei byteOffset, JSObject *wb)
{
WebGLBuffer *boundBuffer = NULL;
@ -510,20 +511,20 @@ WebGLContext::BufferSubData_buf(GLenum target, WebGLsizei byteOffset, js::ArrayB
if (!boundBuffer)
return ErrorInvalidOperation("BufferData: no buffer bound!");
CheckedUint32 checked_neededByteLength = CheckedUint32(byteOffset) + wb->byteLength;
CheckedUint32 checked_neededByteLength = CheckedUint32(byteOffset) + js::ArrayBuffer::getByteLength(wb);
if (!checked_neededByteLength.valid())
return ErrorInvalidOperation("bufferSubData: integer overflow computing the needed byte length");
if (checked_neededByteLength.value() > boundBuffer->ByteLength())
return ErrorInvalidOperation("BufferSubData: not enough data - operation requires %d bytes, but buffer only has %d bytes",
byteOffset, wb->byteLength, boundBuffer->ByteLength());
byteOffset, js::ArrayBuffer::getByteLength(wb), boundBuffer->ByteLength());
MakeContextCurrent();
boundBuffer->CopySubDataIfElementArray(byteOffset, wb->byteLength, wb->data);
boundBuffer->CopySubDataIfElementArray(byteOffset, js::ArrayBuffer::getByteLength(wb), js::ArrayBuffer::getDataOffset(wb));
boundBuffer->InvalidateCachedMaxElements();
gl->fBufferSubData(target, byteOffset, wb->byteLength, wb->data);
gl->fBufferSubData(target, byteOffset, js::ArrayBuffer::getByteLength(wb), js::ArrayBuffer::getDataOffset(wb));
return NS_OK;
}
@ -3084,11 +3085,11 @@ WebGLContext::ReadPixels_array(WebGLint x, WebGLint y, WebGLsizei width, WebGLsi
NS_IMETHODIMP
WebGLContext::ReadPixels_buf(WebGLint x, WebGLint y, WebGLsizei width, WebGLsizei height,
WebGLenum format, WebGLenum type, js::ArrayBuffer *pixels)
WebGLenum format, WebGLenum type, JSObject *pixels)
{
return ReadPixels_base(x, y, width, height, format, type,
pixels ? pixels->data : 0,
pixels ? pixels->byteLength : 0);
pixels ? js::ArrayBuffer::getDataOffset(pixels) : 0,
pixels ? js::ArrayBuffer::getByteLength(pixels) : 0);
}
NS_IMETHODIMP
@ -4283,11 +4284,11 @@ NS_IMETHODIMP
WebGLContext::TexImage2D_buf(WebGLenum target, WebGLint level, WebGLenum internalformat,
WebGLsizei width, WebGLsizei height, WebGLint border,
WebGLenum format, WebGLenum type,
js::ArrayBuffer *pixels)
JSObject *pixels)
{
return TexImage2D_base(target, level, internalformat, width, height, 0, border, format, type,
pixels ? pixels->data : 0,
pixels ? pixels->byteLength : 0,
pixels ? js::ArrayBuffer::getDataOffset(pixels) : 0,
pixels ? js::ArrayBuffer::getByteLength(pixels) : 0,
-1,
WebGLTexelFormat::Auto, PR_FALSE);
}
@ -4458,14 +4459,14 @@ WebGLContext::TexSubImage2D_buf(WebGLenum target, WebGLint level,
WebGLint xoffset, WebGLint yoffset,
WebGLsizei width, WebGLsizei height,
WebGLenum format, WebGLenum type,
js::ArrayBuffer *pixels)
JSObject *pixels)
{
if (!pixels)
return ErrorInvalidValue("TexSubImage2D: pixels must not be null!");
return TexSubImage2D_base(target, level, xoffset, yoffset,
width, height, 0, format, type,
pixels->data, pixels->byteLength,
js::ArrayBuffer::getDataOffset(pixels), js::ArrayBuffer::getByteLength(pixels),
-1,
WebGLTexelFormat::Auto, PR_FALSE);
}

Просмотреть файл

@ -44,6 +44,7 @@
#include "CheckedInt.h"
#include "jsobj.h"
#include "jstypedarray.h"
#if defined(USE_ANGLE)

Просмотреть файл

@ -38,6 +38,7 @@
* ***** END LICENSE BLOCK ***** */
#include "nsDOMNotifyAudioAvailableEvent.h"
#include "jsobj.h"
#include "jstypedarray.h"
nsDOMNotifyAudioAvailableEvent::nsDOMNotifyAudioAvailableEvent(nsPresContext* aPresContext,

Просмотреть файл

@ -68,8 +68,8 @@ struct TypedArray;
#undef NO_ERROR
%}
[ptr] native WebGLArrayBufferPtr (js::ArrayBuffer);
[ptr] native WebGLArrayPtr (js::TypedArray);
[ptr] native WebGLJSObjectPtr (JSObject);
//
// OpenGL object wrappers
@ -140,7 +140,7 @@ interface nsIWebGLExtension : nsISupports
{
};
[scriptable, uuid(44119fc2-b5f0-4acc-b836-5d28cc43e8fb)]
[scriptable, uuid(ef15ae85-4670-4dc4-848d-51ca81e8397a)]
interface nsIDOMWebGLRenderingContext : nsISupports
{
//
@ -587,12 +587,12 @@ interface nsIDOMWebGLRenderingContext : nsISupports
// Modified: void glBufferData(WebGLenum target, long size, const void* data, WebGLenum usage);
void bufferData([optional] in long dummy);
[noscript] void bufferData_size(in WebGLenum target, in WebGLsizei size, in WebGLenum usage);
[noscript] void bufferData_buf(in WebGLenum target, in WebGLArrayBufferPtr data, in WebGLenum usage);
[noscript] void bufferData_buf(in WebGLenum target, in WebGLJSObjectPtr data, in WebGLenum usage);
[noscript] void bufferData_array(in WebGLenum target, in WebGLArrayPtr data, in WebGLenum usage);
[noscript] void bufferData_null();
void bufferSubData([optional] in long dummy);
[noscript] void bufferSubData_buf(in WebGLenum target, in long offset, in WebGLArrayBufferPtr data);
[noscript] void bufferSubData_buf(in WebGLenum target, in long offset, in WebGLJSObjectPtr data);
[noscript] void bufferSubData_array(in WebGLenum target, in long offset, in WebGLArrayPtr data);
[noscript] void bufferSubData_null();
@ -716,7 +716,7 @@ interface nsIDOMWebGLRenderingContext : nsISupports
[noscript] void readPixels_array(in WebGLint x, in WebGLint y, in WebGLsizei width, in WebGLsizei height,
in WebGLenum format, in WebGLenum type, in WebGLArrayPtr pixels);
[noscript] void readPixels_buf(in WebGLint x, in WebGLint y, in WebGLsizei width, in WebGLsizei height,
in WebGLenum format, in WebGLenum type, in WebGLArrayBufferPtr pixels);
in WebGLenum format, in WebGLenum type, in WebGLJSObjectPtr pixels);
//void glReleaseShaderCompiler();
@ -737,7 +737,7 @@ interface nsIDOMWebGLRenderingContext : nsISupports
void texImage2D([optional] in long dummy);
[noscript] void texImage2D_buf(in WebGLenum target, in WebGLint level, in WebGLenum internalformat,
in WebGLsizei width, in WebGLsizei height,
in WebGLint border, in WebGLenum format, in WebGLenum type, in WebGLArrayBufferPtr pixels);
in WebGLint border, in WebGLenum format, in WebGLenum type, in WebGLJSObjectPtr pixels);
[noscript] void texImage2D_array(in WebGLenum target, in WebGLint level, in WebGLenum internalformat,
in WebGLsizei width, in WebGLsizei height,
in WebGLint border, in WebGLenum format, in WebGLenum type, in WebGLArrayPtr pixels);
@ -752,7 +752,7 @@ interface nsIDOMWebGLRenderingContext : nsISupports
void texSubImage2D([optional] in long dummy);
[noscript] void texSubImage2D_buf(in WebGLenum target, in WebGLint level,
in WebGLint xoffset, in WebGLint yoffset, in WebGLsizei width, in WebGLsizei height,
in WebGLenum format, in WebGLenum type, in WebGLArrayBufferPtr pixels);
in WebGLenum format, in WebGLenum type, in WebGLJSObjectPtr pixels);
[noscript] void texSubImage2D_array(in WebGLenum target, in WebGLint level,
in WebGLint xoffset, in WebGLint yoffset, in WebGLsizei width, in WebGLsizei height,
in WebGLenum format, in WebGLenum type, in WebGLArrayPtr pixels);