Skip to content

Commit 0ccfd7d

Browse files
committed
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 a28cb93 commit 0ccfd7d

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

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,
@@ -250,8 +251,10 @@ class NativeModule {
250251
const { ModuleWrap } = internalBinding('module_wrap');
251252
const url = `node:${this.id}`;
252253
const nativeModule = this;
254+
const exportsKeys = ArrayPrototypeSlice(this.exportKeys);
255+
ArrayPrototypePush(exportsKeys, 'default');
253256
this.module = new ModuleWrap(
254-
url, undefined, [...this.exportKeys, 'default'],
257+
url, undefined, exportsKeys,
255258
function() {
256259
nativeModule.syncExports();
257260
this.setExport('default', nativeModule.exports);

0 commit comments

Comments
 (0)