Skip to content

Commit

Permalink
isConstructorOrProto adapted from PR
Browse files Browse the repository at this point in the history
  • Loading branch information
substack authored and ljharb committed Mar 22, 2022
1 parent 36ac5d0 commit ef9153f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion index.js
Expand Up @@ -6,6 +6,10 @@ function isNumber(x) {
return (/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/).test(x);
}

function isConstructorOrProto(obj, key) {
return key === 'constructor' && (typeof obj[key] === 'function' || key === '__proto__');
}

function hasKey(obj, keys) {
var o = obj;
keys.slice(0, -1).forEach(function (key) {
Expand All @@ -21,7 +25,9 @@ function setKey(obj, keys, value) {
var key;
for (var i = 0; i < keys.length - 1; i++) {
key = keys[i];
if (key === '__proto__') { return; }
if (key === '__proto__' || isConstructorOrProto(o, key)) {
return;
}
if (o[key] === undefined) { o[key] = {}; }
if (
o[key] === Object.prototype
Expand Down

0 comments on commit ef9153f

Please sign in to comment.