Skip to content

Data:Event:Manipulation: Prevent collisions with Object.prototype properties #4603

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

Merged
merged 1 commit into from
Mar 2, 2020

Conversation

mgol
Copy link
Member

@mgol mgol commented Feb 5, 2020

Summary

Make sure events & data keys matching Object.prototype properties work.
A separate fix for such events on cloned elements was added as well.

The commit also removes two unnecessary checks:

  1. A check for events in private data in .trigger() - only the handle
    key is needed.
  2. A fallback of the events private data to an empty object in
    jQuery.event.dispatch because that method is called from the handle
    function in element's private data and both events & handle are set and
    removed at the same time.

Fixes gh-3256

Checklist

@mgol
Copy link
Member Author

mgol commented Feb 5, 2020

-19 bytes because of removals of fallbacks where they didn't seem needed IMO. I'd appreciate a review of those cases to be sure.

@mgol mgol force-pushed the event-object-prototype-collision branch from 70f64a0 to 88ad53c Compare February 10, 2020 18:19
@mgol mgol force-pushed the event-object-prototype-collision branch 2 times, most recently from 6e47006 to 06eb190 Compare March 1, 2020 22:59
@mgol
Copy link
Member Author

mgol commented Mar 1, 2020

Adding "Needs review" back as a few things have changed since I reported the PR.

It's now +0 bytes.

@mgol mgol removed the Needs review label Mar 2, 2020
…perties

Make sure events & data keys matching Object.prototype properties work.
A separate fix for such events on cloned elements was added as well.

Fixes jquerygh-3256
@mgol mgol force-pushed the event-object-prototype-collision branch from 06eb190 to 5145f8e Compare March 2, 2020 21:53
@mgol mgol merged commit 9d76c0b into jquery:master Mar 2, 2020
@mgol mgol deleted the event-object-prototype-collision branch March 2, 2020 22:02
mgol added a commit that referenced this pull request Mar 2, 2020
Make sure events & data keys matching Object.prototype properties work.
A separate fix for such events on cloned elements was added as well.

Fixes gh-3256
Closes gh-4603

(cherry picked from commit 9d76c0b)
mgol added a commit to mgol/jquery that referenced this pull request Apr 13, 2020
The change in jquerygh-4603 made the object returned by `elem.data()` a prototype-less
object. That's a desired change to support keys colliding with Object.prototype
properties but it's also a breaking change so it has to wait for jQuery 4.0.0.

A 3.x-only test was added to avoid breaking it in the future on this branch.

Fixes jquerygh-4665
Ref jquerygh-4603
mgol added a commit that referenced this pull request Apr 20, 2020
The change in gh-4603 made the object returned by `elem.data()`
a prototype-less object. That's a desired change to support keys
colliding with `Object.prototype` properties but it's also a breaking
change so it has to wait for jQuery 4.0.0.

A 3.x-only test was added to avoid breaking it in the future on this
branch.

Fixes gh-4665
Ref gh-4603
Closes gh-4666
mgol added a commit to mgol/jquery that referenced this pull request Mar 30, 2023
This is a follow-up to similar changes to data & event storages from
jquerygh-4603.

Ref jquerygh-4603
mgol added a commit that referenced this pull request Apr 3, 2023
This is a follow-up to similar changes to data & event storages from
gh-4603.

Closes gh-5235
Ref gh-4603
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

Event types colliding with Object prototype properties don't work
4 participants