Skip to content

Commit

Permalink
Construct immutable QJSValueList from std::initializer_list args
Browse files Browse the repository at this point in the history
  • Loading branch information
uklotzde committed May 23, 2022
1 parent 3e4cfcb commit a4b7c20
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
13 changes: 7 additions & 6 deletions src/controllers/midi/midicontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,13 @@ void MidiController::processInputMapping(const MidiInputMapping& mapping,
}

QJSValue function = pEngine->wrapFunctionCode(mapping.control.item, 5);
QJSValueList args;
args << QJSValue(channel);
args << QJSValue(control);
args << QJSValue(value);
args << QJSValue(status);
args << QJSValue(mapping.control.group);
const auto args = QJSValueList{
channel,
control,
value,
status,
mapping.control.group,
};
if (!pEngine->executeFunction(function, args)) {
qCWarning(m_logBase) << "MidiController: Invalid script function"
<< mapping.control.item;
Expand Down
20 changes: 10 additions & 10 deletions src/controllers/scripting/legacy/controllerscriptenginelegacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,12 @@ bool ControllerScriptEngineLegacy::initialize() {
wrapFunctionCode(functionName, 2)));
}

QJSValueList args;
if (m_pController) {
args << QJSValue(m_pController->getName());
} else { // m_pController is nullptr in tests.
args << QJSValue();
}
args << QJSValue(m_logger().isDebugEnabled());
// m_pController is nullptr in tests.
const auto controllerName = m_pController ? m_pController->getName() : QString{};
const auto args = QJSValueList{
controllerName,
m_logger().isDebugEnabled(),
};
if (!callFunctionOnObjects(m_scriptFunctionPrefixes, "init", args, true)) {
shutdown();
return false;
Expand All @@ -182,9 +181,10 @@ bool ControllerScriptEngineLegacy::handleIncomingData(const QByteArray& data) {
return false;
}

QJSValueList args;
args << m_pJSEngine->toScriptValue(data);
args << QJSValue(static_cast<uint>(data.size()));
const auto args = QJSValueList{
m_pJSEngine->toScriptValue(data),
static_cast<uint>(data.size()),
};

for (const QJSValue& function : std::as_const(m_incomingDataFunctions)) {
ControllerScriptEngineBase::executeFunction(function, args);
Expand Down
9 changes: 5 additions & 4 deletions src/controllers/scripting/legacy/scriptconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
#include "controllers/scripting/legacy/controllerscriptenginelegacy.h"

void ScriptConnection::executeCallback(double value) const {
QJSValueList args;
args << QJSValue(value);
args << QJSValue(key.group);
args << QJSValue(key.item);
const auto args = QJSValueList{
value,
key.group,
key.item,
};
QJSValue func = callback; // copy function because QJSValue::call is not const
QJSValue result = func.call(args);
if (result.isError()) {
Expand Down

0 comments on commit a4b7c20

Please sign in to comment.