Skip to content

Commit

Permalink
Using "hasOwnProperty" to check for direct properties "type" and
Browse files Browse the repository at this point in the history
"namespace" on events before triggering.
  • Loading branch information
andrewplummer committed Jan 31, 2013
1 parent bb1d148 commit 5935a36
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/event.js
Expand Up @@ -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;

Expand Down
14 changes: 14 additions & 0 deletions test/unit/event.js
Expand Up @@ -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("<p>").trigger('foo.bar');
} catch( e ) {
errored = true;
}
equal(errored, false, 'trigger() should not have errored');
delete String.prototype.namespace;
});

0 comments on commit 5935a36

Please sign in to comment.