From 14e0a418bf8652a9d9ecbcb9d9e0462b7762a647 Mon Sep 17 00:00:00 2001 From: tophf Date: Mon, 17 Jan 2022 03:53:16 +0300 Subject: [PATCH] create URL fallback only when necessary --- js/toolbox.js | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/js/toolbox.js b/js/toolbox.js index a11ae1c0..4e8a277e 100644 --- a/js/toolbox.js +++ b/js/toolbox.js @@ -290,26 +290,24 @@ function tryJSONparse(jsonString) { } catch (e) {} } -function tryURL( - url, - fallback = { - hash: '', - host: '', - hostname: '', - href: '', - origin: '', - password: '', - pathname: '', - port: '', - protocol: '', - search: '', - searchParams: new URLSearchParams(), - username: '', - }) { +function tryURL(url) { try { return new URL(url); } catch (e) { - return fallback; + return { + hash: '', + host: '', + hostname: '', + href: '', + origin: '', + password: '', + pathname: '', + port: '', + protocol: '', + search: '', + searchParams: new URLSearchParams(), + username: '', + }; } }