Skip to content

Commit b5f9744

Browse files
committed
libdot: prefs: fix handling of null defaults
In JS, null is an object, so the "not simple primitive type" test ends up considering all null settings as "not the default". Add an explicit test for the null object to catch that. Change-Id: Ia9a011d1eb1e741cec584f023b2e75d20ba019bf Reviewed-on: https://chromium-review.googlesource.com/c/1352191 Tested-by: Mike Frysinger <[email protected]> Reviewed-by: Vitaliy Shipitsyn <[email protected]>
1 parent 5f342e8 commit b5f9744

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

libdot/js/lib_preference_manager.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -604,12 +604,22 @@ lib.PreferenceManager.prototype.resetAll = function() {
604604
* @param {*} b A value to compare.
605605
*/
606606
lib.PreferenceManager.prototype.diff = function(a, b) {
607-
// If the types are different, or the type is not a simple primitive one.
608-
if ((typeof a) !== (typeof b) ||
609-
!(/^(undefined|boolean|number|string)$/.test(typeof a))) {
607+
// If the types are different.
608+
if ((typeof a) !== (typeof b)) {
610609
return true;
611610
}
612611

612+
// Or if the type is not a simple primitive one.
613+
if (!(/^(undefined|boolean|number|string)$/.test(typeof a))) {
614+
// Special case the null object.
615+
if (a === null && b === null) {
616+
return false;
617+
} else {
618+
return true;
619+
}
620+
}
621+
622+
// Do a normal compare for primitive types.
613623
return a !== b;
614624
};
615625

0 commit comments

Comments
 (0)