Is there any way stopping or pausing the execution of Javascript in a JSContext object? Is there any way stopping or pausing the execution of Javascript in a JSContext object? javascript javascript

Is there any way stopping or pausing the execution of Javascript in a JSContext object?


There actually is an API that allows to stop execution of Javascript code inside of JavascriptCore. Unfortunately though, it is private and thus cannot be used within apps that are to be distributed through the App Store.

The API in question is the JSContextGroupSetExecutionTimeLimit function defined in JSContextRefPrivate. Not only does it allow to specify a timeout for your JS code, but also a callback that will be called regularly to determine whether the execution should be stopped.

You can find more information in my answer to this SO question.


If still relevant, you could create a loop that adds the counter (that is going up after every cycle) and the maximum value of the counter. I assume you can use a second core since it is called javascriptcore. In this second core you can put a function that increases the value of the counter by 10 so it exceeds the max value of the counter and so the code will continue. You don't need a second core if you can call 2 functions at a time.

Otherwise you can store everything under a different name and overwrite the old ones with nothing.


u can use java script timeout callback when on JSContext object is triggered

function myFunction() {    alert('wait is over');}
<!DOCTYPE html><html><body><button onclick="setTimeout(myFunction, 3000);">Click Me</button><!-- In this context im using a simple button to trigger the call back in your case u can triggeer on jscontext--></body></html>