function withDoc(document, func) {
    var oldDoc = doc;
    doc = document;
    try {
      func();
    } finally {
      doc = oldDoc;
    }
  }
Allows you to run func in the context of a different document.
@param {!Document} document The document to use.
@param {function():*} func The function to call.