Bug 783924 - Part 1: Fix ParallelArray constructor being called with non array-like objects (r=dmandelin)

This commit is contained in:
Shu-yu Guo 2012-08-21 12:29:46 -07:00
parent 19580422cb
commit fc9f81855b
3 changed files with 14 additions and 3 deletions

View File

@ -81,7 +81,6 @@ ParallelArrayObject::IndexInfo::initialize(uint32_t space)
// Reserve indices.
return indices.reserve(ndims) && indices.resize(space);
}
inline bool

View File

@ -1050,6 +1050,12 @@ ParallelArrayObject::construct(JSContext *cx, unsigned argc, Value *vp)
if (!iv.dimensions.resize(1) || !ToUint32(cx, args[0], &iv.dimensions[0]))
return false;
}
// If the first argument wasn't a array-like or had no length, assume
// empty parallel array, i.e. with shape being [0].
if (iv.dimensions.length() == 0 && !iv.dimensions.append(0))
return false;
if (!iv.initialize(0))
return false;

View File

@ -1,7 +1,13 @@
// |jit-test| error: TypeError;
load(libdir + "asserts.js");
function buildComprehension() {
// Throws if elemental fun not callable
var p = new ParallelArray([2,2], undefined);
assertThrowsInstanceOf(function () {
var p = new ParallelArray([2,2], undefined);
}, TypeError);
assertThrowsInstanceOf(function () {
var p = new ParallelArray(/x/, /x/);
}, TypeError);
}
buildComprehension();