cxfeng1 closed pull request #1472: [WEEX-592][iOS] fix dic for-each read crash
URL: https://github.com/apache/incubator-weex/pull/1472
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance_performance.m 
b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance_performance.m
index ab1e1b9cfb..7b2f7f082d 100644
--- a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance_performance.m
+++ b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance_performance.m
@@ -51,13 +51,18 @@ - (void)onViewLoad:(WXComponent *)targetComponent{
     targetComponent.hasAdd = true;
     double modifyTime =  CACurrentMediaTime()*1000;
     
+    __weak WXComponent* weakComponent = targetComponent;
     dispatch_async(dispatch_get_main_queue(), ^{
-        if(![self _verifyComponent:targetComponent]){
+        __strong WXComponent* strongComponent = weakComponent;
+        if (nil == strongComponent) {
+            return;
+        }
+        if(![self _verifyComponent:strongComponent]){
             return;
         }
         self.interactionAddCountRecord++;
         
-        [self _handleRenderTime:targetComponent withModifyTime:modifyTime];
+        [self _handleRenderTime:strongComponent withModifyTime:modifyTime];
     });
 }
 
diff --git a/ios/sdk/WeexSDK/Sources/Monitor/WXExceptionUtils.m 
b/ios/sdk/WeexSDK/Sources/Monitor/WXExceptionUtils.m
index 286b6550b3..1c78fbbac9 100644
--- a/ios/sdk/WeexSDK/Sources/Monitor/WXExceptionUtils.m
+++ b/ios/sdk/WeexSDK/Sources/Monitor/WXExceptionUtils.m
@@ -26,58 +26,57 @@
 #import "WXUtility.h"
 #import "WXSDKManager.h"
 #import "WXAnalyzerCenter+Transfer.h"
+#import "WXComponentManager.h"
 
 
 
 @implementation WXExceptionUtils
 
 + (void)commitCriticalExceptionRT:(NSString *)instanceId errCode:(NSString 
*)errCode function:(NSString *)function exception:(NSString *)exception 
extParams:(NSDictionary *)extParams{
-    NSString *bundleUrlCommit = @"BundleUrlDefault";
-    NSString *instanceIdCommit = @"InstanceIdDefalut";
-    
-    WXSDKInstance * instance ;
-    if(![WXUtility isBlankString:instanceId]){
-        instanceIdCommit = instanceId;
-        instance = [WXSDKManager instanceForID:instanceId];
-        if(instance){
-            bundleUrlCommit = instance.pageName?:([instance.scriptURL 
absoluteString]?:bundleUrlCommit);
-            NSMutableDictionary* extInfo = [[NSMutableDictionary alloc] 
initWithDictionary:extParams];
-            if (instance.containerInfo && instance.containerInfo.count >0) {
-                [extInfo addEntriesFromDictionary:instance.containerInfo];
+
+    NSMutableDictionary* extInfo = [[NSMutableDictionary alloc] 
initWithDictionary:extParams];
+    WXPerformBlockOnComponentThread(^{
+        NSString *bundleUrlCommit = @"BundleUrlDefault";
+        NSString *instanceIdCommit = @"InstanceIdDefalut";
+        WXSDKInstance * instance ;
+        if(![WXUtility isBlankString:instanceId]){
+            instanceIdCommit = instanceId;
+            instance = [WXSDKManager instanceForID:instanceId];
+            if(instance){
+                bundleUrlCommit = instance.pageName?:([instance.scriptURL 
absoluteString]?:bundleUrlCommit);
+               
+                if (instance.containerInfo && instance.containerInfo.count >0) 
{
+                    [extInfo addEntriesFromDictionary:instance.containerInfo];
+                }
+                [extInfo setObject:[self _convertInstanceStageToStr:instance] 
forKey:@"wxStageList"];
+                [extInfo 
setObject:instance.pageName?:@"unKnowPageNameCaseUnSet" forKey:@"wxPageName"];
+                [extInfo setObject:instance.bundleTemplate?:@"has recycle" 
forKey:@"wxTemplateOfBundle"];
+            }else if([instanceIdCommit hasPrefix:@"WX_KEY_EXCEPTION"]){
+                bundleUrlCommit = instanceId;
             }
-            [extInfo setObject:[self _convertInstanceStageToStr:instance] 
forKey:@"wxStageList"];
-            [extInfo setObject:instance.pageName?:@"unKnowPageNameCaseUnSet" 
forKey:@"wxPageName"];
-            [extInfo setObject:instance.bundleTemplate?:@"has recycle" 
forKey:@"wxTemplateOfBundle"];
-            extParams = extInfo;
-        }else if([instanceIdCommit hasPrefix:@"WX_KEY_EXCEPTION"]){
-            bundleUrlCommit = instanceId;
         }
-    }
-  
-    WXJSExceptionInfo * jsExceptionInfo = [[WXJSExceptionInfo alloc] 
initWithInstanceId:instanceIdCommit bundleUrl:bundleUrlCommit errorCode:errCode 
functionName:function exception:exception userInfo: [extParams mutableCopy]];
-    
-    //record top5 erromsg ,if errorType is not WX_RENDER_ERROR
-    NSNumberFormatter *formater = [[NSNumberFormatter alloc] init];
-    formater.numberStyle = NSNumberFormatterDecimalStyle;
-    NSNumber *codeNumber = [formater numberFromString:errCode];
-    if (codeNumber) {
-       WXSDKErrorType type = [WXSDKErrCodeUtil 
getErrorTypeByCode:codeNumber.intValue];
+        WXJSExceptionInfo * jsExceptionInfo = [[WXJSExceptionInfo alloc] 
initWithInstanceId:instanceIdCommit bundleUrl:bundleUrlCommit errorCode:errCode 
functionName:function exception:exception userInfo: [extInfo mutableCopy]];
+        
+        //record top5 erromsg ,if errorType is not WX_RENDER_ERROR
+        WXSDKErrorType type = [WXSDKErrCodeUtil 
getErrorTypeByCode:errCode.intValue];
         if (type != WX_RENDER_ERROR && nil != instance) {
             [instance.apmInstance recordErrorMsg:jsExceptionInfo];
         }
-    }
-  
-    [WXExceptionUtils commitCriticalExceptionRT:jsExceptionInfo];
+        [WXExceptionUtils commitCriticalExceptionRT:jsExceptionInfo];
+    });
 }
 
 + (void)commitCriticalExceptionRT:(WXJSExceptionInfo *)jsExceptionInfo{
-    id<WXJSExceptionProtocol> jsExceptionHandler = [WXHandlerFactory 
handlerForProtocol:@protocol(WXJSExceptionProtocol)];
-    if ([jsExceptionHandler respondsToSelector:@selector(onJSException:)]) {
-        [jsExceptionHandler onJSException:jsExceptionInfo];
-    }
-    if ([WXAnalyzerCenter isOpen]) {
-        [WXAnalyzerCenter transErrorInfo:jsExceptionInfo];
-    }
+    
+    WXPerformBlockOnComponentThread(^ {
+        id<WXJSExceptionProtocol> jsExceptionHandler = [WXHandlerFactory 
handlerForProtocol:@protocol(WXJSExceptionProtocol)];
+        if ([jsExceptionHandler respondsToSelector:@selector(onJSException:)]) 
{
+            [jsExceptionHandler onJSException:jsExceptionInfo];
+        }
+        if ([WXAnalyzerCenter isOpen]) {
+            [WXAnalyzerCenter transErrorInfo:jsExceptionInfo];
+        }
+    });
 }
 
 + (NSString*) _convertInstanceStageToStr:(WXSDKInstance *)instance
@@ -90,9 +89,15 @@ + (NSString*) _convertInstanceStageToStr:(WXSDKInstance 
*)instance
         return @"emptyStageRecord";
     }
     NSString* stageStr = @"";
-    for (NSString* key in stageDic) {
+    NSArray<NSString *> *keysArray = [stageDic allKeys];
+    for (int i=0; i<keysArray.count; i++) {
+        NSString* key = [keysArray objectAtIndex:i];
         NSNumber* time = [stageDic objectForKey:key];
-        stageStr = [stageStr stringByAppendingFormat:@"%@ -> 
%@:%@",stageStr,key,time];
+        if (nil!=key && nil != time ) {
+            stageStr = [stageStr stringByAppendingFormat:@"-> %@:%@",key,time];
+        }else{
+             stageStr = [stageStr stringByAppendingFormat:@"-> nilKeyOrValue"];
+        }
     }
     return stageStr;
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to