diff options
author | Timothy Gu <timothygu99@gmail.com> | 2018-03-29 13:02:52 -0700 |
---|---|---|
committer | Timothy Gu <timothygu99@gmail.com> | 2018-04-10 21:37:57 -0700 |
commit | 42d8976dff0e5a5f21d6c89457f348d9fdfd26fe (patch) | |
tree | e67513146b3bde0e8b4ac6cb842caa55dd23f7ae /lib | |
parent | d1af1e4e59f6656428d57e685750f049e7830634 (diff) | |
download | android-node-v8-42d8976dff0e5a5f21d6c89457f348d9fdfd26fe.tar.gz android-node-v8-42d8976dff0e5a5f21d6c89457f348d9fdfd26fe.tar.bz2 android-node-v8-42d8976dff0e5a5f21d6c89457f348d9fdfd26fe.zip |
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>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/buffer.js | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/buffer.js b/lib/buffer.js index 753b16933c..1fbfb756f0 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -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 |