-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
Conversation
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, ' + |
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.
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?
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.
@jasnell Right, done!
d401ef1
to
f1478e9
Compare
@@ -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); |
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 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])
?
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.
@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.
Landed in 2dc1053 |
Fixes: #11954
Refs: #11961
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)