3

How can I understand what engine is being used while JavaScript is executing?

e.g., v8 or spidermonkey or nashhorn

Dmitry Ginzburg
  • 7,391
  • 2
  • 37
  • 48
  • 2
    Are you trying to micro-optimise by taking advantage of specific runtime features? – Gareth Dec 10 '12 at 14:33
  • 1
    Why would you want to know...? – Waleed Khan Dec 10 '12 at 14:34
  • Just like with browsers, it's generally *much* better to *feature-detect* rather than engine-detect. So for instance, if you want to know if the engine supports `Object.defineProperty`, look to see if `defineProperty` is on `Object`. (I'm assuming you're in control to the extent of knowing no one's put in a half-complete shim.) – T.J. Crowder Dec 10 '12 at 14:35
  • 1
    possible duplicate of [How can I detect which javascript engine (v8 or JSC) is used at runtime in Android?](http://stackoverflow.com/questions/6768474/how-can-i-detect-which-javascript-engine-v8-or-jsc-is-used-at-runtime-in-andro) – Fenton Dec 10 '12 at 14:36
  • @SteveFenton: This question doesn't seem to have anything to do with Android, so it's not a duplicate of that. (But I bet there's one around somewhere...) – T.J. Crowder Dec 10 '12 at 14:36
  • 1
    The answer to that question is WebKit dependent, not Android dependent. – Fenton Dec 10 '12 at 14:38

1 Answers1

-1

JavaScript engines (and their versions) are closely linked to browser (versions).

So simply use browser detection, and map it to the JS engine with a table. Many browsers even hold the engine build in their UA string.

Or better: Don't do it, for the very same reason. There's hardly a use case where you need to know the JS engine, apart from browser test suites (in which you just can ask the user). For anything else, you should use feature detection. Different engines differ in different ways from the ES spec, and you can test on these subtleties.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375