add different jse in core & devkit pods
This commit is contained in:
parent
3facc3fdee
commit
d215926387
38
doric-iOS/Devkit/Classes/DoricDebugDriver.h
Normal file
38
doric-iOS/Devkit/Classes/DoricDebugDriver.h
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright [2019] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
//
|
||||
// DoricDebugDriver.h
|
||||
// Doric
|
||||
//
|
||||
// Created by jingpeng.wang on 2020/2/25.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DoricDriverProtocol.h"
|
||||
|
||||
typedef NS_ENUM(NSInteger, DoricQueueMode) {
|
||||
JS = 0,
|
||||
UI,
|
||||
INDEPENDENT
|
||||
};
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface DoricDebugDriver : NSObject <DoricDriverProtocol>
|
||||
+ (instancetype)instance;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
186
doric-iOS/Devkit/Classes/DoricDebugDriver.m
Normal file
186
doric-iOS/Devkit/Classes/DoricDebugDriver.m
Normal file
@ -0,0 +1,186 @@
|
||||
/*
|
||||
* Copyright [2019] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
//
|
||||
// DoricDebugDriver.m
|
||||
// Doric
|
||||
//
|
||||
// Created by jingpeng.wang on 2020/2/25.
|
||||
//
|
||||
|
||||
#import "DoricDebugDriver.h"
|
||||
#import "DoricDebugJSEngine.h"
|
||||
#import "DoricConstant.h"
|
||||
#import "DoricContextManager.h"
|
||||
|
||||
@interface DoricDebugDriver ()
|
||||
@property(nonatomic, strong) DoricJSEngine *jsExecutor;
|
||||
@end
|
||||
|
||||
@implementation DoricDebugDriver
|
||||
|
||||
@dynamic registry;
|
||||
|
||||
- (instancetype)init {
|
||||
if (self = [super init]) {
|
||||
_jsExecutor = [[DoricDebugJSEngine alloc] init];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (DoricRegistry *)registry {
|
||||
return self.jsExecutor.registry;
|
||||
}
|
||||
|
||||
+ (instancetype)instance {
|
||||
static DoricDebugDriver *_instance;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
_instance = [[DoricDebugDriver alloc] init];
|
||||
});
|
||||
return _instance;
|
||||
}
|
||||
|
||||
- (DoricAsyncResult<JSValue *> *)invokeDoricMethod:(NSString *)method, ... {
|
||||
va_list args;
|
||||
va_start(args, method);
|
||||
DoricAsyncResult *ret = [self invokeDoricMethod:method arguments:args];
|
||||
va_end(args);
|
||||
return ret;
|
||||
}
|
||||
|
||||
- (NSString *)aliasWithContextId:(NSString *)contextId {
|
||||
return [[DoricContextManager instance] getContext:contextId].source;
|
||||
}
|
||||
|
||||
- (DoricAsyncResult<JSValue *> *)invokeDoricMethod:(NSString *)method arguments:(va_list)args {
|
||||
DoricAsyncResult *ret = [[DoricAsyncResult alloc] init];
|
||||
NSMutableArray *array = [[NSMutableArray alloc] init];
|
||||
id arg;
|
||||
while ((arg = va_arg(args, id)) != nil) {
|
||||
[array addObject:arg];
|
||||
}
|
||||
__weak typeof(self) _self = self;
|
||||
dispatch_async(self.jsExecutor.jsQueue, ^() {
|
||||
__strong typeof(_self) self = _self;
|
||||
if (!self) return;
|
||||
@try {
|
||||
JSValue *jsValue = [self.jsExecutor invokeDoricMethod:method argumentsArray:array];
|
||||
[ret setupResult:jsValue];
|
||||
} @catch (NSException *exception) {
|
||||
[ret setupError:exception];
|
||||
}
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
- (DoricAsyncResult<JSValue *> *)invokeContextEntity:(NSString *)contextId method:(NSString *)method, ... {
|
||||
va_list args;
|
||||
va_start(args, method);
|
||||
DoricAsyncResult *ret = [self invokeContextEntity:contextId method:method arguments:args];
|
||||
va_end(args);
|
||||
return ret;
|
||||
}
|
||||
|
||||
- (DoricAsyncResult *)invokeContextEntity:(NSString *)contextId method:(NSString *)method arguments:(va_list)args {
|
||||
DoricAsyncResult *ret = [[DoricAsyncResult alloc] init];
|
||||
NSMutableArray *array = [[NSMutableArray alloc] init];
|
||||
[array addObject:contextId];
|
||||
[array addObject:method];
|
||||
id arg = va_arg(args, id);
|
||||
while (arg != nil) {
|
||||
[array addObject:arg];
|
||||
arg = va_arg(args, JSValue *);
|
||||
}
|
||||
__weak typeof(self) _self = self;
|
||||
dispatch_async(self.jsExecutor.jsQueue, ^() {
|
||||
__strong typeof(_self) self = _self;
|
||||
if (!self) return;
|
||||
@try {
|
||||
JSValue *jsValue = [self.jsExecutor invokeDoricMethod:DORIC_CONTEXT_INVOKE argumentsArray:array];
|
||||
[ret setupResult:jsValue];
|
||||
} @catch (NSException *exception) {
|
||||
[ret setupError:exception];
|
||||
[self.jsExecutor.registry onException:exception source:[self aliasWithContextId:contextId]];
|
||||
}
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
- (DoricAsyncResult *)invokeContextEntity:(NSString *)contextId method:(NSString *)method argumentsArray:(NSArray *)args {
|
||||
DoricAsyncResult *ret = [[DoricAsyncResult alloc] init];
|
||||
NSMutableArray *array = [[NSMutableArray alloc] init];
|
||||
[array addObject:contextId];
|
||||
[array addObject:method];
|
||||
for (id arg in args) {
|
||||
[array addObject:arg];
|
||||
}
|
||||
__weak typeof(self) _self = self;
|
||||
dispatch_async(self.jsExecutor.jsQueue, ^() {
|
||||
__strong typeof(_self) self = _self;
|
||||
if (!self) return;
|
||||
@try {
|
||||
JSValue *jsValue = [self.jsExecutor invokeDoricMethod:DORIC_CONTEXT_INVOKE argumentsArray:array];
|
||||
[ret setupResult:jsValue];
|
||||
} @catch (NSException *exception) {
|
||||
[ret setupError:exception];
|
||||
[self.jsExecutor.registry onException:exception source:[self aliasWithContextId:contextId]];
|
||||
}
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
- (DoricAsyncResult *)createContext:(NSString *)contextId script:(NSString *)script source:(NSString *)source {
|
||||
DoricAsyncResult *ret = [[DoricAsyncResult alloc] init];
|
||||
__weak typeof(self) _self = self;
|
||||
dispatch_async(self.jsExecutor.jsQueue, ^() {
|
||||
__strong typeof(_self) self = _self;
|
||||
if (!self) return;
|
||||
@try {
|
||||
[self.jsExecutor prepareContext:contextId script:script source:source];
|
||||
[ret setupResult:@YES];
|
||||
} @catch (NSException *exception) {
|
||||
[ret setupError:exception];
|
||||
[self.jsExecutor.registry onException:exception source:source];
|
||||
}
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
- (DoricAsyncResult *)destroyContext:(NSString *)contextId {
|
||||
DoricAsyncResult *ret = [[DoricAsyncResult alloc] init];
|
||||
__weak typeof(self) _self = self;
|
||||
dispatch_async(self.jsExecutor.jsQueue, ^() {
|
||||
__strong typeof(_self) self = _self;
|
||||
if (!self) return;
|
||||
@try {
|
||||
[self.jsExecutor destroyContext:contextId];
|
||||
[ret setupResult:@YES];
|
||||
} @catch (NSException *exception) {
|
||||
[ret setupError:exception];
|
||||
[self.jsExecutor.registry onException:exception source:[self aliasWithContextId:contextId]];
|
||||
}
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
- (void)ensureSyncInMainQueue:(dispatch_block_t)block {
|
||||
if (strcmp(dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL), dispatch_queue_get_label(dispatch_get_main_queue())) == 0) {
|
||||
block();
|
||||
} else {
|
||||
dispatch_async(dispatch_get_main_queue(), block);
|
||||
}
|
||||
}
|
||||
@end
|
34
doric-iOS/Devkit/Classes/DoricDebugJSEngine.h
Normal file
34
doric-iOS/Devkit/Classes/DoricDebugJSEngine.h
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright [2019] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
//
|
||||
// DoricDebugJSEngine.h
|
||||
// Doric
|
||||
//
|
||||
// Created by jingpeng.wang on 2020/2/25.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <JavaScriptCore/JavaScriptCore.h>
|
||||
|
||||
#import "DoricJSEngine.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface DoricDebugJSEngine : DoricJSEngine
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
41
doric-iOS/Devkit/Classes/DoricDebugJSEngine.m
Normal file
41
doric-iOS/Devkit/Classes/DoricDebugJSEngine.m
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright [2019] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
//
|
||||
// DoricDebugJSEngine.m
|
||||
// Doric
|
||||
//
|
||||
// Created by jingpeng.wang on 2020/2/25.
|
||||
//
|
||||
|
||||
#import "DoricDebugJSEngine.h"
|
||||
#import "DoricJSRemoteExecutor.h"
|
||||
|
||||
@interface DoricDebugJSEngine ()
|
||||
@end
|
||||
|
||||
@implementation DoricDebugJSEngine
|
||||
|
||||
- (instancetype)init {
|
||||
if (self = [super init]) {
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)initJSEngine {
|
||||
self.jsExecutor = [[DoricJSRemoteExecutor alloc] init];
|
||||
}
|
||||
|
||||
@end
|
@ -21,7 +21,7 @@
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DoricDriver.h"
|
||||
#import "DoricDriverProtocol.h"
|
||||
#import "DoricNavigatorDelegate.h"
|
||||
#import "DoricNavBarDelegate.h"
|
||||
|
||||
@ -34,7 +34,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
@property(nonatomic, weak) id <DoricNavigatorDelegate> navigator;
|
||||
@property(nonatomic, weak) id <DoricNavBarDelegate> navBar;
|
||||
@property(nonatomic, strong) NSString *contextId;
|
||||
@property(nonatomic, strong) DoricDriver *driver;
|
||||
@property(nonatomic, strong) id <DoricDriverProtocol> driver;
|
||||
@property(nonatomic, strong) NSMutableDictionary *pluginInstanceMap;
|
||||
@property(nonatomic, strong) NSString *source;
|
||||
@property(nonatomic, strong) NSString *script;;
|
||||
|
@ -25,12 +25,13 @@
|
||||
#import "DoricRootNode.h"
|
||||
#import "DoricConstant.h"
|
||||
#import "DoricExtensions.h"
|
||||
#import "DoricNativeDriver.h"
|
||||
|
||||
@implementation DoricContext
|
||||
|
||||
- (instancetype)initWithScript:(NSString *)script source:(NSString *)source extra:(NSString *)extra {
|
||||
if (self = [super init]) {
|
||||
_driver = [DoricDriver instance];
|
||||
_driver = [DoricNativeDriver instance];
|
||||
_pluginInstanceMap = [NSMutableDictionary new];
|
||||
[[DoricContextManager instance] createContext:self script:script source:source];
|
||||
_headNodes = [NSMutableDictionary new];
|
||||
|
@ -14,26 +14,17 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
//
|
||||
// DoricDriver.h
|
||||
// DoricDriverProtocol.h
|
||||
// Doric
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/7/26.
|
||||
// Created by jingpeng.wang on 2020/2/25.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DoricAsyncResult.h"
|
||||
#import "DoricRegistry.h"
|
||||
|
||||
typedef NS_ENUM(NSInteger, DoricQueueMode) {
|
||||
JS = 0,
|
||||
UI,
|
||||
INDEPENDENT
|
||||
};
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface DoricDriver : NSObject
|
||||
+ (instancetype)instance;
|
||||
@protocol DoricDriverProtocol <NSObject>
|
||||
|
||||
@property(nonatomic, strong) DoricRegistry *registry;
|
||||
|
||||
@ -52,6 +43,5 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
- (void)ensureSyncInMainQueue:(dispatch_block_t)block;
|
||||
|
||||
- (NSString *)aliasWithContextId:(NSString *)contextId;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@end
|
38
doric-iOS/Pod/Classes/DoricNativeDriver.h
Normal file
38
doric-iOS/Pod/Classes/DoricNativeDriver.h
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright [2019] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
//
|
||||
// DoricNativeDriver.h
|
||||
// Doric
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/7/26.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DoricDriverProtocol.h"
|
||||
|
||||
typedef NS_ENUM(NSInteger, DoricQueueMode) {
|
||||
JS = 0,
|
||||
UI,
|
||||
INDEPENDENT
|
||||
};
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface DoricNativeDriver : NSObject <DoricDriverProtocol>
|
||||
+ (instancetype)instance;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
@ -14,22 +14,22 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
//
|
||||
// DoricDriver.m
|
||||
// DoricNativeDriver.m
|
||||
// Doric
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/7/26.
|
||||
//
|
||||
|
||||
#import "DoricDriver.h"
|
||||
#import "DoricNativeDriver.h"
|
||||
#import "DoricJSEngine.h"
|
||||
#import "DoricConstant.h"
|
||||
#import "DoricContextManager.h"
|
||||
|
||||
@interface DoricDriver ()
|
||||
@interface DoricNativeDriver ()
|
||||
@property(nonatomic, strong) DoricJSEngine *jsExecutor;
|
||||
@end
|
||||
|
||||
@implementation DoricDriver
|
||||
@implementation DoricNativeDriver
|
||||
|
||||
@dynamic registry;
|
||||
|
||||
@ -45,10 +45,10 @@ - (DoricRegistry *)registry {
|
||||
}
|
||||
|
||||
+ (instancetype)instance {
|
||||
static DoricDriver *_instance;
|
||||
static DoricNativeDriver *_instance;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
_instance = [[DoricDriver alloc] init];
|
||||
_instance = [[DoricNativeDriver alloc] init];
|
||||
});
|
||||
return _instance;
|
||||
}
|
@ -22,12 +22,16 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <JavaScriptCore/JavaScriptCore.h>
|
||||
|
||||
#import "DoricRegistry.h"
|
||||
#import "DoricJSExecutorProtocol.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface DoricJSEngine : NSObject
|
||||
|
||||
@property(nonatomic, strong) id <DoricJSExecutorProtocol> jsExecutor;
|
||||
|
||||
@property(nonatomic, strong) dispatch_queue_t jsQueue;
|
||||
|
||||
@property(nonatomic, strong) DoricRegistry *registry;
|
||||
|
@ -21,14 +21,12 @@
|
||||
//
|
||||
|
||||
#import "DoricJSEngine.h"
|
||||
#import "DoricJSExecutorProtocol.h"
|
||||
#import "DoricJSCoreExecutor.h"
|
||||
#import "DoricConstant.h"
|
||||
#import "DoricUtil.h"
|
||||
#import "DoricBridgeExtension.h"
|
||||
|
||||
@interface DoricJSEngine ()
|
||||
@property(nonatomic, strong) id <DoricJSExecutorProtocol> jsExecutor;
|
||||
@property(nonatomic, strong) NSMutableDictionary *timers;
|
||||
@property(nonatomic, strong) DoricBridgeExtension *bridgeExtension;
|
||||
@end
|
||||
@ -41,9 +39,7 @@ - (instancetype)init {
|
||||
_bridgeExtension = [[DoricBridgeExtension alloc] init];
|
||||
dispatch_async(_jsQueue, ^() {
|
||||
self.timers = [[NSMutableDictionary alloc] init];
|
||||
// Debug: 切换
|
||||
// self.jsExecutor = [[DoricJSRemoteExecutor alloc] init];
|
||||
self.jsExecutor = [DoricJSCoreExecutor new];
|
||||
[self initJSEngine];
|
||||
self.registry = [[DoricRegistry alloc] init];
|
||||
[self initJSExecutor];
|
||||
[self initDoricEnvironment];
|
||||
@ -52,6 +48,10 @@ - (instancetype)init {
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)initJSEngine {
|
||||
self.jsExecutor = [DoricJSCoreExecutor new];
|
||||
}
|
||||
|
||||
- (void)initJSExecutor {
|
||||
__weak typeof(self) _self = self;
|
||||
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
|
||||
|
Reference in New Issue
Block a user