You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by cx...@apache.org on 2017/07/27 04:07:23 UTC

[1/2] incubator-weex git commit: +[ios] update code for component/module validation

Repository: incubator-weex
Updated Branches:
  refs/heads/0.16-dev 7aad49089 -> a54bcb91d


+[ios] update code for component/module validation


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

Branch: refs/heads/0.16-dev
Commit: b563c6db27342f92e8e0ce3ab06b9520071d0eeb
Parents: 7aad490
Author: xujk2008 <xu...@gmail.com>
Authored: Wed Jul 26 10:50:01 2017 +0800
Committer: xujk2008 <xu...@gmail.com>
Committed: Thu Jul 27 11:43:30 2017 +0800

----------------------------------------------------------------------
 ios/sdk/WeexSDK/Sources/Bridge/WXBridgeContext.m     |  5 +++--
 ios/sdk/WeexSDK/Sources/Bridge/WXModuleMethod.h      |  2 ++
 ios/sdk/WeexSDK/Sources/Bridge/WXModuleMethod.m      | 11 ++++++++---
 ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.m | 15 ++++++++++-----
 ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m        |  2 ++
 .../WeexSDK/Sources/Protocol/WXValidateProtocol.h    |  4 ++--
 6 files changed, 27 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b563c6db/ios/sdk/WeexSDK/Sources/Bridge/WXBridgeContext.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Bridge/WXBridgeContext.m b/ios/sdk/WeexSDK/Sources/Bridge/WXBridgeContext.m
index f04a0db..781dd05 100644
--- a/ios/sdk/WeexSDK/Sources/Bridge/WXBridgeContext.m
+++ b/ios/sdk/WeexSDK/Sources/Bridge/WXBridgeContext.m
@@ -325,7 +325,7 @@ _Pragma("clang diagnostic pop") \
             return nil;
         }
         
-        WXModuleMethod *method = [[WXModuleMethod alloc] initWithModuleName:moduleName methodName:methodName arguments:arguments instance:instance];
+        WXModuleMethod *method = [[WXModuleMethod alloc] initWithModuleName:moduleName methodName:methodName arguments:arguments options:options instance:instance];
         if(![moduleName isEqualToString:@"dom"] && instance.needPrerender){
             [WXPrerenderManager storePrerenderModuleTasks:method forUrl:instance.scriptURL.absoluteString];
             return nil;
@@ -396,7 +396,8 @@ _Pragma("clang diagnostic pop") \
             [WXTracingManager startTracingWithInstanceId:instanceId ref:task[@"ref"] className:nil name:task[@"component"] phase:WXTracingBegin functionName:task[@"method"] options:nil];
         } else {
             NSString *moduleName = task[@"module"];
-            WXModuleMethod *method = [[WXModuleMethod alloc] initWithModuleName:moduleName methodName:methodName arguments:arguments instance:instance];
+            NSDictionary *options = task[@"options"];
+            WXModuleMethod *method = [[WXModuleMethod alloc] initWithModuleName:moduleName methodName:methodName arguments:arguments options:options instance:instance];
             [WXTracingManager startTracingWithInstanceId:instanceId ref:nil className:nil name:task[@"module"] phase:WXTracingBegin functionName:task[@"method"] options:nil];
             [method invoke];
         }

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b563c6db/ios/sdk/WeexSDK/Sources/Bridge/WXModuleMethod.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Bridge/WXModuleMethod.h b/ios/sdk/WeexSDK/Sources/Bridge/WXModuleMethod.h
index 876be42..2e83407 100644
--- a/ios/sdk/WeexSDK/Sources/Bridge/WXModuleMethod.h
+++ b/ios/sdk/WeexSDK/Sources/Bridge/WXModuleMethod.h
@@ -28,10 +28,12 @@ typedef enum : NSUInteger {
 
 @property (nonatomic, assign) WXModuleMethodType methodType;
 @property (nonatomic, strong, readonly) NSString *moduleName;
+@property (nonatomic, strong, readonly) NSDictionary *options;
 
 - (instancetype)initWithModuleName:(NSString *)moduleName
                         methodName:(NSString *)methodName
                          arguments:(NSArray *)arguments
+                           options:(NSDictionary *)options
                           instance:(WXSDKInstance *)instance;
 
 - (NSInvocation *)invoke;

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b563c6db/ios/sdk/WeexSDK/Sources/Bridge/WXModuleMethod.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Bridge/WXModuleMethod.m b/ios/sdk/WeexSDK/Sources/Bridge/WXModuleMethod.m
index fbb53b1..4ad6c91 100644
--- a/ios/sdk/WeexSDK/Sources/Bridge/WXModuleMethod.m
+++ b/ios/sdk/WeexSDK/Sources/Bridge/WXModuleMethod.m
@@ -33,10 +33,12 @@
 - (instancetype)initWithModuleName:(NSString *)moduleName
                         methodName:(NSString *)methodName
                          arguments:(NSArray *)arguments
+                           options:(NSDictionary *)options
                           instance:(WXSDKInstance *)instance
 {
     if (self = [super initWithMethodName:methodName arguments:arguments instance:instance]) {
         _moduleName = moduleName;
+        _options = options;
     }
     
     return self;
@@ -44,12 +46,15 @@
 
 - (NSInvocation *)invoke
 {
-    
     if (self.instance.needValidate) {
         id<WXValidateProtocol> validateHandler = [WXHandlerFactory handlerForProtocol:@protocol(WXValidateProtocol)];
         if (validateHandler) {
-            WXModuleValidateResult* result =  [validateHandler validateWithWXSDKInstance:self.instance module:self.moduleName method:self.methodName args:self.arguments];
-            if (result && !result.isSuccess) {
+            WXModuleValidateResult* result = nil;
+            if ([validateHandler respondsToSelector:@selector(validateWithWXSDKInstance:module:method:args:options:)]) {
+                result =  [validateHandler validateWithWXSDKInstance:self.instance module:self.moduleName method:self.methodName args:self.arguments options:self.options];
+            }
+
+            if (result==nil || !result.isSuccess) {
                 NSString *errorMessage = [result.error.userInfo  objectForKey:@"errorMsg"];
                 WXLogError(@"%@", errorMessage);
                 WX_MONITOR_FAIL(WXMTJSBridge, WX_ERR_INVOKE_NATIVE, errorMessage);

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b563c6db/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.m b/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.m
index e1774dd..7eade8f 100644
--- a/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.m
+++ b/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.m
@@ -40,6 +40,8 @@
 static NSThread *WXComponentThread;
 
 #define WXAssertComponentExist(component)  WXAssert(component, @"component not exists")
+#define WXAUTH_ISV_COMPONENT_TAG    @"isv-div"
+#define WXAUTH_ISV_COMPONENT_KEY    @"isvAppKey"
 
 @implementation WXComponentManager
 {
@@ -201,7 +203,7 @@ static NSThread *WXComponentThread;
     WXAssertComponentThread();
     WXAssertParam(data);
     
-    _rootComponent = [self _buildComponentForData:data];
+    _rootComponent = [self _buildComponentForData:data supercomponent:nil];
     
     [self _initRootCSSNode];
     __weak typeof(self) weakSelf = self;
@@ -244,7 +246,7 @@ static css_node_t * rootNodeGetChild(void *context, int i)
 
 - (void)_recursivelyAddComponent:(NSDictionary *)componentData toSupercomponent:(WXComponent *)supercomponent atIndex:(NSInteger)index appendingInTree:(BOOL)appendingInTree
 {
-    WXComponent *component = [self _buildComponentForData:componentData];
+    WXComponent *component = [self _buildComponentForData:componentData supercomponent:supercomponent];
     if (!supercomponent.subcomponents) {
         index = 0;
     } else {
@@ -353,7 +355,7 @@ static css_node_t * rootNodeGetChild(void *context, int i)
     return _indexDict.count;
 }
 
-- (WXComponent *)_buildComponentForData:(NSDictionary *)data
+- (WXComponent *)_buildComponentForData:(NSDictionary *)data supercomponent:(WXComponent *)supercomponent
 {
     NSString *ref = data[@"ref"];
     NSString *type = data[@"type"];
@@ -364,8 +366,11 @@ static css_node_t * rootNodeGetChild(void *context, int i)
     if (self.weexInstance.needValidate) {
         id<WXValidateProtocol> validateHandler = [WXHandlerFactory handlerForProtocol:@protocol(WXValidateProtocol)];
         if (validateHandler) {
-            WXComponentValidateResult* validateResult =  [validateHandler validateWithWXSDKInstance:self.weexInstance component:type];
-            if (validateResult && !validateResult.isSuccess) {
+            WXComponentValidateResult* validateResult;
+            if ([validateHandler respondsToSelector:@selector(validateWithWXSDKInstance:component:supercomponent:)]) {
+                validateResult = [validateHandler validateWithWXSDKInstance:self.weexInstance component:type supercomponent:supercomponent];
+            }
+            if (validateResult==nil || !validateResult.isSuccess) {
                 type = validateResult.replacedComponent? validateResult.replacedComponent : @"div";
                 WXLogError(@"%@",[validateResult.error.userInfo objectForKey:@"errorMsg"]);
             }

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b563c6db/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
index 579138b..c527ae1 100644
--- a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
+++ b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
@@ -157,6 +157,8 @@ typedef enum : NSUInteger {
     _options = options;
     _jsData = data;
     
+    self.needValidate = [[WXHandlerFactory handlerForProtocol:@protocol(WXValidateProtocol)] needValidate:self.scriptURL];
+    
     [self _renderWithMainBundleString:source];
     
     [WXTracingManager setBundleJSType:source instanceId:self.instanceId];

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b563c6db/ios/sdk/WeexSDK/Sources/Protocol/WXValidateProtocol.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Protocol/WXValidateProtocol.h b/ios/sdk/WeexSDK/Sources/Protocol/WXValidateProtocol.h
index 19cde1a..4284f18 100644
--- a/ios/sdk/WeexSDK/Sources/Protocol/WXValidateProtocol.h
+++ b/ios/sdk/WeexSDK/Sources/Protocol/WXValidateProtocol.h
@@ -43,8 +43,8 @@
 
 -(BOOL)needValidate:(NSURL*) bundleUrl;
 
--(WXModuleValidateResult *)validateWithWXSDKInstance:(WXSDKInstance *)wxsdkInstance module:(NSString*) moduel method:(NSString *)method args:(NSArray *)args;
+-(WXModuleValidateResult *)validateWithWXSDKInstance:(WXSDKInstance *)wxsdkInstance module:(NSString*) moduel method:(NSString *)method args:(NSArray *)args options:(NSDictionary *)options;
 
--(WXComponentValidateResult *)validateWithWXSDKInstance:(WXSDKInstance *)wxsdkInstance component:(NSString *)componentName;
+-(WXComponentValidateResult *)validateWithWXSDKInstance:(WXSDKInstance *)wxsdkInstance component:(NSString *)componentName supercomponent:(WXComponent *)supercomponent;
 
 @end


[2/2] incubator-weex git commit: delete useless 'define' in WXComponentManager

Posted by cx...@apache.org.
delete useless 'define' in WXComponentManager


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

Branch: refs/heads/0.16-dev
Commit: a54bcb91d4776bb76aba277f209d57aa79a1396b
Parents: b563c6d
Author: xujk2008 <xu...@gmail.com>
Authored: Wed Jul 26 11:48:10 2017 +0800
Committer: xujk2008 <xu...@gmail.com>
Committed: Thu Jul 27 11:45:21 2017 +0800

----------------------------------------------------------------------
 ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.m | 2 --
 1 file changed, 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/a54bcb91/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.m b/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.m
index 7eade8f..5513b64 100644
--- a/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.m
+++ b/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.m
@@ -40,8 +40,6 @@
 static NSThread *WXComponentThread;
 
 #define WXAssertComponentExist(component)  WXAssert(component, @"component not exists")
-#define WXAUTH_ISV_COMPONENT_TAG    @"isv-div"
-#define WXAUTH_ISV_COMPONENT_KEY    @"isvAppKey"
 
 @implementation WXComponentManager
 {