arnaucube
arnaucube/socketioMEANseedPublic Self-hosted repository
socketioMEANseed/server/node_modules/depd/lib/compat/callsite-tostring.js
server/node_modules/depd/lib/compat/callsite-tostring.jsRaw
  1/*!
  2 * depd
  3 * Copyright(c) 2014 Douglas Christopher Wilson
  4 * MIT Licensed
  5 */
  6
  7/**
  8 * Module exports.
  9 */
 10
 11module.exports = callSiteToString
 12
 13/**
 14 * Format a CallSite file location to a string.
 15 */
 16
 17function callSiteFileLocation(callSite) {
 18  var fileName
 19  var fileLocation = ''
 20
 21  if (callSite.isNative()) {
 22    fileLocation = 'native'
 23  } else if (callSite.isEval()) {
 24    fileName = callSite.getScriptNameOrSourceURL()
 25    if (!fileName) {
 26      fileLocation = callSite.getEvalOrigin()
 27    }
 28  } else {
 29    fileName = callSite.getFileName()
 30  }
 31
 32  if (fileName) {
 33    fileLocation += fileName
 34
 35    var lineNumber = callSite.getLineNumber()
 36    if (lineNumber != null) {
 37      fileLocation += ':' + lineNumber
 38
 39      var columnNumber = callSite.getColumnNumber()
 40      if (columnNumber) {
 41        fileLocation += ':' + columnNumber
 42      }
 43    }
 44  }
 45
 46  return fileLocation || 'unknown source'
 47}
 48
 49/**
 50 * Format a CallSite to a string.
 51 */
 52
 53function callSiteToString(callSite) {
 54  var addSuffix = true
 55  var fileLocation = callSiteFileLocation(callSite)
 56  var functionName = callSite.getFunctionName()
 57  var isConstructor = callSite.isConstructor()
 58  var isMethodCall = !(callSite.isToplevel() || isConstructor)
 59  var line = ''
 60
 61  if (isMethodCall) {
 62    var methodName = callSite.getMethodName()
 63    var typeName = getConstructorName(callSite)
 64
 65    if (functionName) {
 66      if (typeName && functionName.indexOf(typeName) !== 0) {
 67        line += typeName + '.'
 68      }
 69
 70      line += functionName
 71
 72      if (methodName && functionName.lastIndexOf('.' + methodName) !== functionName.length - methodName.length - 1) {
 73        line += ' [as ' + methodName + ']'
 74      }
 75    } else {
 76      line += typeName + '.' + (methodName || '<anonymous>')
 77    }
 78  } else if (isConstructor) {
 79    line += 'new ' + (functionName || '<anonymous>')
 80  } else if (functionName) {
 81    line += functionName
 82  } else {
 83    addSuffix = false
 84    line += fileLocation
 85  }
 86
 87  if (addSuffix) {
 88    line += ' (' + fileLocation + ')'
 89  }
 90
 91  return line
 92}
 93
 94/**
 95 * Get constructor name of reviver.
 96 */
 97
 98function getConstructorName(obj) {
 99  var receiver = obj.receiver
100  return (receiver.constructor && receiver.constructor.name) || null
101}