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