mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
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: https://github.com/nodejs/node/pull/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>
This commit is contained in:
@@ -198,6 +198,9 @@ const {
|
||||
setInternalLoaders,
|
||||
} = internalBinding('builtins');
|
||||
|
||||
const { ModuleWrap } = internalBinding('module_wrap');
|
||||
ObjectSetPrototypeOf(ModuleWrap.prototype, null);
|
||||
|
||||
const getOwn = (target, property, receiver) => {
|
||||
return ObjectPrototypeHasOwnProperty(target, property) ?
|
||||
ReflectGet(target, property, receiver) :
|
||||
@@ -338,16 +341,11 @@ class BuiltinModule {
|
||||
const internal = StringPrototypeStartsWith(this.id, 'internal/');
|
||||
this.exportKeys = internal ? [] : ObjectKeys(this.exports);
|
||||
}
|
||||
this.getESMFacade();
|
||||
this.syncExports();
|
||||
return this.exports;
|
||||
}
|
||||
|
||||
getESMFacade() {
|
||||
if (this.module) return this.module;
|
||||
const { ModuleWrap } = internalBinding('module_wrap');
|
||||
// TODO(aduh95): move this to C++, alongside the initialization of the class.
|
||||
ObjectSetPrototypeOf(ModuleWrap.prototype, null);
|
||||
const url = `node:${this.id}`;
|
||||
const builtin = this;
|
||||
const exportsKeys = ArrayPrototypeSlice(this.exportKeys);
|
||||
|
||||
Reference in New Issue
Block a user