Qt: add hook after call from native

This commit is contained in:
王劲鹏 2021-09-16 13:22:47 +08:00 committed by osborn
parent 6046bf6163
commit 520a3de6c5
4 changed files with 11 additions and 26 deletions

View File

@ -51,11 +51,6 @@ DoricJSEngine::DoricJSEngine(QObject *parent) : QObject(parent) {
mJSE->injectGlobalJSFunction(DoricConstant::INJECT_LOG, nativeLog,
"function");
// inject empty
DoricNativeEmpty *nativeEmpty = new DoricNativeEmpty();
mJSE->injectGlobalJSFunction(DoricConstant::INJECT_EMPTY, nativeEmpty,
"function");
// inject require
DoricNativeRequire *nativeRequire = new DoricNativeRequire();
mJSE->injectGlobalJSFunction(DoricConstant::INJECT_REQUIRE, nativeRequire,
@ -110,7 +105,15 @@ QString DoricJSEngine::destroyContext(QString contextId) {
QString DoricJSEngine::invokeDoricMethod(QString method,
QVariantList arguments) {
return mJSE->invokeObject(DoricConstant::GLOBAL_DORIC, method, arguments);
QString ret = mJSE->invokeObject(DoricConstant::GLOBAL_DORIC, method, arguments);
if (method != DoricConstant::DORIC_CONTEXT_INVOKE_PURE) {
QVariantList newArguments;
newArguments.append(0);
newArguments.append(false);
mJSE->invokeObject(DoricConstant::GLOBAL_DORIC, DoricConstant::DORIC_HOOK_NATIVE_CALL, newArguments);
}
return ret;
}
void DoricJSEngine::loadBuiltinJS(QString assetName) {

View File

@ -239,24 +239,6 @@ static void InjectedFunction(const v8::FunctionCallbackInfo<v8::Value> &args) {
Q_ARG(QString, QString::fromUtf8(argString3.c_str())),
Q_ARG(QString, QString::fromUtf8(argString4.c_str())));
}
// begin check to perform micro task checkpoint
std::string objectNameString = "global";
std::string functionKeyString = "nativeEmpty";
int objectCompareResult = strncmp(objectKey.c_str(), objectNameString.c_str(),
strlen(objectKey.c_str()));
if (objectCompareResult == 0) {
int functionCompareResult =
strncmp(functionKey.c_str(), functionKeyString.c_str(),
strlen(functionKey.c_str()));
if (functionCompareResult == 0) {
isolate->PerformMicrotaskCheckpoint();
}
}
// end check
}
void V8Executor::injectFunctions(const char *objectName,

View File

@ -6,7 +6,6 @@ const QString DoricConstant::DORIC_MODULE_LIB = "doric";
const QString DoricConstant::INJECT_ENVIRONMENT = "Environment";
const QString DoricConstant::INJECT_LOG = "nativeLog";
const QString DoricConstant::INJECT_EMPTY = "nativeEmpty";
const QString DoricConstant::INJECT_REQUIRE = "nativeRequire";
const QString DoricConstant::INJECT_TIMER_SET = "nativeSetTimer";
const QString DoricConstant::INJECT_TIMER_CLEAR = "nativeClearTimer";
@ -31,6 +30,7 @@ const QString DoricConstant::DORIC_CONTEXT_INVOKE_PURE = "pureCallEntityMethod";
const QString DoricConstant::DORIC_TIMER_CALLBACK = "jsCallbackTimer";
const QString DoricConstant::DORIC_BRIDGE_RESOLVE = "jsCallResolve";
const QString DoricConstant::DORIC_BRIDGE_REJECT = "jsCallReject";
const QString DoricConstant::DORIC_HOOK_NATIVE_CALL = "jsHookAfterNativeCall";
const QString DoricConstant::DORIC_ENTITY_RESPONSE = "__response__";
const QString DoricConstant::DORIC_ENTITY_INIT = "__init__";

View File

@ -14,7 +14,6 @@ public:
static const QString INJECT_ENVIRONMENT;
static const QString INJECT_LOG;
static const QString INJECT_EMPTY;
static const QString INJECT_REQUIRE;
static const QString INJECT_TIMER_SET;
static const QString INJECT_TIMER_CLEAR;
@ -30,6 +29,7 @@ public:
static const QString DORIC_TIMER_CALLBACK;
static const QString DORIC_BRIDGE_RESOLVE;
static const QString DORIC_BRIDGE_REJECT;
static const QString DORIC_HOOK_NATIVE_CALL;
static const QString DORIC_ENTITY_RESPONSE;
static const QString DORIC_ENTITY_CREATE;