Repository navigation
Math.min NOT work with 123021 numbers #36958
Description
Activity
- addedv8 engineIssues and PRs related to the V8 dependency.Issues and PRs related to the V8 dependency.replIssues and PRs related to the REPL subsystem.Issues and PRs related to the REPL subsystem.confirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.and removedv8 engineIssues and PRs related to the V8 dependency.Issues and PRs related to the V8 dependency.
on 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).- addedknown limitationIssues that are identified as known limitations.Issues that are identified as known limitations.and removedconfirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.
on Jan 16, 2021 This is not a bug, rather a known limitation. See #16870
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.
it doesn't happen not on DevTools, nor on Node.js executing a file
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
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.js function 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]:9 console.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- removedreplIssues and PRs related to the REPL subsystem.Issues and PRs related to the REPL subsystem.
on Apr 10, 2021 I am closing this as there's nothing that can be done on Node.js side about this.

What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
always, if with too many params
What is the expected behavior?
What do you see instead?
Uncaught RangeError: Maximum call stack size exceeded
at Math.min ()
Additional information