This fixes a regression with :has() on the test-case of bug 1480477 (but we should still aim to make that faster). While at it, avoid synchronization in some really hot paths, and add tests. Differential Revision: https://phabricator.services.mozilla.com/D212039