Changeset View
Changeset View
Standalone View
Standalone View
src/script/kateindentscript.cpp
Context not available. | |||||
19 | 19 | | |||
---|---|---|---|---|---|
20 | #include "kateindentscript.h" | 20 | #include "kateindentscript.h" | ||
21 | 21 | | |||
22 | #include <QScriptValue> | 22 | #include <QJSValue> | ||
23 | #include <QScriptEngine> | 23 | #include <QJSEngine> | ||
24 | 24 | | |||
25 | #include "katedocument.h" | 25 | #include "katedocument.h" | ||
26 | #include "kateview.h" | 26 | #include "kateview.h" | ||
Context not available. | |||||
62 | } | 62 | } | ||
63 | 63 | | |||
64 | clearExceptions(); | 64 | clearExceptions(); | ||
65 | QScriptValue indentFunction = function(QStringLiteral("indent")); | 65 | QJSValue indentFunction = function(QStringLiteral("indent")); | ||
66 | if (!indentFunction.isValid()) { | 66 | if (!indentFunction.isCallable()) { | ||
67 | return qMakePair(-2, -2); | 67 | return qMakePair(-2, -2); | ||
68 | } | 68 | } | ||
69 | // add the arguments that we are going to pass to the function | 69 | // add the arguments that we are going to pass to the function | ||
70 | QScriptValueList arguments; | 70 | QJSValueList arguments; | ||
71 | arguments << QScriptValue(m_engine, position.line()); | 71 | arguments << QJSValue(position.line()); | ||
72 | arguments << QScriptValue(m_engine, indentWidth); | 72 | arguments << QJSValue(indentWidth); | ||
73 | arguments << QScriptValue(m_engine, typedCharacter.isNull() ? QString() : QString(typedCharacter)); | 73 | arguments << (typedCharacter.isNull() ? QJSValue(QString()) : QJSValue(QString(typedCharacter))); | ||
74 | // get the required indent | 74 | // get the required indent | ||
75 | QScriptValue result = indentFunction.call(QScriptValue(), arguments); | 75 | QJSValue result = indentFunction.call(arguments); | ||
76 | // error during the calling? | 76 | // error during the calling? | ||
77 | if (m_engine->hasUncaughtException()) { | 77 | if (result.isError()) { | ||
78 | displayBacktrace(result, QStringLiteral("Error calling indent()")); | 78 | displayBacktrace(result, QStringLiteral("Error calling indent()")); | ||
79 | return qMakePair(-2, -2); | 79 | return qMakePair(-2, -2); | ||
80 | } | 80 | } | ||
81 | int indentAmount = -2; | 81 | int indentAmount = -2; | ||
82 | int alignAmount = -2; | 82 | int alignAmount = -2; | ||
83 | if (result.isArray()) { | 83 | if (result.isArray()) { | ||
84 | indentAmount = result.property(0).toInt32(); | 84 | indentAmount = result.property(0).toInt(); | ||
85 | alignAmount = result.property(1).toInt32(); | 85 | alignAmount = result.property(1).toInt(); | ||
86 | } else { | 86 | } else { | ||
87 | indentAmount = result.toInt32(); | 87 | indentAmount = result.toInt(); | ||
88 | } | | |||
89 | if (m_engine->hasUncaughtException()) { | | |||
90 | displayBacktrace(QScriptValue(), QStringLiteral("Bad return type (must be integer)")); | | |||
91 | return qMakePair(-2, -2); | | |||
92 | } | 88 | } | ||
89 | | ||||
93 | return qMakePair(indentAmount, alignAmount); | 90 | return qMakePair(indentAmount, alignAmount); | ||
94 | } | 91 | } | ||
95 | 92 | | |||
Context not available. |