From 9110fac9a28d18981e2297f4c84f4c18037ba88e Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Fri, 17 Apr 2020 08:13:49 +0100 Subject: suppress mutation of input `options` (#3785) --- lib/utils.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/utils.js b/lib/utils.js index 508aba9c..7932e05f 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -87,15 +87,11 @@ DefaultsError.prototype.name = "DefaultsError"; configure_error_stack(DefaultsError); function defaults(args, defs, croak) { - if (args === true) args = {}; - var ret = args || {}; - if (croak) for (var i in ret) if (HOP(ret, i) && !HOP(defs, i)) { - throw new DefaultsError("`" + i + "` is not a supported option", defs); + for (var i in args) if (HOP(args, i)) { + if (croak && !HOP(defs, i)) throw new DefaultsError("`" + i + "` is not a supported option", defs); + defs[i] = args[i]; } - for (var i in defs) if (HOP(defs, i)) { - ret[i] = (args && HOP(args, i)) ? args[i] : defs[i]; - } - return ret; + return defs; } function merge(obj, ext) { -- cgit v1.2.3