版博士V2.0程序
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 

47 satır
1.4 KiB

  1. // v8 builtin format stack trace
  2. // for when there was no previous prepareStackTrace function to call
  3. var FormatStackTrace = require('./formatstack');
  4. // some notes on the behavior below:
  5. // because the 'stack' member is a one shot access variable (the raw stack is
  6. // formatted on accessing it)
  7. // we try to avoid modifying what the user would have wanted
  8. // thus we use the previous value for prepareStackTrace
  9. //
  10. // The reason we store the callsite variable is because prepareStackTrace
  11. // will not be called again once it has been called for a given error object
  12. // but we want to support getting the stack out of the error multiple times (cause why not)
  13. module.exports = function(err) {
  14. // save original stacktrace
  15. var save = Error.prepareStackTrace;
  16. // replace capture with our function
  17. Error.prepareStackTrace = function(err, trace) {
  18. // cache stack frames so we don't have to get them again
  19. // use a non-enumerable property
  20. Object.defineProperty(err, '_sb_callsites', {
  21. value: trace
  22. });
  23. return (save || FormatStackTrace)(err, trace);
  24. };
  25. // force capture of the stack frames
  26. err.stack;
  27. // someone already asked for the stack so we can't do this trick
  28. // TODO fallback to string parsing?
  29. if (!err._sb_callsites) {
  30. return [];
  31. }
  32. // return original capture function
  33. Error.prepareStackTrace = save;
  34. return err._sb_callsites;
  35. };