Commit 3dfb2b29 authored by Henrik Boström's avatar Henrik Boström Committed by Commit Bot

Add RTCError, RTCErrorInit, RTCErrorDetailType and WPT coverage.

This allows us to construct the RTCError. Changing error types thrown
by various methods will be done in separate CLs.

Intent to Implement & Ship:
https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/TsJA1XX7mTE

Bug: 821806
Change-Id: I876bb1b7859e69018ba970b528e515313b068c39
Reviewed-on: https://chromium-review.googlesource.com/c/1421797
Commit-Queue: Henrik Boström <hbos@chromium.org>
Reviewed-by: default avatarPhilip Jägenstedt <foolip@chromium.org>
Reviewed-by: default avatarMarina Ciocea <marinaciocea@chromium.org>
Reviewed-by: default avatarHarald Alvestrand <hta@chromium.org>
Cr-Commit-Position: refs/heads/master@{#628585}
parent 0b47f4fe
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
namespace blink { namespace blink {
class CORE_EXPORT DOMException final : public ScriptWrappable { class CORE_EXPORT DOMException : public ScriptWrappable {
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
public: public:
......
...@@ -230,6 +230,7 @@ modules_idl_files = ...@@ -230,6 +230,7 @@ modules_idl_files =
"peerconnection/rtc_dtls_transport.idl", "peerconnection/rtc_dtls_transport.idl",
"peerconnection/rtc_dtmf_sender.idl", "peerconnection/rtc_dtmf_sender.idl",
"peerconnection/rtc_dtmf_tone_change_event.idl", "peerconnection/rtc_dtmf_tone_change_event.idl",
"peerconnection/rtc_error.idl",
"peerconnection/rtc_ice_candidate.idl", "peerconnection/rtc_ice_candidate.idl",
"peerconnection/rtc_ice_transport.idl", "peerconnection/rtc_ice_transport.idl",
"peerconnection/rtc_legacy_stats_report.idl", "peerconnection/rtc_legacy_stats_report.idl",
...@@ -632,6 +633,7 @@ modules_dictionary_idl_files = ...@@ -632,6 +633,7 @@ modules_dictionary_idl_files =
"peerconnection/rtc_data_channel_init.idl", "peerconnection/rtc_data_channel_init.idl",
"peerconnection/rtc_dtls_fingerprint.idl", "peerconnection/rtc_dtls_fingerprint.idl",
"peerconnection/rtc_dtmf_tone_change_event_init.idl", "peerconnection/rtc_dtmf_tone_change_event_init.idl",
"peerconnection/rtc_error_init.idl",
"peerconnection/rtc_ice_candidate_init.idl", "peerconnection/rtc_ice_candidate_init.idl",
"peerconnection/rtc_ice_candidate_pair.idl", "peerconnection/rtc_ice_candidate_pair.idl",
"peerconnection/rtc_ice_gather_options.idl", "peerconnection/rtc_ice_gather_options.idl",
......
...@@ -59,6 +59,8 @@ blink_modules_sources("peerconnection") { ...@@ -59,6 +59,8 @@ blink_modules_sources("peerconnection") {
"rtc_dtmf_sender.h", "rtc_dtmf_sender.h",
"rtc_dtmf_tone_change_event.cc", "rtc_dtmf_tone_change_event.cc",
"rtc_dtmf_tone_change_event.h", "rtc_dtmf_tone_change_event.h",
"rtc_error.cc",
"rtc_error.h",
"rtc_error_util.cc", "rtc_error_util.cc",
"rtc_error_util.h", "rtc_error_util.h",
"rtc_ice_candidate.cc", "rtc_ice_candidate.cc",
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/modules/peerconnection/rtc_error.h"
#include <utility>
namespace blink {
// static
RTCError* RTCError::Create(String message, const RTCErrorInit* init) {
return MakeGarbageCollected<RTCError>(std::move(message), init);
}
RTCError::RTCError(String message, const RTCErrorInit* init)
: DOMException(0u, "RTCError", std::move(message), String()),
error_detail_(init->errorDetail()),
sdp_line_number_(init->hasSdpLineNumber()
? base::Optional<int32_t>(init->sdpLineNumber())
: base::nullopt),
http_request_status_code_(
init->hasHttpRequestStatusCode()
? base::Optional<int32_t>(init->httpRequestStatusCode())
: base::nullopt),
sctp_cause_code_(init->hasSctpCauseCode()
? base::Optional<int32_t>(init->sctpCauseCode())
: base::nullopt),
received_alert_(init->hasReceivedAlert()
? base::Optional<uint32_t>(init->receivedAlert())
: base::nullopt),
sent_alert_(init->hasSentAlert()
? base::Optional<uint32_t>(init->sentAlert())
: base::nullopt) {}
const String& RTCError::errorDetail() const {
return error_detail_;
}
int32_t RTCError::sdpLineNumber(bool& is_null) const {
is_null = !sdp_line_number_;
return sdp_line_number_ ? *sdp_line_number_ : 0;
}
int32_t RTCError::httpRequestStatusCode(bool& is_null) const {
is_null = !http_request_status_code_;
return http_request_status_code_ ? *http_request_status_code_ : 0;
}
int32_t RTCError::sctpCauseCode(bool& is_null) const {
is_null = !sctp_cause_code_;
return sctp_cause_code_ ? *sctp_cause_code_ : 0;
}
uint32_t RTCError::receivedAlert(bool& is_null) const {
is_null = !received_alert_;
return received_alert_ ? *received_alert_ : 0u;
}
uint32_t RTCError::sentAlert(bool& is_null) const {
is_null = !sent_alert_;
return sent_alert_ ? *sent_alert_ : 0u;
}
} // namespace blink
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_PEERCONNECTION_RTC_ERROR_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_PEERCONNECTION_RTC_ERROR_H_
#include "base/optional.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/modules/peerconnection/rtc_error_init.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
namespace blink {
class RTCError final : public DOMException {
DEFINE_WRAPPERTYPEINFO();
public:
static RTCError* Create(String message, const RTCErrorInit* init);
RTCError(String message, const RTCErrorInit* init);
const String& errorDetail() const;
int32_t sdpLineNumber(bool& is_null) const;
int32_t httpRequestStatusCode(bool& is_null) const;
int32_t sctpCauseCode(bool& is_null) const;
uint32_t receivedAlert(bool& is_null) const;
uint32_t sentAlert(bool& is_null) const;
private:
// idl enum RTCErrorDetailType.
String error_detail_;
base::Optional<int32_t> sdp_line_number_;
base::Optional<int32_t> http_request_status_code_;
base::Optional<int32_t> sctp_cause_code_;
base::Optional<uint32_t> received_alert_;
base::Optional<uint32_t> sent_alert_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_PEERCONNECTION_RTC_ERROR_H_
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// https://w3c.github.io/webrtc-pc/#dfn-rtcerrordetailtype
enum RTCErrorDetailType {
"data-channel-failure",
"dtls-failure",
"fingerprint-failure",
"idp-bad-script-failure",
"idp-execution-failure",
"idp-load-failure",
"idp-need-login",
"idp-timeout",
"idp-tls-failure",
"idp-token-expired",
"idp-token-invalid",
"sctp-failure",
"sdp-syntax-error",
"hardware-encoder-not-available",
"hardware-encoder-error"
};
// https://w3c.github.io/webrtc-pc/#dfn-rtcerror
[
Constructor(DOMString message, RTCErrorInit init)
] interface RTCError : DOMException {
readonly attribute RTCErrorDetailType errorDetail;
readonly attribute long? sdpLineNumber;
readonly attribute long? httpRequestStatusCode;
readonly attribute long? sctpCauseCode;
readonly attribute unsigned long? receivedAlert;
readonly attribute unsigned long? sentAlert;
};
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// https://w3c.github.io/webrtc-pc/#dfn-rtcerrorinit
dictionary RTCErrorInit {
required RTCErrorDetailType errorDetail;
long sdpLineNumber;
long httpRequestStatusCode;
long sctpCauseCode;
unsigned long receivedAlert;
unsigned long sentAlert;
};
<!doctype html>
<meta charset=utf-8>
<title>RTCError and RTCErrorInit</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="RTCPeerConnection-helper.js"></script>
<script>
'use strict';
test(() => {
const error = new RTCError('message', {errorDetail:'data-channel-failure'});
assert_equals(error.message, 'message');
assert_equals(error.errorDetail, 'data-channel-failure');
}, 'RTCError constructor with message and errorDetail');
test(() => {
assert_throws(new TypeError(), () => {
new RTCError('message');
});
assert_throws(new TypeError(), () => {
new RTCError();
});
}, 'RTCError constructor throws TypeError if any argument is missing');
test(() => {
assert_throws(new TypeError(), () => {
new RTCError('message', {errorDetail:'invalid-error-detail'});
});
}, 'RTCError constructor throws TypeError if the errorDetail is invalid');
test(() => {
const error = new RTCError('message', {errorDetail:'data-channel-failure'});
assert_equals(error.name, 'RTCError');
}, 'RTCError.name is \'RTCError\'');
test(() => {
const error = new RTCError('message', {errorDetail:'data-channel-failure'});
assert_equals(error.code, 0);
}, 'RTCError.code is 0');
test(() => {
const error = new RTCError('message', {errorDetail:'data-channel-failure'});
assert_throws(new TypeError(), () => {
error.errorDetail = 'dtls-failure';
});
}, 'RTCError.errorDetail is readonly.');
test(() => {
// Infers what are valid RTCErrorInit objects by passing them to the RTCError
// constructor.
assert_throws(new TypeError(), () => {
new RTCError('message', {});
});
new RTCError('message', {errorDetail:'data-channel-failure'});
}, 'RTCErrorInit.errorDetail is the only required attribute');
// All of these are number types (long or unsigned long).
const nullableAttributes = ['sdpLineNumber',
'httpRequestStatusCode',
'sctpCauseCode',
'receivedAlert',
'sentAlert'];
nullableAttributes.forEach(attribute => {
test(() => {
const error = new RTCError('message', {errorDetail:'data-channel-failure'});
assert_equals(error[attribute], null);
}, 'RTCError.' + attribute + ' is null by default');
test(() => {
const error = new RTCError('message', {errorDetail:'data-channel-failure',
[attribute]: 0});
assert_equals(error[attribute], 0);
}, 'RTCError.' + attribute + ' is settable by constructor');
test(() => {
const error = new RTCError('message', {errorDetail:'data-channel-failure'});
assert_throws(new TypeError(), () => {
error[attribute] = 42;
});
}, 'RTCError.' + attribute + ' is readonly');
});
</script>
...@@ -4863,6 +4863,15 @@ interface RTCDataChannelEvent : Event ...@@ -4863,6 +4863,15 @@ interface RTCDataChannelEvent : Event
attribute @@toStringTag attribute @@toStringTag
getter channel getter channel
method constructor method constructor
interface RTCError : DOMException
attribute @@toStringTag
getter errorDetail
getter httpRequestStatusCode
getter receivedAlert
getter sctpCauseCode
getter sdpLineNumber
getter sentAlert
method constructor
interface RTCIceCandidate interface RTCIceCandidate
attribute @@toStringTag attribute @@toStringTag
getter address getter address
......
...@@ -5618,6 +5618,15 @@ interface RTCDtlsTransport : EventTarget ...@@ -5618,6 +5618,15 @@ interface RTCDtlsTransport : EventTarget
method getRemoteCertificates method getRemoteCertificates
setter onerror setter onerror
setter onstatechange setter onstatechange
interface RTCError : DOMException
attribute @@toStringTag
getter errorDetail
getter httpRequestStatusCode
getter receivedAlert
getter sctpCauseCode
getter sdpLineNumber
getter sentAlert
method constructor
interface RTCIceCandidate interface RTCIceCandidate
attribute @@toStringTag attribute @@toStringTag
getter address getter address
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment