diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index eeafab91dac398..1e2bcbfeb9d0f5 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -2361,6 +2361,15 @@ changes: description: Runtime deprecation. --> + +### DEP0126: writing to process[Symbol.toStringTag] + + Type: Runtime The `_stream_wrap` module is deprecated. diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index f8cddb3153ed20..7cf650c35ae8a2 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -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', { diff --git a/test/es-module/test-esm-process.mjs b/test/es-module/test-esm-process.mjs index ea9b4b4936a313..afcfb7eefa4530 100644 --- a/test/es-module/test-esm-process.mjs +++ b/test/es-module/test-esm-process.mjs @@ -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]');