You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by gu...@apache.org on 2017/11/09 09:52:30 UTC

[1/2] incubator-weex git commit: [WEEX-96][iOS] bug-fix about timer exposed on JSContext

Repository: incubator-weex
Updated Branches:
  refs/heads/master d2dd80dca -> 6c27b9b31


[WEEX-96][iOS] bug-fix about timer exposed on JSContext

  Timer exposed on the JSContext, so user can access the function,
though JavaScript, it has setTimeout and setInterval functions, those
function switch to global queue while execute javaScript code, it may
have potential crash about thread safe problem, and for setInterval
function, the timeId can not auto-increment, so it is hard to clear it at
the end of program.
  Overview the code, the difference between timer module and the
JSConext timer is  the execution path is more shorter, the JSContext
timer can execute javascript function immediately, but the timer module
instruction must be dispatched by weex sdk just like the common modules,
the JSContext can be used in canvas scene.

Bug: 96


Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/45c6c7e6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/45c6c7e6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/45c6c7e6

Branch: refs/heads/master
Commit: 45c6c7e6510565030bd8196e194ee0dc542c3f08
Parents: 30716b6
Author: acton393 <zh...@gmail.com>
Authored: Tue Nov 7 23:07:30 2017 +0800
Committer: acton393 <zh...@gmail.com>
Committed: Wed Nov 8 01:36:34 2017 +0800

----------------------------------------------------------------------
 ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m | 52 +++++++++-----------
 .../WeexSDK/Sources/Component/WXListComponent.m | 14 ++++--
 2 files changed, 33 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/45c6c7e6/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m b/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m
index f076817..d14cd92 100644
--- a/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m
+++ b/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m
@@ -473,21 +473,20 @@
 }
 
 
-- (void)callBackInterval:(NSDictionary *)dic functon:(void(^)())block
+- (void)callBackInterval:(NSDictionary *)dic
 {
-    if([dic objectForKey:@"appId"] && [_intervaltimers objectForKey:[dic objectForKey:@"appId"]]){
+    if(dic[@"function"] && [dic objectForKey:@"appId"] && [_intervaltimers objectForKey:[dic objectForKey:@"appId"]]){
         NSMutableArray *timers = [_intervaltimers objectForKey:[dic objectForKey:@"appId"]];
-        if([timers containsObject:[dic objectForKey:@"timerId"]]){
+        void(^block)() = ((void(^)())dic[@"function"]);
+        if(block && [timers containsObject:[dic objectForKey:@"timerId"]]){
             block();
             [self executeInterval:[dic objectForKey:@"appId"] function:block arg:[dic objectForKey:@"arg"] timerId:[[dic objectForKey:@"timerId"] longLongValue]];
         }
     }
 }
 
-
 - (void)triggerTimeout:(NSString *)appId ret:(NSString *)ret arg:(NSString *)arg
 {
-    
     double interval = [arg doubleValue]/1000.0f;
     if(WXFloatEqual(interval,0)) {
         return;
@@ -496,21 +495,19 @@
         [_timers addObject:ret];
         [self addInstance:appId callback:ret];
     }
-    __weak typeof(self) weakSelf = self;
-    dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, interval*NSEC_PER_SEC);
-    dispatch_after(time, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-        NSMutableDictionary *dic = [NSMutableDictionary new];
-        [dic setObject:appId forKey:@"appId"];
-        [dic setObject:ret forKey:@"ret"];
-        [dic setObject:arg forKey:@"arg"];
-        [weakSelf performSelector:@selector(callBack:) withObject:dic ];
-    });
+    
+    NSMutableDictionary *timeoutInfo = [NSMutableDictionary new];
+    [timeoutInfo setObject:appId forKey:@"appId"];
+    [timeoutInfo setObject:ret forKey:@"ret"];
+    [timeoutInfo setObject:arg forKey:@"arg"];
+    [self performSelector:@selector(callBack:) withObject:timeoutInfo afterDelay:interval inModes:@[NSRunLoopCommonModes]];
 }
 
 - (long long)triggerInterval:(NSString *)appId function:(void(^)())block arg:(NSString *)arg
 {
     double interval = [arg doubleValue]/1000.0f;
-    long long timerId = _intervalTimerId + 1;
+    _intervalTimerId = _intervalTimerId + 1; // timerId must auto-increment.
+    long long timerId = _intervalTimerId;
     if(WXFloatEqual(interval,0)) {
         return timerId;
     }
@@ -530,23 +527,20 @@
 -(void)executeInterval:(NSString *)appId function:(void(^)())block arg:(NSString *)arg timerId:(long long)timerId
 {
     double interval = [arg doubleValue]/1000.0f;
-    dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, interval*NSEC_PER_SEC);
-    __weak typeof(self) weakSelf = self;
-    dispatch_after(time, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-        NSMutableDictionary *dic = [NSMutableDictionary new];
-        [dic setObject:appId forKey:@"appId"];
-        [dic setObject:arg forKey:@"arg"];
-        [dic setObject:@(timerId) forKey:@"timerId"];
-        [weakSelf performSelector:@selector(callBackInterval:functon:) withObject:dic withObject:block];
-    });
+    NSMutableDictionary *intervalInfo = [NSMutableDictionary new];
+    [intervalInfo setObject:appId forKey:@"appId"];
+    [intervalInfo setObject:arg forKey:@"arg"];
+    [intervalInfo setObject:@(timerId) forKey:@"timerId"];
+    [intervalInfo setObject:[block copy] forKey:@"function"];
+    [self performSelector:@selector(callBackInterval:) withObject:intervalInfo afterDelay:interval inModes:@[NSRunLoopCommonModes]];
 }
 
-- (void)triggerClearInterval:(NSString *)appId ret:(long long)ret
+- (void)triggerClearInterval:(NSString *)instanceId ret:(long long)timerId
 {
-    if(_intervaltimers && [_intervaltimers objectForKey:@"appId"]){
-        NSMutableArray *timers = [_intervaltimers objectForKey:@"appId"];
-        if(timers && [timers containsObject:@(ret)]){
-            [timers removeObject:@(ret)];
+    if(_intervaltimers && [_intervaltimers objectForKey:instanceId]){
+        NSMutableArray *timers = [_intervaltimers objectForKey:instanceId];
+        if(timers && [timers containsObject:@(timerId)]){
+            [timers removeObject:@(timerId)];
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/45c6c7e6/ios/sdk/WeexSDK/Sources/Component/WXListComponent.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXListComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXListComponent.m
index cb9237f..7c4fe68 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXListComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Component/WXListComponent.m
@@ -543,10 +543,16 @@
             [self removeCellForIndexPath:fromIndexPath withSections:_completedSections];
             [self insertCell:cell forIndexPath:toIndexPath withSections:_completedSections];
             [UIView performWithoutAnimation:^{
-                [_tableView beginUpdates];
-                [_tableView moveRowAtIndexPath:fromIndexPath toIndexPath:toIndexPath];
-                [self handleAppear];
-                [_tableView endUpdates];
+                @try {
+                    [_tableView beginUpdates];
+                    [_tableView moveRowAtIndexPath:fromIndexPath toIndexPath:toIndexPath];
+                    [self handleAppear];
+                    [_tableView endUpdates];
+                }@catch(NSException * exception){
+                    WXLogDebug(@"move cell exception: %@", [exception description]);
+                }@finally {
+                    // do nothing
+                }
             }];
         }
     }];


[2/2] incubator-weex git commit: * [ios] bug-fix about timer exposed on JSContext

Posted by gu...@apache.org.
* [ios] bug-fix about timer exposed on JSContext


Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/6c27b9b3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/6c27b9b3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/6c27b9b3

Branch: refs/heads/master
Commit: 6c27b9b3136dfc3e2c8c34a720784c541ed1c466
Parents: d2dd80d 45c6c7e
Author: gurisxie <27...@qq.com>
Authored: Thu Nov 9 17:52:07 2017 +0800
Committer: gurisxie <27...@qq.com>
Committed: Thu Nov 9 17:52:24 2017 +0800

----------------------------------------------------------------------
 ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m | 52 +++++++++-----------
 .../WeexSDK/Sources/Component/WXListComponent.m | 14 ++++--
 2 files changed, 33 insertions(+), 33 deletions(-)
----------------------------------------------------------------------