es.object.proto.js 1.2 KB

1234567891011121314151617181920212223242526272829
  1. 'use strict';
  2. var DESCRIPTORS = require('../internals/descriptors');
  3. var defineBuiltInAccessor = require('../internals/define-built-in-accessor');
  4. var isObject = require('../internals/is-object');
  5. var toObject = require('../internals/to-object');
  6. var requireObjectCoercible = require('../internals/require-object-coercible');
  7. // eslint-disable-next-line es/no-object-getprototypeof -- safe
  8. var getPrototypeOf = Object.getPrototypeOf;
  9. // eslint-disable-next-line es/no-object-setprototypeof -- safe
  10. var setPrototypeOf = Object.setPrototypeOf;
  11. var ObjectPrototype = Object.prototype;
  12. var PROTO = '__proto__';
  13. // `Object.prototype.__proto__` accessor
  14. // https://tc39.es/ecma262/#sec-object.prototype.__proto__
  15. if (DESCRIPTORS && getPrototypeOf && setPrototypeOf && !(PROTO in ObjectPrototype)) try {
  16. defineBuiltInAccessor(ObjectPrototype, PROTO, {
  17. configurable: true,
  18. get: function __proto__() {
  19. return getPrototypeOf(toObject(this));
  20. },
  21. set: function __proto__(proto) {
  22. var O = requireObjectCoercible(this);
  23. if (!isObject(proto) && proto !== null || !isObject(O)) return;
  24. setPrototypeOf(O, proto);
  25. }
  26. });
  27. } catch (error) { /* empty */ }