diff --git a/content/base/src/nsDOMBlobBuilder.cpp b/content/base/src/nsDOMBlobBuilder.cpp index 27d77281af21..0f02188ed075 100644 --- a/content/base/src/nsDOMBlobBuilder.cpp +++ b/content/base/src/nsDOMBlobBuilder.cpp @@ -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); */ diff --git a/content/base/src/nsXMLHttpRequest.cpp b/content/base/src/nsXMLHttpRequest.cpp index 8a360ee1921c..9ed16c640bf9 100644 --- a/content/base/src/nsXMLHttpRequest.cpp +++ b/content/base/src/nsXMLHttpRequest.cpp @@ -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; diff --git a/content/canvas/src/WebGLContextGL.cpp b/content/canvas/src/WebGLContextGL.cpp index b730c49596b6..693d4a520269 100644 --- a/content/canvas/src/WebGLContextGL.cpp +++ b/content/canvas/src/WebGLContextGL.cpp @@ -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); } diff --git a/content/canvas/src/WebGLContextValidate.cpp b/content/canvas/src/WebGLContextValidate.cpp index ef7a943a41ea..fa9334da890d 100644 --- a/content/canvas/src/WebGLContextValidate.cpp +++ b/content/canvas/src/WebGLContextValidate.cpp @@ -44,7 +44,6 @@ #include "CheckedInt.h" -#include "jsobj.h" #include "jstypedarray.h" #if defined(USE_ANGLE) diff --git a/content/events/src/nsDOMNotifyAudioAvailableEvent.cpp b/content/events/src/nsDOMNotifyAudioAvailableEvent.cpp index 5e38e0eb297e..acdd8d1b1681 100644 --- a/content/events/src/nsDOMNotifyAudioAvailableEvent.cpp +++ b/content/events/src/nsDOMNotifyAudioAvailableEvent.cpp @@ -38,7 +38,6 @@ * ***** END LICENSE BLOCK ***** */ #include "nsDOMNotifyAudioAvailableEvent.h" -#include "jsobj.h" #include "jstypedarray.h" nsDOMNotifyAudioAvailableEvent::nsDOMNotifyAudioAvailableEvent(nsPresContext* aPresContext, diff --git a/js/src/jsclone.cpp b/js/src/jsclone.cpp index 9482924591d1..be41b27af41d 100644 --- a/js/src/jsclone.cpp +++ b/js/src/jsclone.cpp @@ -42,6 +42,7 @@ #include "jstypedarray.h" #include "jsregexpinlines.h" +#include "jstypedarrayinlines.h" using namespace js; diff --git a/js/src/jstypedarray.cpp b/js/src/jstypedarray.cpp index cad28b6b79a8..64d69bf5b883 100644 --- a/js/src/jstypedarray.cpp +++ b/js/src/jstypedarray.cpp @@ -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) { diff --git a/js/src/jstypedarray.h b/js/src/jstypedarray.h index 76458e227823..c485c4d1897c 100644 --- a/js/src/jstypedarray.h +++ b/js/src/jstypedarray.h @@ -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 */ diff --git a/js/src/jstypedarrayinlines.h b/js/src/jstypedarrayinlines.h new file mode 100644 index 000000000000..0837f18cbf5f --- /dev/null +++ b/js/src/jstypedarrayinlines.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 + * + * 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 */