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:
Timothy Gu 2018-03-29 13:02:52 -07:00
parent d1af1e4e59
commit 42d8976dff
No known key found for this signature in database
GPG Key ID: 7FE6B095B582B0D4
2 changed files with 22 additions and 0 deletions

View File

@ -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

View 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);