From: Andrew Plummer Date: Thu, 31 Jan 2013 17:40:42 +0000 (+0900) Subject: Using "hasOwnProperty" to check for direct properties "type" and X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5935a362c75ecef04d5ec9775cbcaf2165921e8d;p=jquery.git Using "hasOwnProperty" to check for direct properties "type" and "namespace" on events before triggering. --- diff --git a/src/event.js b/src/event.js index 5841aff7c..fb9727867 100644 --- a/src/event.js +++ b/src/event.js @@ -208,8 +208,8 @@ jQuery.event = { var i, cur, tmp, bubbleType, ontype, handle, special, eventPath = [ elem || document ], - type = event.type || event, - namespaces = event.namespace ? event.namespace.split(".") : []; + type = core_hasOwn.call(event, 'type') ? event.type : event, + namespaces = core_hasOwn.call(event, 'namespace') ? event.namespace.split(".") : []; cur = tmp = elem = elem || document; diff --git a/test/unit/event.js b/test/unit/event.js index bde9f7f43..2bede51fa 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -2666,3 +2666,17 @@ test( "Check order of focusin/focusout events", 2, function() { input.off(); }); +test("make sure defining 'namespace' on String.prototype does not cause trigger() to error", function() { + expect(1); + var errored = false; + String.prototype.namespace = function() { + return "test"; + }; + try { + jQuery("

").trigger('foo.bar'); + } catch( e ) { + errored = true; + } + equal(errored, false, 'trigger() should not have errored'); + delete String.prototype.namespace; +});