File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -64,7 +64,17 @@ function alignPool() {
6464 * much breakage at this time. It's not likely that the Buffer constructors
6565 * would ever actually be removed.
6666 **/
67+ var newBufferWarned = false ;
6768function Buffer ( arg , encodingOrOffset , length ) {
69+ if ( ! new . target && ! newBufferWarned ) {
70+ newBufferWarned = true ;
71+ process . emitWarning (
72+ 'Using Buffer without `new` will soon stop working. ' +
73+ 'Use `new Buffer()`, or preferably ' +
74+ '`Buffer.from()`, `Buffer.allocUnsafe()` or `Buffer.alloc()` instead.' ,
75+ 'DeprecationWarning'
76+ ) ;
77+ }
6878 // Common case.
6979 if ( typeof arg === 'number' ) {
7080 if ( typeof encodingOrOffset === 'string' ) {
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+ const common = require ( '../common' ) ;
3+ const assert = require ( 'assert' ) ;
4+
5+ const expected =
6+ 'Using Buffer without `new` will soon stop working. ' +
7+ 'Use `new Buffer()`, or preferably ' +
8+ '`Buffer.from()`, `Buffer.allocUnsafe()` or `Buffer.alloc()` instead.' ;
9+
10+ process . on ( 'warning' , common . mustCall ( ( warning ) => {
11+ assert . strictEqual ( warning . name , 'DeprecationWarning' ) ;
12+ assert . strictEqual ( warning . message , expected ,
13+ `unexpected error message: "${ warning . message } "` ) ;
14+ } , 1 ) ) ;
15+
16+ Buffer ( 1 ) ;
17+ Buffer ( 1 ) ;
You can’t perform that action at this time.
0 commit comments