Skip to content

Commit

Permalink
squash: restore support for DataView
Browse files Browse the repository at this point in the history
  • Loading branch information
LiviaMedeiros committed May 28, 2022
1 parent 2b328c8 commit 220bc10
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/tls.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const internalUtil = require('internal/util');
internalUtil.assertCrypto();
const {
isArrayBufferView,
isDataView,
isUint8Array,
} = require('internal/util/types');

Expand Down Expand Up @@ -149,6 +150,11 @@ exports.convertALPNProtocols = function convertALPNProtocols(protocols, out) {
} else if (Buffer.isBuffer(protocols) || isUint8Array(protocols)) {
// Copy new buffer not to be modified by user.
out.ALPNProtocols = Buffer.from(protocols);
} else if (isDataView(protocols)) {
out.ALPNProtocols = Buffer.from(protocols.buffer.slice(
protocols.byteOffset,
protocols.byteOffset + protocols.byteLength
));
} else if (isArrayBufferView(protocols)) {
out.ALPNProtocols = Buffer.from(protocols.slice().buffer);
}
Expand Down
5 changes: 4 additions & 1 deletion test/parallel/test-tls-basic-validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,11 @@ assert.throws(
const inputBuffer = Buffer.from(arrayBufferViewStr.repeat(8), 'utf8');
for (const expectView of common.getArrayBufferViews(inputBuffer)) {
const out = {};
const expected = Buffer.from(expectView.buffer.slice(),
expectView.byteOffset,
expectView.byteLength);
tls.convertALPNProtocols(expectView, out);
assert(out.ALPNProtocols.equals(Buffer.from(expectView.slice().buffer)));
assert(out.ALPNProtocols.equals(expected));
}
}

Expand Down

0 comments on commit 220bc10

Please sign in to comment.