Hi all,
I’m working on quickjs-ios project, and there is one feature that we can set
Objc-Object into javascript, then we can invoke method on that objc object.
The problem is i just want to create a common objc class id, any method
invocation can be redirect to the same api.
But i could not find the best solution with C api.
Below is the current solution, any suggestion please:
QJSRuntime *runtime = [[QJSRuntime alloc] init];
QJSContext *context = [runtime newContext];
TestObject *obj = [TestObject new];
__weak TestObject *weakObj = obj;
[context setGlobalKey:@"testval" value:obj];
obj = nil;
NSDictionary *ret = [context eval:@"testval.invoke('test', 1, 'a',
false);"];
NSLog(@"%@", ret);
// TODO: add this support in native.
[context eval:@"testval = Proxy.revocable(testval, {get: function(target,
name){return function(...args){return "
@"target.invoke(name, ...args)}}}).proxy;"];
ret = [context eval:@"testval.test('a', 3, true);"];
NSLog(@"%@", ret);
context = nil;
XCTAssert(weakObj == nil);
Thanks & Regards,
Sam