[WEEX-240][iOS] support sandbox on iOS
* [iOS] bugfix bridgeManger mutli instance

* [iOS] support multi-context

* [iOS] handle  common javaScript context exposed method

* [iOS] add miss environment information

* [iOS] fix dead lock about dealloc object

* [iOS] try to protect crash when set nil object in dictionary

* [iOS] release jsContext object

* [iOS] support multi-context

* [iOS] release jsContext object

* [iOS] pare bundleType dynamic

* [iOS] mark js vm garbage collect when instance destroyed

* [iOS] support multi-context

* [iOS] release jsContext object

* [iOS] pare bundleType dynamic

* [iOS] mark js vm garbage collect when instance destroyed

* [iOS] fix compier warnings

* [iOS] set the protoType of Vue to the protoType of globalObject

* [iOS] preserve nativeLog function

* [iOS] fix compiler complain

* [jsfm] update jsfm version

* [iOS] use boolValue about the config

* [iOS] bugfix bridgeManger mutli instance

* [iOS] support multi-context

* [iOS] fix dead lock about dealloc object

* [iOS] try to protect crash when set nil object in dictionary

* [iOS] release jsContext object

* [iOS] pare bundleType dynamic

* [iOS] mark js vm garbage collect when instance destroyed

* [iOS] bugfix bridgeManger mutli instance

* [iOS] support multi-context

* [iOS] handle  common javaScript context exposed method

* [iOS] add miss environment information

* [iOS] fix dead lock about dealloc object

* [iOS] try to protect crash when set nil object in dictionary

* [iOS] release jsContext object

* [iOS] bugfix bridgeManger mutli instance

* [iOS] support multi-context

* [iOS] handle  common javaScript context exposed method

* [iOS] fix dead lock about dealloc object

* [iOS] try to protect crash when set nil object in dictionary

* [iOS] release jsContext object

* [iOS] pare bundleType dynamic

* [iOS] mark js vm garbage collect when instance destroyed

* [iOS] fix compier warnings

* [iOS] set the protoType of Vue to the protoType of globalObject

* [iOS] set pageName is empty string if it is null

* [iOS] update config

* [iOS] callJS on instanceContext

* [iOS] update Rax logic

*[iOS] remove useless code

* [iOS] update jsfm about rax

* [iOS] update jsfm

* [iOS] bugfix

* [iOS] remove unused line

* [iOS] trim jsbundle string, so that we can parse the bundleType

* [iOS] downgrade while jsfm restart

* [iOS] add local storage for configuration

* [iOS] add resources for jsfm

* [iOS] downgrade to original process when iOS is less than 9.0

* [iOS] downgrade when iOS version less than 9.0

* [iOS] enable multicontext default

* [iOS] downgrade to single context when iOS lower than 10.0

* [iOS] add globalContext for bridge protocol

* [iOS] fix set env

* [iOS] bugfix about atob & btoa

* [iOS] compatible for rax framework

*[iOS] fix out of range

* [iOS] downgrade to share context as the promise of iOS 10.0

* [iOS] convert to BOOL value from id value

* [iOS] parse javaScript bundleType

+ [jsfm] add standalone Promise polyfill for iOS

* [iOS] add poly-fill for iOS so that it can apply to iOS 9 and iOS 8

* [iOS] update project setting for new resources

* [iOS] refactor multi-context logic for devtool adapter

* [iOS] add header

* [iOS] bugfix about evaluate javaScript with sourceURL

* [iOS] clean unused code

* [iOS] callJSBridgeMethod

* [iOS] fix devtool adapter

* [iOS] refactor multi-context logic for devtool adapter (#3)

* [iOS] refactor multi-context logic for devtool adapter

* [iOS] update project settings

* [iOS] fix compiler error

[WEEX-240][iOS] clean up useless code

[WEEX-240] add weexInstanceId for bridgeProtocol

[WEEX-240][iOS] trim newline and whiteSpace character

[WEEX-240][iOS] update instance id when jscore context updated

close #1101


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

Branch: refs/heads/master
Commit: 080807289c22affee5afa918d7b7cced178b9c6e
Parents: 01f79b3
Author: acton393 <zhangxing610...@gmail.com>
Authored: Tue Dec 12 14:56:44 2017 +0800
Committer: acton393 <zhangxing610...@gmail.com>
Committed: Thu Apr 12 10:54:53 2018 +0800

----------------------------------------------------------------------
 WeexSDK.podspec                                 |   2 +-
 ios/sdk/WeexSDK.xcodeproj/project.pbxproj       |  18 ++
 .../WeexSDK/Sources/Bridge/WXBridgeContext.h    |   7 +-
 .../WeexSDK/Sources/Bridge/WXBridgeContext.m    | 308 +++++++++++++++++--
 ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.h |   2 +-
 ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m | 127 +++-----
 ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m    |  23 +-
 .../WeexSDK/Sources/Manager/WXBridgeManager.m   |   5 -
 ios/sdk/WeexSDK/Sources/Manager/WXSDKManager.h  |   6 +
 ios/sdk/WeexSDK/Sources/Manager/WXSDKManager.m  |  10 +-
 .../WeexSDK/Sources/Manager/WXTracingManager.m  |   4 +-
 ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.h   |  12 +
 ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m   |  88 +++++-
 .../Sources/Model/WXSDKInstance_private.h       |   2 +
 .../WeexSDK/Sources/Protocol/WXBridgeProtocol.h |  23 ++
 pre-build/native-bundle-main.js                 |   2 +-
 pre-build/weex-main-jsfm.js                     |   2 +-
 pre-build/weex-polyfill.js                      |   2 +
 pre-build/weex-rax-api.js                       |   2 +-
 19 files changed, 513 insertions(+), 132 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/08080728/WeexSDK.podspec
----------------------------------------------------------------------
diff --git a/WeexSDK.podspec b/WeexSDK.podspec
index 86aa6e8..21f80ee 100644
--- a/WeexSDK.podspec
+++ b/WeexSDK.podspec
@@ -28,7 +28,7 @@ Pod::Spec.new do |s|
   s.ios.deployment_target = '8.0'
   s.source =  { :path => '.' }
   s.source_files = 'ios/sdk/WeexSDK/Sources/**/*.{h,m,mm,c}'
-  s.resources = 'pre-build/native-bundle-main.js', 
'ios/sdk/WeexSDK/Resources/wx_load_er...@3x.png'
+  s.resources = 
'pre-build/*.js','ios/sdk/WeexSDK/Resources/wx_load_er...@3x.png'
 
   s.user_target_xcconfig  = { 'FRAMEWORK_SEARCH_PATHS' => 
"'$(PODS_ROOT)/WeexSDK'" }
   s.requires_arc = true

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/08080728/ios/sdk/WeexSDK.xcodeproj/project.pbxproj
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK.xcodeproj/project.pbxproj 
b/ios/sdk/WeexSDK.xcodeproj/project.pbxproj
index f017ac8..1ae188f 100644
--- a/ios/sdk/WeexSDK.xcodeproj/project.pbxproj
+++ b/ios/sdk/WeexSDK.xcodeproj/project.pbxproj
@@ -318,6 +318,8 @@
                D3FC0DF81C508B2A002B9E31 /* WXTimerModule.m in Sources */ = 
{isa = PBXBuildFile; fileRef = D3FC0DF61C508B2A002B9E31 /* WXTimerModule.m */; 
};
                DC03ADB91D508719003F76E7 /* WXTextAreaComponent.m in Sources */ 
= {isa = PBXBuildFile; fileRef = DC03ADB71D508719003F76E7 /* 
WXTextAreaComponent.m */; };
                DC03ADBA1D508719003F76E7 /* WXTextAreaComponent.h in Headers */ 
= {isa = PBXBuildFile; fileRef = DC03ADB81D508719003F76E7 /* 
WXTextAreaComponent.h */; };
+               DC15A3DB2010BC93009C8977 /* weex-main-jsfm.js in Resources */ = 
{isa = PBXBuildFile; fileRef = DC15A3D92010BC93009C8977 /* weex-main-jsfm.js 
*/; };
+               DC15A3DC2010BC93009C8977 /* weex-rax-api.js in Resources */ = 
{isa = PBXBuildFile; fileRef = DC15A3DA2010BC93009C8977 /* weex-rax-api.js */; 
};
                DC6836E61EBB12B200AD2D84 /* WXConfigCenterProtocol.h in Headers 
*/ = {isa = PBXBuildFile; fileRef = DC6836E51EBB12B200AD2D84 /* 
WXConfigCenterProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; };
                DC7764931F3C2CA300B5727E /* WXRecyclerDragController.m in 
Sources */ = {isa = PBXBuildFile; fileRef = DC7764911F3C2CA300B5727E /* 
WXRecyclerDragController.m */; };
                DC7764941F3C2CA300B5727E /* WXRecyclerDragController.h in 
Headers */ = {isa = PBXBuildFile; fileRef = DC7764921F3C2CA300B5727E /* 
WXRecyclerDragController.h */; };
@@ -572,6 +574,10 @@
                DCAB35FF1D658EB700C0EA70 /* WXRuleManager.m in Sources */ = 
{isa = PBXBuildFile; fileRef = DCAB35FD1D658EB700C0EA70 /* WXRuleManager.m */; 
};
                DCC77C131D770AE300CE7288 /* WXSliderNeighborComponent.m in 
Sources */ = {isa = PBXBuildFile; fileRef = DCC77C111D770AE300CE7288 /* 
WXSliderNeighborComponent.m */; };
                DCC77C141D770AE300CE7288 /* WXSliderNeighborComponent.h in 
Headers */ = {isa = PBXBuildFile; fileRef = DCC77C121D770AE300CE7288 /* 
WXSliderNeighborComponent.h */; };
+               DCD8D0F32073392A0002C420 /* weex-polyfill.js in Resources */ = 
{isa = PBXBuildFile; fileRef = DCD8D0F22073392A0002C420 /* weex-polyfill.js */; 
};
+               DCD8D0F42073392A0002C420 /* weex-polyfill.js in Resources */ = 
{isa = PBXBuildFile; fileRef = DCD8D0F22073392A0002C420 /* weex-polyfill.js */; 
};
+               DCD8D0F52073393B0002C420 /* weex-main-jsfm.js in Resources */ = 
{isa = PBXBuildFile; fileRef = DC15A3D92010BC93009C8977 /* weex-main-jsfm.js 
*/; };
+               DCD8D0F62073393B0002C420 /* weex-rax-api.js in Resources */ = 
{isa = PBXBuildFile; fileRef = DC15A3DA2010BC93009C8977 /* weex-rax-api.js */; 
};
                DCDFED011E68238F00C228D7 /* WXJSExceptionProtocol.h in Headers 
*/ = {isa = PBXBuildFile; fileRef = DCDFED001E68238F00C228D7 /* 
WXJSExceptionProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; };
                DCE2CF9A1F46D4220021BDC4 /* WXVoiceOverModule.m in Sources */ = 
{isa = PBXBuildFile; fileRef = DCE2CF981F46D4220021BDC4 /* WXVoiceOverModule.m 
*/; };
                DCE2CF9B1F46D4220021BDC4 /* WXVoiceOverModule.h in Headers */ = 
{isa = PBXBuildFile; fileRef = DCE2CF991F46D4220021BDC4 /* WXVoiceOverModule.h 
*/; settings = {ATTRIBUTES = (Public, ); }; };
@@ -903,6 +909,8 @@
                DAB176F008F516E4F9391C61 /* libPods-WeexSDK.a */ = {isa = 
PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = 
"libPods-WeexSDK.a"; sourceTree = BUILT_PRODUCTS_DIR; };
                DC03ADB71D508719003F76E7 /* WXTextAreaComponent.m */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path 
= WXTextAreaComponent.m; sourceTree = "<group>"; };
                DC03ADB81D508719003F76E7 /* WXTextAreaComponent.h */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = 
WXTextAreaComponent.h; sourceTree = "<group>"; };
+               DC15A3D92010BC93009C8977 /* weex-main-jsfm.js */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; 
name = "weex-main-jsfm.js"; path = "../../../../pre-build/weex-main-jsfm.js"; 
sourceTree = "<group>"; };
+               DC15A3DA2010BC93009C8977 /* weex-rax-api.js */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; 
name = "weex-rax-api.js"; path = "../../../../pre-build/weex-rax-api.js"; 
sourceTree = "<group>"; };
                DC6836E51EBB12B200AD2D84 /* WXConfigCenterProtocol.h */ = {isa 
= PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path 
= WXConfigCenterProtocol.h; sourceTree = "<group>"; };
                DC7764911F3C2CA300B5727E /* WXRecyclerDragController.m */ = 
{isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = 
sourcecode.c.objc; name = WXRecyclerDragController.m; path = 
WeexSDK/Sources/Component/Recycler/WXRecyclerDragController.m; sourceTree = 
SOURCE_ROOT; };
                DC7764921F3C2CA300B5727E /* WXRecyclerDragController.h */ = 
{isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; 
name = WXRecyclerDragController.h; path = 
WeexSDK/Sources/Component/Recycler/WXRecyclerDragController.h; sourceTree = 
SOURCE_ROOT; };
@@ -918,6 +926,7 @@
                DCAB35FD1D658EB700C0EA70 /* WXRuleManager.m */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path 
= WXRuleManager.m; sourceTree = "<group>"; };
                DCC77C111D770AE300CE7288 /* WXSliderNeighborComponent.m */ = 
{isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = 
sourcecode.c.objc; path = WXSliderNeighborComponent.m; sourceTree = "<group>"; 
};
                DCC77C121D770AE300CE7288 /* WXSliderNeighborComponent.h */ = 
{isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; 
path = WXSliderNeighborComponent.h; sourceTree = "<group>"; };
+               DCD8D0F22073392A0002C420 /* weex-polyfill.js */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; 
name = "weex-polyfill.js"; path = "../../../../pre-build/weex-polyfill.js"; 
sourceTree = "<group>"; };
                DCDFED001E68238F00C228D7 /* WXJSExceptionProtocol.h */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = 
WXJSExceptionProtocol.h; sourceTree = "<group>"; };
                DCE2CF981F46D4220021BDC4 /* WXVoiceOverModule.m */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path 
= WXVoiceOverModule.m; sourceTree = "<group>"; };
                DCE2CF991F46D4220021BDC4 /* WXVoiceOverModule.h */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = 
WXVoiceOverModule.h; sourceTree = "<group>"; };
@@ -1234,6 +1243,9 @@
                77D161171C02DCB90010B15B /* Resources */ = {
                        isa = PBXGroup;
                        children = (
+                               DCD8D0F22073392A0002C420 /* weex-polyfill.js */,
+                               DC15A3D92010BC93009C8977 /* weex-main-jsfm.js 
*/,
+                               DC15A3DA2010BC93009C8977 /* weex-rax-api.js */,
                                DCF0CD9D1EAF3A6B0062CA8F /* 
native-bundle-main.js */,
                                59AC02501D2A7E6E00355112 /* 
wx_load_er...@3x.png */,
                        );
@@ -2008,7 +2020,10 @@
                        isa = PBXResourcesBuildPhase;
                        buildActionMask = 2147483647;
                        files = (
+                               DC15A3DC2010BC93009C8977 /* weex-rax-api.js in 
Resources */,
                                DCF0CD9E1EAF3A6B0062CA8F /* 
native-bundle-main.js in Resources */,
+                               DCD8D0F32073392A0002C420 /* weex-polyfill.js in 
Resources */,
+                               DC15A3DB2010BC93009C8977 /* weex-main-jsfm.js 
in Resources */,
                                59AC02511D2A7E6E00355112 /* 
wx_load_er...@3x.png in Resources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
@@ -2017,7 +2032,10 @@
                        isa = PBXResourcesBuildPhase;
                        buildActionMask = 2147483647;
                        files = (
+                               DCD8D0F52073393B0002C420 /* weex-main-jsfm.js 
in Resources */,
                                DCA445C91EFA58CE00D0CFA8 /* 
native-bundle-main.js in Resources */,
+                               DCD8D0F42073392A0002C420 /* weex-polyfill.js in 
Resources */,
+                               DCD8D0F62073393B0002C420 /* weex-rax-api.js in 
Resources */,
                                DCA445CA1EFA58CE00D0CFA8 /* 
wx_load_er...@3x.png in Resources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/08080728/ios/sdk/WeexSDK/Sources/Bridge/WXBridgeContext.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Bridge/WXBridgeContext.h 
b/ios/sdk/WeexSDK/Sources/Bridge/WXBridgeContext.h
index 5f6259a..0801fa7 100644
--- a/ios/sdk/WeexSDK/Sources/Bridge/WXBridgeContext.h
+++ b/ios/sdk/WeexSDK/Sources/Bridge/WXBridgeContext.h
@@ -21,6 +21,10 @@
 #import <JavaScriptCore/JavaScriptCore.h>
 #import "WXBridgeProtocol.h"
 
+#import "WXBridgeProtocol.h"
+
+#import "WXBridgeProtocol.h"
+
 @class WXCallJSMethod;
 @class WXSDKInstance;
 
@@ -127,6 +131,7 @@
  **/
 - (void)resetEnvironment;
 
-- (void)callJSMethod:(NSString *)method args:(NSArray *)args 
onContext:(JSContext*)context completion:(void (^)(JSValue * value))complection;
++ (void)mountContextEnvironment:(JSContext*)context;
+- (void)callJSMethod:(NSString *)method args:(NSArray *)args 
onContext:(id<WXBridgeProtocol>)bridge completion:(void (^)(JSValue * 
value))complection;
 
 @end

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/08080728/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 07803ce..8c54021 100644
--- a/ios/sdk/WeexSDK/Sources/Bridge/WXBridgeContext.m
+++ b/ios/sdk/WeexSDK/Sources/Bridge/WXBridgeContext.m
@@ -1,4 +1,4 @@
-/*
+ /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -40,6 +40,12 @@
 #import "WXPrerenderManager.h"
 #import "WXTracingManager.h"
 #import "WXExceptionUtils.h"
+#import "WXSDKEngine.h"
+#import "WXPolyfillSet.h"
+#import "WXJSExceptionProtocol.h"
+#import "WXMonitor.h"
+#import "WXAppMonitorProtocol.h"
+#import "WXConfigCenterProtocol.h"
 
 #define SuppressPerformSelectorLeakWarning(Stuff) \
 do { \
@@ -331,8 +337,26 @@ _Pragma("clang diagnostic pop") \
             WXLogInfo(@"instance not found for callNativeModule:%@.%@, maybe 
already destroyed", moduleName, methodName);
             return nil;
         }
-        
-        WXModuleMethod *method = [[WXModuleMethod alloc] 
initWithModuleName:moduleName methodName:methodName arguments:arguments 
options:options instance:instance];
+        NSMutableDictionary * newOptions = [options mutableCopy];
+        NSMutableArray * newArguments = [arguments mutableCopy];
+        
+        if ([WXSDKManager sharedInstance].multiContext && 
[instance.bundleType.lowercaseString isEqualToString:@"rax"]) {
+            // we need to adjust __weex_options__ params in arguments to 
options compatible with rax javaScript framework.
+            NSDictionary * weexOptions = nil;
+            for(int i = 0;i < [arguments count]; i ++) {
+                if ([arguments[i] isKindOfClass:[NSDictionary class]]) {
+                    NSDictionary * dict = (NSDictionary*)arguments[i];
+                    if (dict[@"__weex_options__"] && 
[dict[@"__weex_options__"] isKindOfClass:[NSDictionary class]]) {
+                        weexOptions = dict;
+                        [newOptions 
addEntriesFromDictionary:(NSDictionary*)(weexOptions[@"__weex_options__"])];
+                    }
+                }
+            }
+            if (weexOptions) {
+                [newArguments removeObject:weexOptions];
+            }
+        }
+        WXModuleMethod *method = [[WXModuleMethod alloc] 
initWithModuleName:moduleName methodName:methodName arguments:[newArguments 
copy] options:[newOptions copy] instance:instance];
         if(![moduleName isEqualToString:@"dom"] && instance.needPrerender){
             [WXPrerenderManager storePrerenderModuleTasks:method 
forUrl:instance.scriptURL.absoluteString];
             return nil;
@@ -415,36 +439,161 @@ _Pragma("clang diagnostic pop") \
     return 1;
 }
 
-- (void)createInstance:(NSString *)instance
-              template:(NSString *)temp
+- (void)createInstance:(NSString *)instanceIdString
+              template:(NSString *)jsBundleString
                options:(NSDictionary *)options
                   data:(id)data
 {
     WXAssertBridgeThread();
-    WXAssertParam(instance);
+    WXAssertParam(instanceIdString);
     
-    if (![self.insStack containsObject:instance]) {
+    if (![self.insStack containsObject:instanceIdString]) {
         if ([options[@"RENDER_IN_ORDER"] boolValue]) {
-            [self.insStack addObject:instance];
+            [self.insStack addObject:instanceIdString];
         } else {
-            [self.insStack insertObject:instance atIndex:0];
+            [self.insStack insertObject:instanceIdString atIndex:0];
         }
     }
     
     //create a sendQueue bind to the current instance
     NSMutableArray *sendQueue = [NSMutableArray array];
-    [self.sendQueue setValue:sendQueue forKey:instance];
-    
+    [self.sendQueue setValue:sendQueue forKey:instanceIdString];
     NSArray *args = nil;
-    if (data){
-        args = @[instance, temp, options ?: @{}, data];
+    WX_MONITOR_INSTANCE_PERF_START(WXFirstScreenJSFExecuteTime, [WXSDKManager 
instanceForID:instanceIdString]);
+    WX_MONITOR_INSTANCE_PERF_START(WXPTJSCreateInstance, [WXSDKManager 
instanceForID:instanceIdString]);
+    BOOL shoudMultiContext = [WXSDKManager sharedInstance].multiContext;
+    __weak typeof(self) weakSelf = self;
+    NSString * bundleType = nil;
+    
+    if (shoudMultiContext) {
+        bundleType = [self _pareJSBundleType:instanceIdString 
jsBundleString:jsBundleString]; // bundleType can be Vue, Rax and the new 
framework.
+    }
+    if (bundleType&&shoudMultiContext) {
+        NSMutableDictionary *newOptions = [options mutableCopy];
+        if (!options) {
+            newOptions = [NSMutableDictionary new];
+        }
+        [newOptions addEntriesFromDictionary:@{@"env":[WXUtility 
getEnvironment]}];
+        newOptions[@"bundleType"] = bundleType;
+        NSString *raxAPIScript = nil;
+        NSString *raxAPIScriptPath = nil;
+        WXSDKInstance *sdkInstance = [WXSDKManager 
instanceForID:instanceIdString];
+        sdkInstance.bundleType = bundleType;
+        if ([bundleType.lowercaseString isEqualToString:@"rax"]) {
+             raxAPIScriptPath = [[NSBundle bundleForClass:[weakSelf class]] 
pathForResource:@"weex-rax-api" ofType:@"js"];
+            raxAPIScript = [NSString stringWithContentsOfFile:raxAPIScriptPath 
encoding:NSUTF8StringEncoding error:nil];
+            if (!raxAPIScript) {
+                WXLogError(@"weex-rax-api can not found");
+            }
+        }
+        
+        if ([WXDebugTool isDevToolDebug]) {
+            [self callJSMethod:@"createInstanceContext" 
args:@[instanceIdString, newOptions, data?:@[],raxAPIScript?:@""]];
+            
+            if ([NSURL URLWithString:sdkInstance.pageName]) {
+                [sdkInstance.instanceJavaScriptContext 
executeJavascript:jsBundleString withSourceURL:[NSURL 
URLWithString:sdkInstance.pageName]];
+            } else {
+                [sdkInstance.instanceJavaScriptContext 
executeJavascript:jsBundleString];
+            }
+        } else {
+            [self callJSMethod:@"createInstanceContext" 
args:@[instanceIdString, newOptions, data?:@[]] onContext:nil 
completion:^(JSValue *instanceContextEnvironment) {
+                if (sdkInstance.pageName) {
+                    if (@available(iOS 8.0, *)) {
+                          
[sdkInstance.instanceJavaScriptContext.javaScriptContext 
setName:sdkInstance.pageName];
+                    } else {
+                        // Fallback
+                    }
+                }
+                JSGlobalContextRef instanceContextRef = 
sdkInstance.instanceJavaScriptContext.javaScriptContext.JSGlobalContextRef;
+                JSObjectRef instanceGlobalObject = 
JSContextGetGlobalObject(instanceContextRef);
+                for (NSString * key in [[instanceContextEnvironment 
toDictionary] allKeys]) {
+                    JSStringRef propertyName = 
JSStringCreateWithUTF8CString([key cStringUsingEncoding:NSUTF8StringEncoding]);
+                    if ([key isEqualToString:@"Vue"]) {
+                        JSObjectSetPrototype(instanceContextRef, 
JSValueToObject(instanceContextRef, [instanceContextEnvironment 
valueForProperty:key].JSValueRef, NULL), 
JSObjectGetPrototype(instanceContextRef, instanceGlobalObject));
+                    }
+                    JSObjectSetProperty(instanceContextRef, 
instanceGlobalObject, propertyName, [instanceContextEnvironment 
valueForProperty:key].JSValueRef, 0, NULL);
+                }
+                
+                if (WX_SYS_VERSION_LESS_THAN(@"10.2")) {
+                    NSString *filePath = [[NSBundle bundleForClass:[weakSelf 
class]] pathForResource:@"weex-polyfill" ofType:@"js"];
+                    NSString *script = [NSString 
stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
+                    if (script) {
+                        [sdkInstance.instanceJavaScriptContext 
executeJavascript:script withSourceURL:[NSURL URLWithString:filePath]];
+                    } else {
+                        WXLogError(@"weex-pollyfill can not found");
+                    }
+                }
+                
+                if (raxAPIScript) {
+                    [sdkInstance.instanceJavaScriptContext 
executeJavascript:raxAPIScript withSourceURL:[NSURL 
URLWithString:raxAPIScriptPath]];
+                }
+                
+                if ([NSURL URLWithString:sdkInstance.pageName]) {
+                    [sdkInstance.instanceJavaScriptContext 
executeJavascript:jsBundleString withSourceURL:[NSURL 
URLWithString:sdkInstance.pageName]];
+                } else {
+                    [sdkInstance.instanceJavaScriptContext 
executeJavascript:jsBundleString];
+                }
+                
+            }];
+        }
+        
+    } else {
+        if (data){
+            args = @[instanceIdString, jsBundleString, options ?: @{}, data];
+        } else {
+            args = @[instanceIdString, jsBundleString, options ?: @{}];
+        }
+        [self callJSMethod:@"createInstance" args:args];
+    }
+    WX_MONITOR_INSTANCE_PERF_END(WXPTJSCreateInstance, [WXSDKManager 
instanceForID:instanceIdString]);
+}
+
+- (NSString *)_pareJSBundleType:(NSString*)instanceIdString 
jsBundleString:(NSString*)jsBundleString
+{
+    NSString * bundleType = nil;
+    WXSDKInstance * instance = [WXSDKManager instanceForID:instanceIdString];
+    NSURLComponents * urlComponent = [NSURLComponents 
componentsWithString:instance.pageName?:@""];
+    if (@available(iOS 8.0, *)) {
+        for (NSURLQueryItem * queryItem in urlComponent.queryItems) {
+            if ([queryItem.name isEqualToString:@"bundleType"] && [@[@"vue", 
@"rax"] containsObject:queryItem.value]) {
+                bundleType = queryItem.value;
+                return bundleType;
+            }
+        }
     } else {
-        args = @[instance, temp, options ?: @{}];
+        // Fallback on earlier versions
+        return bundleType;
+    }
+    // trim like whiteSpace and newline charset
+    jsBundleString = [jsBundleString 
stringByTrimmingCharactersInSet:[NSCharacterSet 
whitespaceAndNewlineCharacterSet]];
+    
+    // use the top 100 characters match the bundleType
+    if (jsBundleString.length > 100) {
+        jsBundleString = [jsBundleString substringWithRange:NSMakeRange(0, 
100)];
+    }
+    
+    if (!jsBundleString ) {
+        return bundleType;
     }
-    WX_MONITOR_INSTANCE_PERF_START(WXFirstScreenJSFExecuteTime, [WXSDKManager 
instanceForID:instance]);
-    WX_MONITOR_INSTANCE_PERF_START(WXPTJSCreateInstance, [WXSDKManager 
instanceForID:instance]);
-    [self callJSMethod:@"createInstance" args:args];
-    WX_MONITOR_INSTANCE_PERF_END(WXPTJSCreateInstance, [WXSDKManager 
instanceForID:instance]);
+    if ([jsBundleString hasPrefix:@"// { \"framework\": \"Vue\""] || 
[jsBundleString hasPrefix:@"// { \"framework\": \"vue\""]) {
+        bundleType = @"Vue";
+    } else if ([jsBundleString hasPrefix:@"// { \"framework\": \"Rax\""] || 
[jsBundleString hasPrefix:@"// { \"framework\": \"rax\""] || [jsBundleString 
hasPrefix:@"// {\"framework\" : \"Rax\"}"] || [jsBundleString hasPrefix:@"// 
{\"framework\" : \"rax\"}"]) {
+        bundleType = @"Rax";
+    }else {
+        NSRegularExpression * regEx = [NSRegularExpression 
regularExpressionWithPattern:@"(use)(\\s+)(weex:vue)" 
options:NSRegularExpressionCaseInsensitive error:NULL];
+        NSTextCheckingResult *match = [regEx firstMatchInString:jsBundleString 
options:0 range:NSMakeRange(0, jsBundleString.length)];
+        if (match) {
+            bundleType = [jsBundleString substringWithRange:match.range];
+            return bundleType;
+        }
+        regEx = [NSRegularExpression 
regularExpressionWithPattern:@"(use)(\\s+)(weex:rax)" 
options:NSRegularExpressionCaseInsensitive error:NULL];
+         match = [regEx firstMatchInString:jsBundleString options:0 
range:NSMakeRange(0, jsBundleString.length)];
+        if (match) {
+            bundleType = [jsBundleString substringWithRange:match.range];
+        }
+    }
+    
+    return bundleType;
 }
 
 - (void)destroyInstance:(NSString *)instance
@@ -556,13 +705,11 @@ _Pragma("clang diagnostic pop") \
     [self performSelector:@selector(_sendQueueLoop) withObject:nil];
 }
 
-- (void)callJSMethod:(NSString *)method args:(NSArray *)args 
onContext:(JSContext*)context completion:(void (^)(JSValue * value))complection
+- (void)callJSMethod:(NSString *)method args:(NSArray *)args 
onContext:(id<WXBridgeProtocol>)bridge completion:(void (^)(JSValue * 
value))complection
 {
     NSMutableArray *newArg = nil;
-    if (!context) {
-        if ([self.jsBridge isKindOfClass:[WXJSCoreBridge class]]) {
-           context = [(NSObject*)_jsBridge valueForKey:@"jsContext"];
-        }
+    if (!bridge) {
+        bridge = self.jsBridge;
     }
     if (self.frameworkLoadFinished) {
         newArg = [args mutableCopy];
@@ -570,9 +717,13 @@ _Pragma("clang diagnostic pop") \
             [newArg removeObject:complection];
         }
         WXLogDebug(@"Calling JS... method:%@, args:%@", method, args);
-        JSValue *value = [[context globalObject] invokeMethod:method 
withArguments:args];
-        if (complection) {
-            complection(value);
+        if ([bridge isKindOfClass:[WXJSCoreBridge class]]) {
+            JSValue *value = [bridge callJSMethod:method args:args];
+            if (complection) {
+                complection(value);
+            }
+        } else {
+            [bridge callJSMethod:method args:args];
         }
     } else {
         newArg = [args mutableCopy];
@@ -704,7 +855,12 @@ _Pragma("clang diagnostic pop") \
     }
     
     if ([tasks count] > 0 && execIns) {
-        [self callJSMethod:@"callJS" args:@[execIns, tasks]];
+        WXSDKInstance * execInstance = [WXSDKManager instanceForID:execIns];
+        if (execInstance.instanceJavaScriptContext) {
+            [self callJSMethod:@"__WEEX_CALL_JAVASCRIPT__" args:@[execIns, 
tasks] onContext:execInstance.instanceJavaScriptContext completion:nil];
+        } else {
+            [self callJSMethod:@"callJS" args:@[execIns, tasks]];
+        }
     }
     
     if (hasTask) {
@@ -712,4 +868,102 @@ _Pragma("clang diagnostic pop") \
     }
 }
 
++ (void)mountContextEnvironment:(JSContext*)context
+{
+    NSDictionary *data = [WXUtility getEnvironment];
+    context[@"WXEnvironment"] = data;
+    // use latin1 encode also named ISO/IEC_8859-1 more: 
https://en.wikipedia.org/wiki/ISO/IEC_8859-1
+    // 8-bit single-byte coded graphic character sets as webkit does
+    // 
https://github.com/WebKit/webkit/blob/master/Source/WebCore/page/Base64Utilities.cpp
+    context[@"btoa"] = ^(JSValue *value ) {
+        NSData *nsdata = [[value toString]
+                          dataUsingEncoding:NSISOLatin1StringEncoding];
+        NSString *base64Encoded = [nsdata base64EncodedStringWithOptions:0];
+        return base64Encoded;
+    };
+    context[@"atob"] = ^(JSValue *value ) {
+        NSData *nsdataFromBase64String = [[NSData alloc]
+                                          initWithBase64EncodedString:[value 
toString] options:0];
+        NSString *base64Decoded = [[NSString alloc]
+                                   initWithData:nsdataFromBase64String 
encoding:NSISOLatin1StringEncoding];
+        return base64Decoded;
+    };
+    context.exceptionHandler = ^(JSContext *context, JSValue *exception){
+        context.exception = exception;
+        
+        WXSDKInstance *instance = [WXSDKEngine topInstance];
+        NSString *bundleUrl = instance.pageName?:([instance.scriptURL 
absoluteString]?:@"WX_KEY_EXCEPTION_WXBRIDGE");
+        NSString *errorCode = [NSString stringWithFormat:@"%d", 
WX_KEY_EXCEPTION_WXBRIDGE];
+        NSString *message = [NSString 
stringWithFormat:@"[WX_KEY_EXCEPTION_WXBRIDGE] [%@:%@:%@] %@\n%@", 
exception[@"sourceURL"], exception[@"line"], exception[@"column"], [exception 
toString], [exception[@"stack"] toObject]];
+        NSMutableDictionary *userInfo = [NSMutableDictionary 
dictionaryWithObjectsAndKeys:
+                                         
instance.userInfo[@"jsMainBundleStringContentLength"]?:@"",@"jsMainBundleStringContentLength",
+                                         
instance.userInfo[@"jsMainBundleStringContentMd5"]?:@"",@"jsMainBundleStringContentMd5",nil];
+        WXJSExceptionInfo * jsExceptionInfo = [[WXJSExceptionInfo alloc] 
initWithInstanceId:instance.instanceId bundleUrl:bundleUrl errorCode:errorCode 
functionName:@"" exception:message userInfo:userInfo];
+        
+        [WXExceptionUtils commitCriticalExceptionRT:jsExceptionInfo];
+        WX_MONITOR_FAIL(WXMTJSBridge, WX_ERR_JS_EXECUTE, message);
+        if (instance.onJSRuntimeException) {
+            instance.onJSRuntimeException(jsExceptionInfo);
+        }
+    };
+    
+    if (WX_SYS_VERSION_LESS_THAN(@"8.0")) {
+        // solve iOS7 memory problem
+        context[@"nativeSet"] = [WXPolyfillSet class];
+    }
+    context[@"console"][@"error"] = ^(){
+        [WXBridgeContext handleConsoleOutputWithArgument:[JSContext 
currentArguments] logLevel:WXLogFlagError];
+    };
+    context[@"console"][@"warn"] = ^(){
+        [WXBridgeContext handleConsoleOutputWithArgument:[JSContext 
currentArguments] logLevel:WXLogFlagWarning];
+    };
+    context[@"console"][@"info"] = ^(){
+        [WXBridgeContext handleConsoleOutputWithArgument:[JSContext 
currentArguments] logLevel:WXLogFlagInfo];
+    };
+    context[@"console"][@"debug"] = ^(){
+        [WXBridgeContext handleConsoleOutputWithArgument:[JSContext 
currentArguments] logLevel:WXLogFlagDebug];
+    };
+    context[@"console"][@"log"] = ^(){
+        [WXBridgeContext handleConsoleOutputWithArgument:[JSContext 
currentArguments] logLevel:WXLogFlagLog];
+    };
+    context[@"nativeLog"] = ^() {
+        static NSDictionary *levelMap;
+        static dispatch_once_t onceToken;
+        dispatch_once(&onceToken, ^{
+            levelMap = @{
+                         @"__ERROR": @(WXLogFlagError),
+                         @"__WARN": @(WXLogFlagWarning),
+                         @"__INFO": @(WXLogFlagInfo),
+                         @"__DEBUG": @(WXLogFlagDebug),
+                         @"__LOG": @(WXLogFlagLog)
+                         };
+        });
+        NSArray * args = [JSContext currentArguments];
+        NSString * levelStr = [[args lastObject] toString];
+        [WXBridgeContext handleConsoleOutputWithArgument:args 
logLevel:(WXLogFlag)levelMap[levelStr]];
+        
+    };
+}
++ (void)handleConsoleOutputWithArgument:(NSArray*)arguments 
logLevel:(WXLogFlag)logLevel
+{
+    NSMutableString *string = [NSMutableString string];
+    [string appendString:@"jsLog: "];
+    [arguments enumerateObjectsUsingBlock:^(JSValue *jsVal, NSUInteger idx, 
BOOL *stop) {
+        [string appendFormat:@"%@ ", jsVal];
+        if (idx == arguments.count - 1) {
+            if (logLevel) {
+                if (WXLogFlagWarning == logLevel) {
+                    id<WXAppMonitorProtocol> appMonitorHandler = [WXSDKEngine 
handlerForProtocol:@protocol(WXAppMonitorProtocol)];
+                    if ([appMonitorHandler 
respondsToSelector:@selector(commitAppMonitorAlarm:monitorPoint:success:errorCode:errorMsg:arg:)])
 {
+                        [appMonitorHandler commitAppMonitorAlarm:@"weex" 
monitorPoint:@"jswarning" success:FALSE errorCode:@"99999" errorMsg:string 
arg:[WXSDKEngine topInstance].pageName];
+                    }
+                }
+                WX_LOG(logLevel, @"%@", string);
+            } else {
+                [string appendFormat:@"%@ ", jsVal]                            
      ;
+                WXLogInfo(@"%@", string);
+            }
+        }
+    }];
+}
 @end

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/08080728/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.h 
b/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.h
index 42e3e1b..6472ea7 100644
--- a/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.h
+++ b/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.h
@@ -20,5 +20,5 @@
 #import "WXBridgeProtocol.h"
 
 @interface WXJSCoreBridge : NSObject <WXBridgeProtocol>
-
+@property (nonatomic,assign)BOOL multiContext;
 @end

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/08080728/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 d177009..6df02b9 100644
--- a/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m
+++ b/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m
@@ -25,25 +25,26 @@
 #import "WXUtility.h"
 #import "WXSDKEngine.h"
 #import "WXSDKError.h"
-#import "WXMonitor.h"
-#import "WXAppMonitorProtocol.h"
-#import "WXHandlerFactory.h"
 #import <sys/utsname.h>
 #import <JavaScriptCore/JavaScriptCore.h>
-#import "WXPolyfillSet.h"
 #import "JSValue+Weex.h"
-#import "WXJSExceptionProtocol.h"
 #import "WXSDKManager.h"
 #import "WXExtendCallNativeManager.h"
 #import "WXTracingManager.h"
 #import "WXExceptionUtils.h"
+#import "WXBridgeContext.h"
+#import "WXMonitor.h"
+#import "WXPolyfillSet.h"
+#import "WXAppMonitorProtocol.h"
 
 #import <dlfcn.h>
 
 #import <mach/mach.h>
 
-
 @interface WXJSCoreBridge ()
+{
+    NSString * _weexInstanceId;
+}
 
 @property (nonatomic, strong)  JSContext *jsContext;
 @property (nonatomic, strong)  NSMutableArray *timers;
@@ -68,11 +69,11 @@
         _callbacks = [NSMutableDictionary new];
         _intervalTimerId = 0;
         _intervaltimers = [NSMutableDictionary new];
+        _multiContext = NO;
 
         __weak typeof(self) weakSelf = self;
         
-        NSDictionary *data = [WXUtility getEnvironment];
-        _jsContext[@"WXEnvironment"] = data;
+        [WXBridgeContext mountContextEnvironment:_jsContext];
         
         _jsContext[@"setTimeout"] = ^(JSValue *function, JSValue *timeout) {
             // this setTimeout is used by internal logic in JS framework, 
normal setTimeout called by users will call WXTimerModule's method;
@@ -100,93 +101,44 @@
             [weakSelf triggerClearTimeout:[ret toString]];
         };
         
-        _jsContext[@"btoa"] = ^(JSValue *value ) {
-            NSData *nsdata = [[value toString]
-                              dataUsingEncoding:NSUTF8StringEncoding];
-            NSString *base64Encoded = [nsdata 
base64EncodedStringWithOptions:0];
-            return base64Encoded;
-        };
-        _jsContext[@"atob"] = ^(JSValue *value ) {
-            NSData *nsdataFromBase64String = [[NSData alloc]
-                                              
initWithBase64EncodedString:[value toString] options:0];
-            NSString *base64Decoded = [[NSString alloc]
-                                       initWithData:nsdataFromBase64String 
encoding:NSUTF8StringEncoding];
-            return base64Decoded;
-        };
         _jsContext[@"extendCallNative"] = ^(JSValue *value ) {
             return [weakSelf extendCallNative:[value toDictionary]];
         };
-        
-        _jsContext[@"nativeLog"] = ^() {
-            static NSDictionary *levelMap;
-            static dispatch_once_t onceToken;
-            dispatch_once(&onceToken, ^{
-                levelMap = @{
-                             @"__ERROR": @(WXLogFlagError),
-                             @"__WARN": @(WXLogFlagWarning),
-                             @"__INFO": @(WXLogFlagInfo),
-                             @"__DEBUG": @(WXLogFlagDebug),
-                             @"__LOG": @(WXLogFlagLog)
-                             };
-            });
-            NSMutableString *string = [NSMutableString string];
-            [string appendString:@"jsLog: "];
-            NSArray *args = [JSContext currentArguments];
-            
-            [args enumerateObjectsUsingBlock:^(JSValue *jsVal, NSUInteger idx, 
BOOL *stop) {
-                if (idx == args.count - 1) {
-                    NSNumber *flag = levelMap[[jsVal toString]];
-                    if (flag) {
-                        if ([flag isEqualToNumber:[NSNumber 
numberWithInteger:WXLogFlagWarning]]) {
-                            id<WXAppMonitorProtocol> appMonitorHandler = 
[WXHandlerFactory handlerForProtocol:@protocol(WXAppMonitorProtocol)];
-                            if ([appMonitorHandler 
respondsToSelector:@selector(commitAppMonitorAlarm:monitorPoint:success:errorCode:errorMsg:arg:)])
 {
-                                [appMonitorHandler 
commitAppMonitorAlarm:@"weex" monitorPoint:@"jswarning" success:FALSE 
errorCode:@"99999" errorMsg:string arg:[WXSDKEngine topInstance].pageName];
-                            }
-                        }
-                        WX_LOG([flag unsignedIntegerValue], @"%@", string);
-                    } else {
-                        [string appendFormat:@"%@ ", jsVal];
-                        WXLogInfo(@"%@", string);
-                    }
-                }
-                [string appendFormat:@"%@ ", jsVal ];
-            }];
-        };
-        
-        _jsContext.exceptionHandler = ^(JSContext *context, JSValue 
*exception){
-            context.exception = exception;
-            
-            WXSDKInstance *instance = [WXSDKEngine topInstance];
-            NSString *bundleUrl = instance.pageName?:([instance.scriptURL 
absoluteString]?:@"WX_KEY_EXCEPTION_WXBRIDGE");
-            NSString *errorCode = [NSString stringWithFormat:@"%d", 
WX_KEY_EXCEPTION_WXBRIDGE];
-            NSString *message = [NSString 
stringWithFormat:@"[WX_KEY_EXCEPTION_WXBRIDGE] [%@:%@:%@] %@\n%@", 
exception[@"sourceURL"], exception[@"line"], exception[@"column"], [exception 
toString], [exception[@"stack"] toObject]];
-            NSMutableDictionary *userInfo = [NSMutableDictionary 
dictionaryWithObjectsAndKeys:
-                
instance.userInfo[@"jsMainBundleStringContentLength"]?:@"",@"jsMainBundleStringContentLength",
-                
instance.userInfo[@"jsMainBundleStringContentMd5"]?:@"",@"jsMainBundleStringContentMd5",nil];
-            WXJSExceptionInfo * jsExceptionInfo = [[WXJSExceptionInfo alloc] 
initWithInstanceId:instance.instanceId bundleUrl:bundleUrl errorCode:errorCode 
functionName:@"" exception:message userInfo:userInfo];
-            
-            [WXExceptionUtils commitCriticalExceptionRT:jsExceptionInfo];
-            WX_MONITOR_FAIL(WXMTJSBridge, WX_ERR_JS_EXECUTE, message);
-            if (instance.onJSRuntimeException) {
-                instance.onJSRuntimeException(jsExceptionInfo);
-            }
-        };
-        
-        if (WX_SYS_VERSION_LESS_THAN(@"8.0")) {
-            // solve iOS7 memory problem
-            _jsContext[@"nativeSet"] = [WXPolyfillSet class];
-        }
     }
     return self;
 }
 
+- (void)setJSContext:(JSContext *)context
+{
+    _jsContext = context;
+}
+
+- (JSContext *)javaScriptContext
+{
+    return _jsContext;
+}
+
+- (NSString *)weexInstanceId
+{
+    return _weexInstanceId;
+}
+
+- (void)setWeexInstanceId:(NSString *)weexInstanceId
+{
+    _weexInstanceId = weexInstanceId;
+}
+
 #pragma mark - WXBridgeProtocol
 
 - (void)executeJSFramework:(NSString *)frameworkScript
 {
     WXAssertParam(frameworkScript);
     if (WX_SYS_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) {
-        [_jsContext evaluateScript:frameworkScript withSourceURL:[NSURL 
URLWithString:@"native-bundle-main.js"]];
+        NSString * fileName = @"native-bundle-main.js";
+        if ([WXSDKManager sharedInstance].multiContext) {
+            fileName = @"weex-main-jsfm.js";
+        }
+        [_jsContext evaluateScript:frameworkScript withSourceURL:[NSURL 
URLWithString:fileName]];
     }else{
         [_jsContext evaluateScript:frameworkScript];
     }
@@ -217,6 +169,16 @@
     [_jsContext evaluateScript:script];
 }
 
+- (JSValue*)executeJavascript:(NSString *)script 
withSourceURL:(NSURL*)sourceURL
+{
+    WXAssertParam(script);
+    if (sourceURL) {
+        return [_jsContext evaluateScript:script withSourceURL:sourceURL];
+    } else {
+        return [_jsContext evaluateScript:script];
+    }
+}
+
 - (void)registerCallAddElement:(WXJSCallAddElement)callAddElement
 {
     id callAddElementBlock = ^(JSValue *instanceId, JSValue *ref, JSValue 
*element, JSValue *index, JSValue *ifCallback) {
@@ -417,6 +379,7 @@
 //    if (garbageCollect != NULL) {
 //        garbageCollect(_jsContext.JSGlobalContextRef);
 //    }
+//    JSGarbageCollect(_jsContext.JSGlobalContextRef);
 }
 
 #pragma mark - Public

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/08080728/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m 
b/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m
index 06c55fc..dad372c 100644
--- a/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m
+++ b/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m
@@ -194,8 +194,17 @@
 
 + (void)initSDKEnvironment
 {
+    NSString *fileName = @"weex-main-jsfm";
+    [WXSDKManager sharedInstance].multiContext = YES;
     
-    NSString *filePath = [[NSBundle bundleForClass:self] 
pathForResource:@"native-bundle-main" ofType:@"js"];
+    if ([[NSUserDefaults standardUserDefaults] 
objectForKey:@"createInstanceUsingMutliContext"]) {
+        BOOL createInstanceUsingMutliContext = [[[NSUserDefaults 
standardUserDefaults] objectForKey:@"createInstanceUsingMutliContext"] 
boolValue];
+        if (!createInstanceUsingMutliContext) {
+            fileName = @"native-bundle-main";
+            [WXSDKManager sharedInstance].multiContext = NO;
+        }
+    }
+    NSString *filePath = [[NSBundle bundleForClass:self] 
pathForResource:fileName ofType:@"js"];
     NSString *script = [NSString stringWithContentsOfFile:filePath 
encoding:NSUTF8StringEncoding error:nil];
     [WXSDKEngine initSDKEnvironment:script];
     
@@ -227,7 +236,6 @@
 
 + (void)initSDKEnvironment:(NSString *)script
 {
-    
     WX_MONITOR_PERF_START(WXPTInitalize)
     WX_MONITOR_PERF_START(WXPTInitalizeSync)
     
@@ -289,7 +297,16 @@ static NSDictionary *_customEnvironment;
 
 + (void)restart
 {
-    NSString *filePath = [[NSBundle bundleForClass:self] 
pathForResource:@"native-bundle-main" ofType:@"js"];
+    NSString *fileName = @"weex-main-jsfm";
+    [WXSDKManager sharedInstance].multiContext = YES;
+    if ([[NSUserDefaults standardUserDefaults] 
objectForKey:@"createInstanceUsingMutliContext"]) {
+        BOOL createInstanceUsingMutliContext = [[[NSUserDefaults 
standardUserDefaults] objectForKey:@"createInstanceUsingMutliContext"] 
boolValue];
+        if (!createInstanceUsingMutliContext) {
+            fileName = @"native-bundle-main";
+            [WXSDKManager sharedInstance].multiContext = NO;
+        }
+    }
+    NSString *filePath = [[NSBundle bundleForClass:self] 
pathForResource:fileName ofType:@"js"];
     NSString *script = [NSString stringWithContentsOfFile:filePath 
encoding:NSUTF8StringEncoding error:nil];
     [self restartWithScript:script];
 }

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/08080728/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.m 
b/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.m
index b59c79f..64d901d 100644
--- a/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.m
+++ b/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.m
@@ -72,11 +72,6 @@ static NSThread *WXBridgeThread;
     _bridgeCtx = nil;
 }
 
-- (void)dealloc
-{
-   
-}
-
 #pragma mark Thread Management
 
 - (void)_runLoopThread

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/08080728/ios/sdk/WeexSDK/Sources/Manager/WXSDKManager.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXSDKManager.h 
b/ios/sdk/WeexSDK/Sources/Manager/WXSDKManager.h
index b0e705f..f272347 100644
--- a/ios/sdk/WeexSDK/Sources/Manager/WXSDKManager.h
+++ b/ios/sdk/WeexSDK/Sources/Manager/WXSDKManager.h
@@ -25,6 +25,12 @@
 
 @interface WXSDKManager : NSObject
 
+@property (nonatomic, assign) BOOL multiContext;
+
+/**
+ *@abstract Returns sdk manager
+ */
++ (WXSDKManager *)sharedInstance;
 /**
  * @abstract Returns bridge manager
  **/

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/08080728/ios/sdk/WeexSDK/Sources/Manager/WXSDKManager.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXSDKManager.m 
b/ios/sdk/WeexSDK/Sources/Manager/WXSDKManager.m
index 3be2e5f..797f4b7 100644
--- a/ios/sdk/WeexSDK/Sources/Manager/WXSDKManager.m
+++ b/ios/sdk/WeexSDK/Sources/Manager/WXSDKManager.m
@@ -44,6 +44,14 @@ static WXSDKManager *_sharedInstance = nil;
     return _sharedInstance;
 }
 
+- (instancetype)init
+{
+    if (self = [super init]){
+        
+    }
+    return self;
+}
+
 + (WXBridgeManager *)bridgeMgr
 {
     WXBridgeManager *bridgeMgr = [self sharedInstance].bridgeMgr;
@@ -77,7 +85,7 @@ static WXSDKManager *_sharedInstance = nil;
         WXSDKInstance *instance = [[self sharedInstance].instanceDict 
objectForKey:instanceID];
         [instance destroyInstance];
     }
-    
+    [[self sharedInstance].bridgeMgr unload];
     [self sharedInstance].bridgeMgr = nil;
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/08080728/ios/sdk/WeexSDK/Sources/Manager/WXTracingManager.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXTracingManager.m 
b/ios/sdk/WeexSDK/Sources/Manager/WXTracingManager.m
index 59e2fa7..07237e6 100644
--- a/ios/sdk/WeexSDK/Sources/Manager/WXTracingManager.m
+++ b/ios/sdk/WeexSDK/Sources/Manager/WXTracingManager.m
@@ -92,7 +92,9 @@
         if(![[WXTracingManager sharedInstance].tracingTasks 
objectForKey:tracing.iid]){
             WXTracingTask *task = [WXTracingTask new];
             task.iid = tracing.iid;
-            [[WXTracingManager sharedInstance].tracingTasks setObject:task 
forKey:tracing.iid];
+            if (tracing.iid) {
+                [[WXTracingManager sharedInstance].tracingTasks setObject:task 
forKey:tracing.iid];
+            }
         }
         WXTracingTask *task = [[WXTracingManager sharedInstance].tracingTasks 
objectForKey:tracing.iid];
         if(task.bundleUrl.length == 0){

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/08080728/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.h 
b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.h
index 23eae9e..b4e7cfc 100644
--- a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.h
+++ b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.h
@@ -22,6 +22,7 @@
 #import "WXJSExceptionInfo.h"
 #import "WXResourceResponse.h"
 #import "WXResourceRequest.h"
+#import "WXBridgeProtocol.h"
 
 extern NSString *const bundleUrlOptionKey;
 
@@ -133,6 +134,11 @@ typedef NS_ENUM(NSInteger, WXErrorCode) {//error.code
 @property (nonatomic, copy) void (^refreshFinish)(UIView *);
 
 /**
+ * bundleType is the DSL type
+ */
+@property (nonatomic, strong) NSString * bundleType;
+
+/**
  *  The callback triggered when the instance fails to render.
  *
  *  @return A block that takes a NSError argument, which is the error occured
@@ -140,6 +146,12 @@ typedef NS_ENUM(NSInteger, WXErrorCode) {//error.code
 @property (nonatomic, copy) void (^onFailed)(NSError *error);
 
 /**
+ *
+ *  @return instance runtime JavaScript.
+ **/
+- (id<WXBridgeProtocol>)instanceJavaScriptContext;
+
+/**
  *  The callback triggered when js occurs runtime error while executing.
  *
  *  @return A block that takes a WXJSExceptionInfo argument, which is the 
exception info

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/08080728/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 6469950..102b408 100644
--- a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
+++ b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
@@ -47,6 +47,8 @@
 #import "WXTracingManager.h"
 #import "WXExceptionUtils.h"
 #import "WXMonitor.h"
+#import "WXBridgeContext.h"
+#import "WXJSCoreBridge.h"
 
 NSString *const bundleUrlOptionKey = @"bundleUrl";
 
@@ -72,6 +74,8 @@ typedef enum : NSUInteger {
     BOOL _performanceCommit;
     BOOL _needDestroy;
     BOOL _syncDestroyComponentManager;
+    BOOL _debugJS;
+    id<WXBridgeProtocol> _instanceJavaScriptContext; // sandbox javaScript 
context
 }
 
 - (void)dealloc
@@ -115,12 +119,50 @@ typedef enum : NSUInteger {
         if ([configCenter 
respondsToSelector:@selector(configForKey:defaultValue:isDefault:)]) {
             _syncDestroyComponentManager = [[configCenter 
configForKey:@"iOS_weex_ext_config.syncDestroyComponentManager" 
defaultValue:@(YES) isDefault:NULL] boolValue];
         }
-       
+        
         [self addObservers];
     }
     return self;
 }
 
+- (id<WXBridgeProtocol>)instanceJavaScriptContext
+{
+    _debugJS = [WXDebugTool isDevToolDebug];
+    
+    Class bridgeClass = _debugJS ? NSClassFromString(@"WXDebugger") : 
[WXJSCoreBridge class];
+    
+    if (_instanceJavaScriptContext && [_instanceJavaScriptContext 
isKindOfClass:bridgeClass]) {
+        return _instanceJavaScriptContext;
+    }
+    
+    if (_instanceJavaScriptContext) {
+        _instanceJavaScriptContext = nil;
+    }
+    
+    _instanceJavaScriptContext = _debugJS ? [NSClassFromString(@"WXDebugger") 
alloc] : [[WXJSCoreBridge alloc] init];
+    
+    if(!_debugJS) {
+        id<WXBridgeProtocol> jsBridge = [[WXSDKManager bridgeMgr] 
valueForKeyPath:@"bridgeCtx.jsBridge"];
+        JSContext* globalContex = jsBridge.javaScriptContext;
+        JSContextGroupRef contextGroup = JSContextGetGroup([globalContex 
JSGlobalContextRef]);
+        JSClassDefinition classDefinition = kJSClassDefinitionEmpty;
+        classDefinition.attributes = kJSClassAttributeNoAutomaticPrototype;
+        JSClassRef globalObjectClass = JSClassCreate(&classDefinition);
+        JSGlobalContextRef sandboxGlobalContextRef = 
JSGlobalContextCreateInGroup(contextGroup, globalObjectClass);
+        JSClassRelease(globalObjectClass);
+        JSContext * instanceContext = [JSContext 
contextWithJSGlobalContextRef:sandboxGlobalContextRef];
+        JSGlobalContextRelease(sandboxGlobalContextRef);
+        [WXBridgeContext mountContextEnvironment:instanceContext];
+        [_instanceJavaScriptContext setJSContext:instanceContext];
+    }
+    
+    if([_instanceJavaScriptContext 
respondsToSelector:@selector(setWeexInstanceId:)]) {
+        [_instanceJavaScriptContext setWeexInstanceId:_instanceId];
+    }
+    
+    return _instanceJavaScriptContext;
+}
+
 - (NSString *)description
 {
     return [NSString stringWithFormat:@"<%@: %p; id = %@; rootView = %@; url= 
%@>", NSStringFromClass([self class]), self, _instanceId, _rootView, 
_scriptURL];
@@ -224,8 +266,17 @@ typedef enum : NSUInteger {
     // ensure default modules/components/handlers are ready before create 
instance
     [WXSDKEngine registerDefaults];
      [[NSNotificationCenter defaultCenter] 
postNotificationName:WX_SDKINSTANCE_WILL_RENDER object:self];
+     
+    _needDestroy = YES;
+    _mainBundleString = mainBundleString;
+    if ([self _handleConfigCenter]) {
+        NSError * error = [NSError errorWithDomain:WX_ERROR_DOMAIN code:9999 
userInfo:nil];
+        if (self.onFailed) {
+            self.onFailed(error);
+        }
+        return;
+    }
     
-    [self _handleConfigCenter];
     _needDestroy = YES;
     [WXTracingManager startTracingWithInstanceId:self.instanceId ref:nil 
className:nil name:WXTExecJS phase:WXTracingBegin 
functionName:@"renderWithMainBundleString" 
options:@{@"threadName":WXTMainThread}];
     [[WXSDKManager bridgeMgr] createInstance:self.instanceId 
template:mainBundleString options:dictionary data:_jsData];
@@ -234,7 +285,7 @@ typedef enum : NSUInteger {
     WX_MONITOR_PERF_SET(WXPTBundleSize, [mainBundleString 
lengthOfBytesUsingEncoding:NSUTF8StringEncoding], self);
 }
 
-- (void)_handleConfigCenter
+- (BOOL)_handleConfigCenter
 {
     id configCenter = [WXSDKEngine 
handlerForProtocol:@protocol(WXConfigCenterProtocol)];
     if ([configCenter 
respondsToSelector:@selector(configForKey:defaultValue:isDefault:)]) {
@@ -242,7 +293,27 @@ typedef enum : NSUInteger {
         [WXTextComponent setRenderUsingCoreText:useCoreText];
         BOOL useThreadSafeLock = [[configCenter 
configForKey:@"iOS_weex_ext_config.useThreadSafeLock" defaultValue:@YES 
isDefault:NULL] boolValue];
         [WXUtility setThreadSafeCollectionUsingLock:useThreadSafeLock];
+        
+        BOOL shoudMultiContext = NO;
+        shoudMultiContext = [[configCenter 
configForKey:@"iOS_weex_ext_config.createInstanceUsingMutliContext" 
defaultValue:@(YES) isDefault:NULL] boolValue];
+        if(shoudMultiContext && ![WXSDKManager sharedInstance].multiContext) {
+            [WXSDKManager sharedInstance].multiContext = YES;
+            [[NSUserDefaults standardUserDefaults] setObject:@"1" 
forKey:@"createInstanceUsingMutliContext"];
+            [WXSDKEngine restart];
+            return YES;
+        }
+        if (!shoudMultiContext && [WXSDKManager sharedInstance].multiContext) {
+            [WXSDKManager sharedInstance].multiContext = NO;
+            [[NSUserDefaults standardUserDefaults] setObject:@"0" 
forKey:@"createInstanceUsingMutliContext"];
+            [WXSDKEngine restart];
+            return YES;
+        }
     }
+    return NO;
+}
+
+- (void)renderWithMainBundleString:(NSNotification*)notification {
+    [self _renderWithMainBundleString:_mainBundleString];
 }
 
 - (void)_renderWithRequest:(WXResourceRequest *)request options:(NSDictionary 
*)options data:(id)data;
@@ -383,7 +454,6 @@ typedef enum : NSUInteger {
     
     [WXTracingManager destroyTraincgTaskWithInstance:self.instanceId];
 
-    
     [WXPrerenderManager removePrerenderTaskforUrl:[self.scriptURL 
absoluteString]];
     [WXPrerenderManager destroyTask:self.instanceId];
     
@@ -392,6 +462,12 @@ typedef enum : NSUInteger {
         _needDestroy = NO;
     }
 
+    [[WXSDKManager bridgeMgr] destroyInstance:self.instanceId];
+    if (_instanceJavaScriptContext && !_debugJS) {
+        
JSGarbageCollect(_instanceJavaScriptContext.javaScriptContext.JSGlobalContextRef);
+    }
+    _instanceJavaScriptContext = nil;
+    
     if (_componentManager) {
         [_componentManager invalidate];
     }
@@ -399,9 +475,7 @@ typedef enum : NSUInteger {
     WXPerformBlockOnComponentThread(^{
         __strong typeof(self) strongSelf = weakSelf;
         [strongSelf.componentManager unload];
-        dispatch_async(dispatch_get_main_queue(), ^{
-            [WXSDKManager removeInstanceforID:strongSelf.instanceId];
-        });
+        [WXSDKManager removeInstanceforID:strongSelf.instanceId];
     });
     if(url.length > 0){
         [WXPrerenderManager addGlobalTask:url callback:nil];

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/08080728/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance_private.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance_private.h 
b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance_private.h
index 1c3090a..4ada797 100644
--- a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance_private.h
+++ b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance_private.h
@@ -22,6 +22,7 @@
 #import "WXComponentManager.h"
 #import "WXModuleMethod.h"
 #import "WXThreadSafeMutableDictionary.h"
+#import <JavaScriptCore/JavaScriptCore.h>
 
 @interface WXSDKInstance ()
 
@@ -31,6 +32,7 @@
 @property (nonatomic, strong) NSMutableDictionary *naviBarStyles;
 @property (nonatomic, strong) NSMutableDictionary *styleConfigs;
 @property (nonatomic, strong) NSMutableDictionary *attrConfigs;
+@property (nonatomic, strong) NSString *mainBundleString;
 
 @property (nonatomic, readonly, strong) WXComponentManager *componentManager;
 

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/08080728/ios/sdk/WeexSDK/Sources/Protocol/WXBridgeProtocol.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Protocol/WXBridgeProtocol.h 
b/ios/sdk/WeexSDK/Sources/Protocol/WXBridgeProtocol.h
index e883b20..e8dc9be 100644
--- a/ios/sdk/WeexSDK/Sources/Protocol/WXBridgeProtocol.h
+++ b/ios/sdk/WeexSDK/Sources/Protocol/WXBridgeProtocol.h
@@ -124,5 +124,28 @@ typedef void (^WXJSCallNativeComponent)(NSString 
*instanceId, NSString *componen
  */
 - 
(void)registerCallNativeComponent:(WXJSCallNativeComponent)callNativeComponentBlock;
 
+@optional
+
+/*
+ * Executes the specified JavaScript code, treating the specified URL as its 
source location.
+ * Evaluating a script runs any top-level code and adds function or object 
definitions to the brige’s global object.
+ * The sourceURL parameter is informative only; debuggers may use this URL 
when reporting exceptions.
+ @param script   The JavaScript source code to evaluate.
+ @param sourceURL A URL to be considered as the script’s origin.
+ @return ReturnsThe last value generated by the script. Note that a script can 
result in the JavaScript value undefined.
+ */
+- (JSValue *)executeJavascript:(NSString *)script 
withSourceURL:(NSURL*)sourceURL;
+
+
+@property (nonatomic, strong) NSString* weexInstanceId;
 
+/**
+ set JavaScriptContext
+ */
+- (void)setJSContext:(JSContext*)context;
+
+/*
+ * javaScript runtime context
+ */
+- (JSContext*)javaScriptContext;
 @end

Reply via email to