Skip to content
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

TIMOB-7434 In rhino, be wary of trying to call undefined/null event call... #1286

Merged
merged 2 commits into from
Jan 31, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 16 additions & 2 deletions android/runtime/common/src/js/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
//USE OR OTHER DEALINGS IN THE SOFTWARE.

// Modifications Copyright 2011 Appcelerator, Inc.
// Modifications Copyright 2011-2012 Appcelerator, Inc.

var TAG = "EventEmitter";
var EventEmitter = exports.EventEmitter = kroll.EventEmitter;
Expand All @@ -32,6 +32,13 @@ var isArray = Array.isArray;
Object.defineProperty(EventEmitter.prototype, "callHandler", {
value: function(handler, type, data) {
//kroll.log(TAG, "calling event handler: type:" + type + ", data: " + data + ", handler: " + handler);
if (!handler || !(handler.call)) {
if (kroll.DBG) {
kroll.log(TAG, "handler for event '" + type + "' is " + (typeof handler) + " and cannot be called.");
}
return;
}

if (data instanceof Object) {
data.type = type;
} else if (!data) {
Expand Down Expand Up @@ -75,6 +82,13 @@ Object.defineProperty(EventEmitter.prototype, "emit", {
return false;
}

if (!this.callHandler) {
if (kroll.DBG) {
kroll.log(TAG, "callHandler function not available for " + type);
}
return false;
}

if (typeof handler == 'function') {
switch (arguments.length) {
case 1:
Expand Down Expand Up @@ -118,7 +132,7 @@ Object.defineProperty(EventEmitter.prototype, "fireSyncEvent", {
Object.defineProperty(EventEmitter.prototype, "addListener", {
value: function(type, listener) {
if ('function' !== typeof listener) {
throw new Error('addListener only takes instances of Function');
throw new Error('addListener only takes instances of Function. The listener for event "' + type + '" is "' + (typeof listener) + '"');
}

if (!this._events) {
Expand Down