Skip to content

Commit

Permalink
module: introduce defaultModuleName in module.js
Browse files Browse the repository at this point in the history
This commit adds a constant named defaultModuleName to avoid duplicating
it in the Module constructor function.

PR-URL: nodejs#20709
Reviewed-By: Yuta Hiroto <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
danbev committed May 16, 2018
1 parent 2b8cd93 commit ea01d30
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/internal/vm/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const linkingStatusMap = new WeakMap();
const initImportMetaMap = new WeakMap();
// ModuleWrap -> vm.Module
const wrapToModuleMap = new WeakMap();
const defaultModuleName = 'vm:module';

class Module {
constructor(src, options = {}) {
Expand Down Expand Up @@ -82,13 +83,13 @@ class Module {
}
url = new URL(url).href;
} else if (context === undefined) {
url = `vm:module(${globalModuleId++})`;
url = `${defaultModuleName}(${globalModuleId++})`;
} else if (perContextModuleId.has(context)) {
const curId = perContextModuleId.get(context);
url = `vm:module(${curId})`;
url = `${defaultModuleName}(${curId})`;
perContextModuleId.set(context, curId + 1);
} else {
url = 'vm:module(0)';
url = `${defaultModuleName}(0)`;
perContextModuleId.set(context, 1);
}

Expand Down

0 comments on commit ea01d30

Please sign in to comment.