Skip to content

Commit ef9153f

Browse files
substackljharb
authored andcommitted
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

Lines changed: 7 additions & 1 deletion
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy