开发者

iphone - JavaScriptCore Framework / library

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 JSGarbag开发者_JS百科eCollect(JSContextRef ctx) { return _JSGarbageCollect(ctx); }


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜