Skip to content

Commit 677b094

Browse files
committed
lib: make process.moduleLoadList a copy of the internal value
process.moduleLoadList was provided as-is instead of a copy of it Refs: nodejs#41233 Refs: nodejs#61276
1 parent b061243 commit 677b094

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

doc/api/process.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2862,6 +2862,10 @@ console.log(memoryUsage.rss());
28622862
28632863
<!-- YAML
28642864
added: v0.5.3
2865+
changes:
2866+
- version: REPLACEME
2867+
pr-url: https://github.com/nodejs/node/pull/61276
2868+
description: Now a copy instead of the internal list itself.
28652869
-->
28662870
28672871
* Returns: {string\[]}

lib/internal/bootstrap/realm.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,9 @@ const {
7474
const moduleLoadList = [];
7575
ObjectDefineProperty(process, 'moduleLoadList', {
7676
__proto__: null,
77-
value: moduleLoadList,
78-
configurable: true,
77+
get() { return ArrayPrototypeSlice(moduleLoadList); },
7978
enumerable: true,
80-
writable: false,
79+
configurable: true,
8180
});
8281

8382

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
require('../common');
4+
const assert = require('assert');
5+
6+
assert.ok(Array.isArray(process.moduleLoadList));
7+
assert.throws(() => process.moduleLoadList = 'foo', /^TypeError: Cannot set property moduleLoadList of #<process> which has only a getter$/);

0 commit comments

Comments
 (0)