android: enable setTimeout and setInterval
This commit is contained in:
@@ -85,6 +85,9 @@ function _rawValue(v) {
|
||||
return v.value;
|
||||
case "object":
|
||||
case "array":
|
||||
if (typeof v.value === 'string') {
|
||||
return JSON.parse(v.value);
|
||||
}
|
||||
return v.value;
|
||||
default:
|
||||
return undefined;
|
||||
@@ -104,21 +107,13 @@ function __injectGlobalFunction(name) {
|
||||
});
|
||||
}
|
||||
function __invokeMethod(objectName, functionName, stringifiedArgs) {
|
||||
NativeClient.log(`invoke:${objectName}.${functionName}(${stringifiedArgs})`);
|
||||
try {
|
||||
const thisObject = Reflect.get(window, objectName);
|
||||
const thisFunction = Reflect.get(thisObject, functionName);
|
||||
const args = JSON.parse(stringifiedArgs);
|
||||
args.forEach(e => {
|
||||
NativeClient.log(`Arg:${e},${typeof e}`);
|
||||
});
|
||||
const rawArgs = args.map(e => _rawValue(e));
|
||||
rawArgs.forEach(e => {
|
||||
NativeClient.log(`RawArg:${e},${typeof e}`);
|
||||
});
|
||||
const ret = Reflect.apply(thisFunction, thisObject, rawArgs);
|
||||
const returnVal = JSON.stringify(_wrappedValue(ret));
|
||||
NativeClient.log(`return:${returnVal}`);
|
||||
const returnVal = ret ? JSON.stringify(_wrappedValue(ret)) : "";
|
||||
NativeClient.returnNative(returnVal);
|
||||
}
|
||||
catch (e) {
|
||||
@@ -126,3 +121,9 @@ function __invokeMethod(objectName, functionName, stringifiedArgs) {
|
||||
NativeClient.returnNative("");
|
||||
}
|
||||
}
|
||||
function _prepared() {
|
||||
window.setTimeout = Reflect.get(window, "doricSetTimeout");
|
||||
window.setInterval = Reflect.get(window, "doricSetInterval");
|
||||
window.clearTimeout = Reflect.get(window, "doricClearTimeout");
|
||||
window.clearInterval = Reflect.get(window, "doricClearInterval");
|
||||
}
|
||||
|
Reference in New Issue
Block a user