Skip to content

Commit

Permalink
Avoid hitting __proto__
Browse files Browse the repository at this point in the history
PR-URL: #201
Credit: @ChALkeR
Close: #201
Reviewed-by: @ljharb, @coreyfarrell
  • Loading branch information
ChALkeR authored and isaacs committed Feb 5, 2021
1 parent 7b85570 commit c55c1b8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion polyfills.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit c55c1b8

Please sign in to comment.