diff options
author | Florian Dold <florian.dold@gmail.com> | 2018-09-20 02:56:13 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2018-09-20 02:56:13 +0200 |
commit | bbff7403fbf46f9ad92240ac213df8d30ef31b64 (patch) | |
tree | c58400ec5124da1c7d56b01aea83309f80a56c3b /node_modules/extend/index.js | |
parent | 003fb34971cf63466184351b4db5f7c67df4f444 (diff) | |
download | wallet-core-bbff7403fbf46f9ad92240ac213df8d30ef31b64.tar.xz |
update packages
Diffstat (limited to 'node_modules/extend/index.js')
-rw-r--r-- | node_modules/extend/index.js | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/node_modules/extend/index.js b/node_modules/extend/index.js index bbe53f660..2aa3faae6 100644 --- a/node_modules/extend/index.js +++ b/node_modules/extend/index.js @@ -2,6 +2,8 @@ var hasOwn = Object.prototype.hasOwnProperty; var toStr = Object.prototype.toString; +var defineProperty = Object.defineProperty; +var gOPD = Object.getOwnPropertyDescriptor; var isArray = function isArray(arr) { if (typeof Array.isArray === 'function') { @@ -31,6 +33,35 @@ var isPlainObject = function isPlainObject(obj) { return typeof key === 'undefined' || hasOwn.call(obj, key); }; +// If name is '__proto__', and Object.defineProperty is available, define __proto__ as an own property on target +var setProperty = function setProperty(target, options) { + if (defineProperty && options.name === '__proto__') { + defineProperty(target, options.name, { + enumerable: true, + configurable: true, + value: options.newValue, + writable: true + }); + } else { + target[options.name] = options.newValue; + } +}; + +// Return undefined instead of __proto__ if '__proto__' is not an own property +var getProperty = function getProperty(obj, name) { + if (name === '__proto__') { + if (!hasOwn.call(obj, name)) { + return void 0; + } else if (gOPD) { + // In early versions of node, obj['__proto__'] is buggy when obj has + // __proto__ as an own property. Object.getOwnPropertyDescriptor() works. + return gOPD(obj, name).value; + } + } + + return obj[name]; +}; + module.exports = function extend() { var options, name, src, copy, copyIsArray, clone; var target = arguments[0]; @@ -55,8 +86,8 @@ module.exports = function extend() { if (options != null) { // Extend the base object for (name in options) { - src = target[name]; - copy = options[name]; + src = getProperty(target, name); + copy = getProperty(options, name); // Prevent never-ending loop if (target !== copy) { @@ -70,11 +101,11 @@ module.exports = function extend() { } // Never move original objects, clone them - target[name] = extend(deep, clone, copy); + setProperty(target, { name: name, newValue: extend(deep, clone, copy) }); // Don't bring in undefined values } else if (typeof copy !== 'undefined') { - target[name] = copy; + setProperty(target, { name: name, newValue: copy }); } } } |