module: refactor NativeModule to avoid unsafe array iteration

PR-URL: https://github.com/nodejs/node/pull/37656
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
This commit is contained in:
Antoine du Hamel authored and Danielle Adams committed 2021-03-16 12:31:35 -04:00
1 parent a2d08d5dfd
commit ae0e76c264
1 file changed
+4 -1
+4 -1
View File
@@ -46,6 +46,7 @@
const {
ArrayPrototypeMap,
ArrayPrototypePush,
ArrayPrototypeSlice,
Error,
ObjectCreate,
ObjectDefineProperty,
@@ -239,8 +240,10 @@ class NativeModule {
const { ModuleWrap } = internalBinding('module_wrap');
const url = `node:${this.id}`;
const nativeModule = this;
const exportsKeys = ArrayPrototypeSlice(this.exportKeys);
ArrayPrototypePush(exportsKeys, 'default');
this.module = new ModuleWrap(
url, undefined, [...this.exportKeys, 'default'],
url, undefined, exportsKeys,
function() {
nativeModule.syncExports();
this.setExport('default', nativeModule.exports);