mirror of
https://github.com/nodejs/node.git
synced 2026-11-29 14:27:57 -05:00
module: use validateString in modules/esm
PR-URL: https://github.com/nodejs/node/pull/24868 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This commit is contained in:
1 parent
a91293d4d9
commit
d695a019ae
2 files changed
+7
-12
No files matched your search
@@ -1,7 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const {
|
||||
ERR_INVALID_ARG_TYPE,
|
||||
ERR_INVALID_RETURN_PROPERTY,
|
||||
ERR_INVALID_RETURN_PROPERTY_VALUE,
|
||||
ERR_INVALID_RETURN_VALUE,
|
||||
@@ -9,6 +8,7 @@ const {
|
||||
ERR_UNKNOWN_MODULE_FORMAT
|
||||
} = require('internal/errors').codes;
|
||||
const { URL } = require('url');
|
||||
const { validateString } = require('internal/validators');
|
||||
const ModuleMap = require('internal/modules/esm/module_map');
|
||||
const ModuleJob = require('internal/modules/esm/module_job');
|
||||
const defaultResolve = require('internal/modules/esm/default_resolve');
|
||||
@@ -52,8 +52,8 @@ class Loader {
|
||||
|
||||
async resolve(specifier, parentURL) {
|
||||
const isMain = parentURL === undefined;
|
||||
if (!isMain && typeof parentURL !== 'string')
|
||||
throw new ERR_INVALID_ARG_TYPE('parentURL', 'string', parentURL);
|
||||
if (!isMain)
|
||||
validateString(parentURL, 'parentURL');
|
||||
|
||||
const resolved = await this._resolve(specifier, parentURL, defaultResolve);
|
||||
|
||||
|
||||
@@ -4,19 +4,16 @@ const ModuleJob = require('internal/modules/esm/module_job');
|
||||
const { SafeMap } = require('internal/safe_globals');
|
||||
const debug = require('util').debuglog('esm');
|
||||
const { ERR_INVALID_ARG_TYPE } = require('internal/errors').codes;
|
||||
const { validateString } = require('internal/validators');
|
||||
|
||||
// Tracks the state of the loader-level module cache
|
||||
class ModuleMap extends SafeMap {
|
||||
get(url) {
|
||||
if (typeof url !== 'string') {
|
||||
throw new ERR_INVALID_ARG_TYPE('url', 'string', url);
|
||||
}
|
||||
validateString(url, 'url');
|
||||
return super.get(url);
|
||||
}
|
||||
set(url, job) {
|
||||
if (typeof url !== 'string') {
|
||||
throw new ERR_INVALID_ARG_TYPE('url', 'string', url);
|
||||
}
|
||||
validateString(url, 'url');
|
||||
if (job instanceof ModuleJob !== true) {
|
||||
throw new ERR_INVALID_ARG_TYPE('job', 'ModuleJob', job);
|
||||
}
|
||||
@@ -24,9 +21,7 @@ class ModuleMap extends SafeMap {
|
||||
return super.set(url, job);
|
||||
}
|
||||
has(url) {
|
||||
if (typeof url !== 'string') {
|
||||
throw new ERR_INVALID_ARG_TYPE('url', 'string', url);
|
||||
}
|
||||
validateString(url, 'url');
|
||||
return super.has(url);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user