镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Math.min NOT work with 123021 numbers #36958

Description

@ihgazni2
  • Version: v16.0.0-pre,v12.18.2
  • Platform: linux
  • Subsystem: ubuntu

What steps will reproduce the bug?

>

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)
Math.min(...arr)


Uncaught RangeError: Maximum call stack size exceeded

/*
> arr[63123]
2
> arr[63124]
3
>

> arr.filter(r=>r===2).length
63124
> arr.filter(r=>r===3).length
60166
>


[
  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  2, 2, 2, 2,
  ... 123190 more items
]

*/


>
> var arr = creat_arr(6312,6016)
undefined
> Math.min(...arr)
2
>
> var arr = creat_arr(63124,59896)
undefined
> Math.min(...arr)
2
> var arr = creat_arr(63124,59897)
undefined
> Math.min(...arr)
Uncaught RangeError: Maximum call stack size exceeded
    at Math.min (<anonymous>)
>

How often does it reproduce? Is there a required condition?

always, if with too many params

What is the expected behavior?

Math.min(...arr)
2

What do you see instead?

Uncaught RangeError: Maximum call stack size exceeded
at Math.min ()

Additional information

Activity

  1. added
    v8 engineIssues and PRs related to the V8 dependency.
    replIssues and PRs related to the REPL subsystem.
    confirmed-bugIssues and PRs for confirmed bugs.
    and removed
    v8 engineIssues and PRs related to the V8 dependency.
    on Jan 16, 2021
  2. aduh95 commented on Jan 16, 2021

    @aduh95
    Contributor

    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).

  3. added
    known limitationIssues that are identified as known limitations.
    and removed
    confirmed-bugIssues and PRs for confirmed bugs.
    on Jan 16, 2021
  4. targos commented on Jan 16, 2021

    @targos
    Member

    This is not a bug, rather a known limitation. See #16870

  5. aduh95 commented on Jan 16, 2021

    @aduh95
    Contributor

    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.

  6. targos commented on Jan 16, 2021

    @targos
    Member

    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

  7. aduh95 commented on Jan 16, 2021

    @aduh95
    Contributor

    I've run the OP code on DevTools (V8 8.7) it outputs the expected result:

    image

    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)
  8. targos commented on Jan 16, 2021

    @targos
    Member

    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.

  9. removed
    replIssues and PRs related to the REPL subsystem.
    on Apr 10, 2021
  10. BridgeAR commented on Apr 10, 2021

    @BridgeAR
    Member

    I am closing this as there's nothing that can be done on Node.js side about this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    known limitationIssues that are identified as known limitations.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions