Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在iOS中使用JSContextGroupSetExecutionTimeLimit_Javascript_Ios_Javascriptcore - Fatal编程技术网

Javascript 在iOS中使用JSContextGroupSetExecutionTimeLimit

Javascript 在iOS中使用JSContextGroupSetExecutionTimeLimit,javascript,ios,javascriptcore,Javascript,Ios,Javascriptcore,我需要停止JSContext对象中Javascript的执行吗?我发现下面的方法正是我所需要的 @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 secon

我需要停止JSContext对象中Javascript的执行吗?我发现下面的方法正是我所需要的

@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;
不幸的是,这种方法没有很好的文档记录,我不知道如何使用它

我的代码是

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);
当我试图调用JSContextGroupSetExecutionTimeLimit时,我得到了编译错误

函数“JSContextGroupSetExecutionTimeLimit”的隐式声明 在C99中无效

这个调用似乎来自JSContextRefPrivate.h,问题是如何将这个头添加到我的项目中,以及实现在哪里


有什么建议我该怎么处理。谢谢

这其实很简单:只需将相关函数的声明(以及
jsshouldtterminatecallback
typedef)复制到源代码中即可。这会告诉编译器函数在运行时可用的确切签名

由于JavascriptCore是开源WebKit项目的一部分,因此函数声明即使在中有有用的描述也可用。有关部分包括:

typedef bool
(*JSShouldTerminateCallback) (JSContextRef ctx, void* context);

JS_EXPORT void JSContextGroupSetExecutionTimeLimit(JSContextGroupRef group,
                                                   double limit, JSShouldTerminateCallback callback, void* context) CF_AVAILABLE(10_6, 7_0);

JS_EXPORT void JSContextGroupClearExecutionTimeLimit(JSContextGroupRef group) CF_AVAILABLE(10_6, 7_0);
此外,您不必自己创建组,因为根据,您创建的每个JSContextRef都会被分配一个新的JSContextGroup。可以使用公共函数获取上下文组

中提供了使用私有
JSContextGroupSetExecutionTimeLimit
API的示例


重要提示:如前所述,使用此私有API的应用程序可能会被应用商店拒绝。

这是一种未记录的方法,可能会导致苹果拒绝该应用程序。您知道如何终止对
JSContext
(Objective-C对象)的评估吗?我尝试了
JSGlobalContextRef contextRef=[jscontext-JSGlobalContextRef]与WebKit测试的方式相同,但不起作用,知道吗?非常感谢。