11var _ = require ( 'underscore' ) ;
22var files = require ( './files.js' ) ;
3+ var parseStack = require ( './parse-stack.js' ) ;
34
45var debugBuild = ! ! process . env . METEOR_DEBUG_BUILD ;
56
@@ -23,7 +24,7 @@ var Job = function (options) {
2324
2425_ . extend ( Job . prototype , {
2526 // options may include type ("error"), message, func, file, line,
26- // column, stack (in the format returned by parseStack)
27+ // column, stack (in the format returned by parseStack.parse() )
2728 addMessage : function ( options ) {
2829 var self = this ;
2930 self . messages . push ( options ) ;
@@ -254,74 +255,14 @@ var jobHasMessages = function () {
254255 return currentJob ? search ( currentJob ) : false ;
255256} ;
256257
257- // Given an Error (eg, 'new Error'), return the stack associated with
258- // that error as an array. More recently called functions appear first
259- // and each element is an object with keys:
260- // - file: filename as it appears in the stack
261- // - line: 1-indexed line number in file, as a Number
262- // - column: 1-indexed column in line, as a Number
263- // - func: name of the function in the frame (maybe null)
264- //
265- // Accomplishes this by parsing the text representation of the stack
266- // with regular expressions. Unlikely to work anywhere but v8.
267- //
268- // If a function on the stack has been marked with markBoundary, don't
269- // return anything past that function. We call this the "user portion"
270- // of the stack.
271- var parseStack = function ( err ) {
272- var frames = err . stack . split ( '\n' ) ;
273-
274- frames . shift ( ) ; // at least the first line is the exception
275- var stop = false ;
276- var ret = [ ] ;
277-
278- _ . each ( frames , function ( frame ) {
279- if ( stop )
280- return ;
281- var m ;
282- if ( m =
283- frame . match ( / ^ \s * a t \s * ( ( n e w ) ? [ ^ \s ] + ) \s * \( ( [ ^ : ] * ) ( : ( \d + ) ) ? ( : ( \d + ) ) ? \) \s * $ / ) ) {
284- // " at My.Function (/path/to/myfile.js:532:39)"
285- // " at Array.forEach (native)"
286- // " at new My.Class (file.js:1:2)"
287- if ( m [ 1 ] === "__mark__" ) {
288- stop = true ;
289- return ;
290- }
291- ret . push ( {
292- func : m [ 1 ] ,
293- file : m [ 3 ] ,
294- line : m [ 5 ] ? + m [ 5 ] : undefined ,
295- column : m [ 7 ] ? + m [ 7 ] : undefined
296- } ) ;
297- } else if ( m = frame . match ( / ^ \s * a t \s + ( [ ^ : ] + ) ( : ( \d + ) ) ? ( : ( \d + ) ) ? \s * $ / ) ) {
298- // " at /path/to/myfile.js:532:39"
299- ret . push ( {
300- file : m [ 1 ] ,
301- line : m [ 3 ] ? + m [ 3 ] : undefined ,
302- column : m [ 5 ] ? + m [ 5 ] : undefined
303- } ) ;
304- } else if ( _ . isEmpty ( ret ) ) {
305- // We haven't found any stack frames, so probably we have newlines in the
306- // error message. Just skip this line.
307- } else {
308- throw new Error ( "Couldn't parse stack frame: '" + frame + "'" ) ;
309- }
310- } ) ;
311-
312- return ret ;
313- } ;
314-
315258// Given a function f, return a "marked" version of f. The mark
316259// indicates that stack traces should stop just above f. So if you
317260// mark a user-supplied callback function before calling it, you'll be
318261// able to show the user just the "user portion" of the stack trace
319262// (the part inside their own code, and not all of the innards of the
320263// code that called it).
321264var markBoundary = function ( f ) {
322- return function __mark__ ( ) {
323- return f . apply ( this , arguments ) ;
324- } ;
265+ return parseStack . markBottom ( f ) ;
325266} ;
326267
327268// Record a build error. If inside a job, add the error to the current
@@ -365,7 +306,7 @@ var error = function (message, options) {
365306
366307 if ( 'useMyCaller' in info ) {
367308 if ( info . useMyCaller ) {
368- info . stack = parseStack ( new Error ( ) ) . slice ( 2 ) ;
309+ info . stack = parseStack . parse ( new Error ( ) ) . slice ( 2 ) ;
369310 var howManyToSkip = (
370311 typeof info . useMyCaller === "number" ? info . useMyCaller : 0 ) ;
371312 var caller = info . stack [ howManyToSkip ] ;
@@ -411,7 +352,7 @@ var exception = function (error) {
411352 column : error . column
412353 } ) ;
413354 } else {
414- var stack = parseStack ( error ) ;
355+ var stack = parseStack . parse ( error ) ;
415356 var locus = stack [ 0 ] ;
416357 currentJob . addMessage ( {
417358 message : message ,
0 commit comments