/**
 * Walk a set of params looking for 'nsGetterAddRefs', and add the referenced
 * variables to the list.
 */
function walk_params(params, list, allparams)
{
  for each (var p in params) {
    if (p.isFunction)
      continue;

    if (p.name == 'getter_AddRefs') {
      if (p.params.length != 1) {
        print("Unexpected number of arguments to getter_AddRefs");
      }
      else if (p.params[0].isFcall) {
        print("Function result passed to getter_AddRefs");
      }
      else {
        list.push(p.params[0].name);
      }
    }
    else if (p.type == 'nsGetterAddRefs') {
      print("Returning nsGetterAddRefs but not from getter_AddRefs?");
    }
    else if (p.isFcall) {
      walk_params(p.params, list, allparams);
    }
    else if (list.indexOf(p.name) != -1) {
      print("Gotcha: using gotten value immediately after getting: " + allparams);
    }
  }
}

function process(vars, state)
{
    var gotten = [];
    walk_params(vars, gotten, vars);
}
