Use more internal mutability for DOM objects.

Part of #1854.