From 0fdb5d59f7bd8eda01410eb95290070242de2f9a Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Fri, 12 Feb 2021 12:26:41 +0100 Subject: [PATCH] module: refactor NativeModule to avoid unsafe array iteration PR-URL: https://github.com/nodejs/node/pull/37656 Reviewed-By: Darshan Sen Reviewed-By: Zijian Liu --- lib/internal/bootstrap/loaders.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/internal/bootstrap/loaders.js b/lib/internal/bootstrap/loaders.js index 4a5e962092d790..960ff07221349d 100644 --- a/lib/internal/bootstrap/loaders.js +++ b/lib/internal/bootstrap/loaders.js @@ -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);