Skip to content

Commit c55c1b8

Browse files
ChALkeRisaacs
authored andcommitted
Avoid hitting __proto__
PR-URL: #201 Credit: @ChALkeR Close: #201 Reviewed-by: @ljharb, @coreyfarrell
1 parent 7b85570 commit c55c1b8

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

clone.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22

33
module.exports = clone
44

5+
var getPrototypeOf = Object.getPrototypeOf || function (obj) {
6+
return obj.__proto__
7+
}
8+
59
function clone (obj) {
610
if (obj === null || typeof obj !== 'object')
711
return obj
812

913
if (obj instanceof Object)
10-
var copy = { __proto__: obj.__proto__ }
14+
var copy = { __proto__: getPrototypeOf(obj) }
1115
else
1216
var copy = Object.create(null)
1317

polyfills.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ function patch (fs) {
133133
}
134134

135135
// This ensures `util.promisify` works as it does for native `fs.read`.
136-
read.__proto__ = fs$read
136+
if (Object.setPrototypeOf) Object.setPrototypeOf(read, fs$read)
137137
return read
138138
})(fs.read)
139139

0 commit comments

Comments
 (0)