From 3bd24d8d5a695a17acc061c463f5ce3f9f9903b2 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 10 Jun 2021 11:05:37 +0200 Subject: [PATCH] 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. --- src/display/display_utils.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/display/display_utils.js b/src/display/display_utils.js index 72f25810e..eba1a6fbd 100644 --- a/src/display/display_utils.js +++ b/src/display/display_utils.js @@ -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); } }