@@ -557,6 +557,15 @@ ObjectDefineProperties(URLSearchParams.prototype, {
557557 } ,
558558} ) ;
559559
560+ /**
561+ * Checks if a value has the shape of a WHATWG URL object.
562+ *
563+ * Using a symbol or instanceof would not be able to recognize URL objects
564+ * coming from other implementations (e.g. in Electron), so instead we are
565+ * checking some well known properties for a lack of a better test.
566+ * @param {* } self
567+ * @returns {self is URL }
568+ */
560569function isURL ( self ) {
561570 return self != null && ObjectPrototypeHasOwnProperty ( self , context ) ;
562571}
@@ -1235,7 +1244,7 @@ function getPathFromURLPosix(url) {
12351244function fileURLToPath ( path ) {
12361245 if ( typeof path === 'string' )
12371246 path = new URL ( path ) ;
1238- else if ( ! isURLInstance ( path ) )
1247+ else if ( ! isURL ( path ) )
12391248 throw new ERR_INVALID_ARG_TYPE ( 'path' , [ 'string' , 'URL' ] , path ) ;
12401249 if ( path . protocol !== 'file:' )
12411250 throw new ERR_INVALID_URL_SCHEME ( 'file' ) ;
@@ -1311,12 +1320,8 @@ function pathToFileURL(filepath) {
13111320 return outURL ;
13121321}
13131322
1314- function isURLInstance ( fileURLOrPath ) {
1315- return fileURLOrPath != null && fileURLOrPath . href && fileURLOrPath . origin ;
1316- }
1317-
13181323function toPathIfFileURL ( fileURLOrPath ) {
1319- if ( ! isURLInstance ( fileURLOrPath ) )
1324+ if ( ! isURL ( fileURLOrPath ) )
13201325 return fileURLOrPath ;
13211326 return fileURLToPath ( fileURLOrPath ) ;
13221327}
@@ -1326,7 +1331,6 @@ module.exports = {
13261331 fileURLToPath,
13271332 pathToFileURL,
13281333 toPathIfFileURL,
1329- isURLInstance,
13301334 URL ,
13311335 URLSearchParams,
13321336 domainToASCII,
0 commit comments