Skip to content

Commit 29b9483

Browse files
committed
process: deprecate toStringTag assignment
1 parent f105654 commit 29b9483

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

doc/api/deprecations.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2361,6 +2361,15 @@ changes:
23612361
description: Runtime deprecation.
23622362
-->
23632363
2364+
<a id="DEP0126"></a>
2365+
### DEP0126: writing to process[Symbol.toStringTag]
2366+
<!-- YAML
2367+
changes:
2368+
- version: REPLACEME
2369+
pr-url: https://github.com/nodejs/node/pull/26715
2370+
description: Runtime deprecation.
2371+
-->
2372+
23642373
Type: Runtime
23652374
23662375
The `_stream_wrap` module is deprecated.

lib/internal/bootstrap/node.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,16 @@ function setupProcessObject() {
279279
const origProcProto = Object.getPrototypeOf(process);
280280
Object.setPrototypeOf(origProcProto, EventEmitter.prototype);
281281
EventEmitter.call(process);
282+
let toStringTag = 'process';
282283
Object.defineProperty(process, Symbol.toStringTag, {
283284
enumerable: false,
284-
writable: true,
285285
configurable: false,
286-
value: 'process'
286+
get() {
287+
return toStringTag;
288+
},
289+
set: deprecate((value) => toStringTag = value,
290+
'Setting \'process[Symbol.toStringTag]\' is deprecated',
291+
'DEP0126')
287292
});
288293
// Make process globally available to users by putting it on the global proxy
289294
Object.defineProperty(global, 'process', {
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
// Flags: --experimental-modules
22
import '../common';
3+
import { expectWarning } from '../common/index.mjs';
34
import assert from 'assert';
45
import process from 'process';
56

67
assert.strictEqual(Object.prototype.toString.call(process), '[object process]');
7-
assert(Object.getOwnPropertyDescriptor(process, Symbol.toStringTag).writable);
8+
process[Symbol.toStringTag] = 'custom process';
9+
expectWarning('DeprecationWarning',
10+
'Setting \'process[Symbol.toStringTag]\' is deprecated',
11+
'DEP0126');
12+
assert.strictEqual(Object.prototype.toString.call(process),
13+
'[object custom process]');

0 commit comments

Comments
 (0)