diff --git a/src/raven.js b/src/raven.js index e454b6c4652e..cdfda43ef849 100644 --- a/src/raven.js +++ b/src/raven.js @@ -1042,13 +1042,7 @@ Raven.prototype = { lineno: frame.line, colno: frame.column, 'function': frame.func || '?' - }, context = this._extractContextFromFrame(frame), i; - - if (context) { - var keys = ['pre_context', 'context_line', 'post_context']; - i = 3; - while (i--) normalized[keys[i]] = context[i]; - } + }; normalized.in_app = !( // determine if an exception came from outside of our app // first we check the global includePaths list. @@ -1062,45 +1056,6 @@ Raven.prototype = { return normalized; }, - _extractContextFromFrame: function(frame) { - // immediately check if we should even attempt to parse a context - if (!frame.context || !this._globalOptions.fetchContext) return; - - var context = frame.context, - pivot = ~~(context.length / 2), - i = context.length, isMinified = false; - - while (i--) { - // We're making a guess to see if the source is minified or not. - // To do that, we make the assumption if *any* of the lines passed - // in are greater than 300 characters long, we bail. - // Sentry will see that there isn't a context - if (context[i].length > 300) { - isMinified = true; - break; - } - } - - if (isMinified) { - // The source is minified and we don't know which column. Fuck it. - if (isUndefined(frame.column)) return; - - // If the source is minified and has a frame column - // we take a chunk of the offending line to hopefully shed some light - return [ - [], // no pre_context - context[pivot].substr(frame.column, 50), // grab 50 characters, starting at the offending column - [] // no post_context - ]; - } - - return [ - context.slice(0, pivot), // pre_context - context[pivot], // context_line - context.slice(pivot + 1) // post_context - ]; - }, - _processException: function(type, message, fileurl, lineno, frames, options) { var stacktrace, fullMessage; diff --git a/test/raven.test.js b/test/raven.test.js index d28dec62eb7c..8dc204b5d1a1 100644 --- a/test/raven.test.js +++ b/test/raven.test.js @@ -246,12 +246,6 @@ describe('globals', function() { describe('normalizeFrame', function() { it('should handle a normal frame', function() { - var context = [ - ['line1'], // pre - 'line2', // culprit - ['line3'] // post - ]; - this.sinon.stub(Raven, '_extractContextFromFrame').returns(context); var frame = { url: 'http://example.com/path/file.js', line: 10, @@ -267,25 +261,18 @@ describe('globals', function() { lineno: 10, colno: 11, 'function': 'lol', - pre_context: ['line1'], - context_line: 'line2', - post_context: ['line3'], in_app: true }); }); it('should handle a frame without context', function() { - this.sinon.stub(Raven, '_extractContextFromFrame').returns(undefined); var frame = { url: 'http://example.com/path/file.js', line: 10, column: 11, func: 'lol' - // context: [] context is stubbed }; - Raven._globalOptions.fetchContext = true; - assert.deepEqual(Raven._normalizeFrame(frame), { filename: 'http://example.com/path/file.js', lineno: 10, @@ -296,13 +283,11 @@ describe('globals', function() { }); it('should not mark `in_app` if rules match', function() { - this.sinon.stub(Raven, '_extractContextFromFrame').returns(undefined); var frame = { url: 'http://example.com/path/file.js', line: 10, column: 11, func: 'lol' - // context: [] context is stubbed }; Raven._globalOptions.fetchContext = true; @@ -318,13 +303,11 @@ describe('globals', function() { }); it('should mark `in_app` if rules do not match', function() { - this.sinon.stub(Raven, '_extractContextFromFrame').returns(undefined); var frame = { url: 'http://lol.com/path/file.js', line: 10, column: 11, func: 'lol' - // context: [] context is stubbed }; Raven._globalOptions.fetchContext = true; @@ -340,13 +323,11 @@ describe('globals', function() { }); it('should mark `in_app` for raven.js', function() { - this.sinon.stub(Raven, '_extractContextFromFrame').returns(undefined); var frame = { url: 'http://lol.com/path/raven.js', line: 10, column: 11, func: 'lol' - // context: [] context is stubbed }; assert.deepEqual(Raven._normalizeFrame(frame), { @@ -359,13 +340,11 @@ describe('globals', function() { }); it('should mark `in_app` for raven.min.js', function() { - this.sinon.stub(Raven, '_extractContextFromFrame').returns(undefined); var frame = { url: 'http://lol.com/path/raven.min.js', line: 10, column: 11, func: 'lol' - // context: [] context is stubbed }; assert.deepEqual(Raven._normalizeFrame(frame), { @@ -378,13 +357,11 @@ describe('globals', function() { }); it('should mark `in_app` for Raven', function() { - this.sinon.stub(Raven, '_extractContextFromFrame').returns(undefined); var frame = { url: 'http://lol.com/path/file.js', line: 10, column: 11, func: 'Raven.wrap' - // context: [] context is stubbed }; assert.deepEqual(Raven._normalizeFrame(frame), { @@ -397,13 +374,11 @@ describe('globals', function() { }); it('should mark `in_app` for TraceKit', function() { - this.sinon.stub(Raven, '_extractContextFromFrame').returns(undefined); var frame = { url: 'http://lol.com/path/file.js', line: 10, column: 11, func: 'TraceKit.lol' - // context: [] context is stubbed }; assert.deepEqual(Raven._normalizeFrame(frame), { @@ -416,95 +391,17 @@ describe('globals', function() { }); it('should not blow up if includePaths is empty, regression for #377', function() { - this.sinon.stub(Raven, '_extractContextFromFrame').returns(undefined); var frame = { url: 'http://lol.com/path/file.js', line: 10, column: 11, func: 'TraceKit.lol' - // context: [] context is stubbed }; Raven._globalOptions.includePaths = []; Raven._normalizeFrame(frame); }); }); - describe('extractContextFromFrame', function() { - it('should handle a normal frame', function() { - var frame = { - column: 2, - context: [ - 'line1', - 'line2', - 'line3', - 'line4', - 'line5', - 'culprit', - 'line7', - 'line8', - 'line9', - 'line10', - 'line11' - ] - }; - var context = Raven._extractContextFromFrame(frame); - assert.deepEqual(context, [ - ['line1', 'line2', 'line3', 'line4', 'line5'], - 'culprit', - ['line7', 'line8', 'line9', 'line10', 'line11'] - ]); - }); - - it('should return nothing if there is no context', function() { - var frame = { - column: 2 - }; - assert.isUndefined(Raven._extractContextFromFrame(frame)); - }); - - it('should reject a context if a line is too long without a column', function() { - var frame = { - context: [ - new Array(1000).join('f') // generate a line that is 1000 chars long - ] - }; - assert.isUndefined(Raven._extractContextFromFrame(frame)); - }); - - it('should reject a minified context with fetchContext disabled', function() { - var frame = { - column: 2, - context: [ - 'line1', - 'line2', - 'line3', - 'line4', - 'line5', - 'culprit', - 'line7', - 'line8', - 'line9', - 'line10', - 'line11' - ] - }; - Raven._globalOptions.fetchContext = false; - assert.isUndefined(Raven._extractContextFromFrame(frame)); - }); - - it('should truncate the minified line if there is a column number without sourcemaps enabled', function() { - // Note to future self: - // Array(51).join('f').length === 50 - var frame = { - column: 2, - context: [ - 'aa' + (new Array(51).join('f')) + (new Array(500).join('z')) - ] - }; - assert.deepEqual(Raven._extractContextFromFrame(frame), [[], new Array(51).join('f'), []]); - }); - }); - describe('processException', function() { it('should respect `ignoreErrors`', function() { this.sinon.stub(Raven, '_send'); diff --git a/test/vendor/tracekit-parser.test.js b/test/vendor/tracekit-parser.test.js index ebef8a004c5f..4c558456d481 100644 --- a/test/vendor/tracekit-parser.test.js +++ b/test/vendor/tracekit-parser.test.js @@ -10,9 +10,9 @@ describe('TraceKit', function () { var stackFrames = TraceKit.computeStackTrace(CapturedExceptions.SAFARI_6); assert.ok(stackFrames); assert.deepEqual(stackFrames.stack.length, 4); - assert.deepEqual(stackFrames.stack[0], { url: 'http://path/to/file.js', func: '?', args: [], line: 48, column: null, context: null }); - assert.deepEqual(stackFrames.stack[1], { url: 'http://path/to/file.js', func: 'dumpException3', args: [], line: 52, column: null, context: null }); - assert.deepEqual(stackFrames.stack[2], { url: 'http://path/to/file.js', func: 'onclick', args: [], line: 82, column: null, context: null }); + assert.deepEqual(stackFrames.stack[0], { url: 'http://path/to/file.js', func: '?', args: [], line: 48, column: null }); + assert.deepEqual(stackFrames.stack[1], { url: 'http://path/to/file.js', func: 'dumpException3', args: [], line: 52, column: null }); + assert.deepEqual(stackFrames.stack[2], { url: 'http://path/to/file.js', func: 'onclick', args: [], line: 82, column: null }); assert.deepEqual(stackFrames.stack[3], { url: '[native code]', func: '?', args: [], line: null, column: null }); }); @@ -20,18 +20,18 @@ describe('TraceKit', function () { var stackFrames = TraceKit.computeStackTrace(CapturedExceptions.SAFARI_7); assert.ok(stackFrames); assert.deepEqual(stackFrames.stack.length, 3); - assert.deepEqual(stackFrames.stack[0], { url: 'http://path/to/file.js', func: '?', args: [], line: 48, column: 22, context: null }); - assert.deepEqual(stackFrames.stack[1], { url: 'http://path/to/file.js', func: 'foo', args: [], line: 52, column: 15, context: null }); - assert.deepEqual(stackFrames.stack[2], { url: 'http://path/to/file.js', func: 'bar', args: [], line: 108, column: 107, context: null }); + assert.deepEqual(stackFrames.stack[0], { url: 'http://path/to/file.js', func: '?', args: [], line: 48, column: 22 }); + assert.deepEqual(stackFrames.stack[1], { url: 'http://path/to/file.js', func: 'foo', args: [], line: 52, column: 15 }); + assert.deepEqual(stackFrames.stack[2], { url: 'http://path/to/file.js', func: 'bar', args: [], line: 108, column: 107 }); }); it('should parse Safari 8 error', function () { var stackFrames = TraceKit.computeStackTrace(CapturedExceptions.SAFARI_8); assert.ok(stackFrames); assert.deepEqual(stackFrames.stack.length, 3); - assert.deepEqual(stackFrames.stack[0], { url: 'http://path/to/file.js', func: '?', args: [], line: 47, column: 22, context: null }); - assert.deepEqual(stackFrames.stack[1], { url: 'http://path/to/file.js', func: 'foo', args: [], line: 52, column: 15, context: null }); - assert.deepEqual(stackFrames.stack[2], { url: 'http://path/to/file.js', func: 'bar', args: [], line: 108, column: 23, context: null }); + assert.deepEqual(stackFrames.stack[0], { url: 'http://path/to/file.js', func: '?', args: [], line: 47, column: 22 }); + assert.deepEqual(stackFrames.stack[1], { url: 'http://path/to/file.js', func: 'foo', args: [], line: 52, column: 15 }); + assert.deepEqual(stackFrames.stack[2], { url: 'http://path/to/file.js', func: 'bar', args: [], line: 108, column: 23 }); }); it('should parse Safari 8 eval error', function () { @@ -40,62 +40,62 @@ describe('TraceKit', function () { assert.ok(stackFrames); assert.deepEqual(stackFrames.stack.length, 3); assert.deepEqual(stackFrames.stack[0], { url: '[native code]', func: 'eval', args: [], line: null, column: null }); - assert.deepEqual(stackFrames.stack[1], { url: 'http://path/to/file.js', func: 'foo', args: [], line: 58, column: 21, context: null }); - assert.deepEqual(stackFrames.stack[2], { url: 'http://path/to/file.js', func: 'bar', args: [], line: 109, column: 91, context: null }); + assert.deepEqual(stackFrames.stack[1], { url: 'http://path/to/file.js', func: 'foo', args: [], line: 58, column: 21 }); + assert.deepEqual(stackFrames.stack[2], { url: 'http://path/to/file.js', func: 'bar', args: [], line: 109, column: 91 }); }); it('should parse Firefox 3 error', function () { var stackFrames = TraceKit.computeStackTrace(CapturedExceptions.FIREFOX_3); assert.ok(stackFrames); assert.deepEqual(stackFrames.stack.length, 7); - assert.deepEqual(stackFrames.stack[0], { url: 'http://127.0.0.1:8000/js/stacktrace.js', func: '?', args: [], line: 44, column: null, context: null }); - assert.deepEqual(stackFrames.stack[1], { url: 'http://127.0.0.1:8000/js/stacktrace.js', func: '?', args: ['null'], line: 31, column: null, context: null }); - assert.deepEqual(stackFrames.stack[2], { url: 'http://127.0.0.1:8000/js/stacktrace.js', func: 'printStackTrace', args: [], line: 18, column: null, context: null }); - assert.deepEqual(stackFrames.stack[3], { url: 'http://127.0.0.1:8000/js/file.js', func: 'bar', args: ['1'], line: 13, column: null, context: null }); - assert.deepEqual(stackFrames.stack[4], { url: 'http://127.0.0.1:8000/js/file.js', func: 'bar', args: ['2'], line: 16, column: null, context: null }); - assert.deepEqual(stackFrames.stack[5], { url: 'http://127.0.0.1:8000/js/file.js', func: 'foo', args: [], line: 20, column: null, context: null }); - assert.deepEqual(stackFrames.stack[6], { url: 'http://127.0.0.1:8000/js/file.js', func: '?', args: [], line: 24, column: null, context: null }); + assert.deepEqual(stackFrames.stack[0], { url: 'http://127.0.0.1:8000/js/stacktrace.js', func: '?', args: [], line: 44, column: null }); + assert.deepEqual(stackFrames.stack[1], { url: 'http://127.0.0.1:8000/js/stacktrace.js', func: '?', args: ['null'], line: 31, column: null }); + assert.deepEqual(stackFrames.stack[2], { url: 'http://127.0.0.1:8000/js/stacktrace.js', func: 'printStackTrace', args: [], line: 18, column: null }); + assert.deepEqual(stackFrames.stack[3], { url: 'http://127.0.0.1:8000/js/file.js', func: 'bar', args: ['1'], line: 13, column: null }); + assert.deepEqual(stackFrames.stack[4], { url: 'http://127.0.0.1:8000/js/file.js', func: 'bar', args: ['2'], line: 16, column: null }); + assert.deepEqual(stackFrames.stack[5], { url: 'http://127.0.0.1:8000/js/file.js', func: 'foo', args: [], line: 20, column: null }); + assert.deepEqual(stackFrames.stack[6], { url: 'http://127.0.0.1:8000/js/file.js', func: '?', args: [], line: 24, column: null }); }); it('should parse Firefox 7 error', function () { var stackFrames = TraceKit.computeStackTrace(CapturedExceptions.FIREFOX_7); assert.ok(stackFrames); assert.deepEqual(stackFrames.stack.length, 7); - assert.deepEqual(stackFrames.stack[0], { url: 'file:///G:/js/stacktrace.js', func: '?', args: [], line: 44, column: null, context: null }); - assert.deepEqual(stackFrames.stack[1], { url: 'file:///G:/js/stacktrace.js', func: '?', args: ['null'], line: 31, column: null, context: null }); - assert.deepEqual(stackFrames.stack[2], { url: 'file:///G:/js/stacktrace.js', func: 'printStackTrace', args: [], line: 18, column: null, context: null }); - assert.deepEqual(stackFrames.stack[3], { url: 'file:///G:/js/file.js', func: 'bar', args: ['1'], line: 13, column: null, context: null }); - assert.deepEqual(stackFrames.stack[4], { url: 'file:///G:/js/file.js', func: 'bar', args: ['2'], line: 16, column: null, context: null }); - assert.deepEqual(stackFrames.stack[5], { url: 'file:///G:/js/file.js', func: 'foo', args: [], line: 20, column: null, context: null }); - assert.deepEqual(stackFrames.stack[6], { url: 'file:///G:/js/file.js', func: '?', args: [], line: 24, column: null, context: null }); + assert.deepEqual(stackFrames.stack[0], { url: 'file:///G:/js/stacktrace.js', func: '?', args: [], line: 44, column: null }); + assert.deepEqual(stackFrames.stack[1], { url: 'file:///G:/js/stacktrace.js', func: '?', args: ['null'], line: 31, column: null }); + assert.deepEqual(stackFrames.stack[2], { url: 'file:///G:/js/stacktrace.js', func: 'printStackTrace', args: [], line: 18, column: null }); + assert.deepEqual(stackFrames.stack[3], { url: 'file:///G:/js/file.js', func: 'bar', args: ['1'], line: 13, column: null }); + assert.deepEqual(stackFrames.stack[4], { url: 'file:///G:/js/file.js', func: 'bar', args: ['2'], line: 16, column: null }); + assert.deepEqual(stackFrames.stack[5], { url: 'file:///G:/js/file.js', func: 'foo', args: [], line: 20, column: null }); + assert.deepEqual(stackFrames.stack[6], { url: 'file:///G:/js/file.js', func: '?', args: [], line: 24, column: null }); }); it('should parse Firefox 14 error', function () { var stackFrames = TraceKit.computeStackTrace(CapturedExceptions.FIREFOX_14); assert.ok(stackFrames); assert.deepEqual(stackFrames.stack.length, 3); - assert.deepEqual(stackFrames.stack[0], { url: 'http://path/to/file.js', func: '?', args: [], line: 48, column: null, context: null }); - assert.deepEqual(stackFrames.stack[1], { url: 'http://path/to/file.js', func: 'dumpException3', args: [], line: 52, column: null, context: null }); - assert.deepEqual(stackFrames.stack[2], { url: 'http://path/to/file.js', func: 'onclick', args: [], line: 1, column: null, context: null }); + assert.deepEqual(stackFrames.stack[0], { url: 'http://path/to/file.js', func: '?', args: [], line: 48, column: null }); + assert.deepEqual(stackFrames.stack[1], { url: 'http://path/to/file.js', func: 'dumpException3', args: [], line: 52, column: null }); + assert.deepEqual(stackFrames.stack[2], { url: 'http://path/to/file.js', func: 'onclick', args: [], line: 1, column: null }); }); it('should parse Firefox 31 error', function () { var stackFrames = TraceKit.computeStackTrace(CapturedExceptions.FIREFOX_31); assert.ok(stackFrames); assert.deepEqual(stackFrames.stack.length, 3); - assert.deepEqual(stackFrames.stack[0], { url: 'http://path/to/file.js', func: 'foo', args: [], line: 41, column: 13, context: null }); - assert.deepEqual(stackFrames.stack[1], { url: 'http://path/to/file.js', func: 'bar', args: [], line: 1, column: 1, context: null }); - assert.deepEqual(stackFrames.stack[2], { url: 'http://path/to/file.js', func: '.plugin/e.fn[c]/<', args: [], line: 1, column: 1, context: null }); + assert.deepEqual(stackFrames.stack[0], { url: 'http://path/to/file.js', func: 'foo', args: [], line: 41, column: 13 }); + assert.deepEqual(stackFrames.stack[1], { url: 'http://path/to/file.js', func: 'bar', args: [], line: 1, column: 1 }); + assert.deepEqual(stackFrames.stack[2], { url: 'http://path/to/file.js', func: '.plugin/e.fn[c]/<', args: [], line: 1, column: 1 }); }); it('should parse Firefox 44 ns exceptions', function () { var stackFrames = TraceKit.computeStackTrace(CapturedExceptions.FIREFOX_44_NS_EXCEPTION); assert.ok(stackFrames); assert.deepEqual(stackFrames.stack.length, 4); - assert.deepEqual(stackFrames.stack[0], { url: 'http://path/to/file.js', func: '[2]', args: ['x'], line: 48, column: 12, context: [ ' x.undef();' ] }); - assert.deepEqual(stackFrames.stack[1], { url: 'http://localhost:8000/ExceptionLab.html', func: 'dumpException3', args: [], line: 46, column: 8, context: [ ' dumpException((function(x) {' ] }); - assert.deepEqual(stackFrames.stack[2], { url: 'http://localhost:8000/ExceptionLab.html', func: '', args: ['event'], line: 1, column: 0, context: [ ' dumpException3();' ] }); + assert.deepEqual(stackFrames.stack[0], { url: 'http://localhost:8000/ExceptionLab.html', func: '', args: ['x'], line: 48, column: 12 }); + assert.deepEqual(stackFrames.stack[1], { url: 'http://localhost:8000/ExceptionLab.html', func: 'dumpException3', args: [], line: 46, column: 8 }); + assert.deepEqual(stackFrames.stack[2], { url: 'http://localhost:8000/ExceptionLab.html', func: '', args: ['event'], line: 1, column: 0 }); }); it('should parse Opera 25 error', function () { var stackFrames = TraceKit.computeStackTrace(CapturedExceptions.OPERA_25); assert.ok(stackFrames); assert.deepEqual(stackFrames.stack.length, 3); - assert.deepEqual(stackFrames.stack[0], { url: 'http://path/to/file.js', func: '?', args: [], line: 47, column: 22, context: null }); - assert.deepEqual(stackFrames.stack[1], { url: 'http://path/to/file.js', func: 'foo', args: [], line: 52, column: 15, context: null }); - assert.deepEqual(stackFrames.stack[2], { url: 'http://path/to/file.js', func: 'bar', args: [], line: 108, column: 168, context: null }); + assert.deepEqual(stackFrames.stack[0], { url: 'http://path/to/file.js', func: '?', args: [], line: 47, column: 22 }); + assert.deepEqual(stackFrames.stack[1], { url: 'http://path/to/file.js', func: 'foo', args: [], line: 52, column: 15 }); + assert.deepEqual(stackFrames.stack[2], { url: 'http://path/to/file.js', func: 'bar', args: [], line: 108, column: 168 }); }); }); }); diff --git a/vendor/TraceKit/tracekit.js b/vendor/TraceKit/tracekit.js index d9ef3d1137ed..59ed64eb95b5 100644 --- a/vendor/TraceKit/tracekit.js +++ b/vendor/TraceKit/tracekit.js @@ -175,7 +175,6 @@ TraceKit.report = (function reportModuleWrapper() { } location.func = UNKNOWN_FUNCTION; - location.context = null; stack = { 'name': name, @@ -278,7 +277,6 @@ TraceKit.report = (function reportModuleWrapper() { * s.stack[i].args - arguments passed to the function, if known * s.stack[i].line - line number, if known * s.stack[i].column - column number, if known - * s.stack[i].context - an array of source code lines; the middle element corresponds to the correct line# * * Supports: * - Firefox: full stack trace with line numbers and unreliable column @@ -428,10 +426,6 @@ TraceKit.computeStackTrace = (function computeStackTraceWrapper() { element.func = UNKNOWN_FUNCTION; } - if (element.line) { - element.context = null; - } - stack.push(element); } @@ -497,7 +491,6 @@ TraceKit.computeStackTrace = (function computeStackTraceWrapper() { if (!element.func && element.line) { element.func = UNKNOWN_FUNCTION; } - element.context = [lines[line + 1]]; stack.push(element); } @@ -585,7 +578,6 @@ TraceKit.computeStackTrace = (function computeStackTraceWrapper() { if (!item.func) { item.func = UNKNOWN_FUNCTION; } - item.context = [lines[line + 1]]; stack.push(item); } @@ -635,7 +627,6 @@ TraceKit.computeStackTrace = (function computeStackTraceWrapper() { return false; // already in stack trace } else if (!stackInfo.stack[0].line && stackInfo.stack[0].func === initial.func) { stackInfo.stack[0].line = initial.line; - stackInfo.stack[0].context = initial.context; return false; } }