jsc

JSCoreBom

JavaScriptCore is missing some things you get used to - setTimeout, XMLHttpRequest, etc. This projects extends JSContext with native implementation of BOM using Objective-C

Showing:

Popularity

Downloads/wk

0

GitHub Stars

55

Maintenance

Last Commit

5yrs ago

Contributors

3

Package

Dependencies

0

License

MIT

Categories

Readme

JSCoreBom

JavaScriptCore framework on iOS/OSX is missing some things from browser object model you get used to - setTimeout, XMLHttpRequest, etc. Also a lot of libraries requires to have such objects, for example rx.js requires to have setTimeout.

This projects extends JSContext with native implementation of some functions of BOM using Objective-C

How to use it?

Using cocoapods: pod 'JSCoreBom', '~> 1.1.1'.

Whenever you would like to extend JSContext with BOM function just use:

JSContext* context = [[JSContext alloc] init];
[[JSCoreBom shared] extendContext:context];

Then just use it:

[context evaluateScript:@"setTimeout(function(){ console.log('Hi in 5 seconds!')},5000"];

What does it contain?

NameDescriptionStatus
setTimeoutImplemented using dispatch_afterDone
console.{info,log,debug,warn,error}Would forward everything to NSLogDone
XmlHTTPRequestUsing NSUrlSessionProto done

For logger you can specify custom log handler:

[[JSCoreBom shared] extend:context logHandler:^(NSString* logLevel, NSArray* params, NSString* formattedLogEntry) {
    if ([logLevel isEqualToString: @"log"])
        [MyCustomLogger log:logEntry];
}];

How does it work?

Like Apple on a page 45 said to!


JSContext* context = [[JSContext alloc] init];
context[@"setTimeout"] = ^(JSValue* function, JSValue* timeout) {
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)([timeout toInt32] * NSEC_PER_MSEC)), dispatch_get_main_queue(), ^{
        [function callWithArguments:@[]];
    });
};

Known issues

XMLHttpRequest:

  • Always sync call is made using NSURLConnection, not NSUrlSession yet

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100