1

I have a JavaScript commandline program that needs more stack space. The option for this is node --stack-size but it's not working for me. Test case:

'use strict'

function f(...a) {
    console.log(a[0] + a[a.length - 1])
}

var a = []
for (var i = 0; i < 1000000; i++) {
    a.push(i)
}
f(...a)

Run with plain node, the above crashes with an error message saying maximum call stack size exceeded. But run with node --stack-size=10000 (specifying ten megabytes of stack space, which should be enough) it just exits silently without printing any output, not even an error message.

I'm using Node 14.16.1 x64 on Windows 10.

What am I doing wrong?

echo %errorlevel% shows -1073741571, which is C00000FD, which is indeed the Windows error code for a stack overflow.

rwallace
  • 31,405
  • 40
  • 123
  • 242
  • But _why_ splat `a` into arguments instead of just using it as an array? – AKX Apr 28 '21 at 18:36
  • @AKX It's a test case. You wouldn't appreciate if I dumped a couple of thousand lines of code from the real program into the question text. – rwallace Apr 28 '21 at 18:37
  • Sure. Why does the real program need to splat an array into arguments when it can just use it as an array? – AKX Apr 28 '21 at 18:37
  • @AKX Outside the scope of this question. Seriously, an architecture document explaining the design of the program wouldn't fit in the comments. If I were asking for advice on the program design, that would be a separate question in its own right. – rwallace Apr 28 '21 at 18:38
  • Sorry if this sounds confrontational, but I think your program design may be wrong if you need to set an interpreter flag to expand stack size to correctly run it. – AKX Apr 28 '21 at 18:40
  • @AKX I have no objection to you holding that opinion. I believe in freedom of thought! But the comments section of a stack overflow question is not the place to debate questions of software architecture. – rwallace Apr 28 '21 at 18:41
  • 1
    You might be running into the parameter count limitation, which is probably below 1 million. – fregante Aug 01 '21 at 18:34

0 Answers0