Look for the root in an iterative way.

Uses a while loop instead of recursivly calling `parentNode`. Reuses node.ownerDocument when shadowRoot isn't supported.