Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Using "hasOwnProperty" to check for direct properties "type" and #1153

Closed
wants to merge 1 commit into from

3 participants

@andrewplummer

This is the same change as #1140, minus a few back and forth commits that were reverted, and with a simpler unit test, as per @gnarf37's request.

@rwaldron rwaldron commented on the diff
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,
@rwaldron Collaborator

Double quotes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@rwaldron rwaldron commented on the diff
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(".") : [];
@rwaldron Collaborator

Double quotes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@rwaldron rwaldron commented on the diff
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("<p>").trigger('foo.bar');
@rwaldron Collaborator

Double quotes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@rwaldron rwaldron commented on the diff
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("<p>").trigger('foo.bar');
+ } catch( e ) {
+ errored = true;
+ }
+ equal(errored, false, 'trigger() should not have errored');
@rwaldron Collaborator

Fix whitespace and use double quotes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@gnarf
Owner

@rwldrn I just took care of the whitespace/quotes myself and made a couple of tweaks. Thanks for pointing em out tho. @andrewplummer http://contribute.jquery.org/style-guide/js/

@gnarf gnarf referenced this pull request from a commit
@andrewplummer andrewplummer event: Stricter type checking in trigger - Fixes #13360 - Closes gh-1153


Squashed commit of the following:

commit 5935a36
Author: Andrew Plummer <plummer.andrew@gmail.com>
Date:   Fri Feb 1 02:40:42 2013 +0900

    Using "hasOwnProperty" to check for direct properties "type" and
    "namespace" on events before triggering.
f005af5
@gnarf gnarf closed this pull request from a commit
@andrewplummer andrewplummer event: Stricter type checking in trigger - Fixes #13360 - Closes gh-1153


Squashed commit of the following:

commit 5935a36
Author: Andrew Plummer <plummer.andrew@gmail.com>
Date:   Fri Feb 1 02:40:42 2013 +0900

    Using "hasOwnProperty" to check for direct properties "type" and
    "namespace" on events before triggering.
(cherry picked from commit f005af5)
d654914
@gnarf gnarf closed this in d654914
@gnarf
Owner

Landed in 1.9-stable and master.

@andrewplummer

@gnarf37 thank you!

Sorry, force of habit.

@gnarf
Owner

:star: Thanks for being persistant, and listening, and above all the contribution. :star:

:+1:

@andrewplummer

Of course! In a sense I'm asking for a lot, I realize that.
Here's hoping there's no more.

@mescoda mescoda referenced this pull request from a commit in mescoda/jquery
@andrewplummer andrewplummer event: Stricter type checking in trigger - Fixes #13360 - Closes gh-1153


Squashed commit of the following:

commit 5935a36
Author: Andrew Plummer <plummer.andrew@gmail.com>
Date:   Fri Feb 1 02:40:42 2013 +0900

    Using "hasOwnProperty" to check for direct properties "type" and
    "namespace" on events before triggering.
4d784db
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 31, 2013
  1. @andrewplummer

    Using "hasOwnProperty" to check for direct properties "type" and

    andrewplummer authored
    "namespace" on events before triggering.
This page is out of date. Refresh to see the latest.
Showing with 16 additions and 2 deletions.
  1. +2 −2 src/event.js
  2. +14 −0 test/unit/event.js
View
4 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,
@rwaldron Collaborator

Double quotes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ namespaces = core_hasOwn.call(event, 'namespace') ? event.namespace.split(".") : [];
@rwaldron Collaborator

Double quotes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
cur = tmp = elem = elem || document;
View
14 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("<p>").trigger('foo.bar');
@rwaldron Collaborator

Double quotes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ } catch( e ) {
+ errored = true;
+ }
+ equal(errored, false, 'trigger() should not have errored');
@rwaldron Collaborator

Fix whitespace and use double quotes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ delete String.prototype.namespace;
+});
Something went wrong with that request. Please try again.