caller.js 409 B

123456789101112
  1. 'use strict';
  2. var $Error = require('es-errors');
  3. module.exports = function () {
  4. // see https://code.google.com/p/v8/wiki/JavaScriptStackTraceApi
  5. var origPrepareStackTrace = $Error.prepareStackTrace;
  6. $Error.prepareStackTrace = function (_, stack) { return stack; };
  7. var stack = (new $Error()).stack;
  8. $Error.prepareStackTrace = origPrepareStackTrace;
  9. return stack[2].getFileName();
  10. };