source: imaps-frontend/node_modules/reflect.getprototypeof/implementation.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.3 KB
Line 
1'use strict';
2
3var GetIntrinsic = require('get-intrinsic');
4var IsCallable = require('es-abstract/2024/IsCallable');
5var Type = require('es-abstract/2024/Type');
6var whichBuiltinType = require('which-builtin-type');
7var $TypeError = require('es-errors/type');
8
9var $gPO = GetIntrinsic('%Object.getPrototypeOf%', true);
10var $ObjectPrototype = GetIntrinsic('%Object.prototype%');
11
12var hasProto = [].__proto__ === Array.prototype; // eslint-disable-line no-proto
13
14module.exports = function getPrototypeOf(O) {
15 if (Type(O) !== 'Object') {
16 throw new $TypeError('Reflect.getPrototypeOf called on non-object');
17 }
18
19 if ($gPO) {
20 return $gPO(O);
21 }
22
23 if (hasProto) {
24 // eslint-disable-next-line no-proto
25 var proto = O.__proto__;
26 if (proto || proto === null) {
27 return proto;
28 }
29 }
30 var type = whichBuiltinType(O);
31 if (type) {
32 var intrinsic = GetIntrinsic('%' + type + '.prototype%', true);
33 if (intrinsic) {
34 return intrinsic;
35 }
36 }
37 if (IsCallable(O.constructor)) {
38 return O.constructor.prototype;
39 }
40 if (O instanceof Object) {
41 return $ObjectPrototype;
42 }
43
44 /*
45 * Correctly return null for Objects created with `Object.create(null)` (shammed or native) or `{ __proto__: null}`. Also returns null for
46 * cross-realm objects on browsers that lack `__proto__` support (like IE <11), but that's the best we can do.
47 */
48 return null;
49};
Note: See TracBrowser for help on using the repository browser.