Skip to content

Commit

Permalink
lib: runtime deprecate SlowBuffer
Browse files Browse the repository at this point in the history
PR-URL: nodejs#55175
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Robert Nagy <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
  • Loading branch information
RafaelGSS authored and louwers committed Nov 2, 2024
1 parent 3bcfac2 commit fb00689
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
5 changes: 4 additions & 1 deletion doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,9 @@ Type: End-of-Life

<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/55175
description: Runtime deprecation.
- version: v6.12.0
pr-url: https://github.com/nodejs/node/pull/10116
description: A deprecation code has been assigned.
Expand All @@ -703,7 +706,7 @@ changes:
description: Documentation-only deprecation.
-->

Type: Documentation-only
Type: Runtime

The [`SlowBuffer`][] class is deprecated. Please use
[`Buffer.allocUnsafeSlow(size)`][] instead.
Expand Down
6 changes: 5 additions & 1 deletion lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ const {
kIsEncodingSymbol,
defineLazyProperties,
encodingsMap,
deprecate,
} = require('internal/util');
const {
isAnyArrayBuffer,
Expand Down Expand Up @@ -1322,7 +1323,10 @@ function isAscii(input) {

module.exports = {
Buffer,
SlowBuffer,
SlowBuffer: deprecate(
SlowBuffer,
'SlowBuffer() is deprecated. Please use Buffer.allocUnsafeSlow()',
'DEP0030'),
transcode,
isUtf8,
isAscii,
Expand Down
8 changes: 7 additions & 1 deletion test/parallel/test-buffer-slow.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
'use strict';

require('../common');
const common = require('../common');
const assert = require('assert');
const buffer = require('buffer');
const SlowBuffer = buffer.SlowBuffer;

const ones = [1, 1, 1, 1];

common.expectWarning(
'DeprecationWarning',
'SlowBuffer() is deprecated. Please use Buffer.allocUnsafeSlow()',
'DEP0030'
);

// Should create a Buffer
let sb = SlowBuffer(4);
assert(sb instanceof Buffer);
Expand Down

0 comments on commit fb00689

Please sign in to comment.