/* eslint-disable no-proto -- safe */
|
var uncurryThis = require('../internals/function-uncurry-this');
|
var anObject = require('../internals/an-object');
|
var aPossiblePrototype = require('../internals/a-possible-prototype');
|
|
// `Object.setPrototypeOf` method
|
// https://tc39.es/ecma262/#sec-object.setprototypeof
|
// Works with __proto__ only. Old v8 can't work with null proto objects.
|
// eslint-disable-next-line es-x/no-object-setprototypeof -- safe
|
module.exports = Object.setPrototypeOf || ('__proto__' in {} ? function () {
|
var CORRECT_SETTER = false;
|
var test = {};
|
var setter;
|
try {
|
// eslint-disable-next-line es-x/no-object-getownpropertydescriptor -- safe
|
setter = uncurryThis(Object.getOwnPropertyDescriptor(Object.prototype, '__proto__').set);
|
setter(test, []);
|
CORRECT_SETTER = test instanceof Array;
|
} catch (error) { /* empty */ }
|
return function setPrototypeOf(O, proto) {
|
anObject(O);
|
aPossiblePrototype(proto);
|
if (CORRECT_SETTER) setter(O, proto);
|
else O.__proto__ = proto;
|
return O;
|
};
|
}() : undefined);
|