MCPcopy Create free account
hub / github.com/TeXworks/texworks / execute

Method execute

src/scripting/ECMAScript.cpp:29–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27namespace Scripting {
28
29bool 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

Callers

nothing calls this directly

Calls 4

setPropertyMethod · 0.80
openMethod · 0.45
cloneMethod · 0.45
SetResultMethod · 0.45

Tested by

no test coverage detected