_toSource.js 556 B

123456789101112131415161718192021222324252627
  1. /** Used for built-in method references. */
  2. var funcProto = Function.prototype;
  3. /** Used to resolve the decompiled source of functions. */
  4. var funcToString = funcProto.toString;
  5. /**
  6. * Converts `func` to its source code.
  7. *
  8. * @private
  9. * @param {Function} func The function to convert.
  10. * @returns {string} Returns the source code.
  11. */
  12. function toSource(func) {
  13. if (func != null) {
  14. try {
  15. return funcToString.call(func);
  16. } catch (e) {}
  17. try {
  18. return (func + '');
  19. } catch (e) {}
  20. }
  21. return '';
  22. }
  23. module.exports = toSource;