-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[experiment] clear error stack from extra entries
- Loading branch information
Showing
3 changed files
with
33 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
var replace = ''.replace; | ||
var split = ''.split; | ||
var slice = [].slice; | ||
var join = [].join; | ||
|
||
var TEST = (function (arg) { return String(Error(arg).stack); })('zxcasd'); | ||
var V8_OR_CHAKRA_STACK_ENTRY = /\n\s*at [^:]*:[^\n]*/; | ||
var IS_V8_OR_CHAKRA_STACK = V8_OR_CHAKRA_STACK_ENTRY.test(TEST); | ||
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, ''); | ||
} else if (IS_FIREFOX_OR_SAFARI_STACK) { | ||
return join.call(slice.call(split.call(stack, '\n'), dropEntries), '\n'); | ||
} return stack; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
var fails = require('../internals/fails'); | ||
var createPropertyDescriptor = require('../internals/create-property-descriptor'); | ||
|
||
module.exports = !fails(function () { | ||
var error = Error('a'); | ||
if (!('stack' in error)) return true; | ||
// eslint-disable-next-line es/no-object-defineproperty -- safe | ||
Object.defineProperty(error, 'stack', createPropertyDescriptor(1, 7)); | ||
return error.stack !== 7; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters