Line data Source code
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/. */
6 :
7 : #include "ipc/IPCMessageUtils.h"
8 : #include "mozilla/ErrorResult.h"
9 : #include "mozilla/Assertions.h"
10 : #include "mozilla/Move.h"
11 :
12 : #ifndef IPC_ErrorIPCUtils_h
13 : #define IPC_ErrorIPCUtils_h
14 :
15 : namespace IPC {
16 :
17 : template<>
18 : struct ParamTraits<mozilla::dom::ErrNum> :
19 : public ContiguousEnumSerializer<mozilla::dom::ErrNum,
20 : mozilla::dom::ErrNum(0),
21 : mozilla::dom::ErrNum(mozilla::dom::Err_Limit)> {};
22 :
23 : template<>
24 : struct ParamTraits<mozilla::ErrorResult>
25 : {
26 : typedef mozilla::ErrorResult paramType;
27 :
28 0 : static void Write(Message* aMsg, const paramType& aParam)
29 : {
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 0 : MOZ_ASSERT_IF(aParam.IsJSException(), aParam.mMightHaveUnreportedJSException);
35 0 : if (aParam.IsJSException()
36 : #ifdef DEBUG
37 0 : || aParam.mMightHaveUnreportedJSException
38 : #endif
39 : ) {
40 0 : MOZ_CRASH("Cannot encode an ErrorResult representing a Javascript exception");
41 : }
42 :
43 0 : WriteParam(aMsg, aParam.mResult);
44 0 : WriteParam(aMsg, aParam.IsErrorWithMessage());
45 0 : WriteParam(aMsg, aParam.IsDOMException());
46 0 : if (aParam.IsErrorWithMessage()) {
47 0 : aParam.SerializeMessage(aMsg);
48 0 : } else if (aParam.IsDOMException()) {
49 0 : aParam.SerializeDOMExceptionInfo(aMsg);
50 : }
51 0 : }
52 :
53 0 : static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
54 : {
55 0 : paramType readValue;
56 0 : if (!ReadParam(aMsg, aIter, &readValue.mResult)) {
57 0 : return false;
58 : }
59 0 : bool hasMessage = false;
60 0 : if (!ReadParam(aMsg, aIter, &hasMessage)) {
61 0 : return false;
62 : }
63 0 : bool hasDOMExceptionInfo = false;
64 0 : if (!ReadParam(aMsg, aIter, &hasDOMExceptionInfo)) {
65 0 : return false;
66 : }
67 0 : if (hasMessage && hasDOMExceptionInfo) {
68 : // Shouldn't have both!
69 0 : return false;
70 : }
71 0 : if (hasMessage && !readValue.DeserializeMessage(aMsg, aIter)) {
72 0 : return false;
73 0 : } else if (hasDOMExceptionInfo &&
74 0 : !readValue.DeserializeDOMExceptionInfo(aMsg, aIter)) {
75 0 : return false;
76 : }
77 0 : *aResult = Move(readValue);
78 0 : return true;
79 : }
80 : };
81 :
82 : } // namespace IPC
83 :
84 : #endif
|