mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
PR-URL: https://github.com/nodejs/node/pull/19137 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
34 lines
938 B
JavaScript
34 lines
938 B
JavaScript
'use strict';
|
|
|
|
const ModuleJob = require('internal/loader/ModuleJob');
|
|
const { SafeMap } = require('internal/safe_globals');
|
|
const debug = require('util').debuglog('esm');
|
|
const { ERR_INVALID_ARG_TYPE } = require('internal/errors').codes;
|
|
|
|
// 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');
|
|
}
|
|
return super.get(url);
|
|
}
|
|
set(url, job) {
|
|
if (typeof url !== 'string') {
|
|
throw new ERR_INVALID_ARG_TYPE('url', 'string');
|
|
}
|
|
if (job instanceof ModuleJob !== true) {
|
|
throw new ERR_INVALID_ARG_TYPE('job', 'ModuleJob');
|
|
}
|
|
debug(`Storing ${url} in ModuleMap`);
|
|
return super.set(url, job);
|
|
}
|
|
has(url) {
|
|
if (typeof url !== 'string') {
|
|
throw new ERR_INVALID_ARG_TYPE('url', 'string');
|
|
}
|
|
return super.has(url);
|
|
}
|
|
}
|
|
module.exports = ModuleMap;
|