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

Method execute

src/scripting/JSScript.cpp:48–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46}
47
48bool JSScript::execute(ScriptAPIInterface * tw) const
49{
50 QFile scriptFile(m_Filename);
51 if (!scriptFile.open(QIODevice::ReadOnly)) {
52 // handle error
53 return false;
54 }
55 QTextStream stream(&scriptFile);
56 stream.setCodec(m_Codec);
57 QString contents = stream.readAll();
58 scriptFile.close();
59
60 QScriptEngine engine;
61 QScriptValue twObject = engine.newQObject(tw->self());
62 engine.globalObject().setProperty(QString::fromLatin1("TW"), twObject);
63
64 QScriptValue val;
65
66 Tw::Settings settings;
67 if (settings.value(QString::fromLatin1("scriptDebugger"), false).toBool()) {
68 QScriptEngineDebugger debugger;
69 debugger.attachTo(&engine);
70 val = engine.evaluate(contents, m_Filename);
71 }
72 else {
73 val = engine.evaluate(contents, m_Filename);
74 }
75
76 if (engine.hasUncaughtException()) {
77 tw->SetResult(engine.uncaughtException().toString());
78 return false;
79 }
80 if (!val.isUndefined())
81 tw->SetResult(convertValue(val));
82 return true;
83}
84
85} // namespace Scripting
86} // namespace Tw

Callers

nothing calls this directly

Calls 6

convertValueFunction · 0.85
setPropertyMethod · 0.80
openMethod · 0.45
selfMethod · 0.45
valueMethod · 0.45
SetResultMethod · 0.45

Tested by

no test coverage detected