Merge pull request #14635 from Snuffleupagus/loadStyles-fetch

Replace XMLHttpRequest usage with the Fetch API in `loadStyles` (in `test/driver.js`)
This commit is contained in:
Tim van der Meij 2022-03-06 15:24:40 +01:00 committed by GitHub
commit 3ac2053d97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -44,24 +44,23 @@ function loadStyles(styles) {
for (const file of styles) {
promises.push(
new Promise(function (resolve, reject) {
const xhr = new XMLHttpRequest();
xhr.open("GET", file);
xhr.onload = function () {
resolve(xhr.responseText);
};
xhr.onerror = function (e) {
reject(new Error(`Error fetching style (${file}): ${e}`));
};
xhr.send(null);
})
fetch(file)
.then(response => {
if (!response.ok) {
throw new Error(response.statusText);
}
return response.text();
})
.catch(reason => {
throw new Error(`Error fetching style (${file}): ${reason}`);
})
);
}
return Promise.all(promises);
}
function writeSVG(svgElement, ctx, outputScale) {
function writeSVG(svgElement, ctx) {
// We need to have UTF-8 encoded XML.
const svg_xml = unescape(
encodeURIComponent(new XMLSerializer().serializeToString(svgElement))