tmpvar/jsdom — pull request #489 by johanoverip (2012-09-07 12:33:57+00:00)
Title: Updated document.write() to behave properly

The current implementation replaces the contents of the *last added* element with whatever is being written by document.write. This causes issues with for example the following structure.

```html

```

The above markup would currently cause the following DOM.

* div
* script
* div
* span
* p
* #text

While it *should* end up with the below.

* div
* script
* p
* #text
* div
* span

I have updated the document.write method to insert the new DOM elements after the script tag being executed, if this happens during the initial tick (before control is returned to JSDOM). This fixes issues with a *lot* of pages on the internet as well. For example the DOM of [duckduckgo.com](https://duckduckgo.com/) gets really messed up without this fix.

This implementation is lacking one thing from the spec however, written data is not buffered until the ending script tag while it should be. The current implementation doesn't do this either however (in fact it trashes any document.write before it), so it should be of little importance at this stage.

This mostly fixes #403.