Skip to content

Commit e52919f

Browse files
fixup! esm,loaders: tidy ESMLoader internals
ObjectCreate(null) → {__proto__:null}
1 parent 26795de commit e52919f

File tree

8 files changed

+21
-29
lines changed

8 files changed

+21
-29
lines changed

lib/internal/modules/esm/assert.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
const {
44
ArrayPrototypeFilter,
55
ArrayPrototypeIncludes,
6-
ObjectCreate,
76
ObjectValues,
87
ObjectPrototypeHasOwnProperty,
98
} = primordials;
@@ -52,8 +51,7 @@ const supportedAssertionTypes = ArrayPrototypeFilter(
5251
* @returns {true}
5352
* @throws {TypeError} If the format and assertion type are incompatible.
5453
*/
55-
function validateAssertions(url, format,
56-
importAssertions = ObjectCreate(null)) {
54+
function validateAssertions(url, format, importAssertions = { __proto__: null }) {
5755
const validType = formatTypeMap[format];
5856

5957
switch (validType) {

lib/internal/modules/esm/create_dynamic_module.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const {
44
ArrayPrototypeJoin,
55
ArrayPrototypeMap,
66
JSONStringify,
7-
ObjectCreate,
87
SafeSet,
98
} = primordials;
109

@@ -40,12 +39,12 @@ import.meta.done();
4039

4140
const readyfns = new SafeSet();
4241
const reflect = {
43-
exports: ObjectCreate(null),
42+
exports: { __proto__: null },
4443
onReady: (cb) => { readyfns.add(cb); },
4544
};
4645

4746
if (imports.length)
48-
reflect.imports = ObjectCreate(null);
47+
reflect.imports = { __proto__: null };
4948

5049
callbackMap.set(m, {
5150
initializeImportMeta: (meta, wrap) => {

lib/internal/modules/esm/get_format.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
'use strict';
22
const {
33
RegExpPrototypeExec,
4-
ObjectAssign,
5-
ObjectCreate,
64
ObjectPrototypeHasOwnProperty,
75
PromisePrototypeThen,
86
PromiseResolve,
@@ -25,13 +23,14 @@ const { getPackageType, getPackageScopeConfig } = require('internal/modules/esm/
2523
const { URL, fileURLToPath } = require('internal/url');
2624
const { ERR_UNKNOWN_FILE_EXTENSION } = require('internal/errors').codes;
2725

28-
const protocolHandlers = ObjectAssign(ObjectCreate(null), {
26+
const protocolHandlers = {
27+
'__proto__': null,
2928
'data:': getDataProtocolModuleFormat,
3029
'file:': getFileProtocolModuleFormat,
3130
'http:': getHttpProtocolModuleFormat,
3231
'https:': getHttpProtocolModuleFormat,
3332
'node:'() { return 'builtin'; },
34-
});
33+
};
3534

3635
/**
3736
* @param {URL} parsed

lib/internal/modules/esm/loader.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const {
1010
ArrayPrototypePush,
1111
FunctionPrototypeCall,
1212
ObjectAssign,
13-
ObjectCreate,
1413
ObjectDefineProperty,
1514
ObjectSetPrototypeOf,
1615
RegExpPrototypeExec,
@@ -269,7 +268,7 @@ class ESMLoader {
269268
transformSource,
270269
}) {
271270
const obsoleteHooks = [];
272-
const acceptedHooks = ObjectCreate(null);
271+
const acceptedHooks = { __proto__: null };
273272

274273
if (getGlobalPreloadCode) {
275274
globalPreload ??= getGlobalPreloadCode;
@@ -414,7 +413,7 @@ class ESMLoader {
414413
// We can skip cloning if there are no user-provided loaders because
415414
// the Node.js default resolve hook does not use import assertions.
416415
importAssertionsForResolve = ObjectAssign(
417-
ObjectCreate(null),
416+
{ __proto__: null },
418417
importAssertions,
419418
);
420419
}
@@ -531,11 +530,11 @@ class ESMLoader {
531530
if (!wasArr) { return namespaces[0]; } // We can skip the pairing below
532531

533532
for (let i = 0; i < count; i++) {
534-
const namespace = ObjectCreate(null);
535-
namespace.url = specifiers[i];
536-
namespace.exports = namespaces[i];
537-
538-
namespaces[i] = namespace;
533+
namespaces[i] = {
534+
__proto__: null,
535+
url: specifiers[i],
536+
exports: namespaces[i],
537+
};
539538
}
540539

541540
return namespaces;
@@ -787,7 +786,7 @@ class ESMLoader {
787786
async resolve(
788787
originalSpecifier,
789788
parentURL,
790-
importAssertions = ObjectCreate(null)
789+
importAssertions = { __proto__: null }
791790
) {
792791
const isMain = parentURL === undefined;
793792

lib/internal/modules/esm/module_job.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const {
55
ArrayPrototypePush,
66
ArrayPrototypeSome,
77
FunctionPrototype,
8-
ObjectCreate,
98
ObjectSetPrototypeOf,
109
PromiseResolve,
1110
PromisePrototypeThen,
@@ -50,7 +49,7 @@ const isCommonJSGlobalLikeNotDefinedError = (errorMessage) =>
5049
class ModuleJob {
5150
// `loader` is the Loader instance used for loading dependencies.
5251
// `moduleProvider` is a function
53-
constructor(loader, url, importAssertions = ObjectCreate(null),
52+
constructor(loader, url, importAssertions = { __proto: null },
5453
moduleProvider, isMain, inspectBrk) {
5554
this.loader = loader;
5655
this.importAssertions = importAssertions;

lib/internal/modules/run_main.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
const {
4-
ObjectCreate,
54
StringPrototypeEndsWith,
65
} = primordials;
76
const CJSLoader = require('internal/modules/cjs/loader');
@@ -60,7 +59,7 @@ function runMainESM(mainPath) {
6059
handleMainPromise(loadESM((esmLoader) => {
6160
const main = path.isAbsolute(mainPath) ?
6261
pathToFileURL(mainPath).href : mainPath;
63-
return esmLoader.import(main, undefined, ObjectCreate(null));
62+
return esmLoader.import(main, undefined, { __proto__: null });
6463
}));
6564
}
6665

lib/internal/process/esm_loader.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const {
44
ArrayIsArray,
5-
ObjectCreate,
65
} = primordials;
76

87
const {
@@ -92,7 +91,7 @@ function loadModulesInIsolation(specifiers, loaders = []) {
9291
return internalEsmLoader.import(
9392
specifiers,
9493
pathToFileURL(cwd).href,
95-
ObjectCreate(null),
94+
{ __proto__: null },
9695
);
9796
}
9897

test/es-module/test-esm-loader-hooks.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ const { ESMLoader } = esmLoaderModule;
1212
const esmLoader = new ESMLoader();
1313

1414
const originalSpecifier = 'foo/bar';
15-
const importAssertions = Object.assign(
16-
Object.create(null),
17-
{ type: 'json' },
18-
);
15+
const importAssertions = {
16+
__proto__: null,
17+
type: 'json',
18+
};
1919
const parentURL = 'file:///entrypoint.js';
2020
const resolvedURL = 'file:///foo/bar.js';
2121
const suggestedFormat = 'test';

0 commit comments

Comments
 (0)