-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix(ng): in angular.copy do not call hasOwnProperty on objects with not ... #10116
Conversation
… prototype angular.copy can be called with an object that has no prototype. Call Object.prototype.hasOwnProperty instead of object.hasOwnProperty to safely check if object has a property
Would it be possible to get some numbers to know if this will have some |
@IgorMinar see this JSPerf http://jsperf.com/hasownproperty-context |
Calling it on the same item might allow browser optimizations that hide the actual performance. In practice, it will be called on many different objects (and will correspond to a small percentage of the overall processing time, so I don't expect it to have any significant impact. Tried with 1,000,000 different objects and the results are equal: http://jsperf.com/instance-vs-prototype-hasownproperty |
Here is another jsperf featuring 2 alternative versions of
|
I would not be happy to have a 10% performance hit... @petebacondarwin @caitp WDYT? |
There isn't a performance difference really. @gkalpak tests are not using JSPerf right. JSPerf does iterations itself. If you put a huge loop in your snippet the result might become less accurate. I've added |
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project, in which case you'll need to sign a Contributor License Agreement (CLA) at https://cla.developers.google.com/. If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check the information on your CLA or see this help article on setting the email on your git commits. Once you've done that, please reply here to let us know. If you signed the CLA as a corporation, please let us know the company's name. |
I don't have a loop in my last jsperf: http://jsperf.com/angularjs-copy-with-hasownproperty-call I implemented the whole |
CLA signature verified! Thank you! Someone from the team will now triage your PR and it will be processed based on the determined priority (doc updates and fixes with tests are prioritized over other changes). |
3 similar comments
CLA signature verified! Thank you! Someone from the team will now triage your PR and it will be processed based on the determined priority (doc updates and fixes with tests are prioritized over other changes). |
CLA signature verified! Thank you! Someone from the team will now triage your PR and it will be processed based on the determined priority (doc updates and fixes with tests are prioritized over other changes). |
CLA signature verified! Thank you! Someone from the team will now triage your PR and it will be processed based on the determined priority (doc updates and fixes with tests are prioritized over other changes). |
CLA signature verified! Thank you! Someone from the team will now triage your PR and it will be processed based on the determined priority (doc updates and fixes with tests are prioritized over other changes). |
This PR is no longer valid, this is already fixed at master |
...prototype
angular.copy can be called with an object that has no prototype. Call
Object.prototype.hasOwnProperty instead of object.hasOwnProperty to
safely check if object has a property