index.js 774 B

12345678910111213141516171819202122232425262728293031
  1. 'use strict';
  2. var functionsHaveNames = function functionsHaveNames() {
  3. return typeof function f() {}.name === 'string';
  4. };
  5. var gOPD = Object.getOwnPropertyDescriptor;
  6. if (gOPD) {
  7. try {
  8. gOPD([], 'length');
  9. } catch (e) {
  10. // IE 8 has a broken gOPD
  11. gOPD = null;
  12. }
  13. }
  14. functionsHaveNames.functionsHaveConfigurableNames = function functionsHaveConfigurableNames() {
  15. if (!functionsHaveNames() || !gOPD) {
  16. return false;
  17. }
  18. var desc = gOPD(function () {}, 'name');
  19. return !!desc && !!desc.configurable;
  20. };
  21. var $bind = Function.prototype.bind;
  22. functionsHaveNames.boundFunctionsHaveNames = function boundFunctionsHaveNames() {
  23. return functionsHaveNames() && typeof $bind === 'function' && function f() {}.bind().name !== '';
  24. };
  25. module.exports = functionsHaveNames;