| 46 | } |
| 47 | |
| 48 | bool 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 |
nothing calls this directly
no test coverage detected