Skip to content

Commit 0fdb5d5

Browse files
aduh95targos
authored andcommitted
module: refactor NativeModule to avoid unsafe array iteration
PR-URL: #37656 Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
1 parent 9320000 commit 0fdb5d5

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

‎lib/internal/bootstrap/loaders.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
const{
4747
ArrayPrototypeMap,
4848
ArrayPrototypePush,
49+
ArrayPrototypeSlice,
4950
Error,
5051
ObjectCreate,
5152
ObjectDefineProperty,
@@ -239,8 +240,10 @@ class NativeModule {
239240
const{ ModuleWrap }=internalBinding('module_wrap');
240241
consturl=`node:${this.id}`;
241242
constnativeModule=this;
243+
constexportsKeys=ArrayPrototypeSlice(this.exportKeys);
244+
ArrayPrototypePush(exportsKeys,'default');
242245
this.module=newModuleWrap(
243-
url,undefined,[...this.exportKeys,'default'],
246+
url,undefined,exportsKeys,
244247
function(){
245248
nativeModule.syncExports();
246249
this.setExport('default',nativeModule.exports);

0 commit comments

Comments
 (0)