Skip to content

Commit

Permalink
[Robustness] rework isConstructorOrProto
Browse files Browse the repository at this point in the history
- modify implementation of isConstructorOrProto to match main branch
- call isConstructorOrProto on last key too
  • Loading branch information
shadowspawn authored and ljharb committed Feb 17, 2023
1 parent c0b2661 commit 34e20b8
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function isNumber(x) {
}

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

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

key = keys[keys.length - 1];
if (key === '__proto__') { return; }
if (isConstructorOrProto(o, key)) { return; }
if (
o === Object.prototype
|| o === Number.prototype
Expand Down

0 comments on commit 34e20b8

Please sign in to comment.