-
-
Notifications
You must be signed in to change notification settings - Fork 35k
buffer: do not emit deprecation notice on Buffer.of #19682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -237,6 +237,17 @@ Buffer.from = function from(value, encodingOrOffset, length) { | |
| ); | ||
| }; | ||
|
|
||
| // Identical to the built-in %TypedArray%.of(), but avoids using the deprecated | ||
| // Buffer() constructor. | ||
| // | ||
| // Refs: https://tc39.github.io/ecma262/#sec-%typedarray%.of | ||
| Buffer.of = (...items) => { | ||
| const newObj = allocate(items.length); | ||
|
||
| for (var k = 0; k < items.length; k++) | ||
| newObj[k] = items[k]; | ||
| return newObj; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line-to-line code duplication of
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. |
||
| }; | ||
|
|
||
| Object.setPrototypeOf(Buffer, Uint8Array); | ||
|
|
||
| // The 'assertSize' method will remove itself from the callstack when an error | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| // Flags: --pending-deprecation --no-warnings | ||
| 'use strict'; | ||
|
|
||
| const common = require('../common'); | ||
|
|
||
| process.on('warning', common.mustNotCall()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, the |
||
|
|
||
| Buffer.of(0, 1); | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changes the name of the function. It should probably be named
'of'.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Grrr, I always thought this kind of assignment names the function automatically. Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are named in cases like
{ of: () => {} }andconst of = () => {}, but not inx.of = () => {}.