diff options
author | Guy Bedford <guybedford@gmail.com> | 2019-10-04 13:37:27 -0400 |
---|---|---|
committer | Guy Bedford <guybedford@gmail.com> | 2019-10-06 13:30:11 -0400 |
commit | ffd22e81983056d09c064c59343a0e488236272d (patch) | |
tree | bf6df052e03191935ed7032f6d2c86e18cd886b3 /lib/internal/bootstrap/loaders.js | |
parent | 0521a98fd6dfbd31994709f0f417c470f98d2b71 (diff) | |
download | android-node-v8-ffd22e81983056d09c064c59343a0e488236272d.tar.gz android-node-v8-ffd22e81983056d09c064c59343a0e488236272d.tar.bz2 android-node-v8-ffd22e81983056d09c064c59343a0e488236272d.zip |
module: use v8 synthetic modules
PR-URL: https://github.com/nodejs/node/pull/29846
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Diffstat (limited to 'lib/internal/bootstrap/loaders.js')
-rw-r--r-- | lib/internal/bootstrap/loaders.js | 30 |
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)); } } }; |