Skip to content

JS engine detection with tail recursion #202

Open
@pygy

Description

@pygy
function detect(){
  "use strict" //necessary for Safari to eliminate tail calls
  function recurse(N) {if (N ===0) return "JavaScriptCore"; else return recurse(N-1)}
  try {return recurse(2**16)} catch(e) {
    if (e instanceof RangeError) return "V8"
    else return "SpiderMonkey" // here, `e instanceof InternalError` is true
  }
}
detect()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions