feat: add type for value in dev

This commit is contained in:
jiangteng 2019-12-09 15:06:12 +08:00
parent ce0e1d0ed0
commit 29e8e73eb9
3 changed files with 32 additions and 8 deletions

View File

@ -50,6 +50,7 @@ - (instancetype)init {
return self; return self;
} }
#pragma mark - SRWebSocketDelegate
- (void)webSocketDidOpen:(SRWebSocket *)webSocket { - (void)webSocketDidOpen:(SRWebSocket *)webSocket {
DoricLog(@"debugger webSocketDidOpen"); DoricLog(@"debugger webSocketDidOpen");
DC_UNLOCK(self.semaphore); DC_UNLOCK(self.semaphore);
@ -93,6 +94,8 @@ - (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message {
result = ((Block4)tmpBlk)(argsArr[0], argsArr[1], argsArr[2], argsArr[3]); result = ((Block4)tmpBlk)(argsArr[0], argsArr[1], argsArr[2], argsArr[3]);
} else if (argsArr.count == 5) { } else if (argsArr.count == 5) {
result = ((Block5)tmpBlk)(argsArr[0], argsArr[1], argsArr[2], argsArr[3], argsArr[4]); result = ((Block5)tmpBlk)(argsArr[0], argsArr[1], argsArr[2], argsArr[3], argsArr[4]);
}else {
DoricLog(@"error:args to more than 5. args:%@",argsArr);
} }
} else if ([cmd isEqualToString:@"invokeMethod"]) { } else if ([cmd isEqualToString:@"invokeMethod"]) {
@ -115,6 +118,7 @@ - (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reas
DoricLog(@"debugger webSocketdidCloseWithCode"); DoricLog(@"debugger webSocketdidCloseWithCode");
} }
#pragma mark - DoricJSExecutorProtocol
- (NSString *)loadJSScript:(NSString *)script source:(NSString *)source { - (NSString *)loadJSScript:(NSString *)script source:(NSString *)source {
return nil; return nil;
@ -141,10 +145,7 @@ - (JSValue *)invokeObject:(NSString *)objName method:(NSString *)funcName args:(
NSMutableArray *argsMArr = [NSMutableArray new]; NSMutableArray *argsMArr = [NSMutableArray new];
for (id arg in args) { for (id arg in args) {
NSDictionary *dic = @{ NSDictionary *dic = [self dicForArg:arg];
@"type": @(DoricargTypeWithArg(arg)),
@"value": arg
};
[argsMArr addObject:dic]; [argsMArr addObject:dic];
} }
@ -168,6 +169,19 @@ - (JSValue *)invokeObject:(NSString *)objName method:(NSString *)funcName args:(
return self.temp; return self.temp;
} }
- (NSDictionary *)dicForArg:(id)arg {
DoricJSRemoteArgType type = DoricargTypeWithArg(arg);
if (type == DoricJSRemoteArgTypeObject || type == DoricJSRemoteArgTypeArray) {
NSString *jsonStr = [NSString dc_convertToJsonWithDic:(NSDictionary *)arg];
arg = jsonStr;
}
NSDictionary *dic = @{
@"type": @(type),
@"value": arg
};
return dic;
}
- (void)close { - (void)close {
[self.srWebSocket close]; [self.srWebSocket close];
} }

View File

@ -11,7 +11,7 @@ NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSUInteger, DoricJSRemoteArgType) { typedef NS_ENUM(NSUInteger, DoricJSRemoteArgType) {
DoricJSRemoteArgTypeNil = 0, DoricJSRemoteArgTypeNil = 0,
DoricJSRemoteArgTypeInteger, DoricJSRemoteArgTypeNumber,
DoricJSRemoteArgTypeBool, DoricJSRemoteArgTypeBool,
DoricJSRemoteArgTypeString, DoricJSRemoteArgTypeString,
DoricJSRemoteArgTypeObject, DoricJSRemoteArgTypeObject,
@ -20,4 +20,5 @@ typedef NS_ENUM(NSUInteger, DoricJSRemoteArgType) {
DoricJSRemoteArgType DoricargTypeWithArg(id arg); DoricJSRemoteArgType DoricargTypeWithArg(id arg);
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

View File

@ -6,7 +6,16 @@
// //
#import "DoricJSRemoteArgType.h" #import "DoricJSRemoteArgType.h"
DoricJSRemoteArgType DoricargTypeWithArg(id arg) { DoricJSRemoteArgType DoricargTypeWithArg(id arg) {
// TODO: DoricJSRemoteArgType type = DoricJSRemoteArgTypeNil;
return DoricJSRemoteArgTypeString; if ([arg isKindOfClass:[NSNumber class]]) {
type = DoricJSRemoteArgTypeNumber;
}else if ([arg isKindOfClass:[NSString class]]) {
type = DoricJSRemoteArgTypeString;
}else if ([arg isKindOfClass:[NSDictionary class]]) {
type = DoricJSRemoteArgTypeObject;
}else if ([arg isKindOfClass:[NSMutableArray class]]) {
type = DoricJSRemoteArgTypeArray;
}
return type;
} }