-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
buffer: make Buffer work with resizable ArrayBuffer
Fixes: #52195 PR-URL: #55377 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
- Loading branch information
Showing
2 changed files
with
30 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Flags: --no-warnings | ||
'use strict'; | ||
|
||
require('../common'); | ||
const { Buffer } = require('node:buffer'); | ||
const { strictEqual } = require('node:assert'); | ||
const { describe, it } = require('node:test'); | ||
|
||
describe('Using resizable ArrayBuffer with Buffer...', () => { | ||
it('works as expected', () => { | ||
const ab = new ArrayBuffer(10, { maxByteLength: 20 }); | ||
const buffer = Buffer.from(ab, 1); | ||
strictEqual(buffer.byteLength, 9); | ||
ab.resize(15); | ||
strictEqual(buffer.byteLength, 14); | ||
ab.resize(5); | ||
strictEqual(buffer.byteLength, 4); | ||
}); | ||
|
||
it('works with the deprecated constructor also', () => { | ||
const ab = new ArrayBuffer(10, { maxByteLength: 20 }); | ||
const buffer = new Buffer(ab, 1); | ||
strictEqual(buffer.byteLength, 9); | ||
ab.resize(15); | ||
strictEqual(buffer.byteLength, 14); | ||
ab.resize(5); | ||
strictEqual(buffer.byteLength, 4); | ||
}); | ||
}); |