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

Appearance settings

Commit 25dae6c

Browse filesBrowse files
ZYSzysBethGriggs
authored andcommitted
module: use validateString in modules/esm
PR-URL: #24868 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
1 parent 1f61c89 commit 25dae6c
Copy full SHA for 25dae6c

File tree

Expand file treeCollapse file tree

2 files changed

+7
-12
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+7
-12
lines changed
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: lib/internal/modules/esm/loader.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
'use strict';
22

33
const {
4-
ERR_INVALID_ARG_TYPE,
54
ERR_INVALID_RETURN_PROPERTY,
65
ERR_INVALID_RETURN_PROPERTY_VALUE,
76
ERR_INVALID_RETURN_VALUE,
87
ERR_MISSING_DYNAMIC_INSTANTIATE_HOOK,
98
ERR_UNKNOWN_MODULE_FORMAT
109
} = require('internal/errors').codes;
1110
const { URL } = require('url');
11+
const { validateString } = require('internal/validators');
1212
const ModuleMap = require('internal/modules/esm/module_map');
1313
const ModuleJob = require('internal/modules/esm/module_job');
1414
const defaultResolve = require('internal/modules/esm/default_resolve');
@@ -52,8 +52,8 @@ class Loader {
5252

5353
async resolve(specifier, parentURL) {
5454
const isMain = parentURL === undefined;
55-
if (!isMain && typeof parentURL !== 'string')
56-
throw new ERR_INVALID_ARG_TYPE('parentURL', 'string', parentURL);
55+
if (!isMain)
56+
validateString(parentURL, 'parentURL');
5757

5858
const resolved = await this._resolve(specifier, parentURL, defaultResolve);
5959

Collapse file

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

Copy file name to clipboardExpand all lines: lib/internal/modules/esm/module_map.js
+4-9Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,24 @@ const ModuleJob = require('internal/modules/esm/module_job');
44
const { SafeMap } = require('internal/safe_globals');
55
const debug = require('util').debuglog('esm');
66
const { ERR_INVALID_ARG_TYPE } = require('internal/errors').codes;
7+
const { validateString } = require('internal/validators');
78

89
// Tracks the state of the loader-level module cache
910
class ModuleMap extends SafeMap {
1011
get(url) {
11-
if (typeof url !== 'string') {
12-
throw new ERR_INVALID_ARG_TYPE('url', 'string', url);
13-
}
12+
validateString(url, 'url');
1413
return super.get(url);
1514
}
1615
set(url, job) {
17-
if (typeof url !== 'string') {
18-
throw new ERR_INVALID_ARG_TYPE('url', 'string', url);
19-
}
16+
validateString(url, 'url');
2017
if (job instanceof ModuleJob !== true) {
2118
throw new ERR_INVALID_ARG_TYPE('job', 'ModuleJob', job);
2219
}
2320
debug(`Storing ${url} in ModuleMap`);
2421
return super.set(url, job);
2522
}
2623
has(url) {
27-
if (typeof url !== 'string') {
28-
throw new ERR_INVALID_ARG_TYPE('url', 'string', url);
29-
}
24+
validateString(url, 'url');
3025
return super.has(url);
3126
}
3227
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.