@@ -557,6 +557,15 @@ ObjectDefineProperties(URLSearchParams.prototype, {
557
557
} ,
558
558
} ) ;
559
559
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
+ */
560
569
function isURL ( self ) {
561
570
return self != null && ObjectPrototypeHasOwnProperty ( self , context ) ;
562
571
}
@@ -1235,7 +1244,7 @@ function getPathFromURLPosix(url) {
1235
1244
function fileURLToPath ( path ) {
1236
1245
if ( typeof path === 'string' )
1237
1246
path = new URL ( path ) ;
1238
- else if ( ! isURLInstance ( path ) )
1247
+ else if ( ! isURL ( path ) )
1239
1248
throw new ERR_INVALID_ARG_TYPE ( 'path' , [ 'string' , 'URL' ] , path ) ;
1240
1249
if ( path . protocol !== 'file:' )
1241
1250
throw new ERR_INVALID_URL_SCHEME ( 'file' ) ;
@@ -1311,12 +1320,8 @@ function pathToFileURL(filepath) {
1311
1320
return outURL ;
1312
1321
}
1313
1322
1314
- function isURLInstance ( fileURLOrPath ) {
1315
- return fileURLOrPath != null && fileURLOrPath . href && fileURLOrPath . origin ;
1316
- }
1317
-
1318
1323
function toPathIfFileURL ( fileURLOrPath ) {
1319
- if ( ! isURLInstance ( fileURLOrPath ) )
1324
+ if ( ! isURL ( fileURLOrPath ) )
1320
1325
return fileURLOrPath ;
1321
1326
return fileURLToPath ( fileURLOrPath ) ;
1322
1327
}
@@ -1326,7 +1331,6 @@ module.exports = {
1326
1331
fileURLToPath,
1327
1332
pathToFileURL,
1328
1333
toPathIfFileURL,
1329
- isURLInstance,
1330
1334
URL ,
1331
1335
URLSearchParams,
1332
1336
domainToASCII,
0 commit comments