Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
  • Loading branch information
aduh95 committed Mar 13, 2021
commit 0ccfd7d27fd5be75bd69bbe35108a796f6c83402
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 @@ -250,8 +251,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