Implementing setTimeout() and setInterval() in pure JavaScript

前端 未结 2 1200
灰色年华
灰色年华 2021-01-14 18:02

I have some JavaScript benchmark code that is supported to be running on browser. But I would like to run it on console mode of JavaScript engine such as \'d8\' in V8 for te

相关标签:
2条回答
  • 2021-01-14 18:27

    You can't to that with just V8 + some JS, you have to embbed the JS engine in some kind of runtime that supports timers. For V8 there's zombie.js for instance.

    0 讨论(0)
  • 2021-01-14 18:35

    Let's take a look how it is implemented in node timers.js. You can see at line #24, that timer_wrap binding is registered. This "internal module" is just a C library that supplies js module with time operations. That means that js timer implementation is based on some modules of an "upper level" and unfortunately can't be achieved in "pure js" as you wish.

    0 讨论(0)
提交回复
热议问题