| 27 | namespace Scripting { |
| 28 | |
| 29 | bool ECMAScript::execute(ScriptAPIInterface *tw) const |
| 30 | { |
| 31 | QFile scriptFile(m_Filename); |
| 32 | if (!scriptFile.open(QIODevice::ReadOnly)) { |
| 33 | // handle error |
| 34 | return false; |
| 35 | } |
| 36 | QString contents = m_Codec->toUnicode(scriptFile.readAll()); |
| 37 | scriptFile.close(); |
| 38 | |
| 39 | |
| 40 | QJSEngine engine; |
| 41 | #if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) |
| 42 | engine.installExtensions(QJSEngine::AllExtensions); |
| 43 | #endif |
| 44 | QJSValue twObject = engine.newQObject(tw->clone()); |
| 45 | engine.globalObject().setProperty(QString::fromLatin1("TW"), twObject); |
| 46 | #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) |
| 47 | QJSValue val = engine.evaluate(contents, m_Filename); |
| 48 | #else |
| 49 | QStringList exceptionStackTrace; |
| 50 | QJSValue val = engine.evaluate(contents, m_Filename, 1, &exceptionStackTrace); |
| 51 | #endif |
| 52 | |
| 53 | if (val.isError()) { |
| 54 | tw->SetResult(val.toString() + |
| 55 | tr("\n\nStack trace:\n") + |
| 56 | val.property(QStringLiteral("stack")).toString()); |
| 57 | return false; |
| 58 | } |
| 59 | #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) |
| 60 | if (!exceptionStackTrace.isEmpty()) { |
| 61 | tw->SetResult(val.toString()); |
| 62 | return false; |
| 63 | } |
| 64 | #endif |
| 65 | if (!val.isUndefined()) |
| 66 | tw->SetResult(val.toVariant()); |
| 67 | return true; |
| 68 | } |
| 69 | |
| 70 | } // namespace Scripting |
| 71 | } // namespace Tw |
nothing calls this directly
no test coverage detected