| 1 |
/* |
| 2 |
* Any copyright is dedicated to the Public Domain. |
| 3 |
* http://creativecommons.org/publicdomain/zero/1.0/ |
| 4 |
*/ |
| 5 |
|
| 6 |
// SKIP test262 export |
| 7 |
// Testing unspecified implementation limits. |
| 8 |
|
| 9 |
var gTestfile = "too-many-arguments-constructing-bound-function.js"; |
| 10 |
//----------------------------------------------------------------------------- |
| 11 |
var BUGNUMBER = 1303678; |
| 12 |
var summary = |
| 13 |
"Don't assert trying to construct a bound function whose bound-target " + |
| 14 |
"construct operation passes more than ARGS_LENGTH_MAX arguments"; |
| 15 |
|
| 16 |
print(BUGNUMBER + ": " + summary); |
| 17 |
|
| 18 |
/************** |
| 19 |
* BEGIN TEST * |
| 20 |
**************/ |
| 21 |
|
| 22 |
const ARGS_LENGTH_MAX = typeof getMaxArgs === "function" |
| 23 |
? getMaxArgs() |
| 24 |
: 500000; |
| 25 |
|
| 26 |
const halfRoundedDown = Math.floor(ARGS_LENGTH_MAX / 2); |
| 27 |
const halfRoundedUp = Math.ceil(ARGS_LENGTH_MAX / 2); |
| 28 |
|
| 29 |
function boundTarget() |
| 30 |
{ |
| 31 |
return new Number(arguments.length); |
| 32 |
} |
| 33 |
|
| 34 |
var boundArgs = Array(halfRoundedDown).fill(0); |
| 35 |
var boundFunction = boundTarget.bind(null, ...boundArgs); |
| 36 |
|
| 37 |
var additionalArgs = Array(halfRoundedUp + 1).fill(0); |
| 38 |
|
| 39 |
try |
| 40 |
{ |
| 41 |
assertEq(new (boundFunction)(...additionalArgs).valueOf(), |
| 42 |
ARGS_LENGTH_MAX + 1); |
| 43 |
// If we reach here, that's fine -- it's okay if ARGS_LENGTH_MAX isn't |
| 44 |
// precisely respected, because there's no specified exact limit. |
| 45 |
} |
| 46 |
catch (e) |
| 47 |
{ |
| 48 |
assertEq(e instanceof RangeError, true, |
| 49 |
"SpiderMonkey throws RangeError for too many args"); |
| 50 |
} |
| 51 |
|
| 52 |
/******************************************************************************/ |
| 53 |
|
| 54 |
if (typeof reportCompare === "function") |
| 55 |
reportCompare(true, true); |
| 56 |
|
| 57 |
print("Tests complete"); |