Bug 1154480 - Make new Uint8Array().set([], -1) throw a RangeError, not merely an Error. r=till

--HG--
extra : rebase_source : eec24e20cd07152378098dc8f5bc21ed804f64e5
This commit is contained in:
Jeff Walden 2015-04-15 10:46:41 -07:00
parent 811dd58432
commit 6e8c9ac24b
3 changed files with 38 additions and 4 deletions

View File

@ -455,8 +455,8 @@ MSG_DEF(JSMSG_TYPEDOBJECT_TOO_BIG, 0, JSEXN_ERR, "Type is too large to alloc
MSG_DEF(JSMSG_BAD_INDEX, 0, JSEXN_RANGEERR, "invalid or out-of-range index")
MSG_DEF(JSMSG_TYPED_ARRAY_BAD_ARGS, 0, JSEXN_TYPEERR, "invalid arguments")
MSG_DEF(JSMSG_TYPED_ARRAY_BAD_OBJECT, 0, JSEXN_TYPEERR, "invalid object argument")
MSG_DEF(JSMSG_TYPED_ARRAY_BAD_INDEX, 0, JSEXN_ERR, "invalid or out-of-range index")
MSG_DEF(JSMSG_TYPED_ARRAY_NEGATIVE_ARG,1, JSEXN_ERR, "argument {0} must be >= 0")
MSG_DEF(JSMSG_TYPED_ARRAY_BAD_INDEX, 0, JSEXN_RANGEERR, "invalid or out-of-range index")
MSG_DEF(JSMSG_TYPED_ARRAY_NEGATIVE_ARG,1, JSEXN_RANGEERR, "argument {0} must be >= 0")
MSG_DEF(JSMSG_TYPED_ARRAY_DETACHED, 0, JSEXN_TYPEERR, "attempting to access detached ArrayBuffer")
// Shared array buffer

View File

@ -0,0 +1,35 @@
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
var gTestfile = "set-negative-offset.js";
//-----------------------------------------------------------------------------
var BUGNUMBER = 1140752;
var summary =
"%TypedArray%.prototype.set must throw a RangeError when passed a negative " +
"offset";
print(BUGNUMBER + ": " + summary);
/**************
* BEGIN TEST *
**************/
try
{
new Uint8Array().set([], -1);
throw new Error("didn't throw at all");
}
catch (e)
{
assertEq(e instanceof RangeError, true,
"expected RangeError, instead got: " + e);
}
/******************************************************************************/
if (typeof reportCompare === "function")
reportCompare(true, true);
print("Tests complete");

View File

@ -686,8 +686,7 @@ class TypedArrayMethods
if (offset < 0 || uint32_t(offset) > target->length()) {
// the given offset is bogus
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr,
JSMSG_TYPED_ARRAY_BAD_INDEX, "2");
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_BAD_INDEX);
return false;
}
}