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

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

lib/internal/bootstrap/loaders.js

+4-1
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
const url = `node:${this.id}`;
241242
const nativeModule = this;
243+
const exportsKeys = ArrayPrototypeSlice(this.exportKeys);
244+
ArrayPrototypePush(exportsKeys, 'default');
242245
this.module = new ModuleWrap(
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)