Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

process: deprecate toStringTag assignment #26717

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
Copy link
Contributor

@vsemozhetbyt vsemozhetbyt Mar 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. This seems to break other deprecation section without adding its own description.
  2. We usually assign a placeholder DEP0XXX till landing.
  3. PR URL should be https://github.com/nodejs/node/pull/26717

### 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]');