Browse Source

Ensure that the `XMLHttpRequest` is `open`ed before attempting to set the `responseType` in the `DOMCMapReaderFactory`, since IE fails otherwise (issue 8193)

I really cannot understand why this change is necessary, since modern browsers such as Firefox and Chrome work just fine with the old code.
Hence this is patch is yet another "hack" that's needed just because IE apparently cannot just work like you'd expect.

For consistency, the Node factory used in the CMap unit-tests is changed as well.

Fixes 8193.
Jonas Jenwald 8 years ago
parent
commit
5c0c122a7d
  1. 9
      src/display/dom_utils.js
  2. 8
      test/unit/test_utils.js

9
src/display/dom_utils.js

@ -76,15 +76,17 @@ var DOMCMapReaderFactory = (function DOMCMapReaderFactoryClosure() {
DOMCMapReaderFactory.prototype = { DOMCMapReaderFactory.prototype = {
fetch: function(params) { fetch: function(params) {
if (!params.name) { var name = params.name;
if (!name) {
return Promise.reject(new Error('CMap name must be specified.')); return Promise.reject(new Error('CMap name must be specified.'));
} }
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
var url = this.baseUrl + params.name; var url = this.baseUrl + name + (this.isCompressed ? '.bcmap' : '');
var request = new XMLHttpRequest(); var request = new XMLHttpRequest();
request.open('GET', url, true);
if (this.isCompressed) { if (this.isCompressed) {
url += '.bcmap';
request.responseType = 'arraybuffer'; request.responseType = 'arraybuffer';
} }
request.onreadystatechange = function () { request.onreadystatechange = function () {
@ -110,7 +112,6 @@ var DOMCMapReaderFactory = (function DOMCMapReaderFactoryClosure() {
} }
}.bind(this); }.bind(this);
request.open('GET', url, true);
request.send(null); request.send(null);
}.bind(this)); }.bind(this));
}, },

8
test/unit/test_utils.js

@ -35,16 +35,14 @@ var NodeCMapReaderFactory = (function NodeCMapReaderFactoryClosure() {
NodeCMapReaderFactory.prototype = { NodeCMapReaderFactory.prototype = {
fetch: function(params) { fetch: function(params) {
if (!params.name) { var name = params.name;
if (!name) {
return Promise.reject(new Error('CMap name must be specified.')); return Promise.reject(new Error('CMap name must be specified.'));
} }
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
var url = this.baseUrl + params.name; var url = this.baseUrl + name + (this.isCompressed ? '.bcmap' : '');
var fs = require('fs'); var fs = require('fs');
if (this.isCompressed) {
url += '.bcmap';
}
fs.readFile(url, function (error, data) { fs.readFile(url, function (error, data) {
if (error || !data) { if (error || !data) {
reject(new Error('Unable to load ' + reject(new Error('Unable to load ' +

Loading…
Cancel
Save