Initial history.length should be 1, not 0.

This brings jsdom in line with both the spec and with browsers, and fixes an issue
where calling `history.pushState()` and then `history.back()` would fail to trigger a
`popstate` event for the `back()` call, since there was no initial history entry to
navigate back to.

From https://html.spec.whatwg.org/multipage/browsers.html#browsing-context:

"When a browsing context is first created, it must be created with a single Document in its session history..."
pushState()/replaceState() shouldn't fire popstate

The spec doesn't say that `pushState()` or `replaceState()` should trigger a
`popstate` event, and browsers don't fire a `popstate` event after a `pushState()` or
`replaceState()` call. `popstate` should only be fired during traversal.

https://html.spec.whatwg.org/multipage/browsers.html#history-1
Cleanups to the living level

This more clearly modularizes the code while avoiding side effects.