Bug 807223 - Implement JS_ArrayBufferViewBuffer. r=sfink
authorRobert O'Callahan <robert@ocallahan.org>
Tue, 30 Oct 2012 21:26:32 -0700
changeset 120091 95187d8e170c6df98ca83267a65667a9bff92118
parent 120090 23c9f61a243b4bbb833b9ac139d425c1805a6660
child 120092 4d0cfc4fd49f0c7356cd34af8188002089a44957
push id1997
push userakeybl@mozilla.com
push dateMon, 07 Jan 2013 21:25:26 +0000
treeherdermozilla-beta@4baf45cdcf21 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfink
bugs807223
milestone19.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 807223 - Implement JS_ArrayBufferViewBuffer. r=sfink This is really sfink's patch, but we wrote basically the same code and the review looks better this way.
js/src/jsapi-tests/testTypedArrays.cpp
js/src/jsfriendapi.h
js/src/jstypedarray.cpp
--- a/js/src/jsapi-tests/testTypedArrays.cpp
+++ b/js/src/jsapi-tests/testTypedArrays.cpp
@@ -94,16 +94,17 @@ TestArrayFromBuffer(JSContext *cx)
     uint8_t *bufdata;
     CHECK(bufdata = JS_GetArrayBufferData(buffer, cx));
     memset(bufdata, 1, nbytes);
 
     RootedObject array(cx, CreateWithBuffer(cx, buffer, 0, -1));
     CHECK_EQUAL(JS_GetTypedArrayLength(array, cx), elts);
     CHECK_EQUAL(JS_GetTypedArrayByteOffset(array, cx), 0);
     CHECK_EQUAL(JS_GetTypedArrayByteLength(array, cx), nbytes);
+    CHECK_EQUAL(JS_GetArrayBufferViewBuffer(array, cx), (JSObject*) buffer);
 
     Element *data;
     CHECK(data = GetData(array, cx));
     CHECK(bufdata = JS_GetArrayBufferData(buffer, cx));
     CHECK_EQUAL((void*) data, (void*) bufdata);
 
     CHECK_EQUAL(*bufdata, 1);
     CHECK_EQUAL(*reinterpret_cast<uint8_t*>(data), 1);
--- a/js/src/jsfriendapi.h
+++ b/js/src/jsfriendapi.h
@@ -1331,16 +1331,24 @@ JS_GetFloat64ArrayData(JSObject *obj, JS
 /*
  * Same as above, but for any kind of ArrayBufferView. Prefer the type-specific
  * versions when possible.
  */
 extern JS_FRIEND_API(void *)
 JS_GetArrayBufferViewData(JSObject *obj, JSContext *maybecx);
 
 /*
+ * Return the ArrayBuffer underlying an ArrayBufferView. If the buffer has been
+ * neutered, this will still return the neutered buffer. |obj| must be an
+ * object that would return true for JS_IsArrayBufferViewObject().
+ */
+extern JS_FRIEND_API(JSObject *)
+JS_GetArrayBufferViewBuffer(JSObject *obj, JSContext *maybecx);
+
+/*
  * Check whether obj supports JS_GetDataView* APIs. Note that this may fail and
  * throw an exception if a security wrapper is encountered that denies the
  * operation.
  */
 JS_FRIEND_API(JSBool)
 JS_IsDataViewObject(JSContext *cx, JSObject *obj, JSBool *isDataView);
 
 /*
--- a/js/src/jstypedarray.cpp
+++ b/js/src/jstypedarray.cpp
@@ -3875,16 +3875,26 @@ JS_GetArrayBufferViewData(JSObject *obj,
 {
     obj = CheckedUnwrap(maybecx, obj);
     if (!obj)
         return NULL;
     JS_ASSERT(obj->isTypedArray() || obj->isDataView());
     return obj->isDataView() ? obj->asDataView().dataPointer() : TypedArray::viewData(obj);
 }
 
+JS_FRIEND_API(JSObject *)
+JS_GetArrayBufferViewBuffer(JSObject *obj, JSContext *maybecx)
+{
+    obj = CheckedUnwrap(maybecx, obj);
+    if (!obj)
+        return NULL;
+    JS_ASSERT(obj->isTypedArray() || obj->isDataView());
+    return &obj->getFixedSlot(BufferView::BUFFER_SLOT).toObject();
+}
+
 JS_FRIEND_API(uint32_t)
 JS_GetArrayBufferViewByteLength(JSObject *obj, JSContext *maybecx)
 {
     obj = CheckedUnwrap(maybecx, obj);
     if (!obj)
         return 0;
     JS_ASSERT(obj->isTypedArray() || obj->isDataView());
     return obj->isDataView()