Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix(ngClass): add/remove classes which are properties of Object.prototype #11814

Closed
wants to merge 1 commit into from

Conversation

caitp
Copy link
Contributor

@caitp caitp commented May 5, 2015

  • fast paths for various internal functions when createMap() is used
  • Make createMap() safe for internal functions like copy/equals/forEach
  • Use createMap() in more places to avoid needing hasOwnProperty()

Closes #11813

@caitp caitp added this to the 1.4.x - jaracimrman-existence milestone May 5, 2015
@matsko
Copy link
Contributor

matsko commented May 5, 2015

Mind rewriting the commit message to clearly explain what the problem is/was and what the patch is fixing? There's a lot of domain-specific stuff in here that is hard to understand.

@caitp
Copy link
Contributor Author

caitp commented May 6, 2015

@matsko PTAL, I've made the commit message more thorough and refactored it a bit.

for (key in obj) {
iterator.call(context, obj[key], key, obj);
}
} else if (typeof obj.hasOwnProperty === 'function') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably don't care, but shadowing hasOwnProperty with a function will not be handled correctly.
Just saying...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depends on how it's shadowed --- I don't think we care, common case is a custom hasOwnProperty method won't be used

@caitp
Copy link
Contributor Author

caitp commented May 6, 2015

huh --- I guess this patch discovered a new IE quirk :< (this is set wrong by Function.prototype.call() when thisArg is undefined and function is strict)

@caitp caitp force-pushed the issue-11813 branch 3 times, most recently from 70da3aa to 40356e7 Compare May 6, 2015 17:00
…type

Previously, ngClass and ngAnimate would track the status of classes using an ordinary object.
This causes problems when class names match names of properties in Object.prototype, including
non-standard Object.prototype properties such as 'watch' and 'unwatch' in Firefox. Because of
this shadowing, ngClass and ngAnimate were unable to correctly determine the changed status
of these classes.

In orderto accomodate this patch, some changes have been necessary elsewhere in the codebase,
in order to facilitate iterating, comparingand copying objects with a null prototype, or which
shadow the `hasOwnProperty` method

Summary:

- fast paths for various internal functions when createMap() is used
- Make createMap() safe for internal functions like copy/equals/forEach
- Use createMap() in more places to avoid needing hasOwnProperty()

Closes angular#11813
@caitp
Copy link
Contributor Author

caitp commented May 6, 2015

ping

@caitp
Copy link
Contributor Author

caitp commented May 6, 2015

pong

@matsko
Copy link
Contributor

matsko commented May 6, 2015

LGTM. Excellent work.

@caitp
Copy link
Contributor Author

caitp commented May 6, 2015

thanks

@caitp caitp closed this in f7b9997 May 6, 2015
netman92 pushed a commit to netman92/angular.js that referenced this pull request Aug 8, 2015
…type

Previously, ngClass and ngAnimate would track the status of classes using an ordinary object.
This causes problems when class names match names of properties in Object.prototype, including
non-standard Object.prototype properties such as 'watch' and 'unwatch' in Firefox. Because of
this shadowing, ngClass and ngAnimate were unable to correctly determine the changed status
of these classes.

In orderto accomodate this patch, some changes have been necessary elsewhere in the codebase,
in order to facilitate iterating, comparingand copying objects with a null prototype, or which
shadow the `hasOwnProperty` method

Summary:

- fast paths for various internal functions when createMap() is used
- Make createMap() safe for internal functions like copy/equals/forEach
- Use createMap() in more places to avoid needing hasOwnProperty()

R=@matsko

Closes angular#11813
Closes angular#11814
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Firefox ignores 'watch' class name in ng-class directive.
4 participants