From fe060bdb7fe5d7c0f6814459483880c882888e13 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Fri, 5 Aug 2022 11:57:09 +0800 Subject: [PATCH] iOS: fix posibblely mutated crash when onException --- doric-iOS/Pod/Classes/DoricRegistry.m | 8 +++++--- doric-iOS/Pod/Classes/Engine/DoricJSEngine.m | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/doric-iOS/Pod/Classes/DoricRegistry.m b/doric-iOS/Pod/Classes/DoricRegistry.m index c4c27245..4786b1dd 100644 --- a/doric-iOS/Pod/Classes/DoricRegistry.m +++ b/doric-iOS/Pod/Classes/DoricRegistry.m @@ -72,7 +72,7 @@ @interface DoricRegistry () @property(nonatomic, strong) NSMutableDictionary *plugins; @property(nonatomic, strong) NSMutableDictionary *nodes; -@property(nonatomic, strong) NSMutableSet > *monitors; +@property(nonatomic, copy) NSSet > *monitors; @property(nonatomic, weak) DoricJSEngine *jsEngine; @end @@ -93,7 +93,7 @@ - (instancetype)initWithJSEngine:(DoricJSEngine *)jsEngine { _jsEngine = jsEngine; _plugins = [NSMutableDictionary new]; _nodes = [NSMutableDictionary new]; - _monitors = [NSMutableSet new]; + _monitors = [NSSet new]; _loaderManager = [DoricResourceManager new]; [self innerRegister]; [DoricSingleton.instance.libraries enumerateObjectsUsingBlock:^(DoricLibrary *obj, BOOL *stop) { @@ -184,7 +184,9 @@ - (void)innerSetEnvironmentValue:(NSDictionary *)value { } - (void)registerMonitor:(id )monitor { - [self.monitors addObject:monitor]; + NSMutableSet *mutableSet = [self.monitors mutableCopy]; + [mutableSet addObject:monitor]; + self.monitors = mutableSet; } - (void)onException:(NSException *)exception inContext:(DoricContext *)context { diff --git a/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m b/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m index 50444bc1..342d3254 100644 --- a/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m +++ b/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m @@ -100,6 +100,7 @@ - (instancetype)init { @"localeLanguage": [[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode] ?: @"", @"localeCountry": [[NSLocale currentLocale] objectForKey:NSLocaleCountryCode] ?: @"", }.mutableCopy; + [self.registry registerMonitor:[DoricDefaultMonitor new]]; [self ensureRunOnJSThread:^() { [self.profile start:@"Init"]; self.timers = [[NSMutableDictionary alloc] init]; @@ -111,7 +112,6 @@ - (instancetype)init { self.initialized = YES; [self.profile end:@"Init"]; }]; - [self.registry registerMonitor:[DoricDefaultMonitor new]]; } return self; }