Rebased from #14661. --- - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #12744 and partially #9604 - [X] There are tests for these changes Source-Repo: https://github.com/servo/servo Source-Revision: eb72c0ec7bc1e3547aa09fbe2ad800310f42989b