How to detect from nodejs which JavaScript engine it is running on?

懵懂的女人 提交于 2019-12-23 10:14:24

问题


There are now several forks of nodejs and some of them support JavaScript engines other than Google's V8 engine.

For my node code to see which JS engine it is running under, what is currently the best way?

The engines I am aware of are:

  • Google's V8 - The only engine supported by the official node.js and the iojs fork. One of the engines supported by JXcore.
  • Mozilla's SpiderMonkey - One of the engines supported by JXcore.
  • Microsoft's ChakraCore - The engine supported by Microsoft's port of node.js and apparently one of the engines supported by JXcore though I haven't got that one to work yet.

(I've asked a separate question about detecting which fork of nodejs is being used. This question is only about detecting the JS engine.)


回答1:


The process object contains a lot of information about the currently running process (in this case, node).

My process.versions for example, contains the current version of V8:

process: {
    versions: {
        http_parser: '2.5.0',
        node: '4.2.4',
        v8: '4.5.103.35',
        uv: '1.7.5',
        zlib: '1.2.8',
        ares: '1.10.1-DEV',
        icu: '56.1',
        modules: '46',
        openssl: '1.0.2e'
    }
}

You should be able to query this object and determine the current engine.



来源:https://stackoverflow.com/questions/35037194/how-to-detect-from-nodejs-which-javascript-engine-it-is-running-on

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!