From 6604334fd25a82dc72a45c350169a2aa092968e0 Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Mon, 30 Sep 2024 10:07:47 -0300 Subject: [PATCH 1/3] lib: runtime deprecate SlowBuffer --- doc/api/deprecations.md | 5 ++++- lib/buffer.js | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 5d036fa2917ce8..c2de5e297a5390 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 2c56b6c504db9b..9c4c46b731a84a 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -88,6 +88,7 @@ const { kIsEncodingSymbol, defineLazyProperties, encodingsMap, + deprecate, } = require('internal/util'); const { isAnyArrayBuffer, @@ -1324,7 +1325,10 @@ function isAscii(input) { module.exports = { Buffer, - SlowBuffer, + SlowBuffer: deprecate( + SlowBuffer, + 'SlowBuffer() is deprecated. Please use Buffer.allowUnsafeSlow()', + 'DEP0030'), transcode, isUtf8, isAscii, From 895ec9b54d2eb6cc9ca623e853522a2605f6aa8a Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Mon, 30 Sep 2024 10:13:22 -0300 Subject: [PATCH 2/3] fixup! lib: runtime deprecate SlowBuffer --- lib/buffer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/buffer.js b/lib/buffer.js index 9c4c46b731a84a..40a508de063988 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -1327,7 +1327,7 @@ module.exports = { Buffer, SlowBuffer: deprecate( SlowBuffer, - 'SlowBuffer() is deprecated. Please use Buffer.allowUnsafeSlow()', + 'SlowBuffer() is deprecated. Please use Buffer.allocUnsafeSlow()', 'DEP0030'), transcode, isUtf8, From 0a56956ca4b05cbb8ca46640fd02ed1f3c6565c1 Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Thu, 10 Oct 2024 10:26:00 -0300 Subject: [PATCH 3/3] fixup! fixup! lib: runtime deprecate SlowBuffer --- test/parallel/test-buffer-slow.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-buffer-slow.js b/test/parallel/test-buffer-slow.js index 07138d5db0b397..0d89491cfbd155 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);