From 5e7859bd23342abdaf3587c99cda693eb4d46213 Mon Sep 17 00:00:00 2001 From: Shu-yu Guo Date: Mon, 20 Aug 2012 22:02:18 -0700 Subject: [PATCH] Bug 784015 - Fix division by 0 when calling ParallelArray.prototype.partition (r=dmandelin) --- js/src/builtin/ParallelArray.cpp | 2 +- js/src/jit-test/tests/parallelarray/partition-throws.js | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/js/src/builtin/ParallelArray.cpp b/js/src/builtin/ParallelArray.cpp index 7299a1c02f3..e9c8eceb9f5 100644 --- a/js/src/builtin/ParallelArray.cpp +++ b/js/src/builtin/ParallelArray.cpp @@ -1366,7 +1366,7 @@ ParallelArrayObject::partition(JSContext *cx, CallArgs args) // Throw if the outer dimension is not divisible by the new dimension. uint32_t outer = obj->outermostDimension(); - if (outer % newDimension) { + if (newDimension == 0 || outer % newDimension) { JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_PAR_ARRAY_BAD_PARTITION); return false; } diff --git a/js/src/jit-test/tests/parallelarray/partition-throws.js b/js/src/jit-test/tests/parallelarray/partition-throws.js index 4361207ffc9..c0c3548f56a 100644 --- a/js/src/jit-test/tests/parallelarray/partition-throws.js +++ b/js/src/jit-test/tests/parallelarray/partition-throws.js @@ -1,8 +1,10 @@ -// |jit-test| error: Error; +load(libdir + "asserts.js"); function testPartitionDivisible() { var p = new ParallelArray([1,2,3,4]); - var pp = p.partition(3); + var pp; + assertThrowsInstanceOf(function () { pp = p.partition(3); }, Error); + assertThrowsInstanceOf(function () { pp = p.partition(.34); }, Error); } testPartitionDivisible();