3 * Copyright(c) 2014 Douglas Christopher Wilson
13 module.exports = callSiteToString
16 * Format a CallSite file location to a string.
19 function callSiteFileLocation (callSite) {
23 if (callSite.isNative()) {
24 fileLocation = 'native'
25 } else if (callSite.isEval()) {
26 fileName = callSite.getScriptNameOrSourceURL()
28 fileLocation = callSite.getEvalOrigin()
31 fileName = callSite.getFileName()
35 fileLocation += fileName
37 var lineNumber = callSite.getLineNumber()
38 if (lineNumber != null) {
39 fileLocation += ':' + lineNumber
41 var columnNumber = callSite.getColumnNumber()
43 fileLocation += ':' + columnNumber
48 return fileLocation || 'unknown source'
52 * Format a CallSite to a string.
55 function callSiteToString (callSite) {
57 var fileLocation = callSiteFileLocation(callSite)
58 var functionName = callSite.getFunctionName()
59 var isConstructor = callSite.isConstructor()
60 var isMethodCall = !(callSite.isToplevel() || isConstructor)
64 var methodName = callSite.getMethodName()
65 var typeName = getConstructorName(callSite)
68 if (typeName && functionName.indexOf(typeName) !== 0) {
69 line += typeName + '.'
74 if (methodName && functionName.lastIndexOf('.' + methodName) !== functionName.length - methodName.length - 1) {
75 line += ' [as ' + methodName + ']'
78 line += typeName + '.' + (methodName || '<anonymous>')
80 } else if (isConstructor) {
81 line += 'new ' + (functionName || '<anonymous>')
82 } else if (functionName) {
90 line += ' (' + fileLocation + ')'
97 * Get constructor name of reviver.
100 function getConstructorName (obj) {
101 var receiver = obj.receiver
102 return (receiver.constructor && receiver.constructor.name) || null