Qml app allow registrer same callback

As I haven't investigated this enough yet, allow it happening but warn
  if it happens while debugging
This commit is contained in:
Gioacchino Mazzurco 2017-04-18 13:06:57 +02:00
parent 943a4213fb
commit 871ea333fc

View File

@ -30,16 +30,23 @@ QtObject
{ {
if (Array.isArray(tokens[token])) if (Array.isArray(tokens[token]))
{ {
// Do not register if it is registered already if(QT_DEBUG)
var arrLen = tokens[token].length
for(var i=0; i<arrLen; ++i)
{ {
if(callback === tokens[token][i]) /* Haven't properly investigated yet if it may happen in normal
* situations that a callback is registered more then once, so
* if we are in a debug session and that happens print warning
* and stacktrace */
var arrLen = tokens[token].length
for(var i=0; i<arrLen; ++i)
{ {
console.warn("tokensManager.registerToken(token, callback)", if(callback === tokens[token][i])
"Attempt to register same callback twice for:", {
i, token, callback) console.warn("tokensManager.registerToken(token," +
return " callback) Attempt to register same" +
" callback twice for:",
i, token, callback)
console.trace()
}
} }
} }
tokens[token].push(callback) tokens[token].push(callback)