Extend Your App With
JavaScriptCoreMicha MAZAHERI
iOS > Mac > Python > React
@mittsh
API BlueprintIntegration?
How can we make
Paw hackable with
JavaScriptCore?
OpenSource
Clean Your App
FocusSmallApps
Updates
Updates
CocoaScript
WebKit
Your JS API
InterfaceContract
Testing Use itLike it?
Example
JSContext* context = [[JSContext alloc] init];JSValue* gigaValue = [context evaluateScript:@"Math.pow(2,30)"];NSLog(@"1 GiB = %ld bytes", [gigaValue toNumber].integerValue);// 1 GiB = 1073741824 bytes
JSValueJavaScript Type Objective-C Type Swift Type
string NSString String
boolean BOOL Bool
number
NSNumberdoubleint32_tuint32_t
NSNumber!DoubleInt32UInt32
Date NSDate Date
Array NSArray [AnyObject]
Object NSDictionary [NSObject : AnyObject]
Object custom type custom type
JSContext
VirtualMachine
Holds AllObjects
SingleThread
JSExport
SwiftClass
JavaScriptPrototype
SwiftInstance
JavaScriptObject
/* Extend JSExport protocol */@protocol LMJSRequest <JSExport>
JSExportAs(getMethod, -(id)method);JSExportAs(getUrl, -(id)url);
JSExportAs(setMethod, -(id)method:(NSString*)method);JSExportAs(setUrl, -(id)url:(NSString*)url);
@end
/* Implement protocol as a category */@interface LMRequest (LMJSRequest) <LMJSRequest>
@end
Not The Web
DOM WebWorkers Web Crypto
Local Storage
XHR (Ajax)setTimeout
CSSPromiseWebSocket
File API
Not The Web
Pure Vanilla JS
Multithreading
Core Data Grand Central
Dispatch
Run LoopsetTimeout()
DispatchQueue.main.asyncAfter(deadline: time)
…run code…
Extensions in Paw
ImportersCodeGenerators
DynamicValues
Code Generators• Client Code (Swift, ObjC, Python, Ruby…)• Command Line (cURL, HTTPie)• API Descriptions (API Blueprint, Swagger, RAML…)• 3rd party (Postman)
Importers• HTTP Archives (HAR)• API Descriptions (API Blueprint, Swagger, RAML…)• 3rd party (Postman)
Dynamic Values• Auth (JWT, Digest, Django…)• 3rd party auth (Amazon, Auth0…)• Randomizers (Chance.js, UUID, JSON Schema)
Who uses JavaScriptCore?
React NativeSafari Build Apps
Conclusion
• We can open source more• Always have an answer• More features than any competitor• Update extensions multiple times a week