error-stack-clear.js 656 B

12345678910111213141516
  1. 'use strict';
  2. var uncurryThis = require('../internals/function-uncurry-this');
  3. var $Error = Error;
  4. var replace = uncurryThis(''.replace);
  5. var TEST = (function (arg) { return String(new $Error(arg).stack); })('zxcasd');
  6. // eslint-disable-next-line redos/no-vulnerable, sonarjs/slow-regex -- safe
  7. var V8_OR_CHAKRA_STACK_ENTRY = /\n\s*at [^:]*:[^\n]*/;
  8. var IS_V8_OR_CHAKRA_STACK = V8_OR_CHAKRA_STACK_ENTRY.test(TEST);
  9. module.exports = function (stack, dropEntries) {
  10. if (IS_V8_OR_CHAKRA_STACK && typeof stack == 'string' && !$Error.prepareStackTrace) {
  11. while (dropEntries--) stack = replace(stack, V8_OR_CHAKRA_STACK_ENTRY, '');
  12. } return stack;
  13. };