summaryrefslogtreecommitdiff
path: root/lib/internal/loader/ModuleMap.js
blob: dce8f834ba6d1002bde636a3602fd5b5f5248ac2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'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;