feat: Native add legacy mode

This commit is contained in:
pengfei.zhou
2022-07-15 15:59:06 +08:00
committed by osborn
parent 64a370c701
commit 7a126531af
21 changed files with 15180 additions and 15119 deletions

View File

@@ -61,4 +61,9 @@
+ (void)setEnvironmentValue:(NSDictionary *)value;
+ (DoricJSLoaderManager *)jsLoaderManager;
/**
* Set legacy mode to compat es5 code
* */
+ (void)setLegacyMode:(BOOL)legacy;
@end

View File

@@ -55,4 +55,8 @@ + (void)setEnvironmentValue:(NSDictionary *)value {
+ (DoricJSLoaderManager *)jsLoaderManager {
return DoricSingleton.instance.jsLoaderManager;
}
+ (void)setLegacyMode:(BOOL)legacy {
[DoricSingleton.instance setLegacyMode:legacy];
}
@end

View File

@@ -32,6 +32,7 @@
@property(nonatomic, strong) NSMutableDictionary *envDic;
@property(nonatomic, assign) BOOL enablePerformance;
@property(nonatomic, assign) BOOL enableRecordSnapshot;
@property(nonatomic, assign) BOOL legacyMode;
@property(nonatomic, strong) DoricJSLoaderManager *jsLoaderManager;
@property(nonatomic, strong) DoricNativeDriver *nativeDriver;
@property(nonatomic, strong) DoricContextManager *contextManager;

View File

@@ -38,6 +38,7 @@ - (instancetype)init {
valueOptions:NSPointerFunctionsWeakMemory
capacity:0];
_bundles = [NSMutableDictionary new];
_legacyMode = NO;
}
return self;
}

View File

@@ -30,6 +30,7 @@
#import "DoricContextManager.h"
#import "DoricPerformanceProfile.h"
#import "JSValue+Doric.h"
#import "DoricSingleton.h"
@interface DoricDefaultMonitor : NSObject <DoricMonitorProtocol>
@end
@@ -220,10 +221,20 @@ - (void)initDoricEnvironment {
@try {
[self loadBuiltinJS:DORIC_BUNDLE_SANDBOX];
NSString *path;
BOOL useLegacy;
if (@available(iOS 10.0, *)) {
path = [DoricBundle() pathForResource:DORIC_BUNDLE_LIB ofType:@"js"];
if (DoricSingleton.instance.legacyMode) {
useLegacy = YES;
} else {
useLegacy = NO;
}
} else {
useLegacy = NO;
}
if (useLegacy) {
path = [DoricBundle() pathForResource:[NSString stringWithFormat:@"%@.es5", DORIC_BUNDLE_LIB] ofType:@"js"];
} else {
path = [DoricBundle() pathForResource:DORIC_BUNDLE_LIB ofType:@"js"];
}
NSString *jsContent = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
[self.jsExecutor loadJSScript:[self packageModuleScript:DORIC_MODULE_LIB content:jsContent]
@@ -235,10 +246,20 @@ - (void)initDoricEnvironment {
- (void)loadBuiltinJS:(NSString *)fileName {
NSString *path;
BOOL useLegacy;
if (@available(iOS 10.0, *)) {
path = [DoricBundle() pathForResource:DORIC_BUNDLE_SANDBOX ofType:@"js"];
if (DoricSingleton.instance.legacyMode) {
useLegacy = YES;
} else {
useLegacy = NO;
}
} else {
useLegacy = NO;
}
if (useLegacy) {
path = [DoricBundle() pathForResource:[NSString stringWithFormat:@"%@.es5", DORIC_BUNDLE_SANDBOX] ofType:@"js"];
} else {
path = [DoricBundle() pathForResource:DORIC_BUNDLE_SANDBOX ofType:@"js"];
}
NSString *jsContent = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
[self.jsExecutor loadJSScript:jsContent source:[@"Assets://" stringByAppendingString:fileName]];