summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/extensions/too-many-arguments-constructing-bound-function.js
blob: e108e4c0b29447e21334f751ceb004414de2170a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
 * Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

var gTestfile = "too-many-arguments-constructing-bound-function.js";
//-----------------------------------------------------------------------------
var BUGNUMBER = 1303678;
var summary =
  "Don't assert trying to construct a bound function whose bound-target " +
  "construct operation passes more than ARGS_LENGTH_MAX arguments";

print(BUGNUMBER + ": " + summary);

/**************
 * BEGIN TEST *
 **************/

const ARGS_LENGTH_MAX = typeof getMaxArgs === "function"
                      ? getMaxArgs()
                      : 500000;

const halfRoundedDown = Math.floor(ARGS_LENGTH_MAX / 2);
const halfRoundedUp = Math.ceil(ARGS_LENGTH_MAX / 2);

function boundTarget()
{
  return new Number(arguments.length);
}

var boundArgs = Array(halfRoundedDown).fill(0);
var boundFunction = boundTarget.bind(null, ...boundArgs);

var additionalArgs = Array(halfRoundedUp + 1).fill(0);

try
{
  assertEq(new (boundFunction)(...additionalArgs).valueOf(),
           ARGS_LENGTH_MAX + 1);
  // If we reach here, that's fine -- it's okay if ARGS_LENGTH_MAX isn't
  // precisely respected, because there's no specified exact limit.
}
catch (e)
{
  assertEq(e instanceof RangeError, true,
           "SpiderMonkey throws RangeError for too many args");
}

/******************************************************************************/

if (typeof reportCompare === "function")
  reportCompare(true, true);

print("Tests complete");