michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, you can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: var EXPORTED_SYMBOLS = ['findCallerFrame']; michael@0: michael@0: michael@0: /** michael@0: * @namespace Defines utility methods for handling stack frames michael@0: */ michael@0: michael@0: /** michael@0: * Find the frame to use for logging the test result. If a start frame has michael@0: * been specified, we walk down the stack until a frame with the same filename michael@0: * as the start frame has been found. The next file in the stack will be the michael@0: * frame to use for logging the result. michael@0: * michael@0: * @memberOf stack michael@0: * @param {Object} [aStartFrame=Components.stack] Frame to start from walking up the stack. michael@0: * @returns {Object} Frame of the stack to use for logging the result. michael@0: */ michael@0: function findCallerFrame(aStartFrame) { michael@0: let frame = Components.stack; michael@0: let filename = frame.filename.replace(/(.*)-> /, ""); michael@0: michael@0: // If a start frame has been specified, walk up the stack until we have michael@0: // found the corresponding file michael@0: if (aStartFrame) { michael@0: filename = aStartFrame.filename.replace(/(.*)-> /, ""); michael@0: michael@0: while (frame.caller && michael@0: frame.filename && (frame.filename.indexOf(filename) == -1)) { michael@0: frame = frame.caller; michael@0: } michael@0: } michael@0: michael@0: // Walk even up more until the next file has been found michael@0: while (frame.caller && michael@0: (!frame.filename || (frame.filename.indexOf(filename) != -1))) michael@0: frame = frame.caller; michael@0: michael@0: return frame; michael@0: }