Bug 977647 -- check for empty arrays in mapPar r=shu
authorNicholas D. Matsakis <nmatsakis@mozilla.com>
Fri, 28 Feb 2014 11:21:56 -0500
changeset 171735 2cab8c44a9b976f6f11ead9e843ead2bbaf2f3a4
parent 171734 5b678e143116d162aff13659da3257068fce1db4
child 171736 b64a3c8d9172acb6cb4fa5b2058a5973a2926fab
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersshu
bugs977647
milestone30.0a1
Bug 977647 -- check for empty arrays in mapPar r=shu
js/src/builtin/TypedObject.js
js/src/jit-test/tests/parallel/bug977647.js
--- a/js/src/builtin/TypedObject.js
+++ b/js/src/builtin/TypedObject.js
@@ -1433,16 +1433,18 @@ function MapTypedParImplDepth1(inArray, 
   const outGrainTypeSize = DESCR_SIZE(outGrainType);
   const inGrainTypeIsComplex = !TypeDescrIsSimpleType(inGrainType);
   const outGrainTypeIsComplex = !TypeDescrIsSimpleType(outGrainType);
 
   const length = inArray.length;
   const mode = undefined;
 
   const outArray = new outArrayType(length);
+  if (length === 0)
+    return outArray;
 
   const outGrainTypeIsTransparent = ObjectIsTransparentTypedObject(outArray);
 
   // Construct the slices and initial pointers for each worker:
   const slicesInfo = ComputeSlicesInfo(length);
   const numWorkers = ForkJoinNumWorkers();
   assert(numWorkers > 0, "Should have at least the main thread");
   const pointers = [];
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/parallel/bug977647.js
@@ -0,0 +1,12 @@
+// Check for mapPar() applied to an empty array.
+// Public domain.
+
+if (!this.hasOwnProperty("TypedObject"))
+  quit();
+
+var { ArrayType, StructType, uint32 } = TypedObject;
+var Point = new StructType({x: uint32, y: uint32});
+var Points = Point.array();
+var points = new Points();
+points.mapPar(function() {});
+