function searchForReference(object, needle) {
  const /** !Set<!Object> */ visited = new Set();
  const /** !Array<string> */ stack = [];
  /** @return {boolean} */
  const doSearch = (/** !Object */ object, /** ? */ needle) => {
    if (object === needle) {
      return true;
    }
    if (!object || visited.has(object)) {
      return false;  // cycle or null
    }
    visited.add(object);
    for (const key in object) {
      stack.push(key);
      if (doSearch(object[key], needle)) {
        return true;
      }
      stack.pop();
    }
    return false;
  };
  if (doSearch(object, needle)) {
    return stack;
  }
  return null;
}
Searches an object for a value and returns the path to it, or `null` if it
cannot be found.

@param {!Object} object The object to search, recursively
@param {?} needle The value to search for
@return {?Array<string>} the path to the value, or `null` if there is no such
    path