-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbridge.js
47 lines (40 loc) · 930 Bytes
/
bridge.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import global from './global'
let callbackSet = {};
let cbId = 0;
// 用于与oc 通信表示方法的定义
export function declare (...arg){
try {
_lufix_declare(...arg);
}
catch(e){
// console.log(e);
}
}
// 用于与oc 通信表示表示指令的执行
export function evaluate(...arg){
//return undefined;
let ret;
try {
ret = _lufix_evaluate(...arg);
}catch(e){
// console.log(e);
}finally{
return ret ;
}
}
global["_lufix_callback"] = function(callbackId) {
let fn = callbackSet[callbackId];
delete callbackSet[callbackId];
return fn;
}
// 可能存在溢出,这块儿的算法需要调整一下
export function getCallbackId(fn){
callbackSet[++cbId] = fn;
return cbId;
}
const jsLogger = global.console.log;
global.console.log = function(...args) {
evaluate({__type:'log_i',__content:{info:args}});
jsLogger.apply(global.console,args);
}
export let logger = jsLogger;