Improve the error handling when loading of built-in CMap files fail (PR 8064 follow-up)

I happened to notice that the error handling wasn't that great, which I missed previously since there were no unit-tests for failure to load built-in CMap files.
Hence this patch, which improves the error handling *and* adds tests.
This commit is contained in:
Jonas Jenwald 2017-03-28 12:08:44 +02:00
parent 07f7c97b2b
commit 437104969d
3 changed files with 48 additions and 6 deletions

View file

@ -90,8 +90,10 @@ var DOMCMapReaderFactory = (function DOMCMapReaderFactoryClosure() {
request.responseType = 'arraybuffer';
}
request.onreadystatechange = function () {
if (request.readyState === XMLHttpRequest.DONE &&
(request.status === 200 || request.status === 0)) {
if (request.readyState !== XMLHttpRequest.DONE) {
return;
}
if (request.status === 200 || request.status === 0) {
var data;
if (this.isCompressed && request.response) {
data = new Uint8Array(request.response);
@ -106,10 +108,10 @@ var DOMCMapReaderFactory = (function DOMCMapReaderFactoryClosure() {
});
return;
}
reject(new Error('Unable to load ' +
(this.isCompressed ? 'binary ' : '') +
'CMap at: ' + url));
}
reject(new Error('Unable to load ' +
(this.isCompressed ? 'binary ' : '') +
'CMap at: ' + url));
}.bind(this);
request.send(null);