Skip to content

Commit 984da23

Browse files
committed
lib,doc: make process.moduleLoadList immutable and document it
process.moduleLoadList was added in the early days but never documented and exposed as mutable array. This is a breaking change for code that used this undocumented array as a mutable array. Fixes: #41233
1 parent 650f51f commit 984da23

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

doc/api/process.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2858,6 +2858,35 @@ console.log(memoryUsage.rss());
28582858
// 35655680
28592859
```
28602860
2861+
## `process.moduleLoadList`
2862+
2863+
<!-- YAML
2864+
added: v0.5.3
2865+
changes:
2866+
- version: REPLACEME
2867+
pr-url: REPLACEME
2868+
description: Make `moduleLoadList` immutable.
2869+
-->
2870+
2871+
* Returns: {string\[]}
2872+
2873+
The `process.moduleLoadList` property returns an array of internal bindings and core modules that
2874+
were loaded during the current Node.js process execution.
2875+
2876+
```mjs
2877+
import { moduleLoadList } from 'node:process';
2878+
2879+
console.log(moduleLoadList);
2880+
// ['Internal Binding builtins', 'Internal Binding module_wrap', 'Internal Binding errors', ...]
2881+
```
2882+
2883+
```cjs
2884+
const { moduleLoadList } = require('node:process');
2885+
2886+
console.log(moduleLoadList);
2887+
// ['Internal Binding builtins', 'Internal Binding module_wrap', 'Internal Binding errors', ...]
2888+
```
2889+
28612890
## `process.nextTick(callback[, ...args])`
28622891
28632892
<!-- YAML

lib/internal/bootstrap/realm.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const {
5858
ArrayPrototypeSlice,
5959
Error,
6060
ObjectDefineProperty,
61+
ObjectFreeze,
6162
ObjectKeys,
6263
ObjectPrototypeHasOwnProperty,
6364
ObjectSetPrototypeOf,
@@ -74,10 +75,9 @@ const {
7475
const moduleLoadList = [];
7576
ObjectDefineProperty(process, 'moduleLoadList', {
7677
__proto__: null,
77-
value: moduleLoadList,
78-
configurable: true,
78+
get() { return ObjectFreeze(moduleLoadList.slice()); },
79+
configurable: false,
7980
enumerable: true,
80-
writable: false,
8181
});
8282

8383

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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.push('foo'), /^TypeError: Cannot add property \d+, object is not extensible$/);
8+
assert.throws(() => process.moduleLoadList = 'foo', /^TypeError: Cannot set property moduleLoadList of #<process> which has only a getter$/);

0 commit comments

Comments
 (0)