source: imaps-frontend/node_modules/function.prototype.name/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: 2.1 KB
Line 
1'use strict';
2
3var IsCallable = require('es-abstract/2023/IsCallable');
4var HasOwnProperty = require('es-abstract/2023/HasOwnProperty');
5var functionsHaveNames = require('functions-have-names')();
6var callBound = require('call-bind/callBound');
7var $functionToString = callBound('Function.prototype.toString');
8var $stringMatch = callBound('String.prototype.match');
9var toStr = callBound('Object.prototype.toString');
10
11var classRegex = /^class /;
12
13var isClass = function isClassConstructor(fn) {
14 if (IsCallable(fn)) {
15 return false;
16 }
17 if (typeof fn !== 'function') {
18 return false;
19 }
20 try {
21 var match = $stringMatch($functionToString(fn), classRegex);
22 return !!match;
23 } catch (e) {}
24 return false;
25};
26
27var regex = /\s*function\s+([^(\s]*)\s*/;
28
29var isIE68 = !(0 in [,]); // eslint-disable-line no-sparse-arrays, comma-spacing
30
31var objectClass = '[object Object]';
32var ddaClass = '[object HTMLAllCollection]';
33
34var functionProto = Function.prototype;
35
36var isDDA = function isDocumentDotAll() {
37 return false;
38};
39if (typeof document === 'object') {
40 // Firefox 3 canonicalizes DDA to undefined when it's not accessed directly
41 var all = document.all;
42 if (toStr(all) === toStr(document.all)) {
43 isDDA = function isDocumentDotAll(value) {
44 /* globals document: false */
45 // in IE 6-8, typeof document.all is "object" and it's truthy
46 if ((isIE68 || !value) && (typeof value === 'undefined' || typeof value === 'object')) {
47 try {
48 var str = toStr(value);
49 // IE 6-8 uses `objectClass`
50 return (str === ddaClass || str === objectClass) && value('') == null; // eslint-disable-line eqeqeq
51 } catch (e) { /**/ }
52 }
53 return false;
54 };
55 }
56}
57
58module.exports = function getName() {
59 if (isDDA(this) || (!isClass(this) && !IsCallable(this))) {
60 throw new TypeError('Function.prototype.name sham getter called on non-function');
61 }
62 if (functionsHaveNames && HasOwnProperty(this, 'name')) {
63 return this.name;
64 }
65 if (this === functionProto) {
66 return '';
67 }
68 var str = $functionToString(this);
69 var match = $stringMatch(str, regex);
70 var name = match && match[1];
71 return name;
72};
Note: See TracBrowser for help on using the repository browser.