From e2c703a96f70e6cc99b6e7585c734b47aa7ec595 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Wed, 21 Dec 2016 15:21:21 -0600 Subject: [PATCH] Avoid more coercion. --- lodash.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lodash.js b/lodash.js index 97808d92c..c1227b234 100644 --- a/lodash.js +++ b/lodash.js @@ -5454,7 +5454,7 @@ var func = Math[methodName]; return function(number, precision) { number = toNumber(number); - precision = nativeMin(toInteger(precision), 292); + precision = precision == null ? 0 : nativeMin(toInteger(precision), 292); if (precision) { // Shift with exponential notation to avoid floating-point issues. // See [MDN](https://mdn.io/round#Examples) for more details. @@ -10852,7 +10852,7 @@ if (typeof func != 'function') { throw new TypeError(FUNC_ERROR_TEXT); } - start = start === undefined ? 0 : nativeMax(toInteger(start), 0); + start = start == null ? 0 : nativeMax(toInteger(start), 0); return baseRest(function(args) { var array = args[start], otherArgs = castSlice(args, 0, start); @@ -12542,7 +12542,9 @@ * // => 3 */ function toSafeInteger(value) { - return baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER); + return value + ? baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER) + : (value === 0 ? value : 0); } /** @@ -14631,7 +14633,7 @@ */ function startsWith(string, target, position) { string = toString(string); - position = position === undefined + position = position == null ? 0 : baseClamp(toInteger(position), 0, string.length);