I need to stop the execution of Javascript in a JSContext object? I found the following method which exactly what I need
@function
@abstract Sets the script execution time limit.
@param group The JavaScript context group that this time limit applies to.
@param limit The time limit of allowed script execution time in seconds.
@param callback The callback function that will be invoked when the time limit
has been reached. This will give you a chance to decide if you want to
terminate the script or not. If you pass a NULL callback, the script will be
terminated unconditionally when the time limit has been reached.
@param context User data that you can provide to be passed back to you
in your callback.
In order to guarantee that the execution time limit will take effect, you will
need to call JSContextGroupSetExecutionTimeLimit before you start executing
any scripts.
*/
JS_EXPORT void JSContextGroupSetExecutionTimeLimit(JSContextGroupRef, double limit, JSShouldTerminateCallback, void* context) AVAILABLE_IN_WEBKIT_VERSION_4_0;
Unfortunately the method is not well documented and I can't figure out how I can use it.
My code is
JSContextGroupRef group = JSContextGroupCreate();
JSGlobalContextRef context = JSGlobalContextCreateInGroup(group, NULL);
NSString *code = @"while(1){}";
JSStringRef script = JSStringCreateWithCFString((__bridge CFStringRef)code);
JSContextGroupSetExecutionTimeLimit(group,.200f,nil,0);
JSValueRef error = NULL;
JSValueRef value = JSEvaluateScript(context, script, NULL, NULL, 0, &error);
when I try to to call to JSContextGroupSetExecutionTimeLimit I get compilation error.
Implicit declaration of function "JSContextGroupSetExecutionTimeLimit" is invalid in C99,
seems like the call comes from JSContextRefPrivate.h, the question how I can add this header to my project and where is the implementation.
any advice how can I handle this. thanks