summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2017-03-22 07:17:05 +0100
committerAnna Henningsen <anna@addaleax.net>2017-03-27 02:03:51 +0200
commit2dc1053b0a6800ab7baf052017d37eaebf5e5a7e (patch)
treeaaca4b20fc1a17830ee076ecb9b0b41c08536ece /lib
parent90403dd1d06d01ca69aea810bcaa7f41b031e8b4 (diff)
downloadandroid-node-v8-2dc1053b0a6800ab7baf052017d37eaebf5e5a7e.tar.gz
android-node-v8-2dc1053b0a6800ab7baf052017d37eaebf5e5a7e.tar.bz2
android-node-v8-2dc1053b0a6800ab7baf052017d37eaebf5e5a7e.zip
dgram: support Uint8Array input to send()
Fixes: https://github.com/nodejs/node/issues/11954 Refs: https://github.com/nodejs/node/pull/11961 PR-URL: https://github.com/nodejs/node/pull/11985 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/dgram.js16
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/dgram.js b/lib/dgram.js
index f39487ba1b..0104d962b1 100644
--- a/lib/dgram.js
+++ b/lib/dgram.js
@@ -29,6 +29,7 @@ const UV_UDP_REUSEADDR = process.binding('constants').os.UV_UDP_REUSEADDR;
const UDP = process.binding('udp_wrap').UDP;
const SendWrap = process.binding('udp_wrap').SendWrap;
+const { isUint8Array } = process.binding('util');
const BIND_STATE_UNBOUND = 0;
const BIND_STATE_BINDING = 1;
@@ -266,10 +267,12 @@ Socket.prototype.sendto = function(buffer,
function sliceBuffer(buffer, offset, length) {
- if (typeof buffer === 'string')
+ if (typeof buffer === 'string') {
buffer = Buffer.from(buffer);
- 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, ' +
+ 'Uint8Array or string');
+ }
offset = offset >>> 0;
length = length >>> 0;
@@ -285,7 +288,7 @@ function fixBufferList(list) {
var buf = list[i];
if (typeof buf === 'string')
newlist[i] = Buffer.from(buf);
- else if (!(buf instanceof Buffer))
+ else if (!isUint8Array(buf))
return null;
else
newlist[i] = buf;
@@ -359,8 +362,9 @@ Socket.prototype.send = function(buffer,
if (!Array.isArray(buffer)) {
if (typeof buffer === 'string') {
list = [ Buffer.from(buffer) ];
- } else if (!(buffer instanceof Buffer)) {
- throw new TypeError('First argument must be a buffer or a string');
+ } else if (!isUint8Array(buffer)) {
+ throw new TypeError('First argument must be a Buffer, ' +
+ 'Uint8Array or string');
} else {
list = [ buffer ];
}