services/sync/tps/extensions/mozmill/resource/modules/stack.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/services/sync/tps/extensions/mozmill/resource/modules/stack.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,43 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, you can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +var EXPORTED_SYMBOLS = ['findCallerFrame'];
     1.9 +
    1.10 +
    1.11 +/**
    1.12 + * @namespace Defines utility methods for handling stack frames
    1.13 + */
    1.14 +
    1.15 +/**
    1.16 + * Find the frame to use for logging the test result. If a start frame has
    1.17 + * been specified, we walk down the stack until a frame with the same filename
    1.18 + * as the start frame has been found. The next file in the stack will be the
    1.19 + * frame to use for logging the result.
    1.20 + *
    1.21 + * @memberOf stack
    1.22 + * @param {Object} [aStartFrame=Components.stack] Frame to start from walking up the stack.
    1.23 + * @returns {Object} Frame of the stack to use for logging the result.
    1.24 + */
    1.25 +function findCallerFrame(aStartFrame) {
    1.26 +  let frame = Components.stack;
    1.27 +  let filename = frame.filename.replace(/(.*)-> /, "");
    1.28 +
    1.29 +  // If a start frame has been specified, walk up the stack until we have
    1.30 +  // found the corresponding file
    1.31 +  if (aStartFrame) {
    1.32 +    filename = aStartFrame.filename.replace(/(.*)-> /, "");
    1.33 +
    1.34 +    while (frame.caller &&
    1.35 +           frame.filename && (frame.filename.indexOf(filename) == -1)) {
    1.36 +      frame = frame.caller;
    1.37 +    }
    1.38 +  }
    1.39 +
    1.40 +  // Walk even up more until the next file has been found
    1.41 +  while (frame.caller &&
    1.42 +         (!frame.filename || (frame.filename.indexOf(filename) != -1)))
    1.43 +    frame = frame.caller;
    1.44 +
    1.45 +  return frame;
    1.46 +}

mercurial