mbostock/d3 — pull request #1956 by jasondavies (2014-07-29 13:46:04+00:00)
Title: Fix InvalidStateError for non-text local files.

Fixes a regression introduced when XDomainRequest support was added in
2eeb2057b2a058a15f9b4d155a4650dcab4ef070. XDomainRequest only supports
request.responseText, not request.response, but XMLHttpRequest throws an
error if request.responseText is read for non-text response types.

A status code of 0 can mean either a local file was accessed, or there
was an error. The response is checked to see if the error flag was set:

* In the case of request.responseType being "text" or "",
request.responseText should be "". Unfortunately it’s impossible to
distinguish between an empty local text file and an error state, but
wanting to load empty local files seems rare.
XDomainRequest doesn’t have a responseType and it only has
responseText, so we handle it here too.

* For other response types, request.response should be null. At the
moment, Safari 7.0.5 doesn’t respect this, e.g. the response will be a
zero-length blob for the "blob" response type if the local file wasn’t
found, but this seems to be fixed as of WebKit r171650.