Skip to content

Commit f864509

Browse files
ChALkeRaddaleax
authored andcommitted
test,benchmark: use new Buffer API where appropriate
For tests / benchmarks that are creating Buffer instances for any reason other than to test Buffer constructor, use the new Buffer.alloc/Buffer.from API instead of the deprecated API. PR-URL: #18980 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Daijiro Wachi <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
1 parent cab6c8e commit f864509

12 files changed

+19
-18
lines changed

‎benchmark/streams/pipe.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const bench = common.createBenchmark(main,{
88
});
99

1010
functionmain({ n }){
11-
constb=newBuffer(1024);
11+
constb=Buffer.alloc(1024);
1212
constr=newReadable();
1313
constw=newWritable();
1414

‎benchmark/streams/readable-bigread.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const bench = common.createBenchmark(main,{
88
});
99

1010
functionmain({ n }){
11-
constb=newBuffer(32);
11+
constb=Buffer.alloc(32);
1212
consts=newReadable();
1313
functionnoop(){}
1414
s._read=noop;

‎benchmark/streams/readable-bigunevenread.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const bench = common.createBenchmark(main,{
88
});
99

1010
functionmain({ n }){
11-
constb=newBuffer(32);
11+
constb=Buffer.alloc(32);
1212
consts=newReadable();
1313
functionnoop(){}
1414
s._read=noop;

‎benchmark/streams/readable-readall.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const bench = common.createBenchmark(main,{
88
});
99

1010
functionmain({ n }){
11-
constb=newBuffer(32);
11+
constb=Buffer.alloc(32);
1212
consts=newReadable();
1313
functionnoop(){}
1414
s._read=noop;

‎benchmark/streams/readable-unevenread.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const bench = common.createBenchmark(main,{
88
});
99

1010
functionmain({ n }){
11-
constb=newBuffer(32);
11+
constb=Buffer.alloc(32);
1212
consts=newReadable();
1313
functionnoop(){}
1414
s._read=noop;

‎test/async-hooks/test-udpsendwrap.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const sock = dgram
1818

1919
functiononlistening(){
2020
sock.send(
21-
newBuffer(2),0,2,sock.address().port,
21+
Buffer.alloc(2),0,2,sock.address().port,
2222
undefined,common.mustCall(onsent));
2323

2424
// init not called synchronously because dns lookup always wraps

‎test/parallel/test-buffer-badhex.js‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ const assert = require('assert');
66
{
77
constbuf=Buffer.alloc(4);
88
assert.strictEqual(buf.length,4);
9-
assert.deepStrictEqual(buf,newBuffer([0,0,0,0]));
9+
assert.deepStrictEqual(buf,Buffer.from([0,0,0,0]));
1010
assert.strictEqual(buf.write('abcdxx',0,'hex'),2);
11-
assert.deepStrictEqual(buf,newBuffer([0xab,0xcd,0x00,0x00]));
11+
assert.deepStrictEqual(buf,Buffer.from([0xab,0xcd,0x00,0x00]));
1212
assert.strictEqual(buf.toString('hex'),'abcd0000');
1313
assert.strictEqual(buf.write('abcdef01',0,'hex'),4);
14-
assert.deepStrictEqual(buf,newBuffer([0xab,0xcd,0xef,0x01]));
14+
assert.deepStrictEqual(buf,Buffer.from([0xab,0xcd,0xef,0x01]));
1515
assert.strictEqual(buf.toString('hex'),'abcdef01');
1616

1717
constcopy=Buffer.from(buf.toString('hex'),'hex');
@@ -26,13 +26,13 @@ const assert = require('assert');
2626

2727
{
2828
constbuf=Buffer.alloc(4);
29-
assert.deepStrictEqual(buf,newBuffer([0,0,0,0]));
29+
assert.deepStrictEqual(buf,Buffer.from([0,0,0,0]));
3030
assert.strictEqual(buf.write('xxabcd',0,'hex'),0);
31-
assert.deepStrictEqual(buf,newBuffer([0,0,0,0]));
31+
assert.deepStrictEqual(buf,Buffer.from([0,0,0,0]));
3232
assert.strictEqual(buf.write('xxab',1,'hex'),0);
33-
assert.deepStrictEqual(buf,newBuffer([0,0,0,0]));
33+
assert.deepStrictEqual(buf,Buffer.from([0,0,0,0]));
3434
assert.strictEqual(buf.write('cdxxab',0,'hex'),1);
35-
assert.deepStrictEqual(buf,newBuffer([0xcd,0,0,0]));
35+
assert.deepStrictEqual(buf,Buffer.from([0xcd,0,0,0]));
3636
}
3737

3838
{

‎test/parallel/test-buffer-fill.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ common.expectsError(() =>{
427427

428428
// Test that bypassing 'length' won't cause an abort.
429429
common.expectsError(()=>{
430-
constbuf=newBuffer('w00t');
430+
constbuf=Buffer.from('w00t');
431431
Object.defineProperty(buf,'length',{
432432
value: 1337,
433433
enumerable: true

‎test/parallel/test-buffer-indexof.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ assert.strictEqual(buf_bc.lastIndexOf('你好', 5, 'binary'), -1);
504504
assert.strictEqual(buf_bc.lastIndexOf(Buffer.from('你好'),7),-1);
505505

506506
// Test lastIndexOf on a longer buffer:
507-
constbufferString=newBuffer('a man a plan a canal panama');
507+
constbufferString=Buffer.from('a man a plan a canal panama');
508508
assert.strictEqual(15,bufferString.lastIndexOf('canal'));
509509
assert.strictEqual(21,bufferString.lastIndexOf('panama'));
510510
assert.strictEqual(0,bufferString.lastIndexOf('a man a plan a canal panama'));
@@ -566,7 +566,7 @@ const parts = [];
566566
for(leti=0;i<1000000;i++){
567567
parts.push((countBits(i)%2===0) ? 'yolo' : 'swag');
568568
}
569-
constreallyLong=newBuffer(parts.join(' '));
569+
constreallyLong=Buffer.from(parts.join(' '));
570570
assert.strictEqual('yolo swag swag yolo',reallyLong.slice(0,19).toString());
571571

572572
// Expensive reverse searches. Stress test lastIndexOf:

‎test/parallel/test-buffer-zero-fill.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require('../common');
44
constassert=require('assert');
55

6+
// Tests deprecated Buffer API on purpose
67
constbuf1=Buffer(100);
78
constbuf2=newBuffer(100);
89

0 commit comments

Comments
(0)