summaryrefslogtreecommitdiff
path: root/lib/internal/bootstrap/loaders.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/internal/bootstrap/loaders.js')
-rw-r--r--lib/internal/bootstrap/loaders.js30
1 files changed, 15 insertions, 15 deletions
diff --git a/lib/internal/bootstrap/loaders.js b/lib/internal/bootstrap/loaders.js
index dbc21a9697..0cad5209c4 100644
--- a/lib/internal/bootstrap/loaders.js
+++ b/lib/internal/bootstrap/loaders.js
@@ -150,8 +150,7 @@ function NativeModule(id) {
this.filename = `${id}.js`;
this.id = id;
this.exports = {};
- this.reflect = undefined;
- this.esmFacade = undefined;
+ this.module = undefined;
this.exportKeys = undefined;
this.loaded = false;
this.loading = false;
@@ -240,16 +239,18 @@ NativeModule.prototype.getURL = function() {
};
NativeModule.prototype.getESMFacade = function() {
- if (this.esmFacade) return this.esmFacade;
- const createDynamicModule = nativeModuleRequire(
- 'internal/modules/esm/create_dynamic_module');
+ if (this.module) return this.module;
+ const { ModuleWrap } = internalBinding('module_wrap');
const url = this.getURL();
- return this.esmFacade = createDynamicModule(
- [], [...this.exportKeys, 'default'], url, (reflect) => {
- this.reflect = reflect;
- this.syncExports();
- reflect.exports.default.set(this.exports);
- });
+ const nativeModule = this;
+ this.module = new ModuleWrap(function() {
+ nativeModule.syncExports();
+ this.setExport('default', nativeModule.exports);
+ }, [...this.exportKeys, 'default'], url);
+ // Ensure immediate sync execution to capture exports now
+ this.module.instantiate();
+ this.module.evaluate(-1, false);
+ return this.module;
};
// Provide named exports for all builtin libraries so that the libraries
@@ -258,13 +259,12 @@ NativeModule.prototype.getESMFacade = function() {
// called so that APMs and other behavior are supported.
NativeModule.prototype.syncExports = function() {
const names = this.exportKeys;
- if (this.reflect) {
+ if (this.module) {
for (let i = 0; i < names.length; i++) {
const exportName = names[i];
if (exportName === 'default') continue;
- this.reflect.exports[exportName].set(
- getOwn(this.exports, exportName, this.exports)
- );
+ this.module.setExport(exportName,
+ getOwn(this.exports, exportName, this.exports));
}
}
};