Skip to content

Commit ef9153f

Browse files
substackljharb
substack
authored andcommittedMar 22, 2022
isConstructorOrProto adapted from PR
1 parent 36ac5d0 commit ef9153f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed
 

‎index.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ function isNumber(x) {
66
return (/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/).test(x);
77
}
88

9+
function isConstructorOrProto(obj, key) {
10+
return key === 'constructor' && (typeof obj[key] === 'function' || key === '__proto__');
11+
}
12+
913
function hasKey(obj, keys) {
1014
var o = obj;
1115
keys.slice(0, -1).forEach(function (key) {
@@ -21,7 +25,9 @@ function setKey(obj, keys, value) {
2125
var key;
2226
for (var i = 0; i < keys.length - 1; i++) {
2327
key = keys[i];
24-
if (key === '__proto__') { return; }
28+
if (key === '__proto__' || isConstructorOrProto(o, key)) {
29+
return;
30+
}
2531
if (o[key] === undefined) { o[key] = {}; }
2632
if (
2733
o[key] === Object.prototype

0 commit comments

Comments
 (0)
Please sign in to comment.