にて
配列がクソ長いとエラーがでるかもしれない。
とあったので試してみた。
Microsoft Edge
バージョン
Microsoft Edge for Business バージョン 131.0.2903.51 (公式ビルド 64ビット)
試したのは F12 のコンソールにて。
do it.
> Math.max(...Array.from({length:125467}, (v,index)=> index))
<- 125466
> Math.max(...Array.from({length:125468}, (v,index)=> index))
VM2349:1 Uncaught RangeError: Maximum call stack size exceeded
at Math.max (<anonymous>)
at <anonymous>:1:6
確かに発生を確認できた。
> Math.max.apply(null, Array.from({length:125466}, (v,index)=> index))
<- 125465
> Math.max.apply(null, Array.from({length:125467}, (v,index)=> index))
VM2671:1 Uncaught RangeError: Maximum call stack size exceeded
at max (<anonymous>)
at <anonymous>:1:10
range 展開の方がいろいろ食いそうなのに apply の方が 数が少なくてエラーになるの何故……。
Firefox
バージョン
do it.
> Math.max(...Array.from({length:500000}, (v,index)=> index))
<- 499999
> Math.max(...Array.from({length:500001}, (v,index)=> index))
Uncaught RangeError: too many function arguments
<anonymous> debugger eval code:1
引数限界ぽいエラー
> Math.max.apply(null, Array.from({length:500000}, (v,index)=> index))
<- 499999
> Math.max.apply(null, Array.from({length:500001}, (v,index)=> index))
Uncaught RangeError: too many arguments provided for a function call
<anonymous> debugger eval code:1
また違ったエラーになる……?
というか firefox だと apply もそうじゃないのも同じ数でエラーになってる?