SoFunction
Updated on 2025-03-01

Provide sleep function for JavaScript (sleep) self-compiled JS engine

Even though this function is required so, why is such a function not provided in js?

Currently, browsers are parsing js on UI threads. Taking Firefox browser as an example, I recompiled the js engine and added the sleep method to the js alarm, which calls the thread sleep function in the C language.
Attach the method to the Object, the method signature is sleep(); no parameters. The default sleep is 1 second, and if you call the function in js, the browser UI interface will be blocked.


In addition, if your js function has a dead loop, the browser's js parsing will detect that the js execution timeout will remind you whether to terminate the execution of js on this page.
Finally, provide the newly compiled js engines and replace them with the js engine under firefox.

Then you can write a piece of js to play with it, such as "testSleep".sleep(); because I added it in Object, you can call this function on any js object.

Instructions for use:
The main thing is that the website visitors need to install your customized browser.
You just need to publish the Firefox client yourself, if your project really needs it.
It is as easy as requiring users to install flash plugins.

appendix:firefox_js.rar