1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef IPC_ErrorIPCUtils_h
8 #define IPC_ErrorIPCUtils_h
12 #include "ipc/EnumSerializer.h"
13 #include "ipc/IPCMessageUtils.h"
14 #include "mozilla/Assertions.h"
15 #include "mozilla/ErrorResult.h"
20 struct ParamTraits
<mozilla::dom::ErrNum
>
21 : public ContiguousEnumSerializer
<
22 mozilla::dom::ErrNum
, mozilla::dom::ErrNum(0),
23 mozilla::dom::ErrNum(mozilla::dom::Err_Limit
)> {};
26 struct ParamTraits
<mozilla::ErrorResult
> {
27 typedef mozilla::ErrorResult paramType
;
29 static void Write(Message
* aMsg
, const paramType
& aParam
) {
30 // It should be the case that mMightHaveUnreportedJSException can only be
31 // true when we're expecting a JS exception. We cannot send such messages
32 // over the IPC channel since there is no sane way of transferring the JS
33 // value over to the other side. Callers should never do that.
34 MOZ_ASSERT_IF(aParam
.IsJSException(),
35 aParam
.mMightHaveUnreportedJSException
);
36 if (aParam
.IsJSException()
38 || aParam
.mMightHaveUnreportedJSException
42 "Cannot encode an ErrorResult representing a Javascript exception");
45 WriteParam(aMsg
, aParam
.mResult
);
46 WriteParam(aMsg
, aParam
.IsErrorWithMessage());
47 WriteParam(aMsg
, aParam
.IsDOMException());
48 if (aParam
.IsErrorWithMessage()) {
49 aParam
.SerializeMessage(aMsg
);
50 } else if (aParam
.IsDOMException()) {
51 aParam
.SerializeDOMExceptionInfo(aMsg
);
55 static void Write(Message
* aMsg
, paramType
&& aParam
) {
56 Write(aMsg
, static_cast<const paramType
&>(aParam
));
57 aParam
.SuppressException();
60 static bool Read(const Message
* aMsg
, PickleIterator
* aIter
,
63 if (!ReadParam(aMsg
, aIter
, &readValue
.mResult
)) {
66 bool hasMessage
= false;
67 if (!ReadParam(aMsg
, aIter
, &hasMessage
)) {
70 bool hasDOMExceptionInfo
= false;
71 if (!ReadParam(aMsg
, aIter
, &hasDOMExceptionInfo
)) {
74 if (hasMessage
&& hasDOMExceptionInfo
) {
75 // Shouldn't have both!
78 if (hasMessage
&& !readValue
.DeserializeMessage(aMsg
, aIter
)) {
80 } else if (hasDOMExceptionInfo
&&
81 !readValue
.DeserializeDOMExceptionInfo(aMsg
, aIter
)) {
84 *aResult
= std::move(readValue
);
90 struct ParamTraits
<mozilla::CopyableErrorResult
> {
91 typedef mozilla::CopyableErrorResult paramType
;
93 static void Write(Message
* aMsg
, const paramType
& aParam
) {
94 ParamTraits
<mozilla::ErrorResult
>::Write(aMsg
, aParam
);
97 static bool Read(const Message
* aMsg
, PickleIterator
* aIter
,
99 // We can't cast *aResult to ErrorResult&, so cheat and just cast
101 return ParamTraits
<mozilla::ErrorResult
>::Read(
102 aMsg
, aIter
, reinterpret_cast<mozilla::ErrorResult
*>(aResult
));