You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.2 KiB

7 years ago
  1. /*!
  2. * depd
  3. * Copyright(c) 2014 Douglas Christopher Wilson
  4. * MIT Licensed
  5. */
  6. /**
  7. * Module exports.
  8. */
  9. lazyProperty(module.exports, 'bufferConcat', function bufferConcat() {
  10. return Buffer.concat || require('./buffer-concat')
  11. })
  12. lazyProperty(module.exports, 'callSiteToString', function callSiteToString() {
  13. var limit = Error.stackTraceLimit
  14. var obj = {}
  15. var prep = Error.prepareStackTrace
  16. function prepareObjectStackTrace(obj, stack) {
  17. return stack
  18. }
  19. Error.prepareStackTrace = prepareObjectStackTrace
  20. Error.stackTraceLimit = 2
  21. // capture the stack
  22. Error.captureStackTrace(obj)
  23. // slice the stack
  24. var stack = obj.stack.slice()
  25. Error.prepareStackTrace = prep
  26. Error.stackTraceLimit = limit
  27. return stack[0].toString ? toString : require('./callsite-tostring')
  28. })
  29. /**
  30. * Define a lazy property.
  31. */
  32. function lazyProperty(obj, prop, getter) {
  33. function get() {
  34. var val = getter()
  35. Object.defineProperty(obj, prop, {
  36. configurable: true,
  37. enumerable: true,
  38. value: val
  39. })
  40. return val
  41. }
  42. Object.defineProperty(obj, prop, {
  43. configurable: true,
  44. enumerable: true,
  45. get: get
  46. })
  47. }
  48. /**
  49. * Call toString() on the obj
  50. */
  51. function toString(obj) {
  52. return obj.toString()
  53. }