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
1 change: 1 addition & 0 deletions src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ var VALIDITY_STATE_PROPERTY = 'validity';
*/
var lowercase = function(string){return isString(string) ? string.toLowerCase() : string;};
var hasOwnProperty = Object.prototype.hasOwnProperty;
var valueOfObject = Object.prototype.valueOf;

/**
* @ngdoc function
Expand Down
6 changes: 3 additions & 3 deletions src/ng/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.)


if (typeof newValue === 'object') {
// objects/arrays are not supported - deep-watching them would be too expensive
Expand All @@ -1119,7 +1119,7 @@ function $ParseProvider() {
var newInputValue = inputExpressions(scope);
if (!expressionInputDirtyCheck(newInputValue, oldInputValue)) {
lastResult = parsedExpression(scope);
oldInputValue = newInputValue && newInputValue.valueOf();
oldInputValue = newInputValue && valueOfObject.call(newInputValue);
}
return lastResult;
}, listener, objectEquality);
Expand All @@ -1136,7 +1136,7 @@ function $ParseProvider() {
for (var i = 0, ii = inputExpressions.length; i < ii; i++) {
var newInputValue = inputExpressions[i](scope);
if (changed || (changed = !expressionInputDirtyCheck(newInputValue, oldInputValueOfValues[i]))) {
oldInputValueOfValues[i] = newInputValue && newInputValue.valueOf();
oldInputValueOfValues[i] = newInputValue && valueOfObject.call(newInputValue);
}
}

Expand Down