From ed7d1865104c1b373c3e01144774786ce1af7f3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Mon, 8 Feb 2021 11:37:51 +0800 Subject: [PATCH] add view node --- doric-Qt/doric/DoricInterfaceDriver.h | 2 +- doric-Qt/doric/DoricNativeDriver.cpp | 9 ++++++++- doric-Qt/doric/DoricNativeDriver.h | 3 ++- doric-Qt/doric/async/DoricAsyncCall.h | 4 +++- doric-Qt/doric/demo/DoricDemoBridge.cpp | 2 +- doric-Qt/doric/doric.pro | 2 ++ doric-Qt/doric/engine/DoricNativeJSE.cpp | 8 +++++++- doric-Qt/doric/shader/DoricViewNode.cpp | 1 + doric-Qt/doric/shader/DoricViewNode.h | 10 ++++++++++ doric-Qt/doric/utils/DoricConstant.cpp | 4 ++-- 10 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 doric-Qt/doric/shader/DoricViewNode.cpp create mode 100644 doric-Qt/doric/shader/DoricViewNode.h diff --git a/doric-Qt/doric/DoricInterfaceDriver.h b/doric-Qt/doric/DoricInterfaceDriver.h index 7e630667..113ce957 100644 --- a/doric-Qt/doric/DoricInterfaceDriver.h +++ b/doric-Qt/doric/DoricInterfaceDriver.h @@ -16,7 +16,7 @@ public: virtual void invokeDoricMethod(QString method, QVariantList args) = 0; - virtual DoricAsyncResult *asyncCall(QRunnable *runnable, + virtual DoricAsyncResult *asyncCall(std::function lambda, DoricThreadMode mode) = 0; virtual void createContext(QString contextId, QString script, diff --git a/doric-Qt/doric/DoricNativeDriver.cpp b/doric-Qt/doric/DoricNativeDriver.cpp index f35dc323..11d2f4cd 100644 --- a/doric-Qt/doric/DoricNativeDriver.cpp +++ b/doric-Qt/doric/DoricNativeDriver.cpp @@ -19,8 +19,15 @@ void DoricNativeDriver::invokeDoricMethod(QString method, QVariantList args) { }); } -DoricAsyncResult *DoricNativeDriver::asyncCall(QRunnable *runnable, +DoricAsyncResult *DoricNativeDriver::asyncCall(std::function lambda, DoricThreadMode mode) { + switch (mode) { + case UI: + break; + case JS: + DoricAsyncCall::ensureRunInThreadPool(&jsEngine.mJSThreadPool, lambda); + break; + } return NULL; } diff --git a/doric-Qt/doric/DoricNativeDriver.h b/doric-Qt/doric/DoricNativeDriver.h index 48f54494..78ee25b0 100644 --- a/doric-Qt/doric/DoricNativeDriver.h +++ b/doric-Qt/doric/DoricNativeDriver.h @@ -26,7 +26,8 @@ public: void invokeDoricMethod(QString method, QVariantList args) override; - DoricAsyncResult * asyncCall(QRunnable *runnable, DoricThreadMode mode) override; + DoricAsyncResult *asyncCall(std::function lambda, + DoricThreadMode mode) override; void createContext(QString contextId, QString script, QString source) override; diff --git a/doric-Qt/doric/async/DoricAsyncCall.h b/doric-Qt/doric/async/DoricAsyncCall.h index 047efca1..bc883ac0 100644 --- a/doric-Qt/doric/async/DoricAsyncCall.h +++ b/doric-Qt/doric/async/DoricAsyncCall.h @@ -1,6 +1,7 @@ #ifndef ASYNC_CALL_H #define ASYNC_CALL_H +#include #include #include @@ -9,7 +10,8 @@ class DoricAsyncCall { public: static void ensureRunInThreadPool(QThreadPool *threadPool, std::function lambda) { - QtConcurrent::run(threadPool, lambda); + QFuture::result_type> future = + QtConcurrent::run(threadPool, lambda); } }; diff --git a/doric-Qt/doric/demo/DoricDemoBridge.cpp b/doric-Qt/doric/demo/DoricDemoBridge.cpp index 09e24f80..3d56d32f 100644 --- a/doric-Qt/doric/demo/DoricDemoBridge.cpp +++ b/doric-Qt/doric/demo/DoricDemoBridge.cpp @@ -9,7 +9,7 @@ DoricDemoBridge::DoricDemoBridge(QObject *parent) : QObject(parent) {} void DoricDemoBridge::navigate(QVariant route) { switch (route.toInt()) { case 0: - QString name = "Snake.es5.js"; + QString name = "Snake.js"; QString script = DoricUtils::readAssetFile("/doric/bundles", name); DoricPanel panel; diff --git a/doric-Qt/doric/doric.pro b/doric-Qt/doric/doric.pro index 71a22e42..7b4b33c7 100644 --- a/doric-Qt/doric/doric.pro +++ b/doric-Qt/doric/doric.pro @@ -32,6 +32,7 @@ SOURCES += \ main.cpp \ plugin/DoricShaderPlugin.cpp \ shader/DoricRootNode.cpp \ + shader/DoricViewNode.cpp \ utils/DoricConstant.cpp \ utils/DoricContextHolder.cpp @@ -71,6 +72,7 @@ HEADERS += \ plugin/DoricNativePlugin.h \ plugin/DoricShaderPlugin.h \ shader/DoricRootNode.h \ + shader/DoricViewNode.h \ template/DoricSingleton.h \ utils/DoricConstant.h \ utils/DoricContextHolder.h \ diff --git a/doric-Qt/doric/engine/DoricNativeJSE.cpp b/doric-Qt/doric/engine/DoricNativeJSE.cpp index b019835b..0bb2bfc7 100644 --- a/doric-Qt/doric/engine/DoricNativeJSE.cpp +++ b/doric-Qt/doric/engine/DoricNativeJSE.cpp @@ -57,9 +57,15 @@ QJSValue DoricNativeJSE::invokeObject(QString objectName, QString functionName, } QJSValue result = function.call(args); - if (result.isError()) + if (result.isError()) { qDebug() << "Uncaught exception at line" << result.property("lineNumber").toInt() << ":" << result.toString(); + QStringList stacktraces = result.property("stack").toString().split("\n"); + qDebug() << "++++++++++++++++++++++++"; + foreach (QString stacktrace, stacktraces) { qDebug() << stacktrace; } + qDebug() << "------------------------"; + } + return result; } diff --git a/doric-Qt/doric/shader/DoricViewNode.cpp b/doric-Qt/doric/shader/DoricViewNode.cpp new file mode 100644 index 00000000..258c1382 --- /dev/null +++ b/doric-Qt/doric/shader/DoricViewNode.cpp @@ -0,0 +1 @@ +#include "DoricViewNode.h" diff --git a/doric-Qt/doric/shader/DoricViewNode.h b/doric-Qt/doric/shader/DoricViewNode.h new file mode 100644 index 00000000..b1ef2d7e --- /dev/null +++ b/doric-Qt/doric/shader/DoricViewNode.h @@ -0,0 +1,10 @@ +#ifndef DORICVIEWNODE_H +#define DORICVIEWNODE_H + +#include "../utils/DoricContextHolder.h" + +class DoricViewNode : public DoricContextHolder { +public: + using DoricContextHolder::DoricContextHolder; +}; +#endif // DORICVIEWNODE_H diff --git a/doric-Qt/doric/utils/DoricConstant.cpp b/doric-Qt/doric/utils/DoricConstant.cpp index 3128019f..aa615006 100644 --- a/doric-Qt/doric/utils/DoricConstant.cpp +++ b/doric-Qt/doric/utils/DoricConstant.cpp @@ -1,7 +1,7 @@ #include "DoricConstant.h" -const QString DoricConstant::DORIC_BUNDLE_SANDBOX = "doric-sandbox.es5.js"; -const QString DoricConstant::DORIC_BUNDLE_LIB = "doric-lib.es5.js"; +const QString DoricConstant::DORIC_BUNDLE_SANDBOX = "doric-sandbox.js"; +const QString DoricConstant::DORIC_BUNDLE_LIB = "doric-lib.js"; const QString DoricConstant::DORIC_MODULE_LIB = "doric"; const QString DoricConstant::INJECT_ENVIRONMENT = "Environment";