Bug 926401 - Zero-length arrays r=waldo
authorNicholas D. Matsakis <nmatsakis@mozilla.com>
Fri, 01 Nov 2013 11:07:37 -0400
changeset 156399 2ea9176d5e7e800f84275d37999f29267b2197ed
parent 156398 28ed31db6d984ca2414edf40b4931613b3f150fa
child 156400 5b797c0177d3675a582924b8367bc370ce34fa31
push id25678
push userryanvm@gmail.com
push dateWed, 20 Nov 2013 03:26:13 +0000
treeherdermozilla-central@4f993fa378eb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswaldo
bugs926401
milestone28.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 926401 - Zero-length arrays r=waldo
js/src/builtin/TypedObject.js
js/src/tests/ecma_6/TypedObject/arrayzerolen.js
--- a/js/src/builtin/TypedObject.js
+++ b/js/src/builtin/TypedObject.js
@@ -131,17 +131,17 @@ TypedObjectPointer.prototype.moveTo = fu
 // must be a array type and `index` must be within bounds. Returns
 // `this`.
 TypedObjectPointer.prototype.moveToElem = function(index) {
   assert(this.kind() == JS_TYPEREPR_ARRAY_KIND,
          "moveToElem invoked on non-array");
   assert(TO_INT32(index) === index,
          "moveToElem invoked with non-integer index");
   assert(index >= 0 && index < REPR_LENGTH(this.typeRepr),
-         "moveToElem invoked with out-of-bounds index");
+         "moveToElem invoked with out-of-bounds index: " + index);
 
   var elementTypeObj = this.typeObj.elementType;
   var elementTypeRepr = TYPE_TYPE_REPR(elementTypeObj);
   this.typeRepr = elementTypeRepr;
   this.typeObj = elementTypeObj;
   var elementSize = REPR_SIZE(elementTypeRepr);
 
   // Note: we do not allow construction of arrays where the offset
@@ -263,21 +263,23 @@ TypedObjectPointer.prototype.set = funct
       break;
 
     // Check that "array-like" fromValue has an appropriate length.
     var length = REPR_LENGTH(typeRepr);
     if (fromValue.length !== length)
       break;
 
     // Adapt each element.
-    var tempPtr = this.copy().moveToElem(0);
-    var size = REPR_SIZE(tempPtr.typeRepr);
-    for (var i = 0; i < length; i++) {
-      tempPtr.set(fromValue[i]);
-      tempPtr.offset += size;
+    if (length > 0) {
+      var tempPtr = this.copy().moveToElem(0);
+      var size = REPR_SIZE(tempPtr.typeRepr);
+      for (var i = 0; i < length; i++) {
+        tempPtr.set(fromValue[i]);
+        tempPtr.offset += size;
+      }
     }
     return;
 
   case JS_TYPEREPR_STRUCT_KIND:
     if (!IsObject(fromValue))
       break;
 
     // Adapt each field.
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_6/TypedObject/arrayzerolen.js
@@ -0,0 +1,17 @@
+// |reftest| skip-if(!this.hasOwnProperty("TypedObject"))
+var BUGNUMBER = 926401;
+var summary = 'TypedObjects ArrayType implementation';
+
+// Test creation of zero-length array
+
+function runTest() {
+  var T = TypedObject;
+  var Color = new T.StructType({'r': T.uint8, 'g': T.uint8, 'b': T.uint8});
+  var Rainbow = new T.ArrayType(Color, 0);
+  var theOneISawWasJustBlack = new Rainbow([]);
+  if (typeof reportCompare === "function")
+    reportCompare(true, true);
+  print("Tests complete");
+}
+
+runTest();