-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't override XML mapping when using makeInputHandler
#13089
Don't override XML mapping when using makeInputHandler
#13089
Conversation
@@ -631,6 +631,12 @@ QJSValue MidiController::makeInputHandler(int status, int midino, const QJSValue | |||
return QJSValue(); | |||
} | |||
|
|||
if (m_pMapping->getInputMappings().contains(status)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This just check if an existing mapping exists. Should it perform a more thourough search to check if existing binding is an XML type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd argue yes. I think its valid that JS would like to bind different handlers to the same message. It's also possible in the XML manually, so the limitation for pure JS seems arbitrary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before, all bindings are from XML right? So the question is regarding to allow a second js binding. Is that your point? Do we have a use case for it? I think in such cases you could just put both features onto one callback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why midino
is not relevant here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh that's a mistake. Fixed.
@@ -631,6 +631,12 @@ QJSValue MidiController::makeInputHandler(int status, int midino, const QJSValue | |||
return QJSValue(); | |||
} | |||
|
|||
if (m_pMapping->getInputMappings().contains(status)) { | |||
qDebug(m_logBase).nospace() << "Ignoring anonymous JS function for status " | |||
<< status << " because a previous binding exists"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, I just log a message. I was thinking maybe also log the script line. getScriptEngine()->throwJSError()
indicates a line in the script. Is there a similar method to just log a warning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not that I'd know of. I think its easy enough to identify if you also include the midino
in the warning. Alternatively consider using ControllerScriptEngineBase::logOrThrowError
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My guess is:
getScriptEngine()->currentStackFrame->lineNumber()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that doesn't exist / is private, or at least it seems to be undocumented. where is this from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have skimmed through the Qt source.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't find getScriptEngine()->currentStackFrame
.
I didn't write any tests here. Should I? |
At least don't spend to much time on that. ;-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. Here some comments.
@@ -631,6 +631,12 @@ QJSValue MidiController::makeInputHandler(int status, int midino, const QJSValue | |||
return QJSValue(); | |||
} | |||
|
|||
if (m_pMapping->getInputMappings().contains(status)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before, all bindings are from XML right? So the question is regarding to allow a second js binding. Is that your point? Do we have a use case for it? I think in such cases you could just put both features onto one callback.
@@ -631,6 +631,12 @@ QJSValue MidiController::makeInputHandler(int status, int midino, const QJSValue | |||
return QJSValue(); | |||
} | |||
|
|||
if (m_pMapping->getInputMappings().contains(status)) { | |||
qDebug(m_logBase).nospace() << "Ignoring anonymous JS function for status " | |||
<< status << " because a previous binding exists"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My guess is:
getScriptEngine()->currentStackFrame->lineNumber()
@@ -631,6 +631,12 @@ QJSValue MidiController::makeInputHandler(int status, int midino, const QJSValue | |||
return QJSValue(); | |||
} | |||
|
|||
if (m_pMapping->getInputMappings().contains(status)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why midino
is not relevant here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, forgot to submit my review earlier
@@ -631,6 +631,12 @@ QJSValue MidiController::makeInputHandler(int status, int midino, const QJSValue | |||
return QJSValue(); | |||
} | |||
|
|||
if (m_pMapping->getInputMappings().contains(status)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd argue yes. I think its valid that JS would like to bind different handlers to the same message. It's also possible in the XML manually, so the limitation for pure JS seems arbitrary.
@@ -631,6 +631,12 @@ QJSValue MidiController::makeInputHandler(int status, int midino, const QJSValue | |||
return QJSValue(); | |||
} | |||
|
|||
if (m_pMapping->getInputMappings().contains(status)) { | |||
qDebug(m_logBase).nospace() << "Ignoring anonymous JS function for status " | |||
<< status << " because a previous binding exists"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not that I'd know of. I think its easy enough to identify if you also include the midino
in the warning. Alternatively consider using ControllerScriptEngineBase::logOrThrowError
.
43893b7
to
c158455
Compare
You're right. That's fixed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm otherwise
qCWarning(m_logBase) << QString( | ||
"Ignoring anonymous JS function for status=%1,midino=%2 " | ||
"because a previous XML binding exists") | ||
.arg(status) | ||
.arg(midino); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
qCWarning(m_logBase) << QString( | |
"Ignoring anonymous JS function for status=%1,midino=%2 " | |
"because a previous XML binding exists") | |
.arg(status) | |
.arg(midino); | |
qCWarning(m_logBase) << QStringLiteral( | |
"Ignoring anonymous JS function for status=%1,midino=%2 " | |
"because a previous XML binding exists") | |
.arg(status, midino); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Erf, no, that works only for objects that can be casted to QString. When used with (status, midino)
, C++ select this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do:
qCWarning(m_logBase) << QString( | |
"Ignoring anonymous JS function for status=%1,midino=%2 " | |
"because a previous XML binding exists") | |
.arg(status) | |
.arg(midino); | |
qCWarning(m_logBase) << QString( | |
"Ignoring anonymous JS function for status=%1,midino=%2 " | |
"because a previous XML binding exists") | |
.arg(QString::number(status), QString::number(midino)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whoops, good point. yeah, then the double arg
is probably fine. suboptimal Qt Api. Still, please wrap the string literal in a QStringLiteral
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
c158455
to
8cb1014
Compare
8cb1014
to
d070bae
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. wdyt @daschuer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, Thank you.
Follow up of #12781. This PR is designed to prevent overriting an existing XML mapping when when using
makeInputHandler
.