Skip to content

Commit

Permalink
module: refactor NativeModule to avoid unsafe array iteration
Browse files Browse the repository at this point in the history
PR-URL: #37656
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
  • Loading branch information
aduh95 authored and targos committed Jun 11, 2021
1 parent 9320000 commit 0fdb5d5
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/internal/bootstrap/loaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
const {
ArrayPrototypeMap,
ArrayPrototypePush,
ArrayPrototypeSlice,
Error,
ObjectCreate,
ObjectDefineProperty,
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 0fdb5d5

Please sign in to comment.