implementation.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. 'use strict';
  2. var GetIntrinsic = require('get-intrinsic');
  3. var IsCallable = require('es-abstract/2024/IsCallable');
  4. var isObject = require('es-abstract/helpers/isObject');
  5. var whichBuiltinType = require('which-builtin-type');
  6. var $TypeError = require('es-errors/type');
  7. var gPO = require('get-proto');
  8. var $Object = require('es-object-atoms');
  9. module.exports = function getPrototypeOf(O) {
  10. if (!isObject(O)) {
  11. throw new $TypeError('Reflect.getPrototypeOf called on non-object');
  12. }
  13. if (gPO) {
  14. return gPO(O);
  15. }
  16. var type = whichBuiltinType(O);
  17. if (type) {
  18. var intrinsic = GetIntrinsic('%' + type + '.prototype%', true);
  19. if (intrinsic) {
  20. return intrinsic;
  21. }
  22. }
  23. if (IsCallable(O.constructor)) {
  24. return O.constructor.prototype;
  25. }
  26. if (O instanceof Object) {
  27. return $Object.prototype;
  28. }
  29. /*
  30. * Correctly return null for Objects created with `Object.create(null)` (shammed or native) or `{ __proto__: null}`. Also returns null for
  31. * cross-realm objects on browsers that lack `__proto__` support (like IE <11), but that's the best we can do.
  32. */
  33. return null;
  34. };