Changeset View
Changeset View
Standalone View
Standalone View
src/script/katecommandlinescript.cpp
Context not available. | |||||
20 | 20 | | |||
---|---|---|---|---|---|
21 | #include "katecommandlinescript.h" | 21 | #include "katecommandlinescript.h" | ||
22 | 22 | | |||
23 | #include <QScriptValue> | 23 | #include <QJSValue> | ||
24 | #include <QScriptEngine> | 24 | #include <QJSEngine> | ||
25 | 25 | | |||
26 | #include <KLocalizedString> | 26 | #include <KLocalizedString> | ||
27 | #include <KShell> | 27 | #include <KShell> | ||
Context not available. | |||||
50 | bool KateCommandLineScript::callFunction(const QString &cmd, const QStringList args, QString &errorMessage) | 50 | bool KateCommandLineScript::callFunction(const QString &cmd, const QStringList args, QString &errorMessage) | ||
51 | { | 51 | { | ||
52 | clearExceptions(); | 52 | clearExceptions(); | ||
53 | QScriptValue command = function(cmd); | 53 | QJSValue command = function(cmd); | ||
54 | if (!command.isValid()) { | 54 | if (!command.isCallable()) { | ||
55 | errorMessage = i18n("Function '%1' not found in script: %2", cmd, url()); | 55 | errorMessage = i18n("Function '%1' not found in script: %2", cmd, url()); | ||
56 | return false; | 56 | return false; | ||
57 | } | 57 | } | ||
58 | 58 | | |||
59 | // add the arguments that we are going to pass to the function | 59 | // add the arguments that we are going to pass to the function | ||
60 | QScriptValueList arguments; | 60 | QJSValueList arguments; | ||
61 | foreach (const QString &arg, args) { | 61 | for (const QString &arg : args) { | ||
62 | arguments << QScriptValue(m_engine, arg); | 62 | arguments << QJSValue(arg); | ||
63 | } | 63 | } | ||
64 | 64 | | |||
65 | QScriptValue result = command.call(QScriptValue(), arguments); | 65 | QJSValue result = command.call(arguments); | ||
66 | // error during the calling? | 66 | // error during the calling? | ||
67 | if (m_engine->hasUncaughtException()) { | 67 | if (result.isError()) { | ||
68 | errorMessage = backtrace(result, i18n("Error calling %1", cmd)); | 68 | errorMessage = backtrace(result, i18n("Error calling %1", cmd)); | ||
69 | return false; | 69 | return false; | ||
70 | } | 70 | } | ||
71 | 71 | | |||
72 | return true; | 72 | return true; | ||
73 | } | 73 | } | ||
Context not available. | |||||
119 | } | 119 | } | ||
120 | 120 | | |||
121 | clearExceptions(); | 121 | clearExceptions(); | ||
122 | QScriptValue helpFunction = function(QStringLiteral("help")); | 122 | QJSValue helpFunction = function(QStringLiteral("help")); | ||
123 | if (!helpFunction.isValid()) { | 123 | if (!helpFunction.isCallable()) { | ||
124 | return false; | 124 | return false; | ||
125 | } | 125 | } | ||
126 | 126 | | |||
127 | // add the arguments that we are going to pass to the function | 127 | // add the arguments that we are going to pass to the function | ||
128 | QScriptValueList arguments; | 128 | QJSValueList arguments; | ||
129 | arguments << QScriptValue(m_engine, cmd); | 129 | arguments << QJSValue(cmd); | ||
130 | 130 | | |||
131 | QScriptValue result = helpFunction.call(QScriptValue(), arguments); | 131 | QJSValue result = helpFunction.call(arguments); | ||
132 | 132 | | |||
133 | // error during the calling? | 133 | // error during the calling? | ||
134 | if (m_engine->hasUncaughtException()) { | 134 | if (result.isError()) { | ||
135 | msg = backtrace(result, i18n("Error calling 'help %1'", cmd)); | 135 | msg = backtrace(result, i18n("Error calling 'help %1'", cmd)); | ||
136 | return false; | 136 | return false; | ||
137 | } | 137 | } | ||
Context not available. |