You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems to happen only on REPL and when using eval (E.G.: node -p 'Math.min(...Array.from({length:1<<10<<10}, ()=>2))'). Saving the script to a file and execute it works perfectly though.
I can also reproduce using Reflect.apply(Math.min, null, arr).
This is not a bug, rather a known limitation. See #16870
I'm not sure this is exactly the same problem, as it doesn't happen not on DevTools, nor on Node.js executing a file – so it's not a V8 limitation. It seems there's another limitation with REPL and eval, which we may be able to workaround.
I've run the OP code on DevTools (V8 8.7) it outputs the expected result:
And on Node.js (V8 8.6) it works only when executing a file rather than eval a string:
$ cat math:min.jsfunction creat_arr(lngth2,lngth3){ let arr_two = Array.from({length:lngth2}).map(r=>2) let arr_three = Array.from({length:lngth3}).map(r=>3) let arr = Array.prototype.concat(arr_two,arr_three) return(arr)}var arr = creat_arr(63124,60166)console.log(Math.min(...arr))
$ node math:min.js 2
$ node < math:min.js [stdin]:9console.log(Math.min(...arr)) ^RangeError: Maximum call stack size exceeded at [stdin]:9:18 at Script.runInThisContext (node:vm:133:18) at Object.runInThisContext (node:vm:310:38) at node:internal/process/execution:77:19 at [stdin]-wrapper:6:22 at evalScript (node:internal/process/execution:76:60) at node:internal/main/eval_stdin:29:5 at ReadStream.<anonymous> (node:internal/process/execution:205:5) at ReadStream.emit (node:events:376:20) at endReadableNT (node:internal/streams/readable:1295:12)
It's probably because depending on the situations, the code stays below your stack size. If you execute the same code with larger arrays you should be able to reproduce everywhere.
Reacted by Antoine du Hamel, Darshan Sen, Ross F. Calimlim and Ruben Bridgewater
Activity
aduh95 commentedon Jan 16, 2021
It seems to happen only on REPL and when using eval (E.G.:
node -p 'Math.min(...Array.from({length:1<<10<<10}, ()=>2))'). Saving the script to a file and execute it works perfectly though.I can also reproduce using
Reflect.apply(Math.min, null, arr).targos commentedon Jan 16, 2021
This is not a bug, rather a known limitation. See #16870
aduh95 commentedon Jan 16, 2021
I'm not sure this is exactly the same problem, as it doesn't happen not on DevTools, nor on Node.js executing a file – so it's not a V8 limitation. It seems there's another limitation with REPL and eval, which we may be able to workaround.
targos commentedon Jan 16, 2021
I don't know what you mean exactly. The example code you gave in #36958 (comment) also fails if executed from a file or in Chrome devtools
aduh95 commentedon Jan 16, 2021
I've run the OP code on DevTools (V8 8.7) it outputs the expected result:
And on Node.js (V8 8.6) it works only when executing a file rather than eval a string:
targos commentedon Jan 16, 2021
It's probably because depending on the situations, the code stays below your stack size. If you execute the same code with larger arrays you should be able to reproduce everywhere.
BridgeAR commentedon Apr 10, 2021
I am closing this as there's nothing that can be done on Node.js side about this.