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 Michaël Zasso committed 2021-06-11 09:30:02 +02:00
1 parent 932000020a
commit 0fdb5d59f7
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);