From 019efe1453ba2c3f3cb6d6cd99d18bb72c16b84f Mon Sep 17 00:00:00 2001 From: Rafael Gonzaga Date: Tue, 15 Oct 2024 18:24:39 -0300 Subject: [PATCH] lib: runtime deprecate SlowBuffer PR-URL: https://github.com/nodejs/node/pull/55175 Reviewed-By: Yagiz Nizipli Reviewed-By: Robert Nagy Reviewed-By: Ruben Bridgewater Reviewed-By: Matteo Collina --- doc/api/deprecations.md | 5 ++++- lib/buffer.js | 6 +++++- test/parallel/test-buffer-slow.js | 8 +++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 5d036fa2917..c2de5e297a5 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -695,6 +695,9 @@ Type: End-of-Life -Type: Documentation-only +Type: Runtime The [`SlowBuffer`][] class is deprecated. Please use [`Buffer.allocUnsafeSlow(size)`][] instead. diff --git a/lib/buffer.js b/lib/buffer.js index 756657e9108..88625299bce 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -88,6 +88,7 @@ const { kIsEncodingSymbol, defineLazyProperties, encodingsMap, + deprecate, } = require('internal/util'); const { isAnyArrayBuffer, @@ -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, diff --git a/test/parallel/test-buffer-slow.js b/test/parallel/test-buffer-slow.js index 07138d5db0b..0d89491cfbd 100644 --- a/test/parallel/test-buffer-slow.js +++ b/test/parallel/test-buffer-slow.js @@ -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);