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: #20709
Reviewed-By: Yuta Hiroto <hello@hiroppy.me>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
danbev authored and MylesBorins committed May 22, 2018
1 parent d5db576 commit 678b754
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 678b754

Please sign in to comment.