Report exceptions to JS when the DOM implementation fails.

As a bonus, adds some debugging statements.
Add test.