Bug 1531904 - Part 3: Fix some validation logic in createDataChannel. r=jib

Differential Revision: https://phabricator.services.mozilla.com/D26772

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Byron Campen [:bwc] 2019-04-16 16:38:32 +00:00
parent 4d1281bbfd
commit 2c684f17ba
2 changed files with 15 additions and 2 deletions

View File

@ -1605,7 +1605,7 @@ class RTCPeerConnection {
}
createDataChannel(label, {
maxRetransmits, ordered, negotiated, id = 0xFFFF,
maxRetransmits, ordered, negotiated, id = null,
maxRetransmitTime, maxPacketLifeTime,
protocol,
} = {}) {
@ -1619,11 +1619,21 @@ class RTCPeerConnection {
if (maxRetransmitTime !== undefined) {
this.logWarning("Use maxPacketLifeTime instead of deprecated maxRetransmitTime which will stop working soon in createDataChannel!");
}
if (!negotiated) {
id = null;
} else if (id === null) {
throw new this._win.DOMException(
"id is required when negotiated is true", "TypeError");
}
if (maxPacketLifeTime !== undefined && maxRetransmits !== undefined) {
throw new this._win.DOMException(
"Both maxPacketLifeTime and maxRetransmits cannot be provided",
"InvalidParameterError");
}
if (id == 65535) {
throw new this._win.DOMException(
"id cannot be 65535", "TypeError");
}
// Must determine the type where we still know if entries are undefined.
let type;
if (maxPacketLifeTime !== undefined) {

View File

@ -2342,7 +2342,10 @@ already_AddRefed<DataChannel> DataChannelConnection::Open(
const nsACString &label, const nsACString &protocol, Type type,
bool inOrder, uint32_t prValue, DataChannelListener *aListener,
nsISupports *aContext, bool aExternalNegotiated, uint16_t aStream) {
// aStream == INVALID_STREAM to have the protocol allocate
if (!aExternalNegotiated) {
// aStream == INVALID_STREAM to have the protocol allocate
aStream = INVALID_STREAM;
}
uint16_t prPolicy = SCTP_PR_SCTP_NONE;
uint32_t flags;