function ownerDocument(node) {
  if (!node) {
    return document;
  } else if (node.nodeType == DOM_DOCUMENT_NODE) {
    return /** @type Document */(node);
  } else {
    return node.ownerDocument || document;
  }
}
Returns the document owner of the given element. In particular,
returns window.document if node is null or the browser does not
support ownerDocument.  If the node is a document itself, returns
itself.

@param {Node|null|undefined} node  The node whose ownerDocument is required.
@returns {Document}  The owner document or window.document if unsupported.