mirror of
https://github.com/nodejs/node.git
synced 2025-05-13 02:59:02 +00:00

Store all primordials as properties of the primordials object. Static functions are prefixed by the constructor's name and prototype methods are prefixed by the constructor's name followed by "Prototype". For example: primordials.Object.keys becomes primordials.ObjectKeys. PR-URL: https://github.com/nodejs/node/pull/30610 Refs: https://github.com/nodejs/node/issues/29766 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
32 lines
853 B
JavaScript
32 lines
853 B
JavaScript
'use strict';
|
|
|
|
const ModuleJob = require('internal/modules/esm/module_job');
|
|
const {
|
|
SafeMap,
|
|
} = primordials;
|
|
const debug = require('internal/util/debuglog').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) {
|
|
validateString(url, 'url');
|
|
return super.get(url);
|
|
}
|
|
set(url, job) {
|
|
validateString(url, 'url');
|
|
if (job instanceof ModuleJob !== true &&
|
|
typeof job !== 'function') {
|
|
throw new ERR_INVALID_ARG_TYPE('job', 'ModuleJob', job);
|
|
}
|
|
debug(`Storing ${url} in ModuleMap`);
|
|
return super.set(url, job);
|
|
}
|
|
has(url) {
|
|
validateString(url, 'url');
|
|
return super.has(url);
|
|
}
|
|
}
|
|
module.exports = ModuleMap;
|