From 7a547098d5b13e14b8ad86145fd889fb18b7f3d4 Mon Sep 17 00:00:00 2001 From: Myles Borins Date: Thu, 28 Mar 2019 01:21:15 -0400 Subject: [PATCH] esm: use primordials MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Converted uses of Object and Map to use frozen built in primordials. PR-URL: https://github.com/nodejs/node/pull/26954 Reviewed-By: Michaƫl Zasso Reviewed-By: Ruben Bridgewater Reviewed-By: Guy Bedford Reviewed-By: Gus Caplan Reviewed-By: Joyee Cheung --- lib/internal/modules/esm/default_resolve.js | 7 ++++++- lib/internal/modules/esm/loader.js | 7 ++++++- lib/internal/modules/esm/translators.js | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/internal/modules/esm/default_resolve.js b/lib/internal/modules/esm/default_resolve.js index 8da24cf5b3afab..8b8c5a2b5af702 100644 --- a/lib/internal/modules/esm/default_resolve.js +++ b/lib/internal/modules/esm/default_resolve.js @@ -17,7 +17,12 @@ const { pathToFileURL, fileURLToPath } = require('internal/url'); const { ERR_ENTRY_TYPE_MISMATCH, ERR_UNKNOWN_FILE_EXTENSION } = require('internal/errors').codes; -const realpathCache = new Map(); +const { + Object, + SafeMap +} = primordials; + +const realpathCache = new SafeMap(); // const TYPE_NONE = 0; const TYPE_COMMONJS = 1; diff --git a/lib/internal/modules/esm/loader.js b/lib/internal/modules/esm/loader.js index 465775f56ffc72..88f03119fcfc80 100644 --- a/lib/internal/modules/esm/loader.js +++ b/lib/internal/modules/esm/loader.js @@ -22,6 +22,11 @@ const FunctionBind = Function.call.bind(Function.prototype.bind); const debug = require('internal/util/debuglog').debuglog('esm'); +const { + Object, + SafeMap +} = primordials; + /* A Loader instance is used as the main entry point for loading ES modules. * Currently, this is a singleton -- there is only one used for loading * the main module and everything in its dependency graph. */ @@ -35,7 +40,7 @@ class Loader { this.moduleMap = new ModuleMap(); // Map of already-loaded CJS modules to use - this.cjsCache = new Map(); + this.cjsCache = new SafeMap(); // The resolver has the signature // (specifier : string, parentURL : string, defaultResolve) diff --git a/lib/internal/modules/esm/translators.js b/lib/internal/modules/esm/translators.js index 172569fb042c69..4b2db024c5848f 100644 --- a/lib/internal/modules/esm/translators.js +++ b/lib/internal/modules/esm/translators.js @@ -13,6 +13,7 @@ const createDynamicModule = require( const fs = require('fs'); const { SafeMap, + JSON } = primordials; const { fileURLToPath, URL } = require('url'); const { debuglog } = require('internal/util/debuglog');