Allow Error.prepareStackTrace to be temporarily reassigned

Fixes https://github.com/atom/atom/issues/9660

Signed-off-by: Nathan Sobo <nathan@github.com>
This commit is contained in:
Max Brunsfeld 2015-11-23 15:22:15 -08:00 committed by Nathan Sobo
parent d17ab332ec
commit 4616b426b0
2 changed files with 21 additions and 2 deletions

View File

@ -69,3 +69,15 @@ describe 'CompileCache', ->
CompileCache.addPathToCache(path.join(fixtures, 'cson.cson'), atomHome)
expect(CSONParser.parse.callCount).toBe 1
describe 'overriding Error.prepareStackTrace', ->
it 'removes the override on the next tick', ->
Error.prepareStackTrace = -> 'a-stack-trace'
error = new Error("Oops")
expect(error.stack).toBe 'a-stack-trace'
waits(1)
runs ->
error = new Error("Oops again")
expect(error.stack).not.toBe 'a-stack-trace'

View File

@ -166,10 +166,17 @@ function prepareStackTraceWithRawStack (error, frames) {
return sourceMapPrepareStackTrace(error, frames)
}
let prepareStackTrace = prepareStackTraceWithRawStack
// Prevent coffee-script from reassigning Error.prepareStackTrace
Object.defineProperty(Error, 'prepareStackTrace', {
get: function () { return prepareStackTraceWithRawStack },
set: function (newValue) {}
get: function () { return prepareStackTrace },
set: function (newValue) {
prepareStackTrace = newValue
process.nextTick(function () {
prepareStackTrace = prepareStackTraceWithRawStack
})
}
})
Error.prototype.getRawStack = function () { // eslint-disable-line no-extend-native