Skip to content
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

dgram: support Uint8Array input to send() #11985

Closed
wants to merge 2 commits into from

Conversation

addaleax
Copy link
Member

Fixes: #11954
Refs: #11961

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

@addaleax addaleax added dgram Issues and PRs related to the dgram subsystem / UDP. semver-major PRs that contain breaking changes and should be released in the next major version. labels Mar 22, 2017
@addaleax addaleax requested a review from TimothyGu March 22, 2017 07:07
@nodejs-github-bot nodejs-github-bot added the dgram Issues and PRs related to the dgram subsystem / UDP. label Mar 22, 2017
lib/dgram.js Outdated
else if (!(buffer instanceof Buffer))
throw new TypeError('First argument must be a buffer or string');
} else if (!isUint8Array(buffer)) {
throw new TypeError('First argument must be a buffer, ' +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the error message is changing anyway, can you s/buffer/Buffer here to make it consistent with the other error messages thrown in this module?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasnell Right, done!

@addaleax
Copy link
Member Author

@@ -16,7 +16,7 @@ const received = [];
client.on('listening', common.mustCall(() => {
const port = client.address().port;
client.send(toSend[0], 0, toSend[0].length, port);
client.send(toSend[1], port);
client.send(new Uint8Array([...toSend[1]]), port);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing test cases for socket.send(u8a, offset, length, port) and socket.send(buffer, port).

Also, is new Uint8Array([...toSend[1]]) here the same as new Uint8Array(toSend[1])?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joyeecheung Right, thanks for pointing that out. I’ve updated the file so all the tests are run twice now, once with the original input types and once with Uint8Arrays.

@addaleax
Copy link
Member Author

Landed in 2dc1053

@addaleax addaleax closed this Mar 27, 2017
@addaleax addaleax deleted the dgram-uint8array branch March 27, 2017 00:08
addaleax added a commit that referenced this pull request Mar 27, 2017
Fixes: #11954
Refs: #11961
PR-URL: #11985
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Timothy Gu <[email protected]>
@jasnell jasnell mentioned this pull request Apr 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dgram Issues and PRs related to the dgram subsystem / UDP. semver-major PRs that contain breaking changes and should be released in the next major version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Buffer::Length hard crashes
7 participants