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

fix(parse): dirty checking support for objects with null prototype #9568

Closed
wants to merge 8 commits into from
Closed

fix(parse): dirty checking support for objects with null prototype #9568

wants to merge 8 commits into from

Conversation

HeberLZ
Copy link
Contributor

@HeberLZ HeberLZ commented Oct 10, 2014

With this changes, objects initially created with Object.create(null) can be bind to the view. This is because if the valueOf function is not available, it will use Object.valueOf.apply instead

@@ -1092,7 +1092,8 @@ function $ParseProvider() {
// attempt to convert the value to a primitive type
// TODO(docs): add a note to docs that by implementing valueOf even objects and arrays can
// be cheaply dirty-checked
newValue = newValue.valueOf();
typeof newValue.valueOf !== 'function' && (newValue = Object.valueOf.apply(newValue)) ||
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you cache Object.prototype.valueOf as valueOfObject in src/Angular.js instead, and just always use newValue = valueOfObject.call(newValue); ? thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was not sure to do that in case valueOf may have been overriden, i'll update it right away!

@caitp
Copy link
Contributor

caitp commented Oct 10, 2014

need a test for this change which fails without it

@HeberLZ
Copy link
Contributor Author

HeberLZ commented Oct 10, 2014

Working on the test

@mary-poppins
Copy link

I'm sorry, but I wasn't able to verify your Contributor License Agreement (CLA) signature. CLA signature is required for any code contributions to AngularJS.

Please sign our CLA and ensure that the CLA signature email address and the email address in this PR's commits match.

If you signed the CLA as a corporation, please let us know the company's name.

Thanks a bunch!

PS: If you signed the CLA in the past then most likely the email addresses don't match. Please sign the CLA again or update the email address in the commit of this PR.
PS2: If you are a Googler, please sign the CLA as well to simplify the CLA verification process.

@@ -1092,7 +1092,7 @@ function $ParseProvider() {
// attempt to convert the value to a primitive type
// TODO(docs): add a note to docs that by implementing valueOf even objects and arrays can
// be cheaply dirty-checked
newValue = newValue.valueOf();
newValue = valueOfObject.call(newValue);
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is right. Won't this always use Object.prototype's method ?
The point is to only use it when there is no newValue.valueOf() method.
(The same goes for the other changes below.)

@HeberLZ
Copy link
Contributor Author

HeberLZ commented Oct 12, 2014

Pull request updated with test case and CLA signed. Special thanks to Julian Mayorga who provided the test case!

@mary-poppins
Copy link

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).

@HeberLZ HeberLZ changed the title Dirty checking support for Object.create(null) bindings fix(parse): dirty checking support for Object.create(null) bindings Oct 13, 2014
if(typeof value.valueOf !== 'function'){
return Object.prototype.valueOf.call(value);
}
return value.valueOf();
Copy link
Contributor

Choose a reason for hiding this comment

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

how about:

var objectValueOf = Object.prototype.valueOf;

function getValueOf(value) {
  return isFunction(value.valueOf) ? value.valueOf() : objectValueOf(value);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll update it right away!

@IgorMinar
Copy link
Contributor

@caitp can you get this in please?

@HeberLZ
Copy link
Contributor Author

HeberLZ commented Oct 13, 2014

PR updated with the recommendations from @IgorMinar

@caitp
Copy link
Contributor

caitp commented Oct 14, 2014

I'll get it in

var objectValueOf = Object.prototype.valueOf.call;

function getValueOf(value) {
return isFunction(value.valueOf) ? value.valueOf() : objectValueOf(value);
Copy link
Contributor

Choose a reason for hiding this comment

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

You can't do this this way, it needs to be

var objectValueOf = Object.prototype.valueOf;

// ...
objectValueOf.call(value);
// ...

@caitp
Copy link
Contributor

caitp commented Oct 14, 2014

If you fix those up, the tests should be green and I'll land it for you =)

@HeberLZ
Copy link
Contributor Author

HeberLZ commented Oct 14, 2014

I'll update it right away!

On Mon, Oct 13, 2014 at 10:42 PM, Caitlin Potter notifications@github.com
wrote:

If you fix those up, the tests should be green and I'll land it for you =)


Reply to this email directly or view it on GitHub
#9568 (comment).

Heber López | Google Developers Group Lead Organizer, Mendoza | +HeberLZ
https://plus.google.com/+HeberLopez | +54 261 5342773 |

@HeberLZ HeberLZ changed the title fix(parse): dirty checking support for Object.create(null) bindings fix(parse): dirty checking support for objects with null prototype Oct 14, 2014
@caitp
Copy link
Contributor

caitp commented Oct 14, 2014

lgtm, will land when travis finishes (it looks like it will be green already)

@HeberLZ
Copy link
Contributor Author

HeberLZ commented Oct 14, 2014

PR updated with the comments! Thanks @gkalpak @caitp @IgorMinar and @JulianMayorga for the help on my first contribution to AngularJS!!

@caitp
Copy link
Contributor

caitp commented Oct 14, 2014

Merged in 28661d1, thanks!

@caitp caitp closed this in 28661d1 Oct 14, 2014
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.

None yet

5 participants