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

src: deprecate native typechecking bindings #30818

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
5 changes: 4 additions & 1 deletion doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -2006,6 +2006,9 @@ could lead to hard to find errors and crashes.
### DEP0103: process.binding('util').is\[...\] typechecks
<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/30818
description: Runtime deprecation.
- version: v10.9.0
pr-url: https://github.com/nodejs/node/pull/22004
description: Superseded by [DEP0111](#DEP0111).
Expand All @@ -2014,7 +2017,7 @@ changes:
description: Documentation-only deprecation.
-->

Type: Documentation-only (supports [`--pending-deprecation`][])
Type: Runtime

Using `process.binding()` in general should be avoided. The type checking
methods in particular can be replaced by using [`util.types`][].
Expand Down
12 changes: 5 additions & 7 deletions lib/internal/bootstrap/pre_execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,11 @@ function initializeDeprecations() {
'isUint8Array',
'isAnyArrayBuffer'
]) {
utilBinding[name] = pendingDeprecation ?
deprecate(types[name],
'Accessing native typechecking bindings of Node ' +
'directly is deprecated. ' +
`Please use \`util.types.${name}\` instead.`,
'DEP0103') :
types[name];
utilBinding[name] = deprecate(types[name],
'Accessing native typechecking bindings ' +
'of Node directly is deprecated. ' +
`Please use \`util.types.${name}\` instead.`,
'DEP0103');
}

// TODO(joyeecheung): this is a legacy property exposed to process.
Expand Down
33 changes: 33 additions & 0 deletions test/parallel/test-process-isX-deprecation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';

require('../common');
const assert = require('assert');
const { spawnSync } = require('child_process');

[
'isArrayBuffer',
'isArrayBufferView',
'isAsyncFunction',
'isDataView',
'isDate',
'isExternal',
'isMap',
'isMapIterator',
'isNativeError',
'isPromise',
'isRegExp',
'isSet',
'isSetIterator',
'isTypedArray',
'isUint8Array',
'isAnyArrayBuffer'
].forEach((method) => {
const { stderr } = spawnSync(process.execPath, ['-p', `
process.binding('util')['${method}']('meow');
`]);
juanarbol marked this conversation as resolved.
Show resolved Hide resolved
const expectedWarning = '[DEP0103] DeprecationWarning: ' +
'Accessing native typechecking bindings ' +
'of Node directly is deprecated. ' +
`Please use \`util.types.${method}\` instead.`;
assert(stderr.includes(expectedWarning), stderr);
});