Skip to content

Instantly share code, notes, and snippets.

@matt-curtis
Last active August 22, 2019 07:13
Show Gist options
  • Save matt-curtis/4d0a64048307fb54f874d665aac7e0e1 to your computer and use it in GitHub Desktop.
Save matt-curtis/4d0a64048307fb54f874d665aac7e0e1 to your computer and use it in GitHub Desktop.
MOJavaScriptObject function execution
@import JavaScriptCore;
/// Retaining MOJavaScriptObject retains your JSContext/JSObject as well
@interface MOJavaScriptObject : NSObject
@property (readonly) JSObjectRef JSObject;
@property (readonly) JSContextRef JSContext;
@end
@implementation MOJavaScriptObject ()
- (JSValue*) callWithArguments:(NSArray*)argumentsArray {
JSContext *context = [JSContext contextWithJSGlobalContextRef:(JSGlobalContextRef)self.JSContext];
JSValue *function = [JSValue valueWithJSValueRef:self.JSObject inContext:context];
return [function callWithArguments:argumentsArray];
}
@end
Copy link

ghost commented Aug 22, 2019

@jamztang can you paste your closure code witch is how you trigger the runSomething method.

fn1(a, b) { return a + b; }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment