Using JSContextGroupSetExecutionTimeLimit in iOS

半腔热情 提交于 2019-12-06 01:12:14

It's actually pretty trivial: Just copy the declarations of the relevant functions (and the JSShouldTerminateCallback typedef) into your source code. This tells the compiler the exact signatures with which the functions will be available at runtime.

As JavascriptCore is part of the open source WebKit project, the function declarations are available even with useful descriptions in the WebKit repository. The relevant parts are:

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);

Also, you don't have to create a group yourself, as according to the JavascriptCore documentation, every JSContextRef you create is assigned a new JSContextGroup. You can get the group of a context using the public JSContextGetGroup function.

An example using the private JSContextGroupSetExecutionTimeLimit API is available in the WebKit tests.

IMPORTANT: As already pointed out, an app using this private API is likely to be rejected from the App Store.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!