Skip to content

Commit 7a54709

Browse files
MylesBorinstargos
authored andcommitted
esm: use primordials
Converted uses of Object and Map to use frozen built in primordials. PR-URL: #26954 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Guy Bedford <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
1 parent 6bc2ab1 commit 7a54709

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

lib/internal/modules/esm/default_resolve.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ const { pathToFileURL, fileURLToPath } = require('internal/url');
1717
const { ERR_ENTRY_TYPE_MISMATCH,
1818
ERR_UNKNOWN_FILE_EXTENSION } = require('internal/errors').codes;
1919

20-
const realpathCache = new Map();
20+
const {
21+
Object,
22+
SafeMap
23+
} = primordials;
24+
25+
const realpathCache = new SafeMap();
2126

2227
// const TYPE_NONE = 0;
2328
const TYPE_COMMONJS = 1;

lib/internal/modules/esm/loader.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ const FunctionBind = Function.call.bind(Function.prototype.bind);
2222

2323
const debug = require('internal/util/debuglog').debuglog('esm');
2424

25+
const {
26+
Object,
27+
SafeMap
28+
} = primordials;
29+
2530
/* A Loader instance is used as the main entry point for loading ES modules.
2631
* Currently, this is a singleton -- there is only one used for loading
2732
* the main module and everything in its dependency graph. */
@@ -35,7 +40,7 @@ class Loader {
3540
this.moduleMap = new ModuleMap();
3641

3742
// Map of already-loaded CJS modules to use
38-
this.cjsCache = new Map();
43+
this.cjsCache = new SafeMap();
3944

4045
// The resolver has the signature
4146
// (specifier : string, parentURL : string, defaultResolve)

lib/internal/modules/esm/translators.js

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const createDynamicModule = require(
1313
const fs = require('fs');
1414
const {
1515
SafeMap,
16+
JSON
1617
} = primordials;
1718
const { fileURLToPath, URL } = require('url');
1819
const { debuglog } = require('internal/util/debuglog');

0 commit comments

Comments
 (0)