Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
forked fromnodejs/node

Commitd327cc2

Browse files
committed
url: backport non-major changes fromnodejs#46904
1 parent17e3fd0 commitd327cc2

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

‎lib/internal/modules/cjs/loader.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const { BuiltinModule } = require('internal/bootstrap/loaders');
7979
const{
8080
maybeCacheSourceMap,
8181
}=require('internal/source_map/source_map_cache');
82-
const{ pathToFileURL, fileURLToPath,isURLInstance}=require('internal/url');
82+
const{ pathToFileURL, fileURLToPath,isURL}=require('internal/url');
8383
const{
8484
deprecate,
8585
emitExperimentalWarning,
@@ -1363,7 +1363,7 @@ const createRequireError = 'must be a file URL object, file URL string, or ' +
13631363
functioncreateRequire(filename){
13641364
letfilepath;
13651365

1366-
if(isURLInstance(filename)||
1366+
if(isURL(filename)||
13671367
(typeoffilename==='string'&&!path.isAbsolute(filename))){
13681368
try{
13691369
filepath=fileURLToPath(filename);

‎lib/internal/modules/esm/loader.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const {
3131
ERR_INVALID_RETURN_VALUE,
3232
ERR_UNKNOWN_MODULE_FORMAT,
3333
}=require('internal/errors').codes;
34-
const{ pathToFileURL,isURLInstance,URL}=require('internal/url');
34+
const{ pathToFileURL,isURL,URL}=require('internal/url');
3535
const{ emitExperimentalWarning}=require('internal/util');
3636
const{
3737
isAnyArrayBuffer,
@@ -789,7 +789,7 @@ class ESMLoader {
789789
if(
790790
!isMain&&
791791
typeofparentURL!=='string'&&
792-
!isURLInstance(parentURL)
792+
!isURL(parentURL)
793793
){
794794
thrownewERR_INVALID_ARG_TYPE(
795795
'parentURL',

‎lib/internal/url.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,16 @@ 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+
*
567+
*@param {*} self
568+
*@returns {self is URL}
569+
*/
560570
functionisURL(self){
561571
returnself!=null&&ObjectPrototypeHasOwnProperty(self,context);
562572
}
@@ -1235,7 +1245,7 @@ function getPathFromURLPosix(url) {
12351245
functionfileURLToPath(path){
12361246
if(typeofpath==='string')
12371247
path=newURL(path);
1238-
elseif(!isURLInstance(path))
1248+
elseif(!isURL(path))
12391249
thrownewERR_INVALID_ARG_TYPE('path',['string','URL'],path);
12401250
if(path.protocol!=='file:')
12411251
thrownewERR_INVALID_URL_SCHEME('file');
@@ -1311,12 +1321,8 @@ function pathToFileURL(filepath) {
13111321
returnoutURL;
13121322
}
13131323

1314-
functionisURLInstance(fileURLOrPath){
1315-
returnfileURLOrPath!=null&&fileURLOrPath.href&&fileURLOrPath.origin;
1316-
}
1317-
13181324
functiontoPathIfFileURL(fileURLOrPath){
1319-
if(!isURLInstance(fileURLOrPath))
1325+
if(!isURL(fileURLOrPath))
13201326
returnfileURLOrPath;
13211327
returnfileURLToPath(fileURLOrPath);
13221328
}
@@ -1326,7 +1332,6 @@ module.exports = {
13261332
fileURLToPath,
13271333
pathToFileURL,
13281334
toPathIfFileURL,
1329-
isURLInstance,
13301335
URL,
13311336
URLSearchParams,
13321337
domainToASCII,

‎lib/internal/worker.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const {
5555
WritableWorkerStdio,
5656
}=workerIo;
5757
const{ deserializeError}=require('internal/error_serdes');
58-
const{ fileURLToPath,isURLInstance, pathToFileURL}=require('internal/url');
58+
const{ fileURLToPath,isURL, pathToFileURL}=require('internal/url');
5959
const{ kEmptyObject}=require('internal/util');
6060
const{ validateArray, validateString}=require('internal/validators');
6161

@@ -145,13 +145,13 @@ class Worker extends EventEmitter {
145145
}
146146
url=null;
147147
doEval='classic';
148-
}elseif(isURLInstance(filename)&&filename.protocol==='data:'){
148+
}elseif(isURL(filename)&&filename.protocol==='data:'){
149149
url=null;
150150
doEval='module';
151151
filename=`import${JSONStringify(`${filename}`)}`;
152152
}else{
153153
doEval=false;
154-
if(isURLInstance(filename)){
154+
if(isURL(filename)){
155155
url=filename;
156156
filename=fileURLToPath(filename);
157157
}elseif(typeoffilename!=='string'){

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp