有没有人在iOS项目中使用过JavaScriptCore框架/库?我在现有的框架列表中没有看到任何这样的框架,所以我从苹果开源网站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
.
}在@实现之前,它也有类似这样的方法
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)有没有人尝试过使用iPhone应用的JavaScriptCore?如果是,是如何实现的?
2) dlsym方法是做什么的?
3)最后提到的方法是如何工作的?例如void (*_JSGarbageCollect)(JSContextRef ctx); void JSGarbageCollect(JSContextRef ctx) { return _JSGarbageCollect(ctx); }
发布于 2011-04-28 17:10:42
您可以将JavaScriptCore与您的应用程序捆绑在一起,但您必须在您的应用程序中包含整个项目。有关更多详细信息,请参阅http://www.phoboslab.org/log/2011/04/ios-and-javascript-for-real-this-time。
https://stackoverflow.com/questions/5816150
复制相似问题