UNPKG

859 BJavaScriptView Raw
1var anObject = require('../internals/an-object');
2var aPossiblePrototype = require('../internals/a-possible-prototype');
3
4// `Object.setPrototypeOf` method
5// https://tc39.github.io/ecma262/#sec-object.setprototypeof
6// Works with __proto__ only. Old v8 can't work with null proto objects.
7/* eslint-disable no-proto */
8module.exports = Object.setPrototypeOf || ('__proto__' in {} ? function () {
9 var CORRECT_SETTER = false;
10 var test = {};
11 var setter;
12 try {
13 setter = Object.getOwnPropertyDescriptor(Object.prototype, '__proto__').set;
14 setter.call(test, []);
15 CORRECT_SETTER = test instanceof Array;
16 } catch (error) { /* empty */ }
17 return function setPrototypeOf(O, proto) {
18 anObject(O);
19 aPossiblePrototype(proto);
20 if (CORRECT_SETTER) setter.call(O, proto);
21 else O.__proto__ = proto;
22 return O;
23 };
24}() : undefined);