iOS:add protection for SIGSEGV
This commit is contained in:
parent
4ef508d3a7
commit
de9b96c490
@ -52,6 +52,22 @@ - (DoricRegistry *)registry {
|
|||||||
return ret;
|
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<JSValue *> *)invokeDoricMethod:(NSString *)method arguments:(va_list)args {
|
||||||
DoricAsyncResult *ret = [[DoricAsyncResult alloc] init];
|
DoricAsyncResult *ret = [[DoricAsyncResult alloc] init];
|
||||||
NSMutableArray *array = [[NSMutableArray 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;
|
- (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;
|
- (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];
|
DoricRootNode *rootNode = [[DoricRootNode alloc] initWithContext:self];
|
||||||
_rootNode = rootNode;
|
_rootNode = rootNode;
|
||||||
[self init:extra];
|
[self init:extra];
|
||||||
[self callEntity:DORIC_ENTITY_CREATE, nil];
|
[self callEntity:DORIC_ENTITY_CREATE withArgumentsArray:@[]];
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@ -60,7 +60,7 @@ - (DoricViewNode *)targetViewNode:(NSString *)viewId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
[self callEntity:DORIC_ENTITY_DESTROY, nil];
|
[self callEntity:DORIC_ENTITY_DESTROY withArgumentsArray:@[]];
|
||||||
[[DoricContextManager instance] destroyContext:self];
|
[[DoricContextManager instance] destroyContext:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ - (DoricAsyncResult *)callEntity:(NSString *)method withArgumentsArray:(NSArray
|
|||||||
- (void)init:(NSString *)initData {
|
- (void)init:(NSString *)initData {
|
||||||
self.extra = initData;
|
self.extra = initData;
|
||||||
if (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[@"width"] = @(size.width);
|
||||||
it[@"height"] = @(size.height);
|
it[@"height"] = @(size.height);
|
||||||
}];
|
}];
|
||||||
[self callEntity:DORIC_ENTITY_BUILD, self.initialParams, nil];
|
[self callEntity:DORIC_ENTITY_BUILD withArgumentsArray:@[self.initialParams]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)reload:(NSString *)script {
|
- (void)reload:(NSString *)script {
|
||||||
@ -100,17 +100,17 @@ - (void)reload:(NSString *)script {
|
|||||||
self.script = script;
|
self.script = script;
|
||||||
[self.driver createContext:self.contextId script:script source:self.source];
|
[self.driver createContext:self.contextId script:script source:self.source];
|
||||||
[self init:self.extra];
|
[self init:self.extra];
|
||||||
[self callEntity:DORIC_ENTITY_CREATE, nil];
|
[self callEntity:DORIC_ENTITY_CREATE withArgumentsArray:@[]];
|
||||||
[self callEntity:DORIC_ENTITY_BUILD, self.initialParams, nil];
|
[self callEntity:DORIC_ENTITY_BUILD withArgumentsArray:@[self.initialParams]];
|
||||||
[self onShow];
|
[self onShow];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)onShow {
|
- (void)onShow {
|
||||||
[self callEntity:DORIC_ENTITY_SHOW, nil];
|
[self callEntity:DORIC_ENTITY_SHOW withArgumentsArray:@[]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)onHidden {
|
- (void)onHidden {
|
||||||
[self callEntity:DORIC_ENTITY_HIDDEN, nil];
|
[self callEntity:DORIC_ENTITY_HIDDEN withArgumentsArray:@[]];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -32,9 +32,11 @@
|
|||||||
|
|
||||||
- (DoricAsyncResult *)destroyContext:(NSString *)contextId;
|
- (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;
|
- (DoricAsyncResult *)invokeContextEntity:(NSString *)contextId method:(NSString *)method arguments:(va_list)args;
|
||||||
|
|
||||||
|
@ -53,6 +53,22 @@ + (instancetype)instance {
|
|||||||
return _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, ... {
|
- (DoricAsyncResult<JSValue *> *)invokeDoricMethod:(NSString *)method, ... {
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, method);
|
va_start(args, method);
|
||||||
|
@ -40,7 +40,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
|
|
||||||
- (void)destroyContext:(NSString *)contextId;
|
- (void)destroyContext:(NSString *)contextId;
|
||||||
|
|
||||||
- (JSValue *)invokeDoricMethod:(NSString *)method, ...;
|
- (JSValue *)invokeDoricMethod:(NSString *)method, ... NS_REQUIRES_NIL_TERMINATION;
|
||||||
|
|
||||||
- (JSValue *)invokeDoricMethod:(NSString *)method arguments:(va_list)args;
|
- (JSValue *)invokeDoricMethod:(NSString *)method arguments:(va_list)args;
|
||||||
|
|
||||||
|
@ -40,8 +40,13 @@ - (instancetype)initWithContext:(DoricContext *)context callbackId:(NSString *)c
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)resolve:(id)result {
|
- (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) {
|
setExceptionCallback:^(NSException *e) {
|
||||||
|
__strong typeof(__self) self = __self;
|
||||||
[self.context.driver.registry
|
[self.context.driver.registry
|
||||||
onException:e
|
onException:e
|
||||||
inContext:self.context];
|
inContext:self.context];
|
||||||
@ -49,8 +54,13 @@ - (void)resolve:(id)result {
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)reject:(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) {
|
setExceptionCallback:^(NSException *e) {
|
||||||
|
__strong typeof(__self) self = __self;
|
||||||
[self.context.driver.registry
|
[self.context.driver.registry
|
||||||
onException:e
|
onException:e
|
||||||
inContext:self.context];
|
inContext:self.context];
|
||||||
|
Reference in New Issue
Block a user