Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Oct 18, 2021
1 parent df3de2c commit a4a4783
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions packages/core-js/internals/clear-error-stack.js
@@ -1,7 +1,9 @@
var replace = ''.replace;
var split = ''.split;
var slice = [].slice;
var join = [].join;
var uncurryThis = require('../internals/function-uncurry-this');
var arraySlice = require('../internals/array-slice');

var replace = uncurryThis(''.replace);
var split = uncurryThis(''.split);
var join = uncurryThis([].join);

var TEST = (function (arg) { return String(Error(arg).stack); })('zxcasd');
var V8_OR_CHAKRA_STACK_ENTRY = /\n\s*at [^:]*:[^\n]*/;
Expand All @@ -11,8 +13,8 @@ var IS_FIREFOX_OR_SAFARI_STACK = /@[^\n]*\n/.test(TEST) && !/zxcasd/.test(TEST);
module.exports = function (stack, dropEntries) {
if (typeof stack != 'string') return stack;
if (IS_V8_OR_CHAKRA_STACK) {
while (dropEntries--) stack = replace.call(stack, V8_OR_CHAKRA_STACK_ENTRY, '');
while (dropEntries--) stack = replace(stack, V8_OR_CHAKRA_STACK_ENTRY, '');
} else if (IS_FIREFOX_OR_SAFARI_STACK) {
return join.call(slice.call(split.call(stack, '\n'), dropEntries), '\n');
return join(arraySlice(split(stack, '\n'), dropEntries), '\n');
} return stack;
};

0 comments on commit a4a4783

Please sign in to comment.