packages/devtools-reps/src/reps/error.js
function parseStackString(stack) {
  const res = [];
  if (!stack) {
    return res;
  }

  const isStacktraceALongString = isLongString(stack);
  const stackString = isStacktraceALongString ? stack.initial : stack;

  stackString.split("\n").forEach((frame, index, frames) => {
    if (!frame) {
      // Skip any blank lines
      return;
    }

    // If the stacktrace is a longString, don't include the last frame in the
    // array, since it is certainly incomplete.
    // Can be removed when https://bugzilla.mozilla.org/show_bug.cgi?id=1448833
    // is fixed.
    if (isStacktraceALongString && index === frames.length - 1) {
      return;
    }

    let functionName;
    let location;

    // Given the input: "functionName@scriptLocation:2:100"
    // Result: [
    //   "functionName@scriptLocation:2:100",
    //   "functionName",
    //   "scriptLocation:2:100"
    // ]
    const result = frame.match(/^(.*)@(.*)$/);
    if (result && result.length === 3) {
      functionName = result[1];

      // If the resource was loaded by base-loader.js, the location looks like:
      // resource://devtools/shared/base-loader.js -> resource://path/to/file.js .
      // What's needed is only the last part after " -> ".
      location = result[2].split(" -> ").pop();
    }

    if (!functionName) {
      functionName = "<anonymous>";
    }

    // Given the input: "scriptLocation:2:100"
    // Result:
    // ["scriptLocation:2:100", "scriptLocation", "2", "100"]
    const locationParts = location.match(/^(.*):(\d+):(\d+)$/);

    if (location && locationParts) {
      const [, filename, line, column] = locationParts;
      res.push({
        filename,
        functionName,
        location,
        columnNumber: Number(column),
        lineNumber: Number(line)
      });
    }
  });

  return res;
}
function parseStackString(stack) {
  const res = [];
  if (!stack) {
    return res;
  }

  const isStacktraceALongString = isLongString(stack);
  const stackString = isStacktraceALongString ? stack.initial : stack;

  stackString.split("\n").forEach((frame, index, frames) => {
    if (!frame) {
      // Skip any blank lines
      return;
    }

    // If the stacktrace is a longString, don't include the last frame in the
    // array, since it is certainly incomplete.
    // Can be removed when https://bugzilla.mozilla.org/show_bug.cgi?id=1448833
    // is fixed.
    if (isStacktraceALongString && index === frames.length - 1) {
      return;
    }

    let functionName;
    let location;

    // Given the input: "functionName@scriptLocation:2:100"
    // Result: [
    //   "functionName@scriptLocation:2:100",
    //   "functionName",
    //   "scriptLocation:2:100"
    // ]
    const result = frame.match(/^(.*)@(.*)$/);
    if (result && result.length === 3) {
      functionName = result[1];

      // If the resource was loaded by base-loader.js, the location looks like:
      // resource://devtools/shared/base-loader.js -> resource://path/to/file.js .
      // What's needed is only the last part after " -> ".
      location = result[2].split(" -> ").pop();
    }

    if (!functionName) {
      functionName = "<anonymous>";
    }

    // Given the input: "scriptLocation:2:100"
    // Result:
    // ["scriptLocation:2:100", "scriptLocation", "2", "100"]
    const locationParts = location.match(/^(.*):(\d+):(\d+)$/);

    if (location && locationParts) {
      const [, filename, line, column] = locationParts;
      res.push({
        filename,
        functionName,
        location,
        columnNumber: Number(column),
        lineNumber: Number(line)
      });
    }
  });

  return res;
}
function parseStackString ( stack ) { const res = [ ] ; if ( ! stack ) { return res ; } const isStacktraceALongString = isLongString ( stack ) ; const stackString = isStacktraceALongString ? stack . initial : stack ; stackString . split ( "\n" ) . forEach ( ( frame , index , frames ) => { if ( ! frame ) { // Skip any blank lines return ; } // If the stacktrace is a longString, don't include the last frame in the // array, since it is certainly incomplete. // Can be removed when https://bugzilla.mozilla.org/show_bug.cgi?id=1448833 // is fixed. if ( isStacktraceALongString && index === frames . length - 1 ) { return ; } let functionName ; let location ; // Given the input: "functionName@scriptLocation:2:100" // Result: [ //   "functionName@scriptLocation:2:100", //   "functionName", //   "scriptLocation:2:100" // ] const result = frame . match ( / ^(.*)@(.*)$ / ) ; if ( result && result . length === 3 ) { functionName = result [ 1 ] ; // If the resource was loaded by base-loader.js, the location looks like: // resource://devtools/shared/base-loader.js -> resource://path/to/file.js . // What's needed is only the last part after " -> ". location = result [ 2 ] . split ( " -> " ) . pop ( ) ; } if ( ! functionName ) { functionName = "<anonymous>" ; } // Given the input: "scriptLocation:2:100" // Result: // ["scriptLocation:2:100", "scriptLocation", "2", "100"] const locationParts = location . match ( / ^(.*):(\d+):(\d+)$ / ) ; if ( location && locationParts ) { const [ , filename , line , column ] = locationParts ; res . push ( { filename , functionName , location , columnNumber : Number ( column ) , lineNumber : Number ( line ) } ) ; } } ) ; return res ; }
Parse a string that should represent a stack trace and returns an array of
the frames. The shape of the frames are extremely important as they can then
be processed here or in the toolbox by other components.
@param {String} stack
@returns {Array} Array of frames, which are object with the following shape:
- {String} filename
- {String} functionName
- {String} location
- {Number} columnNumber
- {Number} lineNumber
Parse a string that should represent a stack trace and returns an array of the frames . The shape of the frames are extremely important as they can then be processed here or in the toolbox by other components .