-
-
Notifications
You must be signed in to change notification settings - Fork 34.3k
buffer: hard-deprecate calling Buffer without new #8169
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 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,7 +64,17 @@ function alignPool() { | |
| * much breakage at this time. It's not likely that the Buffer constructors | ||
| * would ever actually be removed. | ||
| **/ | ||
| var newBufferWarned = false; | ||
| function Buffer(arg, encodingOrOffset, length) { | ||
| if (!new.target && !newBufferWarned) { | ||
| newBufferWarned = true; | ||
| process.emitWarning( | ||
| 'Using Buffer without `new` will soon stop working. ' + | ||
| 'Use `new Buffer`, or preferably ' + | ||
| 'Buffer.from, Buffer.allocUnsafe or Buffer.alloc instead.', | ||
|
||
| 'DeprecationWarning' | ||
| ); | ||
| } | ||
|
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. Instead of this, please use process.emitWarning(
'Calling Buffer() without `new` is deprecated. Use Buffer.alloc(), ' +
'Buffer.allocUnsafe(), Buffer.from(), or new Buffer() instead.',
'DeprecationWarning'
);
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. @jasnell That would emit a warning every time
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. right.. there should be a gate... like so: var newBufferWarned = false;
function Buffer(arg, encodingOrOffset, length) {
if (!new.target && !newBufferWarned) {
newBufferWarned = true;
process.emitWarning(
'Calling Buffer() without `new` is deprecated. Use Buffer.alloc(), ' +
'Buffer.allocUnsafe(), Buffer.from(), or new Buffer() instead.',
'DeprecationWarning'
);
}
//...
Contributor
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. Could you clarify the purpose of such change? It would introduce needless boilerplate and make it inconsistent with the rest of node.
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. See #8166 ... I'm working towards making this more consistent. If you look at the current implementation of the Also, the way that
Contributor
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. @jasnell Done. I kept the wording because "Calling Buffer() without |
||
| // Common case. | ||
| if (typeof arg === 'number') { | ||
| if (typeof encodingOrOffset === 'string') { | ||
|
|
||
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.
Actually since this will be in v7... maybe we should only recommend
Buffer.from()andBuffer.alloc()(pref with the parenthesis?)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.
That works for memisread the comment... see #8169 (comment) instead.