-
-
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.
Merge pull request #996 from zloirock/error-stack-experiment
- Loading branch information
Showing
3 changed files
with
35 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,20 @@ | ||
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]*/; | ||
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(stack, V8_OR_CHAKRA_STACK_ENTRY, ''); | ||
} else if (IS_FIREFOX_OR_SAFARI_STACK) { | ||
return join(arraySlice(split(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