2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Math.max で 糞長いパラメータを食わせてみるテスト

Last updated at Posted at 2024-11-20

にて

配列がクソ長いとエラーがでるかもしれない。

とあったので試してみた。

Microsoft Edge

バージョン

Microsoft Edge for Business バージョン 131.0.2903.51 (公式ビルド 64ビット)

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

バージョン

Firefox 123.0.2 (64ビット)
Firefox 123.0.2 (64ビット)

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 もそうじゃないのも同じ数でエラーになってる?

2
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?