Make sure non-SpiderMonkey users don't require knowledge about JSObject when using ArrayBuffers. r=mrbkap

This commit is contained in:
Nikhil Marathe 2011-06-16 15:46:39 -04:00
Родитель a47384ceb8
Коммит 4600bb18b1
9 изменённых файлов: 97 добавлений и 27 удалений

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

@ -35,7 +35,6 @@
*
* ***** END LICENSE BLOCK ***** */
#include "jsobj.h"
#include "jstypedarray.h"
#include "nsAutoPtr.h"
#include "nsDOMClassInfo.h"
@ -335,7 +334,7 @@ nsDOMBlobBuilder::AppendBlob(nsIDOMBlob* aBlob)
nsresult
nsDOMBlobBuilder::AppendArrayBuffer(JSObject* aBuffer)
{
return AppendVoidPtr(js::ArrayBuffer::getDataOffset(aBuffer), js::ArrayBuffer::getByteLength(aBuffer));
return AppendVoidPtr(JS_GetArrayBufferData(aBuffer), JS_GetArrayBufferByteLength(aBuffer));
}
/* nsIDOMBlob getBlob ([optional] in DOMString contentType); */

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

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

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

@ -53,7 +53,6 @@
#include "CanvasUtils.h"
#include "jsobj.h"
#include "jstypedarray.h"
#if defined(USE_ANGLE)
@ -439,12 +438,12 @@ WebGLContext::BufferData_buf(WebGLenum target, JSObject *wb, WebGLenum usage)
MakeContextCurrent();
boundBuffer->SetByteLength(js::ArrayBuffer::getByteLength(wb));
if (!boundBuffer->CopyDataIfElementArray(js::ArrayBuffer::getDataOffset(wb)))
boundBuffer->SetByteLength(JS_GetArrayBufferByteLength(wb));
if (!boundBuffer->CopyDataIfElementArray(JS_GetArrayBufferData(wb)))
return ErrorOutOfMemory("bufferData: out of memory");
boundBuffer->InvalidateCachedMaxElements();
gl->fBufferData(target, js::ArrayBuffer::getByteLength(wb), js::ArrayBuffer::getDataOffset(wb), usage);
gl->fBufferData(target, JS_GetArrayBufferByteLength(wb), JS_GetArrayBufferData(wb), usage);
return NS_OK;
}
@ -511,20 +510,20 @@ WebGLContext::BufferSubData_buf(GLenum target, WebGLsizei byteOffset, JSObject *
if (!boundBuffer)
return ErrorInvalidOperation("BufferData: no buffer bound!");
CheckedUint32 checked_neededByteLength = CheckedUint32(byteOffset) + js::ArrayBuffer::getByteLength(wb);
CheckedUint32 checked_neededByteLength = CheckedUint32(byteOffset) + JS_GetArrayBufferByteLength(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, js::ArrayBuffer::getByteLength(wb), boundBuffer->ByteLength());
byteOffset, JS_GetArrayBufferByteLength(wb), boundBuffer->ByteLength());
MakeContextCurrent();
boundBuffer->CopySubDataIfElementArray(byteOffset, js::ArrayBuffer::getByteLength(wb), js::ArrayBuffer::getDataOffset(wb));
boundBuffer->CopySubDataIfElementArray(byteOffset, JS_GetArrayBufferByteLength(wb), JS_GetArrayBufferData(wb));
boundBuffer->InvalidateCachedMaxElements();
gl->fBufferSubData(target, byteOffset, js::ArrayBuffer::getByteLength(wb), js::ArrayBuffer::getDataOffset(wb));
gl->fBufferSubData(target, byteOffset, JS_GetArrayBufferByteLength(wb), JS_GetArrayBufferData(wb));
return NS_OK;
}
@ -3088,8 +3087,8 @@ WebGLContext::ReadPixels_buf(WebGLint x, WebGLint y, WebGLsizei width, WebGLsize
WebGLenum format, WebGLenum type, JSObject *pixels)
{
return ReadPixels_base(x, y, width, height, format, type,
pixels ? js::ArrayBuffer::getDataOffset(pixels) : 0,
pixels ? js::ArrayBuffer::getByteLength(pixels) : 0);
pixels ? JS_GetArrayBufferData(pixels) : 0,
pixels ? JS_GetArrayBufferByteLength(pixels) : 0);
}
NS_IMETHODIMP
@ -4287,8 +4286,8 @@ WebGLContext::TexImage2D_buf(WebGLenum target, WebGLint level, WebGLenum interna
JSObject *pixels)
{
return TexImage2D_base(target, level, internalformat, width, height, 0, border, format, type,
pixels ? js::ArrayBuffer::getDataOffset(pixels) : 0,
pixels ? js::ArrayBuffer::getByteLength(pixels) : 0,
pixels ? JS_GetArrayBufferData(pixels) : 0,
pixels ? JS_GetArrayBufferByteLength(pixels) : 0,
-1,
WebGLTexelFormat::Auto, PR_FALSE);
}
@ -4466,7 +4465,7 @@ WebGLContext::TexSubImage2D_buf(WebGLenum target, WebGLint level,
return TexSubImage2D_base(target, level, xoffset, yoffset,
width, height, 0, format, type,
js::ArrayBuffer::getDataOffset(pixels), js::ArrayBuffer::getByteLength(pixels),
JS_GetArrayBufferData(pixels), JS_GetArrayBufferByteLength(pixels),
-1,
WebGLTexelFormat::Auto, PR_FALSE);
}

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

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

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

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

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

@ -42,6 +42,7 @@
#include "jstypedarray.h"
#include "jsregexpinlines.h"
#include "jstypedarrayinlines.h"
using namespace js;

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

@ -63,6 +63,7 @@
#include "jstypedarray.h"
#include "jsobjinlines.h"
#include "jstypedarrayinlines.h"
using namespace js;
using namespace js::gc;
@ -1794,6 +1795,19 @@ js_IsArrayBuffer(JSObject *obj)
return obj->getClass() == &ArrayBuffer::fastClass;
}
JSUint32
JS_GetArrayBufferByteLength(JSObject *obj)
{
return *((JSUint32*) obj->slots);
}
uint8 *
JS_GetArrayBufferData(JSObject *obj)
{
uint64 *base = ((uint64*)obj->slots) + 1;
return (uint8*) base;
}
JS_FRIEND_API(JSBool)
js_IsTypedArray(JSObject *obj)
{

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

@ -108,16 +108,9 @@ struct JS_FRIEND_API(ArrayBuffer) {
static JSObject *
getArrayBuffer(JSObject *obj);
static inline unsigned int
getByteLength(JSObject *obj) {
return *((unsigned int*) obj->slots);
}
static inline unsigned int getByteLength(JSObject *obj);
static inline uint8 *
getDataOffset(JSObject *obj) {
uint64 *base = ((uint64*)obj->slots) + 1;
return (uint8*) base;
}
static inline uint8 * getDataOffset(JSObject *obj);
};
/*
@ -259,4 +252,10 @@ js_CreateTypedArrayWithBuffer(JSContext *cx, jsint atype, JSObject *bufArg,
extern int32 JS_FASTCALL
js_TypedArray_uint8_clamp_double(const double x);
JS_FRIEND_API(JSUint32)
JS_GetArrayBufferByteLength(JSObject *obj);
JS_FRIEND_API(uint8 *)
JS_GetArrayBufferData(JSObject *obj);
#endif /* jstypedarray_h */

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

@ -0,0 +1,60 @@
/* -*- Mode: c++; c-basic-offset: 4; tab-width: 40; indent-tabs-mode: nil -*- */
/* vim: set ts=40 sw=4 et tw=99: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla WebGL impl
*
* The Initial Developer of the Original Code is
* Mozilla Foundation
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Nikhil Marathe <nsm.nikhil@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef jstypedarrayinlines_h
#define jstypedarrayinlines_h
#include "jsapi.h"
#include "jsvalue.h"
#include "jsobj.h"
namespace js {
inline JSUint32
ArrayBuffer::getByteLength(JSObject *obj)
{
return *((JSUint32*) obj->slots);
}
inline uint8 *
ArrayBuffer::getDataOffset(JSObject *obj) {
uint64 *base = ((uint64*)obj->slots) + 1;
return (uint8*) base;
}
}
#endif /* jstypedarrayinlines_h */