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

Commit a0fd098

Browse files
committed
updated to use own valueOf when available
1 parent 9123536 commit a0fd098

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/Angular.js

-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ var VALIDITY_STATE_PROPERTY = 'validity';
126126
*/
127127
var lowercase = function(string){return isString(string) ? string.toLowerCase() : string;};
128128
var hasOwnProperty = Object.prototype.hasOwnProperty;
129-
var valueOfObject = Object.prototype.valueOf;
130129

131130
/**
132131
* @ngdoc function

src/ng/parse.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,13 @@ function getterFn(path, options, fullExp) {
946946
return fn;
947947
}
948948

949+
function valueOfAgnostic(value){
950+
if(typeof value.valueOf !== 'function'){
951+
return Object.prototype.valueOf.call(value);
952+
}
953+
return value.valueOf();
954+
}
955+
949956
///////////////////////////////////
950957

951958
/**
@@ -1092,7 +1099,7 @@ function $ParseProvider() {
10921099
// attempt to convert the value to a primitive type
10931100
// TODO(docs): add a note to docs that by implementing valueOf even objects and arrays can
10941101
// be cheaply dirty-checked
1095-
newValue = valueOfObject.call(newValue);
1102+
newValue = valueOfAgnostic(newValue);
10961103

10971104
if (typeof newValue === 'object') {
10981105
// objects/arrays are not supported - deep-watching them would be too expensive
@@ -1119,7 +1126,7 @@ function $ParseProvider() {
11191126
var newInputValue = inputExpressions(scope);
11201127
if (!expressionInputDirtyCheck(newInputValue, oldInputValue)) {
11211128
lastResult = parsedExpression(scope);
1122-
oldInputValue = newInputValue && valueOfObject.call(newInputValue);
1129+
oldInputValue = newInputValue && valueOfAgnostic(newInputValue);
11231130
}
11241131
return lastResult;
11251132
}, listener, objectEquality);
@@ -1136,7 +1143,7 @@ function $ParseProvider() {
11361143
for (var i = 0, ii = inputExpressions.length; i < ii; i++) {
11371144
var newInputValue = inputExpressions[i](scope);
11381145
if (changed || (changed = !expressionInputDirtyCheck(newInputValue, oldInputValueOfValues[i]))) {
1139-
oldInputValueOfValues[i] = newInputValue && valueOfObject.call(newInputValue);
1146+
oldInputValueOfValues[i] = newInputValue && valueOfAgnostic(newInputValue);
11401147
}
11411148
}
11421149

0 commit comments

Comments
 (0)