optimize stack trace print

This commit is contained in:
王劲鹏 2021-02-08 14:36:05 +08:00 committed by osborn
parent e00bae87f8
commit 47cf75a0aa

View File

@ -1,5 +1,8 @@
#include "DoricNativeJSE.h"
#include <QDebug> #include <QDebug>
#include <QJSValueIterator>
#include "../utils/DoricUtils.h"
#include "DoricNativeJSE.h"
DoricNativeJSE::DoricNativeJSE() { DoricNativeJSE::DoricNativeJSE() {
mJSEngine.installExtensions(QJSEngine::AllExtensions); mJSEngine.installExtensions(QJSEngine::AllExtensions);
@ -34,6 +37,9 @@ void DoricNativeJSE::injectGlobalJSFunction(QString name, QObject *function,
QJSValue DoricNativeJSE::invokeObject(QString objectName, QString functionName, QJSValue DoricNativeJSE::invokeObject(QString objectName, QString functionName,
QVariantList arguments) { QVariantList arguments) {
QString script = DoricUtils::readAssetFile("/test", "test.js");
mJSEngine.evaluate(script);
QJSValue object = mJSEngine.evaluate(objectName); QJSValue object = mJSEngine.evaluate(objectName);
QJSValue function = object.property(functionName); QJSValue function = object.property(functionName);
@ -58,13 +64,11 @@ QJSValue DoricNativeJSE::invokeObject(QString objectName, QString functionName,
QJSValue result = function.call(args); QJSValue result = function.call(args);
if (result.isError()) { if (result.isError()) {
qDebug() << "++++++++++++++++++++++++"; qCritical() << "++++++++++++++++++++++++++++++++++++++++++++++++";
qCritical() << "Uncaught exception at line" qCritical() << result.toString();
<< result.property("lineNumber").toInt() << ":"
<< result.toString();
QStringList stacktraces = result.property("stack").toString().split("\n"); QStringList stacktraces = result.property("stack").toString().split("\n");
foreach (QString stacktrace, stacktraces) { qDebug() << stacktrace; } foreach (QString stacktrace, stacktraces) { qDebug() << stacktrace; }
qDebug() << "------------------------"; qCritical() << "------------------------------------------------";
} }
return result; return result;