buffer: do not emit deprecation notice on Buffer.of
PR-URL: https://github.com/nodejs/node/pull/19682 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
parent
d1af1e4e59
commit
42d8976dff
@ -236,6 +236,20 @@ Buffer.from = function from(value, encodingOrOffset, length) {
|
||||
);
|
||||
};
|
||||
|
||||
// Identical to the built-in %TypedArray%.of(), but avoids using the deprecated
|
||||
// Buffer() constructor. Must use arrow function syntax to avoid automatically
|
||||
// adding a `prototype` property and making the function a constructor.
|
||||
//
|
||||
// Refs: https://tc39.github.io/ecma262/#sec-%typedarray%.of
|
||||
// Refs: https://esdiscuss.org/topic/isconstructor#content-11
|
||||
const of = (...items) => {
|
||||
const newObj = createUnsafeBuffer(items.length);
|
||||
for (var k = 0; k < items.length; k++)
|
||||
newObj[k] = items[k];
|
||||
return newObj;
|
||||
};
|
||||
Buffer.of = of;
|
||||
|
||||
Object.setPrototypeOf(Buffer, Uint8Array);
|
||||
|
||||
// The 'assertSize' method will remove itself from the callstack when an error
|
||||
|
8
test/parallel/test-buffer-of-no-deprecation.js
Normal file
8
test/parallel/test-buffer-of-no-deprecation.js
Normal file
@ -0,0 +1,8 @@
|
||||
// Flags: --pending-deprecation --no-warnings
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
|
||||
process.on('warning', common.mustNotCall());
|
||||
|
||||
Buffer.of(0, 1);
|
Loading…
x
Reference in New Issue
Block a user