iOS: fix posibblely mutated crash when onException

This commit is contained in:
pengfei.zhou 2022-08-05 11:57:09 +08:00 committed by osborn
parent e042ce732e
commit fe060bdb7f
2 changed files with 6 additions and 4 deletions

View File

@ -72,7 +72,7 @@ @interface DoricRegistry ()
@property(nonatomic, strong) NSMutableDictionary *plugins; @property(nonatomic, strong) NSMutableDictionary *plugins;
@property(nonatomic, strong) NSMutableDictionary *nodes; @property(nonatomic, strong) NSMutableDictionary *nodes;
@property(nonatomic, strong) NSMutableSet <id <DoricMonitorProtocol>> *monitors; @property(nonatomic, copy) NSSet <id <DoricMonitorProtocol>> *monitors;
@property(nonatomic, weak) DoricJSEngine *jsEngine; @property(nonatomic, weak) DoricJSEngine *jsEngine;
@end @end
@ -93,7 +93,7 @@ - (instancetype)initWithJSEngine:(DoricJSEngine *)jsEngine {
_jsEngine = jsEngine; _jsEngine = jsEngine;
_plugins = [NSMutableDictionary new]; _plugins = [NSMutableDictionary new];
_nodes = [NSMutableDictionary new]; _nodes = [NSMutableDictionary new];
_monitors = [NSMutableSet new]; _monitors = [NSSet new];
_loaderManager = [DoricResourceManager new]; _loaderManager = [DoricResourceManager new];
[self innerRegister]; [self innerRegister];
[DoricSingleton.instance.libraries enumerateObjectsUsingBlock:^(DoricLibrary *obj, BOOL *stop) { [DoricSingleton.instance.libraries enumerateObjectsUsingBlock:^(DoricLibrary *obj, BOOL *stop) {
@ -184,7 +184,9 @@ - (void)innerSetEnvironmentValue:(NSDictionary *)value {
} }
- (void)registerMonitor:(id <DoricMonitorProtocol>)monitor { - (void)registerMonitor:(id <DoricMonitorProtocol>)monitor {
[self.monitors addObject:monitor]; NSMutableSet *mutableSet = [self.monitors mutableCopy];
[mutableSet addObject:monitor];
self.monitors = mutableSet;
} }
- (void)onException:(NSException *)exception inContext:(DoricContext *)context { - (void)onException:(NSException *)exception inContext:(DoricContext *)context {

View File

@ -100,6 +100,7 @@ - (instancetype)init {
@"localeLanguage": [[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode] ?: @"", @"localeLanguage": [[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode] ?: @"",
@"localeCountry": [[NSLocale currentLocale] objectForKey:NSLocaleCountryCode] ?: @"", @"localeCountry": [[NSLocale currentLocale] objectForKey:NSLocaleCountryCode] ?: @"",
}.mutableCopy; }.mutableCopy;
[self.registry registerMonitor:[DoricDefaultMonitor new]];
[self ensureRunOnJSThread:^() { [self ensureRunOnJSThread:^() {
[self.profile start:@"Init"]; [self.profile start:@"Init"];
self.timers = [[NSMutableDictionary alloc] init]; self.timers = [[NSMutableDictionary alloc] init];
@ -111,7 +112,6 @@ - (instancetype)init {
self.initialized = YES; self.initialized = YES;
[self.profile end:@"Init"]; [self.profile end:@"Init"];
}]; }];
[self.registry registerMonitor:[DoricDefaultMonitor new]];
} }
return self; return self;
} }