You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
1.4 KiB
JavaScript
80 lines
1.4 KiB
JavaScript
6 years ago
|
/*!
|
||
|
* depd
|
||
|
* Copyright(c) 2014-2015 Douglas Christopher Wilson
|
||
|
* MIT Licensed
|
||
|
*/
|
||
|
|
||
|
'use strict'
|
||
|
|
||
|
/**
|
||
|
* Module dependencies.
|
||
|
* @private
|
||
|
*/
|
||
|
|
||
|
var EventEmitter = require('events').EventEmitter
|
||
|
|
||
|
/**
|
||
|
* Module exports.
|
||
|
* @public
|
||
|
*/
|
||
|
|
||
|
lazyProperty(module.exports, 'callSiteToString', function callSiteToString () {
|
||
|
var limit = Error.stackTraceLimit
|
||
|
var obj = {}
|
||
|
var prep = Error.prepareStackTrace
|
||
|
|
||
|
function prepareObjectStackTrace (obj, stack) {
|
||
|
return stack
|
||
|
}
|
||
|
|
||
|
Error.prepareStackTrace = prepareObjectStackTrace
|
||
|
Error.stackTraceLimit = 2
|
||
|
|
||
|
// capture the stack
|
||
|
Error.captureStackTrace(obj)
|
||
|
|
||
|
// slice the stack
|
||
|
var stack = obj.stack.slice()
|
||
|
|
||
|
Error.prepareStackTrace = prep
|
||
|
Error.stackTraceLimit = limit
|
||
|
|
||
|
return stack[0].toString ? toString : require('./callsite-tostring')
|
||
|
})
|
||
|
|
||
|
lazyProperty(module.exports, 'eventListenerCount', function eventListenerCount () {
|
||
|
return EventEmitter.listenerCount || require('./event-listener-count')
|
||
|
})
|
||
|
|
||
|
/**
|
||
|
* Define a lazy property.
|
||
|
*/
|
||
|
|
||
|
function lazyProperty (obj, prop, getter) {
|
||
|
function get () {
|
||
|
var val = getter()
|
||
|
|
||
|
Object.defineProperty(obj, prop, {
|
||
|
configurable: true,
|
||
|
enumerable: true,
|
||
|
value: val
|
||
|
})
|
||
|
|
||
|
return val
|
||
|
}
|
||
|
|
||
|
Object.defineProperty(obj, prop, {
|
||
|
configurable: true,
|
||
|
enumerable: true,
|
||
|
get: get
|
||
|
})
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Call toString() on the obj
|
||
|
*/
|
||
|
|
||
|
function toString (obj) {
|
||
|
return obj.toString()
|
||
|
}
|