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

(newValue = newValue.valueOf());

if (typeof newValue === 'object') {
// objects/arrays are not supported - deep-watching them would be too expensive
Expand All @@ -1119,7 +1120,8 @@ function $ParseProvider() {
var newInputValue = inputExpressions(scope);
if (!expressionInputDirtyCheck(newInputValue, oldInputValue)) {
lastResult = parsedExpression(scope);
oldInputValue = newInputValue && newInputValue.valueOf();
oldInputValue = newInputValue && typeof newInputValue.valueOf !== 'function' &&
Object.valueOf.apply(newInputValue) || newInputValue.valueOf();
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

}
return lastResult;
}, listener, objectEquality);
Expand All @@ -1136,7 +1138,8 @@ 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 && typeof newInputValue.valueOf !== 'function' &&
Object.valueOf.apply(newInputValue) || newInputValue.valueOf();
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

}
}

Expand Down