Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4dfc9e0

Browse filesBrowse files
joyeecheungmarco-ippolito
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 <targos@protonmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent e4d4bc6 commit 4dfc9e0
Copy full SHA for 4dfc9e0

File tree

Expand file treeCollapse file tree

1 file changed

+3
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+3
-5
lines changed
Open diff view settings
Collapse file

‎lib/internal/bootstrap/realm.js‎

Copy file name to clipboardExpand all lines: lib/internal/bootstrap/realm.js
+3-5Lines changed: 3 additions & 5 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.