From 100c749c2adc485e7b00822a1f9df44d02bee7cf Mon Sep 17 00:00:00 2001 From: Aviv Keller <38299977+RedYetiDev@users.noreply.github.com> Date: Sat, 4 May 2024 11:00:07 -0400 Subject: [PATCH 1/4] url: improve `isURL` performance by adding a typecheck --- lib/internal/url.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/url.js b/lib/internal/url.js index 9c18aab07ff19d..0dcc4823c64a45 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -767,7 +767,7 @@ ObjectDefineProperties(URLSearchParams.prototype, { * @returns {self is URL} */ function isURL(self) { - return Boolean(self?.href && self.protocol && self.auth === undefined && self.path === undefined); + return typeof self === 'object' && Boolean(self?.href && self.protocol && self.auth === undefined && self.path === undefined); } /** From d38d2f89bb37cf321c0a933ebdf9187cbb5106ba Mon Sep 17 00:00:00 2001 From: Aviv Keller <38299977+RedYetiDev@users.noreply.github.com> Date: Sat, 4 May 2024 11:02:43 -0400 Subject: [PATCH 2/4] url: remove extra imports --- lib/internal/url.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/internal/url.js b/lib/internal/url.js index 0dcc4823c64a45..431aafd93effaa 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -8,7 +8,6 @@ const { ArrayPrototypePush, ArrayPrototypeReduce, ArrayPrototypeSlice, - Boolean, Int8Array, IteratorPrototype, Number, @@ -767,7 +766,7 @@ ObjectDefineProperties(URLSearchParams.prototype, { * @returns {self is URL} */ function isURL(self) { - return typeof self === 'object' && Boolean(self?.href && self.protocol && self.auth === undefined && self.path === undefined); + return typeof self === 'object' && self.href && self.protocol && self.auth === undefined && self.path === undefined; } /** From e93e0433f0169f524991d6cec9fa4339dd1949a0 Mon Sep 17 00:00:00 2001 From: Aviv Keller <38299977+RedYetiDev@users.noreply.github.com> Date: Sat, 4 May 2024 11:15:21 -0400 Subject: [PATCH 3/4] url: add null-check --- lib/internal/url.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/url.js b/lib/internal/url.js index 431aafd93effaa..f1361cc55770a2 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -766,7 +766,7 @@ ObjectDefineProperties(URLSearchParams.prototype, { * @returns {self is URL} */ function isURL(self) { - return typeof self === 'object' && self.href && self.protocol && self.auth === undefined && self.path === undefined; + return typeof self === 'object' && self?.href && self.protocol && self.auth === undefined && self.path === undefined; } /** From 0eba487b3ff64600a06500f036694bd59486a355 Mon Sep 17 00:00:00 2001 From: Aviv Keller <38299977+RedYetiDev@users.noreply.github.com> Date: Sat, 4 May 2024 11:18:21 -0400 Subject: [PATCH 4/4] url: lint and ensure boolean --- lib/internal/url.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/internal/url.js b/lib/internal/url.js index f1361cc55770a2..c2d2971e168a37 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -8,6 +8,7 @@ const { ArrayPrototypePush, ArrayPrototypeReduce, ArrayPrototypeSlice, + Boolean, Int8Array, IteratorPrototype, Number, @@ -766,7 +767,11 @@ ObjectDefineProperties(URLSearchParams.prototype, { * @returns {self is URL} */ function isURL(self) { - return typeof self === 'object' && self?.href && self.protocol && self.auth === undefined && self.path === undefined; + return Boolean(typeof self === 'object' && + self?.href && + self.protocol && + self.auth === undefined && + self.path === undefined); } /**