@@ -536,6 +536,16 @@ ObjectDefineProperties(URLSearchParams.prototype, {
536536 } ,
537537} ) ;
538538
539+ /**
540+ * Checks if a value has the shape of a WHATWG URL object.
541+ *
542+ * Using a symbol or instanceof would not be able to recognize URL objects
543+ * coming from other implementations (e.g. in Electron), so instead we are
544+ * checking some well known properties for a lack of a better test.
545+ *
546+ * @param {* } self
547+ * @returns {self is URL }
548+ */
539549function isURL ( self ) {
540550 return self != null && ObjectPrototypeHasOwnProperty ( self , context ) ;
541551}
@@ -1209,7 +1219,7 @@ function getPathFromURLPosix(url) {
12091219function fileURLToPath ( path ) {
12101220 if ( typeof path === 'string' )
12111221 path = new URL ( path ) ;
1212- else if ( ! isURLInstance ( path ) )
1222+ else if ( ! isURL ( path ) )
12131223 throw new ERR_INVALID_ARG_TYPE ( 'path' , [ 'string' , 'URL' ] , path ) ;
12141224 if ( path . protocol !== 'file:' )
12151225 throw new ERR_INVALID_URL_SCHEME ( 'file' ) ;
@@ -1285,12 +1295,8 @@ function pathToFileURL(filepath) {
12851295 return outURL ;
12861296}
12871297
1288- function isURLInstance ( fileURLOrPath ) {
1289- return fileURLOrPath != null && fileURLOrPath . href && fileURLOrPath . origin ;
1290- }
1291-
12921298function toPathIfFileURL ( fileURLOrPath ) {
1293- if ( ! isURLInstance ( fileURLOrPath ) )
1299+ if ( ! isURL ( fileURLOrPath ) )
12941300 return fileURLOrPath ;
12951301 return fileURLToPath ( fileURLOrPath ) ;
12961302}
@@ -1300,7 +1306,6 @@ module.exports = {
13001306 fileURLToPath,
13011307 pathToFileURL,
13021308 toPathIfFileURL,
1303- isURLInstance,
13041309 URL ,
13051310 URLSearchParams,
13061311 domainToASCII,
0 commit comments