clear-error-stack.js 562 B

1234567891011121314
  1. var uncurryThis = require('../internals/function-uncurry-this');
  2. var $Error = Error;
  3. var replace = uncurryThis(''.replace);
  4. var TEST = (function (arg) { return String($Error(arg).stack); })('zxcasd');
  5. var V8_OR_CHAKRA_STACK_ENTRY = /\n\s*at [^:]*:[^\n]*/;
  6. var IS_V8_OR_CHAKRA_STACK = V8_OR_CHAKRA_STACK_ENTRY.test(TEST);
  7. module.exports = function (stack, dropEntries) {
  8. if (IS_V8_OR_CHAKRA_STACK && typeof stack == 'string' && !$Error.prepareStackTrace) {
  9. while (dropEntries--) stack = replace(stack, V8_OR_CHAKRA_STACK_ENTRY, '');
  10. } return stack;
  11. };