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