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

RTCError: Make "message" optional and be the last argument.

Based on https://github.com/w3c/webrtc-pc/pull/2112.

Bug: 937844
Change-Id: I7ad149f47fb394f15055cc8fd77e79b4e5e0f317
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1499613
Commit-Queue: Henrik Boström <hbos@chromium.org>
Reviewed-by: default avatarMarina Ciocea <marinaciocea@chromium.org>
Cr-Commit-Position: refs/heads/master@{#638192}
parent 8523708a
...@@ -9,11 +9,11 @@ ...@@ -9,11 +9,11 @@
namespace blink { namespace blink {
// static // static
RTCError* RTCError::Create(String message, const RTCErrorInit* init) { RTCError* RTCError::Create(const RTCErrorInit* init, String message) {
return MakeGarbageCollected<RTCError>(std::move(message), init); return MakeGarbageCollected<RTCError>(init, std::move(message));
} }
RTCError::RTCError(String message, const RTCErrorInit* init) RTCError::RTCError(const RTCErrorInit* init, String message)
: DOMException(0u, "RTCError", std::move(message), String()), : DOMException(0u, "RTCError", std::move(message), String()),
error_detail_(init->errorDetail()), error_detail_(init->errorDetail()),
sdp_line_number_(init->hasSdpLineNumber() sdp_line_number_(init->hasSdpLineNumber()
......
...@@ -17,8 +17,8 @@ class RTCError final : public DOMException { ...@@ -17,8 +17,8 @@ class RTCError final : public DOMException {
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
public: public:
static RTCError* Create(String message, const RTCErrorInit* init); static RTCError* Create(const RTCErrorInit* init, String message);
RTCError(String message, const RTCErrorInit* init); RTCError(const RTCErrorInit* init, String message);
const String& errorDetail() const; const String& errorDetail() const;
int32_t sdpLineNumber(bool& is_null) const; int32_t sdpLineNumber(bool& is_null) const;
......
...@@ -23,7 +23,7 @@ enum RTCErrorDetailType { ...@@ -23,7 +23,7 @@ enum RTCErrorDetailType {
// https://w3c.github.io/webrtc-pc/#dfn-rtcerror // https://w3c.github.io/webrtc-pc/#dfn-rtcerror
[ [
Constructor(DOMString message, RTCErrorInit init) Constructor(RTCErrorInit init, optional DOMString message = "")
] interface RTCError : DOMException { ] interface RTCError : DOMException {
readonly attribute RTCErrorDetailType errorDetail; readonly attribute RTCErrorDetailType errorDetail;
readonly attribute long? sdpLineNumber; readonly attribute long? sdpLineNumber;
......
...@@ -8,38 +8,43 @@ ...@@ -8,38 +8,43 @@
'use strict'; 'use strict';
test(() => { test(() => {
const error = new RTCError('message', {errorDetail:'data-channel-failure'}); const error = new RTCError({errorDetail:'data-channel-failure'}, 'message');
assert_equals(error.message, 'message'); assert_equals(error.message, 'message');
assert_equals(error.errorDetail, 'data-channel-failure'); assert_equals(error.errorDetail, 'data-channel-failure');
}, 'RTCError constructor with message and errorDetail'); }, 'RTCError constructor with errorDetail and message');
test(() => {
const error = new RTCError({errorDetail:'data-channel-failure'});
assert_equals(error.message, '');
}, 'RTCError constructor\'s message argument is optional');
test(() => { test(() => {
assert_throws(new TypeError(), () => { assert_throws(new TypeError(), () => {
new RTCError('message'); new RTCError();
}); });
assert_throws(new TypeError(), () => { assert_throws(new TypeError(), () => {
new RTCError(); new RTCError({}); // {errorDetail} is missing.
}); });
}, 'RTCError constructor throws TypeError if any argument is missing'); }, 'RTCError constructor throws TypeError if arguments are missing');
test(() => { test(() => {
assert_throws(new TypeError(), () => { assert_throws(new TypeError(), () => {
new RTCError('message', {errorDetail:'invalid-error-detail'}); new RTCError({errorDetail:'invalid-error-detail'}, 'message');
}); });
}, 'RTCError constructor throws TypeError if the errorDetail is invalid'); }, 'RTCError constructor throws TypeError if the errorDetail is invalid');
test(() => { test(() => {
const error = new RTCError('message', {errorDetail:'data-channel-failure'}); const error = new RTCError({errorDetail:'data-channel-failure'}, 'message');
assert_equals(error.name, 'RTCError'); assert_equals(error.name, 'RTCError');
}, 'RTCError.name is \'RTCError\''); }, 'RTCError.name is \'RTCError\'');
test(() => { test(() => {
const error = new RTCError('message', {errorDetail:'data-channel-failure'}); const error = new RTCError({errorDetail:'data-channel-failure'}, 'message');
assert_equals(error.code, 0); assert_equals(error.code, 0);
}, 'RTCError.code is 0'); }, 'RTCError.code is 0');
test(() => { test(() => {
const error = new RTCError('message', {errorDetail:'data-channel-failure'}); const error = new RTCError({errorDetail:'data-channel-failure'}, 'message');
assert_throws(new TypeError(), () => { assert_throws(new TypeError(), () => {
error.errorDetail = 'dtls-failure'; error.errorDetail = 'dtls-failure';
}); });
...@@ -49,9 +54,9 @@ test(() => { ...@@ -49,9 +54,9 @@ test(() => {
// Infers what are valid RTCErrorInit objects by passing them to the RTCError // Infers what are valid RTCErrorInit objects by passing them to the RTCError
// constructor. // constructor.
assert_throws(new TypeError(), () => { assert_throws(new TypeError(), () => {
new RTCError('message', {}); new RTCError({}, 'message');
}); });
new RTCError('message', {errorDetail:'data-channel-failure'}); new RTCError({errorDetail:'data-channel-failure'}, 'message');
}, 'RTCErrorInit.errorDetail is the only required attribute'); }, 'RTCErrorInit.errorDetail is the only required attribute');
// All of these are number types (long or unsigned long). // All of these are number types (long or unsigned long).
...@@ -63,18 +68,18 @@ const nullableAttributes = ['sdpLineNumber', ...@@ -63,18 +68,18 @@ const nullableAttributes = ['sdpLineNumber',
nullableAttributes.forEach(attribute => { nullableAttributes.forEach(attribute => {
test(() => { test(() => {
const error = new RTCError('message', {errorDetail:'data-channel-failure'}); const error = new RTCError({errorDetail:'data-channel-failure'}, 'message');
assert_equals(error[attribute], null); assert_equals(error[attribute], null);
}, 'RTCError.' + attribute + ' is null by default'); }, 'RTCError.' + attribute + ' is null by default');
test(() => { test(() => {
const error = new RTCError('message', {errorDetail:'data-channel-failure', const error = new RTCError(
[attribute]: 0}); {errorDetail:'data-channel-failure', [attribute]: 0}, 'message');
assert_equals(error[attribute], 0); assert_equals(error[attribute], 0);
}, 'RTCError.' + attribute + ' is settable by constructor'); }, 'RTCError.' + attribute + ' is settable by constructor');
test(() => { test(() => {
const error = new RTCError('message', {errorDetail:'data-channel-failure'}); const error = new RTCError({errorDetail:'data-channel-failure'}, 'message');
assert_throws(new TypeError(), () => { assert_throws(new TypeError(), () => {
error[attribute] = 42; error[attribute] = 42;
}); });
......
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