Skip to content

Commit ec814e4

Browse files
committed
test(#309): Failing test
Demonstrating that the current implementation of `Array`'s `Bind` instance causes `RangeError: Maximum call stack size exceeded` when the output of `f` in `ma >>= f` is sufficiently large. This is due to usage of `Function.prototype.apply`. From [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply#using_apply_and_built-in_functions): > But beware: by using apply() (or the spread syntax) with an arbitrarily long arguments list, you run the risk of exceeding the JavaScript engine's argument length limit. > The consequences of calling a function with too many arguments (that is, more than tens of thousands of arguments) is unspecified and varies across engines. (The JavaScriptCore engine has a hard-coded [argument limit of 65536](https://webkit.org/b/80797).) Node v20.18.1 seems to have a higher limit around 106,000.
1 parent f4cad0a commit ec814e4

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

test/Test/Main.js

+8
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,11 @@ export function testNumberShow(showNumber) {
4040
]);
4141
};
4242
}
43+
44+
export function makeArray(length) {
45+
var arr = [];
46+
for (var i = 0; i < length; i++) {
47+
arr.push(i);
48+
}
49+
return arr;
50+
}

test/Test/Main.purs

+12
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ main = do
2222
testReflectType
2323
testReifyType
2424
testSignum
25+
testArrayBind
2526

2627
foreign import testNumberShow :: (Number -> String) -> AlmostEff
2728

@@ -189,3 +190,14 @@ testSignum = do
189190
assert "signum positive zero" $ show (1.0/(signum 0.0)) == "Infinity"
190191
assert "Clarifies what 'signum negative zero' test is doing" $ show (1.0/(-0.0)) == "-Infinity"
191192
assert "signum negative zero" $ show (1.0/(signum (-0.0))) == "-Infinity"
193+
194+
foreign import makeArray :: Int -> Array Int
195+
196+
testArrayBind :: AlmostEff
197+
testArrayBind = do
198+
assert "Array bind does not cause RangeError" do
199+
let
200+
_ = do
201+
_ <- [unit]
202+
makeArray 106_000
203+
true

0 commit comments

Comments
 (0)