0

有没有人在 iOS 项目中使用过 JavaScriptCore 框架/库?我在现有框架列表中看不到任何此类框架,因此我从 Apple 开源网站http://www.opensource.apple.com/release/ios-40/下载了源代码

现在我想知道我需要做什么才能将它集成到我的应用程序中。这些 API 是否已经存在于 SDK 中,我可以通过仅复制标头来调用方法,还是需要将所有源代码复制到项目中?

我有一个工作项目,它只是复制和导入标题。但我无法理解它是如何工作的。它有一个在启动时调用的方法如下。

#include <dlfcn.h>
@implementation JSCocoaSymbolFetcher
+ (void)populateJavascriptCoreSymbols
{
_JSEvaluateScript = dlsym(RTLD_DEFAULT, "JSEvaluateScript");
_JSGarbageCollect = dlsym(RTLD_DEFAULT, "JSGarbageCollect");
_JSGlobalContextCreate = dlsym(RTLD_DEFAULT, "JSGlobalContextCreate");
_JSGlobalContextRetain = dlsym(RTLD_DEFAULT, "JSGlobalContextRetain");
_JSGlobalContextRelease = dlsym(RTLD_DEFAULT, "JSGlobalContextRelease");
_JSContextGetGlobalObject = dlsym(RTLD_DEFAULT, "JSContextGetGlobalObject");
_JSClassCreate = dlsym(RTLD_DEFAULT, "JSClassCreate");
_JSClassRetain = dlsym(RTLD_DEFAULT, "JSClassRetain");
.
.
.//other similar code
.
}

在@implementation 之前它也有这样的方法

JSValueRef (*_JSEvaluateScript)(JSContextRef ctx, JSStringRef script, JSObjectRef thisObject, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception);
JSValueRef JSEvaluateScript(JSContextRef ctx, JSStringRef script, JSObjectRef thisObject, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
{
return _JSEvaluateScript(ctx, script, thisObject, sourceURL, startingLineNumber, exception);
}

void (*_JSGarbageCollect)(JSContextRef ctx);
void JSGarbageCollect(JSContextRef ctx)
{
return _JSGarbageCollect(ctx);
}

所以我的问题是

1) 有人尝试过使用 JavaScriptCore for iPhone 应用程序吗?如果是怎么办?

2) dlsym 方法是做什么的?

3)最后提到的方法是如何工作的?例如void (*_JSGarbageCollect)(JSContextRef ctx); void JSGarbageCollect(JSContextRef ctx) { return _JSGarbageCollect(ctx); }

4

1 回答 1

0

You can bundle JavaScriptCore with your app, but you have to include the entire project in your application. See http://www.phoboslab.org/log/2011/04/ios-and-javascript-for-real-this-time for more details.

于 2011-04-28T09:10:41.520 回答