| 238 | } |
| 239 | |
| 240 | QJSValue ScopyJS::evaluateFile(const QString &path) |
| 241 | { |
| 242 | QTextStream out(stdout); |
| 243 | QFile file(path); |
| 244 | if(!file.open(QFile::ReadOnly)) { |
| 245 | out << "Unable to open the script file: " << path << Qt::endl; |
| 246 | return ""; |
| 247 | } |
| 248 | const QString scriptContent = getScriptContent(&file); |
| 249 | QJSValue val = ScopyJS::GetInstance()->engine()->evaluate(scriptContent, path); |
| 250 | if(val.isError()) { |
| 251 | out << "Exception:" << val.toString() << Qt::endl; |
| 252 | } else if(!val.isUndefined()) { |
| 253 | out << val.toString() << Qt::endl; |
| 254 | } |
| 255 | |
| 256 | out.flush(); |
| 257 | |
| 258 | return val; |
| 259 | } |
| 260 | |
| 261 | const QString ScopyJS::getScriptContent(QFile *file) |
| 262 | { |