Browse Source

Revert "buffer: runtime deprecation of calling Buffer without new"

This reverts commit f2fe5583c4
(https://github.com/nodejs/node/pull/8169) as the original
justification for the runtime-deprecation does not appear
to justify the disruption to Node’s existing ecosystem.
Futhermore, the possibility of deprecating the Buffer constructor
entirely in v8.0 might lead to people having to change their code twice.

PR-URL: https://github.com/nodejs/node/pull/9529
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Nikolai Vavilov <vvnicholas@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
v6
Anna Henningsen 8 years ago
committed by Evan Lucas
parent
commit
4fffe32a4b
  1. 10
      lib/buffer.js
  2. 11
      test/parallel/test-buffer-deprecated.js

10
lib/buffer.js

@ -72,17 +72,7 @@ function alignPool() {
* much breakage at this time. It's not likely that the Buffer constructors * much breakage at this time. It's not likely that the Buffer constructors
* would ever actually be removed. * would ever actually be removed.
**/ **/
var newBufferWarned = false;
function Buffer(arg, encodingOrOffset, length) { function Buffer(arg, encodingOrOffset, length) {
if (!new.target && !newBufferWarned) {
newBufferWarned = true;
process.emitWarning(
'Using Buffer without `new` will soon stop working. ' +
'Use `new Buffer()`, or preferably ' +
'`Buffer.from()`, `Buffer.allocUnsafe()` or `Buffer.alloc()` instead.',
'DeprecationWarning'
);
}
// Common case. // Common case.
if (typeof arg === 'number') { if (typeof arg === 'number') {
if (typeof encodingOrOffset === 'string') { if (typeof encodingOrOffset === 'string') {

11
test/parallel/test-buffer-deprecated.js

@ -1,11 +0,0 @@
'use strict';
const common = require('../common');
const expected =
'Using Buffer without `new` will soon stop working. ' +
'Use `new Buffer()`, or preferably ' +
'`Buffer.from()`, `Buffer.allocUnsafe()` or `Buffer.alloc()` instead.';
common.expectWarning('DeprecationWarning', expected);
Buffer(1);
Buffer(1);
Loading…
Cancel
Save