Skip to content

Commit 55011d2

Browse files
joyeecheungrichardlau
authored andcommitted
lib: only build the ESM facade for builtins when they are needed
We previously build the ESM facade (synthetic modules re-exporting builtin's exports) for builtins even when they are not directly import'ed (which rarely happens for internal builtins as that requires --expose-internals). This patch removes the eager generation to avoid the overhead and the extra promises created in facade building when it's not reqested by the user. When the facade is needed the ESM loader that can be requested it in the translator on-demand. Drive-by: set the ModuleWrap prototype to null in the built-in snapshot. PR-URL: #51669 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent 91c8624 commit 55011d2

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

lib/internal/bootstrap/realm.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ const {
198198
setInternalLoaders,
199199
} = internalBinding('builtins');
200200

201+
const { ModuleWrap } = internalBinding('module_wrap');
202+
ObjectSetPrototypeOf(ModuleWrap.prototype, null);
203+
201204
const getOwn = (target, property, receiver) => {
202205
return ObjectPrototypeHasOwnProperty(target, property) ?
203206
ReflectGet(target, property, receiver) :
@@ -338,16 +341,11 @@ class BuiltinModule {
338341
const internal = StringPrototypeStartsWith(this.id, 'internal/');
339342
this.exportKeys = internal ? [] : ObjectKeys(this.exports);
340343
}
341-
this.getESMFacade();
342-
this.syncExports();
343344
return this.exports;
344345
}
345346

346347
getESMFacade() {
347348
if (this.module) return this.module;
348-
const { ModuleWrap } = internalBinding('module_wrap');
349-
// TODO(aduh95): move this to C++, alongside the initialization of the class.
350-
ObjectSetPrototypeOf(ModuleWrap.prototype, null);
351349
const url = `node:${this.id}`;
352350
const builtin = this;
353351
const exportsKeys = ArrayPrototypeSlice(this.exportKeys);

0 commit comments

Comments
 (0)