|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, you can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 var EXPORTED_SYMBOLS = ['findCallerFrame']; |
|
6 |
|
7 |
|
8 /** |
|
9 * @namespace Defines utility methods for handling stack frames |
|
10 */ |
|
11 |
|
12 /** |
|
13 * Find the frame to use for logging the test result. If a start frame has |
|
14 * been specified, we walk down the stack until a frame with the same filename |
|
15 * as the start frame has been found. The next file in the stack will be the |
|
16 * frame to use for logging the result. |
|
17 * |
|
18 * @memberOf stack |
|
19 * @param {Object} [aStartFrame=Components.stack] Frame to start from walking up the stack. |
|
20 * @returns {Object} Frame of the stack to use for logging the result. |
|
21 */ |
|
22 function findCallerFrame(aStartFrame) { |
|
23 let frame = Components.stack; |
|
24 let filename = frame.filename.replace(/(.*)-> /, ""); |
|
25 |
|
26 // If a start frame has been specified, walk up the stack until we have |
|
27 // found the corresponding file |
|
28 if (aStartFrame) { |
|
29 filename = aStartFrame.filename.replace(/(.*)-> /, ""); |
|
30 |
|
31 while (frame.caller && |
|
32 frame.filename && (frame.filename.indexOf(filename) == -1)) { |
|
33 frame = frame.caller; |
|
34 } |
|
35 } |
|
36 |
|
37 // Walk even up more until the next file has been found |
|
38 while (frame.caller && |
|
39 (!frame.filename || (frame.filename.indexOf(filename) != -1))) |
|
40 frame = frame.caller; |
|
41 |
|
42 return frame; |
|
43 } |