Skip to content

Commit

Permalink
process: deprecate toStringTag assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Mar 17, 2019
1 parent f105654 commit 29b9483
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
9 changes: 9 additions & 0 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -2361,6 +2361,15 @@ changes:
description: Runtime deprecation.
-->
<a id="DEP0126"></a>
### DEP0126: writing to process[Symbol.toStringTag]
<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/26715
description: Runtime deprecation.
-->
Type: Runtime
The `_stream_wrap` module is deprecated.
Expand Down
9 changes: 7 additions & 2 deletions lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,16 @@ function setupProcessObject() {
const origProcProto = Object.getPrototypeOf(process);
Object.setPrototypeOf(origProcProto, EventEmitter.prototype);
EventEmitter.call(process);
let toStringTag = 'process';
Object.defineProperty(process, Symbol.toStringTag, {
enumerable: false,
writable: true,
configurable: false,
value: 'process'
get() {
return toStringTag;
},
set: deprecate((value) => toStringTag = value,
'Setting \'process[Symbol.toStringTag]\' is deprecated',
'DEP0126')
});
// Make process globally available to users by putting it on the global proxy
Object.defineProperty(global, 'process', {
Expand Down
8 changes: 7 additions & 1 deletion test/es-module/test-esm-process.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
// Flags: --experimental-modules
import '../common';
import { expectWarning } from '../common/index.mjs';
import assert from 'assert';
import process from 'process';

assert.strictEqual(Object.prototype.toString.call(process), '[object process]');
assert(Object.getOwnPropertyDescriptor(process, Symbol.toStringTag).writable);
process[Symbol.toStringTag] = 'custom process';
expectWarning('DeprecationWarning',
'Setting \'process[Symbol.toStringTag]\' is deprecated',
'DEP0126');
assert.strictEqual(Object.prototype.toString.call(process),
'[object custom process]');

0 comments on commit 29b9483

Please sign in to comment.