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 <[email protected]>
Reviewed-By: Zijian Liu <[email protected]>
  • Loading branch information
aduh95 authored and danielleadams committed Mar 16, 2021
1 parent a2d08d5 commit ae0e76c
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 ae0e76c

Please sign in to comment.