feat:fix when android excute js on same thread,cause stucked
This commit is contained in:
@@ -93,7 +93,7 @@ function _rawValue(v) {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
function _injectGlobalObject(name, args) {
|
||||
function __injectGlobalObject(name, args) {
|
||||
Reflect.set(window, name, JSON.parse(args));
|
||||
}
|
||||
function __injectGlobalFunction(name) {
|
||||
@@ -107,6 +107,7 @@ 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);
|
||||
@@ -114,6 +115,7 @@ function __invokeMethod(objectName, functionName, stringifiedArgs) {
|
||||
const rawArgs = args.map(e => _rawValue(e));
|
||||
const ret = Reflect.apply(thisFunction, thisObject, rawArgs);
|
||||
const returnVal = ret ? JSON.stringify(_wrappedValue(ret)) : "";
|
||||
NativeClient.log(`return:${returnVal}`);
|
||||
NativeClient.returnNative(returnVal);
|
||||
}
|
||||
catch (e) {
|
||||
|
@@ -103,7 +103,7 @@ function _rawValue(v: WrappedValue): RawValue {
|
||||
}
|
||||
}
|
||||
|
||||
function _injectGlobalObject(name: string, args: string) {
|
||||
function __injectGlobalObject(name: string, args: string) {
|
||||
Reflect.set(window, name, JSON.parse(args));
|
||||
}
|
||||
|
||||
@@ -119,6 +119,7 @@ function __injectGlobalFunction(name: string) {
|
||||
}
|
||||
|
||||
function __invokeMethod(objectName: string, functionName: string, stringifiedArgs: string) {
|
||||
// NativeClient.log(`invoke:${objectName}.${functionName}(${stringifiedArgs})`)
|
||||
try {
|
||||
const thisObject = Reflect.get(window, objectName);
|
||||
const thisFunction = Reflect.get(thisObject, functionName);
|
||||
@@ -126,6 +127,7 @@ function __invokeMethod(objectName: string, functionName: string, stringifiedArg
|
||||
const rawArgs = args.map(e => _rawValue(e));
|
||||
const ret = Reflect.apply(thisFunction, thisObject, rawArgs);
|
||||
const returnVal = ret ? JSON.stringify(_wrappedValue(ret)) : ""
|
||||
// NativeClient.log(`return:${returnVal}`)
|
||||
NativeClient.returnNative(returnVal)
|
||||
} catch (e) {
|
||||
NativeClient.log(`error:${e},${(e as any).stack}`)
|
||||
|
2
doric-js/lib/index.web.d.ts
vendored
2
doric-js/lib/index.web.d.ts
vendored
@@ -23,7 +23,7 @@ declare function _binaryValue(v: RawValue): {
|
||||
};
|
||||
declare function _wrappedValue(v: RawValue): WrappedValue;
|
||||
declare function _rawValue(v: WrappedValue): RawValue;
|
||||
declare function _injectGlobalObject(name: string, args: string): void;
|
||||
declare function __injectGlobalObject(name: string, args: string): void;
|
||||
declare function __injectGlobalFunction(name: string): void;
|
||||
declare function __invokeMethod(objectName: string, functionName: string, stringifiedArgs: string): void;
|
||||
declare function _prepared(): void;
|
||||
|
@@ -91,7 +91,7 @@ function _rawValue(v) {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
function _injectGlobalObject(name, args) {
|
||||
function __injectGlobalObject(name, args) {
|
||||
Reflect.set(window, name, JSON.parse(args));
|
||||
}
|
||||
function __injectGlobalFunction(name) {
|
||||
@@ -105,6 +105,7 @@ 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);
|
||||
@@ -112,6 +113,7 @@ function __invokeMethod(objectName, functionName, stringifiedArgs) {
|
||||
const rawArgs = args.map(e => _rawValue(e));
|
||||
const ret = Reflect.apply(thisFunction, thisObject, rawArgs);
|
||||
const returnVal = ret ? JSON.stringify(_wrappedValue(ret)) : "";
|
||||
NativeClient.log(`return:${returnVal}`);
|
||||
NativeClient.returnNative(returnVal);
|
||||
}
|
||||
catch (e) {
|
||||
|
Reference in New Issue
Block a user