Skip to content

Commit 703e37c

Browse files
committed
process: deprecate process.assert()
This was never documented and the `assert` module should be used instead. PR-URL: nodejs#18666 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 1bd3208 commit 703e37c

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

doc/api/deprecations.md

+10
Original file line numberDiff line numberDiff line change
@@ -902,11 +902,21 @@ Certain versions of `node::MakeCallback` APIs available to native modules are
902902
deprecated. Please use the versions of the API that accept an `async_context`
903903
parameter.
904904
905+
<a id="DEP0100"></a>
906+
### DEP0100: process.assert()
907+
908+
Type: Runtime
909+
910+
`process.assert()` is deprecated. Please use the [`assert`][] module instead.
911+
912+
This was never a documented feature.
913+
905914
[`--pending-deprecation`]: cli.html#cli_pending_deprecation
906915
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size
907916
[`Buffer.from(array)`]: buffer.html#buffer_class_method_buffer_from_array
908917
[`Buffer.from(buffer)`]: buffer.html#buffer_class_method_buffer_from_buffer
909918
[`Buffer.isBuffer()`]: buffer.html#buffer_class_method_buffer_isbuffer_obj
919+
[`assert`]: assert.html
910920
[`clearInterval()`]: timers.html#timers_clearinterval_timeout
911921
[`clearTimeout()`]: timers.html#timers_cleartimeout_timeout
912922
[`EventEmitter.listenerCount(emitter, eventName)`]: events.html#events_eventemitter_listenercount_emitter_eventname

lib/internal/process.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
const errors = require('internal/errors');
44
const util = require('util');
55
const constants = process.binding('constants').os.signals;
6-
7-
const assert = process.assert = function(x, msg) {
8-
if (!x) throw new errors.Error('ERR_ASSERTION', msg || 'assertion error');
9-
};
10-
6+
const assert = require('assert').strict;
7+
const { deprecate } = require('internal/util');
8+
9+
process.assert = deprecate(
10+
function(x, msg) {
11+
if (!x) throw new errors.Error('ERR_ASSERTION', msg || 'assertion error');
12+
},
13+
'process.assert() is deprecated. Please use the `assert` module instead.',
14+
'DEP0100');
1115

1216
function setup_performance() {
1317
require('perf_hooks');

test/parallel/test-process-assert.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,24 @@
22
const common = require('../common');
33
const assert = require('assert');
44

5+
common.expectWarning(
6+
'DeprecationWarning',
7+
'process.assert() is deprecated. Please use the `assert` module instead.',
8+
'DEP0100'
9+
);
10+
511
assert.strictEqual(process.assert(1, 'error'), undefined);
612
common.expectsError(() => {
713
process.assert(undefined, 'errorMessage');
814
}, {
915
code: 'ERR_ASSERTION',
1016
type: Error,
1117
message: 'errorMessage'
12-
}
13-
);
18+
});
1419
common.expectsError(() => {
1520
process.assert(false);
1621
}, {
1722
code: 'ERR_ASSERTION',
1823
type: Error,
1924
message: 'assertion error'
20-
}
21-
);
25+
});

0 commit comments

Comments
 (0)