iOS:add protection for SIGSEGV
This commit is contained in:
parent
4ef508d3a7
commit
de9b96c490
@ -52,6 +52,22 @@ - (DoricRegistry *)registry {
|
||||
return ret;
|
||||
}
|
||||
|
||||
- (DoricAsyncResult *)invokeDoricMethod:(NSString *)method argumentsArray:(NSArray *)args {
|
||||
DoricAsyncResult *ret = [[DoricAsyncResult alloc] init];
|
||||
__weak typeof(self) _self = self;
|
||||
dispatch_async(self.jsExecutor.jsQueue, ^() {
|
||||
__strong typeof(_self) self = _self;
|
||||
if (!self) return;
|
||||
@try {
|
||||
JSValue *jsValue = [self.jsExecutor invokeDoricMethod:method argumentsArray:args];
|
||||
[ret setupResult:jsValue];
|
||||
} @catch (NSException *exception) {
|
||||
[ret setupError:exception];
|
||||
}
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
- (DoricAsyncResult<JSValue *> *)invokeDoricMethod:(NSString *)method arguments:(va_list)args {
|
||||
DoricAsyncResult *ret = [[DoricAsyncResult alloc] init];
|
||||
NSMutableArray *array = [[NSMutableArray alloc] init];
|
||||
|
@ -45,7 +45,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
- (instancetype)initWithScript:(NSString *)script source:(NSString *)source extra:(NSString *)extra;
|
||||
|
||||
- (DoricAsyncResult *)callEntity:(NSString *)method, ...;
|
||||
- (DoricAsyncResult *)callEntity:(NSString *)method, ... NS_REQUIRES_NIL_TERMINATION;
|
||||
|
||||
- (DoricAsyncResult *)callEntity:(NSString *)method withArguments:(va_list)args;
|
||||
|
||||
|
@ -41,7 +41,7 @@ - (instancetype)initWithScript:(NSString *)script source:(NSString *)source extr
|
||||
DoricRootNode *rootNode = [[DoricRootNode alloc] initWithContext:self];
|
||||
_rootNode = rootNode;
|
||||
[self init:extra];
|
||||
[self callEntity:DORIC_ENTITY_CREATE, nil];
|
||||
[self callEntity:DORIC_ENTITY_CREATE withArgumentsArray:@[]];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@ -60,7 +60,7 @@ - (DoricViewNode *)targetViewNode:(NSString *)viewId {
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[self callEntity:DORIC_ENTITY_DESTROY, nil];
|
||||
[self callEntity:DORIC_ENTITY_DESTROY withArgumentsArray:@[]];
|
||||
[[DoricContextManager instance] destroyContext:self];
|
||||
}
|
||||
|
||||
@ -83,7 +83,7 @@ - (DoricAsyncResult *)callEntity:(NSString *)method withArgumentsArray:(NSArray
|
||||
- (void)init:(NSString *)initData {
|
||||
self.extra = initData;
|
||||
if (initData) {
|
||||
[self callEntity:DORIC_ENTITY_INIT, initData, nil];
|
||||
[self callEntity:DORIC_ENTITY_INIT withArgumentsArray:@[initData]];
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ - (void)build:(CGSize)size {
|
||||
it[@"width"] = @(size.width);
|
||||
it[@"height"] = @(size.height);
|
||||
}];
|
||||
[self callEntity:DORIC_ENTITY_BUILD, self.initialParams, nil];
|
||||
[self callEntity:DORIC_ENTITY_BUILD withArgumentsArray:@[self.initialParams]];
|
||||
}
|
||||
|
||||
- (void)reload:(NSString *)script {
|
||||
@ -100,17 +100,17 @@ - (void)reload:(NSString *)script {
|
||||
self.script = script;
|
||||
[self.driver createContext:self.contextId script:script source:self.source];
|
||||
[self init:self.extra];
|
||||
[self callEntity:DORIC_ENTITY_CREATE, nil];
|
||||
[self callEntity:DORIC_ENTITY_BUILD, self.initialParams, nil];
|
||||
[self callEntity:DORIC_ENTITY_CREATE withArgumentsArray:@[]];
|
||||
[self callEntity:DORIC_ENTITY_BUILD withArgumentsArray:@[self.initialParams]];
|
||||
[self onShow];
|
||||
}
|
||||
|
||||
- (void)onShow {
|
||||
[self callEntity:DORIC_ENTITY_SHOW, nil];
|
||||
[self callEntity:DORIC_ENTITY_SHOW withArgumentsArray:@[]];
|
||||
}
|
||||
|
||||
- (void)onHidden {
|
||||
[self callEntity:DORIC_ENTITY_HIDDEN, nil];
|
||||
[self callEntity:DORIC_ENTITY_HIDDEN withArgumentsArray:@[]];
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -32,9 +32,11 @@
|
||||
|
||||
- (DoricAsyncResult *)destroyContext:(NSString *)contextId;
|
||||
|
||||
- (DoricAsyncResult *)invokeDoricMethod:(NSString *)method, ...;
|
||||
- (DoricAsyncResult *)invokeDoricMethod:(NSString *)method, ... NS_REQUIRES_NIL_TERMINATION;
|
||||
|
||||
- (DoricAsyncResult *)invokeContextEntity:(NSString *)contextId method:(NSString *)method, ...;
|
||||
- (DoricAsyncResult *)invokeDoricMethod:(NSString *)method argumentsArray:(NSArray *)args;
|
||||
|
||||
- (DoricAsyncResult *)invokeContextEntity:(NSString *)contextId method:(NSString *)method, ... NS_REQUIRES_NIL_TERMINATION;
|
||||
|
||||
- (DoricAsyncResult *)invokeContextEntity:(NSString *)contextId method:(NSString *)method arguments:(va_list)args;
|
||||
|
||||
|
@ -53,6 +53,22 @@ + (instancetype)instance {
|
||||
return _instance;
|
||||
}
|
||||
|
||||
- (DoricAsyncResult *)invokeDoricMethod:(NSString *)method argumentsArray:(NSArray *)args {
|
||||
DoricAsyncResult *ret = [[DoricAsyncResult alloc] init];
|
||||
__weak typeof(self) _self = self;
|
||||
dispatch_async(self.jsExecutor.jsQueue, ^() {
|
||||
__strong typeof(_self) self = _self;
|
||||
if (!self) return;
|
||||
@try {
|
||||
JSValue *jsValue = [self.jsExecutor invokeDoricMethod:method argumentsArray:args];
|
||||
[ret setupResult:jsValue];
|
||||
} @catch (NSException *exception) {
|
||||
[ret setupError:exception];
|
||||
}
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
- (DoricAsyncResult<JSValue *> *)invokeDoricMethod:(NSString *)method, ... {
|
||||
va_list args;
|
||||
va_start(args, method);
|
||||
|
@ -40,7 +40,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
- (void)destroyContext:(NSString *)contextId;
|
||||
|
||||
- (JSValue *)invokeDoricMethod:(NSString *)method, ...;
|
||||
- (JSValue *)invokeDoricMethod:(NSString *)method, ... NS_REQUIRES_NIL_TERMINATION;
|
||||
|
||||
- (JSValue *)invokeDoricMethod:(NSString *)method arguments:(va_list)args;
|
||||
|
||||
|
@ -228,7 +228,7 @@ - (void)callbackTimer:(NSTimer *)timer {
|
||||
NSDictionary *userInfo = timer.userInfo;
|
||||
NSNumber *timerId = [userInfo valueForKey:@"timerId"];
|
||||
NSNumber *repeat = [userInfo valueForKey:@"repeat"];
|
||||
|
||||
|
||||
__strong typeof(_self) self = _self;
|
||||
@try {
|
||||
[self invokeDoricMethod:DORIC_TIMER_CALLBACK, timerId, nil];
|
||||
|
@ -40,8 +40,13 @@ - (instancetype)initWithContext:(DoricContext *)context callbackId:(NSString *)c
|
||||
}
|
||||
|
||||
- (void)resolve:(id)result {
|
||||
[[self.context.driver invokeDoricMethod:DORIC_BRIDGE_RESOLVE, self.context.contextId, self.callbackId, result, nil]
|
||||
__weak typeof(self) __self = self;
|
||||
[[self.context.driver invokeDoricMethod:DORIC_BRIDGE_RESOLVE
|
||||
argumentsArray:result
|
||||
? @[self.context.contextId, self.callbackId, result]
|
||||
: @[self.context.contextId, self.callbackId]]
|
||||
setExceptionCallback:^(NSException *e) {
|
||||
__strong typeof(__self) self = __self;
|
||||
[self.context.driver.registry
|
||||
onException:e
|
||||
inContext:self.context];
|
||||
@ -49,8 +54,13 @@ - (void)resolve:(id)result {
|
||||
}
|
||||
|
||||
- (void)reject:(id)result {
|
||||
[[self.context.driver invokeDoricMethod:DORIC_BRIDGE_REJECT, self.context.contextId, self.callbackId, result, nil]
|
||||
__weak typeof(self) __self = self;
|
||||
[[self.context.driver invokeDoricMethod:DORIC_BRIDGE_REJECT
|
||||
argumentsArray:result
|
||||
? @[self.context.contextId, self.callbackId, result]
|
||||
: @[self.context.contextId, self.callbackId]]
|
||||
setExceptionCallback:^(NSException *e) {
|
||||
__strong typeof(__self) self = __self;
|
||||
[self.context.driver.registry
|
||||
onException:e
|
||||
inContext:self.context];
|
||||
|
Reference in New Issue
Block a user