From c55c1b8cb32510f92bd33d7c833364ecd3964dea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=BA=D0=BE=D0=B2=D0=BE=D1=80=D0=BE=D0=B4=D0=B0=20?= =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=90=D0=BD=D0=B4=D1=80?= =?UTF-8?q?=D0=B5=D0=B5=D0=B2=D0=B8=D1=87?= Date: Sat, 23 Jan 2021 00:28:40 +0300 Subject: [PATCH] Avoid hitting __proto__ PR-URL: https://github.com/isaacs/node-graceful-fs/pull/201 Credit: @ChALkeR Close: #201 Reviewed-by: @ljharb, @coreyfarrell --- clone.js | 6 +++++- polyfills.js | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/clone.js b/clone.js index 028356c..dff3cc8 100644 --- a/clone.js +++ b/clone.js @@ -2,12 +2,16 @@ module.exports = clone +var getPrototypeOf = Object.getPrototypeOf || function (obj) { + return obj.__proto__ +} + function clone (obj) { if (obj === null || typeof obj !== 'object') return obj if (obj instanceof Object) - var copy = { __proto__: obj.__proto__ } + var copy = { __proto__: getPrototypeOf(obj) } else var copy = Object.create(null) diff --git a/polyfills.js b/polyfills.js index 3dd7074..56d08d1 100644 --- a/polyfills.js +++ b/polyfills.js @@ -133,7 +133,7 @@ function patch (fs) { } // This ensures `util.promisify` works as it does for native `fs.read`. - read.__proto__ = fs$read + if (Object.setPrototypeOf) Object.setPrototypeOf(read, fs$read) return read })(fs.read)