feat:add pureCallEntityMethod,avoid hook affects
This commit is contained in:
1
doric-js/lib/src/runtime/sandbox.d.ts
vendored
1
doric-js/lib/src/runtime/sandbox.d.ts
vendored
@@ -23,6 +23,7 @@ export declare function jsReleaseContext(id: string): void;
|
||||
export declare function __require__(name: string): any;
|
||||
export declare function jsRegisterModule(name: string, moduleObject: any): void;
|
||||
export declare function jsCallEntityMethod(contextId: string, methodName: string, args?: any): any;
|
||||
export declare function pureCallEntityMethod(contextId: string, methodName: string, args?: any): any;
|
||||
declare type ClassType<T> = new (...args: any) => T;
|
||||
export declare function jsObtainEntry(contextId: string): () => ClassType<object> | ((constructor: ClassType<object>) => ClassType<object>);
|
||||
export declare function jsCallbackTimer(timerId: number): void;
|
||||
|
@@ -215,6 +215,27 @@ export function jsCallEntityMethod(contextId, methodName, args) {
|
||||
loge(`Cannot find method for context id:${contextId},method name is:${methodName}`);
|
||||
}
|
||||
}
|
||||
export function pureCallEntityMethod(contextId, methodName, args) {
|
||||
const context = gContexts.get(contextId);
|
||||
if (context === undefined) {
|
||||
loge(`Cannot find context for context id:${contextId}`);
|
||||
return;
|
||||
}
|
||||
if (context.entity === undefined) {
|
||||
loge(`Cannot find holder for context id:${contextId}`);
|
||||
return;
|
||||
}
|
||||
if (Reflect.has(context.entity, methodName)) {
|
||||
const argumentsList = [];
|
||||
for (let i = 2; i < arguments.length; i++) {
|
||||
argumentsList.push(arguments[i]);
|
||||
}
|
||||
return Reflect.apply(Reflect.get(context.entity, methodName), context.entity, argumentsList);
|
||||
}
|
||||
else {
|
||||
loge(`Cannot find method for context id:${contextId},method name is:${methodName}`);
|
||||
}
|
||||
}
|
||||
export function jsObtainEntry(contextId) {
|
||||
const context = jsObtainContext(contextId);
|
||||
const exportFunc = (constructor) => {
|
||||
|
Reference in New Issue
Block a user