Skip to content

Commit

Permalink
[Refactor] minimize dynamic lookups of __proto__
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Mar 23, 2023
1 parent 99be112 commit abcecb9
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions es6-shim.js
Expand Up @@ -1535,7 +1535,7 @@
var ES5ObjectShims = {
// 19.1.3.9
// shim from https://gist.github.com/WebReflection/5593554
setPrototypeOf: (function (Object, magic) {
setPrototypeOf: (function (Object) {
var set;

var checkArgs = function (O, proto) {
Expand All @@ -1555,16 +1555,16 @@

try {
// this works already in Firefox and Safari
set = Object.getOwnPropertyDescriptor(Object.prototype, magic).set;
set = Object.getOwnPropertyDescriptor(Object.prototype, '__proto__').set;
_call(set, {}, null);
} catch (e) {
if (Object.prototype !== {}[magic]) {
if (Object.prototype !== ({}).__proto__) { // eslint-disable-line no-proto
// IE < 11 cannot be shimmed
return;
}
// probably Chrome or some old Mobile stock browser
set = function (proto) {
this[magic] = proto;
this.__proto__ = proto; // eslint-disable-line no-proto
};
// please note that this will **not** work
// in those browsers that do not inherit
Expand All @@ -1584,7 +1584,7 @@
// we can even delete Object.prototype.__proto__;
}
return setPrototypeOf;
}(Object, '__proto__'))
}(Object))
};

defineProperties(Object, ES5ObjectShims);
Expand Down

0 comments on commit abcecb9

Please sign in to comment.