Throw errors directly, rather than using assert, in the DOMSVGFactory

This is similar to all of the other factories in this file, since they *directly* throw errors.
This commit is contained in:
Jonas Jenwald 2021-06-10 11:05:37 +02:00
parent 26011c65f4
commit 3bd24d8d5a

View File

@ -118,8 +118,9 @@ class DOMStandardFontDataFactory extends BaseStandardFontDataFactory {
class DOMSVGFactory {
create(width, height) {
assert(width > 0 && height > 0, "Invalid SVG dimensions");
if (width <= 0 || height <= 0) {
throw new Error("Invalid SVG dimensions");
}
const svg = document.createElementNS(SVG_NS, "svg:svg");
svg.setAttribute("version", "1.1");
svg.setAttribute("width", width + "px");
@ -131,8 +132,9 @@ class DOMSVGFactory {
}
createElement(type) {
assert(typeof type === "string", "Invalid SVG element type");
if (typeof type !== "string") {
throw new Error("Invalid SVG element type");
}
return document.createElementNS(SVG_NS, type);
}
}