blob: 0c9d987d51a45c1396acf3a78ba5dc49a4e9edae [file] [log] [blame]
/*
* weinre is available under *either* the terms of the modified BSD license *or* the
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
*
* Copyright (c) 2010, 2011 IBM Corporation
*/
requireClass ./Ex
requireClass ./Weinre
//-----------------------------------------------------------------------------
class EventListeners
this._listeners = []
//-----------------------------------------------------------------------------
method add(listener, useCapture)
this._listeners.push([listener, useCapture])
//-----------------------------------------------------------------------------
method remove(listener, useCapture)
for (var i=0; i<this._listeners.length; i++) {
var listener = this._listeners[i]
if (listener[0] != listener) continue;
if (listener[1] != useCapture) continue;
this._listeners.splice(i,1)
return
}
//-----------------------------------------------------------------------------
method fire(event)
this._listeners.slice().forEach(function(listener) {
var listener = listener[0]
if (typeof listener == "function") {
try {
listener.call(null, event)
}
catch(e) {
Weinre.logError(arguments.callee.signature + " invocation exception: " + e)
}
return
}
if (typeof listener.handleEvent != "function") {
throw new Ex(arguments, "listener does not implement the handleEvent() method")
}
try {
listener.handleEvent.call(listener, event)
}
catch(e) {
Weinre.logError(arguments.callee.signature + " invocation exception: " + e)
}
})