Bug 553938 - Use array capacity [r=jorendorff r=vlad sr=bz a=beltzner]
authorReed Loden <reed@reedloden.com>
Thu, 29 Apr 2010 16:39:45 -0500
changeset 26906 e28579a435853df583d496f8097b3729d63edd68
parent 26905 8cf59c16b1d51c080407510800e6fbb47d9b7266
child 26907 673cfcdf8da3fc6c18bc24b2d1afa496e8452d8c
push id2364
push userreed@reedloden.com
push dateThu, 29 Apr 2010 21:39:56 +0000
reviewersjorendorff, vlad, bz, beltzner
bugs553938
milestone1.9.1.10pre
Bug 553938 - Use array capacity [r=jorendorff r=vlad sr=bz a=beltzner]
js/src/jsarray.cpp
--- a/js/src/jsarray.cpp
+++ b/js/src/jsarray.cpp
@@ -3467,25 +3467,29 @@ js_ArrayInfo(JSContext *cx, JSObject *ob
     return JS_TRUE;
 }
 #endif
 
 JS_FRIEND_API(JSBool)
 js_ArrayToJSUint8Buffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,
                         JSUint8 *dest)
 {
-    uint32 length;
+    uint32 length, capacity;
 
     if (!obj || !OBJ_IS_DENSE_ARRAY(cx, obj))
         return JS_FALSE;
 
     length = obj->fslots[JSSLOT_ARRAY_LENGTH];
     if (length < offset + count)
         return JS_FALSE;
 
+    capacity = js_DenseArrayCapacity(obj);
+    if (capacity < offset + count)
+        return JS_FALSE;
+
     jsval v;
     jsint vi;
 
     JSUint8 *dp = dest;
     for (uintN i = offset; i < offset+count; i++) {
         v = obj->dslots[i];
         if (!JSVAL_IS_INT(v) || (vi = JSVAL_TO_INT(v)) < 0)
             return JS_FALSE;
@@ -3495,25 +3499,29 @@ js_ArrayToJSUint8Buffer(JSContext *cx, J
 
     return JS_TRUE;
 }
 
 JS_FRIEND_API(JSBool)
 js_ArrayToJSUint16Buffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,
                          JSUint16 *dest)
 {
-    uint32 length;
+    uint32 length, capacity;
 
     if (!obj || !OBJ_IS_DENSE_ARRAY(cx, obj))
         return JS_FALSE;
 
     length = obj->fslots[JSSLOT_ARRAY_LENGTH];
     if (length < offset + count)
         return JS_FALSE;
 
+    capacity = js_DenseArrayCapacity(obj);
+    if (capacity < offset + count)
+        return JS_FALSE;
+
     jsval v;
     jsint vi;
 
     JSUint16 *dp = dest;
     for (uintN i = offset; i < offset+count; i++) {
         v = obj->dslots[i];
         if (!JSVAL_IS_INT(v) || (vi = JSVAL_TO_INT(v)) < 0)
             return JS_FALSE;
@@ -3523,25 +3531,29 @@ js_ArrayToJSUint16Buffer(JSContext *cx, 
 
     return JS_TRUE;
 }
 
 JS_FRIEND_API(JSBool)
 js_ArrayToJSUint32Buffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,
                          JSUint32 *dest)
 {
-    uint32 length;
+    uint32 length, capacity;
 
     if (!obj || !OBJ_IS_DENSE_ARRAY(cx, obj))
         return JS_FALSE;
 
     length = obj->fslots[JSSLOT_ARRAY_LENGTH];
     if (length < offset + count)
         return JS_FALSE;
 
+    capacity = js_DenseArrayCapacity(obj);
+    if (capacity < offset + count)
+        return JS_FALSE;
+
     jsval v;
     jsint vi;
 
     JSUint32 *dp = dest;
     for (uintN i = offset; i < offset+count; i++) {
         v = obj->dslots[i];
         if (!JSVAL_IS_INT(v) || (vi = JSVAL_TO_INT(v)) < 0)
             return JS_FALSE;
@@ -3551,25 +3563,29 @@ js_ArrayToJSUint32Buffer(JSContext *cx, 
 
     return JS_TRUE;
 }
 
 JS_FRIEND_API(JSBool)
 js_ArrayToJSInt8Buffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,
                        JSInt8 *dest)
 {
-    uint32 length;
+    uint32 length, capacity;
 
     if (!obj || !OBJ_IS_DENSE_ARRAY(cx, obj))
         return JS_FALSE;
 
     length = obj->fslots[JSSLOT_ARRAY_LENGTH];
     if (length < offset + count)
         return JS_FALSE;
 
+    capacity = js_DenseArrayCapacity(obj);
+    if (capacity < offset + count)
+        return JS_FALSE;
+
     jsval v;
     JSInt8 *dp = dest;
     for (uintN i = offset; i < offset+count; i++) {
         v = obj->dslots[i];
         if (!JSVAL_IS_INT(v))
             return JS_FALSE;
 
         *dp++ = (JSInt8) JSVAL_TO_INT(v);
@@ -3577,25 +3593,29 @@ js_ArrayToJSInt8Buffer(JSContext *cx, JS
 
     return JS_TRUE;
 }
 
 JS_FRIEND_API(JSBool)
 js_ArrayToJSInt16Buffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,
                         JSInt16 *dest)
 {
-    uint32 length;
+    uint32 length, capacity;
 
     if (!obj || !OBJ_IS_DENSE_ARRAY(cx, obj))
         return JS_FALSE;
 
     length = obj->fslots[JSSLOT_ARRAY_LENGTH];
     if (length < offset + count)
         return JS_FALSE;
 
+    capacity = js_DenseArrayCapacity(obj);
+    if (capacity < offset + count)
+        return JS_FALSE;
+
     jsval v;
     JSInt16 *dp = dest;
     for (uintN i = offset; i < offset+count; i++) {
         v = obj->dslots[i];
         if (!JSVAL_IS_INT(v))
             return JS_FALSE;
 
         *dp++ = (JSInt16) JSVAL_TO_INT(v);
@@ -3603,25 +3623,29 @@ js_ArrayToJSInt16Buffer(JSContext *cx, J
 
     return JS_TRUE;
 }
 
 JS_FRIEND_API(JSBool)
 js_ArrayToJSInt32Buffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,
                         JSInt32 *dest)
 {
-    uint32 length;
+    uint32 length, capacity;
 
     if (!obj || !OBJ_IS_DENSE_ARRAY(cx, obj))
         return JS_FALSE;
 
     length = obj->fslots[JSSLOT_ARRAY_LENGTH];
     if (length < offset + count)
         return JS_FALSE;
 
+    capacity = js_DenseArrayCapacity(obj);
+    if (capacity < offset + count)
+        return JS_FALSE;
+
     jsval v;
     JSInt32 *dp = dest;
     for (uintN i = offset; i < offset+count; i++) {
         v = obj->dslots[i];
         if (!JSVAL_IS_INT(v))
             return JS_FALSE;
 
         *dp++ = (JSInt32) JSVAL_TO_INT(v);
@@ -3629,25 +3653,29 @@ js_ArrayToJSInt32Buffer(JSContext *cx, J
 
     return JS_TRUE;
 }
 
 JS_FRIEND_API(JSBool)
 js_ArrayToJSDoubleBuffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,
                          jsdouble *dest)
 {
-    uint32 length;
+    uint32 length, capacity;
 
     if (!obj || !OBJ_IS_DENSE_ARRAY(cx, obj))
         return JS_FALSE;
 
     length = obj->fslots[JSSLOT_ARRAY_LENGTH];
     if (length < offset + count)
         return JS_FALSE;
 
+    capacity = js_DenseArrayCapacity(obj);
+    if (capacity < offset + count)
+        return JS_FALSE;
+
     jsval v;
     jsdouble *dp = dest;
     for (uintN i = offset; i < offset+count; i++) {
         v = obj->dslots[i];
         if (JSVAL_IS_INT(v))
             *dp++ = (jsdouble) JSVAL_TO_INT(v);
         else if (JSVAL_IS_DOUBLE(v))
             *dp++ = *(JSVAL_TO_DOUBLE(v));