Bug 748915 - Implement JS_IsArrayBufferViewObject
authorSteve Fink <sfink@mozilla.com>
Wed, 28 Mar 2012 14:43:01 -0700
changeset 92444 3a708ccedb3df3edf67de64b91da08cbd46fc0b0
parent 92443 add8917f9123da804f889e09073fee41e36a89fa
child 92445 c9c3950e04dc6cd4b9f9818a0137f813b3f269e7
push id8691
push usersfink@mozilla.com
push dateWed, 25 Apr 2012 23:55:44 +0000
treeherdermozilla-inbound@ef75d8acb2a5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs748915
milestone15.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 748915 - Implement JS_IsArrayBufferViewObject Also includes some warnings fixes.
js/src/jsfriendapi.h
js/src/jstypedarray.cpp
js/src/jstypedarray.h
js/src/vm/ObjectImpl.h
--- a/js/src/jsfriendapi.h
+++ b/js/src/jsfriendapi.h
@@ -1059,16 +1059,24 @@ JS_GetTypedArrayByteOffset(JSObject *obj
  * be known that it would pass such a test: it is a typed array or a wrapper of
  * a typed array, and the unwrapping will succeed. If cx is NULL, then DEBUG
  * builds may be unable to assert when unwrapping should be disallowed.
  */
 extern JS_FRIEND_API(uint32_t)
 JS_GetTypedArrayByteLength(JSObject *obj, JSContext *cx);
 
 /*
+ * Check whether obj supports JS_ArrayBufferView* APIs. Note that this may
+ * return false if a security wrapper is encountered that denies the
+ * unwrapping.
+ */
+extern JS_FRIEND_API(JSBool)
+JS_IsArrayBufferViewObject(JSObject *obj, JSContext *cx);
+
+/*
  * More generic name for JS_GetTypedArrayByteLength to cover DataViews as well
  */
 extern JS_FRIEND_API(uint32_t)
 JS_GetArrayBufferViewByteLength(JSObject *obj, JSContext *cx);
 
 /*
  * Return a pointer to the start of the data referenced by a typed array. The
  * data is still owned by the typed array, and should not be modified on
--- a/js/src/jstypedarray.cpp
+++ b/js/src/jstypedarray.cpp
@@ -2537,16 +2537,23 @@ JS_IsArrayBufferObject(JSObject *obj, JS
 
 JS_FRIEND_API(JSBool)
 JS_IsTypedArrayObject(JSObject *obj, JSContext *cx)
 {
     obj = UnwrapObject(obj);
     return obj->isTypedArray();
 }
 
+JS_FRIEND_API(JSBool)
+JS_IsArrayBufferViewObject(JSObject *obj, JSContext *cx)
+{
+    obj = UnwrapObject(obj);
+    return obj->isTypedArray();
+}
+
 JS_FRIEND_API(uint32_t)
 JS_GetArrayBufferByteLength(JSObject *obj, JSContext *cx)
 {
     obj = UnwrapObject(obj);
     return obj->asArrayBuffer().byteLength();
 }
 
 JS_FRIEND_API(uint8_t *)
--- a/js/src/jstypedarray.h
+++ b/js/src/jstypedarray.h
@@ -52,17 +52,19 @@ namespace js {
 /*
  * ArrayBufferObject
  *
  * This class holds the underlying raw buffer that the various ArrayBufferView
  * subclasses (DataView and the TypedArrays) access. It can be created
  * explicitly and passed to an ArrayBufferView subclass, or can be created
  * implicitly by constructing a TypedArray with a size.
  */
-struct ArrayBufferObject : public JSObject {
+class ArrayBufferObject : public JSObject
+{
+  public:
     static Class protoClass;
     static JSPropertySpec jsprops[];
     static JSFunctionSpec jsfuncs[];
 
     static JSBool prop_getByteLength(JSContext *cx, JSObject *obj, jsid id, Value *vp);
 
     static JSBool fun_slice(JSContext *cx, unsigned argc, Value *vp);
 
--- a/js/src/vm/ObjectImpl.h
+++ b/js/src/vm/ObjectImpl.h
@@ -570,17 +570,17 @@ ElementsHeader::asArrayBufferElements()
  * pointing to the beginning of that array (the end of this structure).
  * See below for usage of this structure.
  */
 class ArrayBufferObject;
 class ObjectElements
 {
     friend struct ::JSObject;
     friend class ObjectImpl;
-    friend struct js::ArrayBufferObject;
+    friend class ArrayBufferObject;
 
     /* Number of allocated slots. */
     uint32_t capacity;
 
     /*
      * Number of initialized elements. This is <= the capacity, and for arrays
      * is <= the length. Memory for elements above the initialized length is
      * uninitialized, but values between the initialized length and the proper