3 * Copyright(c) 2014 Douglas Christopher Wilson
11 module.exports = callSiteToString
14 * Format a CallSite file location to a string.
17 function callSiteFileLocation(callSite) {
21 if (callSite.isNative()) {
22 fileLocation = 'native'
23 } else if (callSite.isEval()) {
24 fileName = callSite.getScriptNameOrSourceURL()
26 fileLocation = callSite.getEvalOrigin()
29 fileName = callSite.getFileName()
33 fileLocation += fileName
35 var lineNumber = callSite.getLineNumber()
36 if (lineNumber != null) {
37 fileLocation += ':' + lineNumber
39 var columnNumber = callSite.getColumnNumber()
41 fileLocation += ':' + columnNumber
46 return fileLocation || 'unknown source'
50 * Format a CallSite to a string.
53 function callSiteToString(callSite) {
55 var fileLocation = callSiteFileLocation(callSite)
56 var functionName = callSite.getFunctionName()
57 var isConstructor = callSite.isConstructor()
58 var isMethodCall = !(callSite.isToplevel() || isConstructor)
62 var methodName = callSite.getMethodName()
63 var typeName = getConstructorName(callSite)
66 if (typeName && functionName.indexOf(typeName) !== 0) {
67 line += typeName + '.'
72 if (methodName && functionName.lastIndexOf('.' + methodName) !== functionName.length - methodName.length - 1) {
73 line += ' [as ' + methodName + ']'
76 line += typeName + '.' + (methodName || '<anonymous>')
78 } else if (isConstructor) {
79 line += 'new ' + (functionName || '<anonymous>')
80 } else if (functionName) {
88 line += ' (' + fileLocation + ')'
95 * Get constructor name of reviver.
98 function getConstructorName(obj) {
99 var receiver = obj.receiver
100 return (receiver.constructor && receiver.constructor.name) || null