iphone - JavaScriptCore 框架/库
有人在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) { 返回 _JSGarbageCollect(ctx); }
Has any one used JavaScriptCore framework/library in iOS project?
I do not see any such framework available in the existing framework list so I downloaded the source code from Apple Open Source site http://www.opensource.apple.com/release/ios-40/
Now I want to know what I need to do to integrate this in my application. Are these API already present in SDK and I can just call the methods by copying just headers or I need to copy all the source code in to the project?
I have a working project which just copy and import headers. But I am not able to understand how it works. It has a method as below which is called at the startup.
#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
.
}
It also has methods like this before the @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);
}
So My question is
1) Any one has tried using JavaScriptCore for iPhone application? if yes How?
2) what dlsym method does?
3) how the methods mentioned at the last works? e.g. void (*_JSGarbageCollect)(JSContextRef ctx);
void JSGarbageCollect(JSContextRef ctx)
{
return _JSGarbageCollect(ctx);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将 JavaScriptCore 与您的应用程序捆绑在一起,但您必须将整个项目包含在您的应用程序中。请参阅 http://www.phoboslab。 org/log/2011/04/ios-and-javascript-for-real-this-time 了解更多详细信息。
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.