Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/ipc/ErrorIPCUtils.h
Line
Count
Source (jump to first uncovered line)
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
  static void Write(Message* aMsg, const paramType& aParam)
29
0
  {
30
0
    // It should be the case that mMightHaveUnreportedJSException can only be
31
0
    // true when we're expecting a JS exception.  We cannot send such messages
32
0
    // over the IPC channel since there is no sane way of transferring the JS
33
0
    // 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
        || aParam.mMightHaveUnreportedJSException
38
#endif
39
0
        ) {
40
0
      MOZ_CRASH("Cannot encode an ErrorResult representing a Javascript exception");
41
0
    }
42
0
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
0
    }
51
0
  }
52
53
  static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
54
0
  {
55
0
    paramType readValue;
56
0
    if (!ReadParam(aMsg, aIter, &readValue.mResult)) {
57
0
      return false;
58
0
    }
59
0
    bool hasMessage = false;
60
0
    if (!ReadParam(aMsg, aIter, &hasMessage)) {
61
0
      return false;
62
0
    }
63
0
    bool hasDOMExceptionInfo = false;
64
0
    if (!ReadParam(aMsg, aIter, &hasDOMExceptionInfo)) {
65
0
      return false;
66
0
    }
67
0
    if (hasMessage && hasDOMExceptionInfo) {
68
0
      // Shouldn't have both!
69
0
      return false;
70
0
    }
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
0
    }
77
0
    *aResult = std::move(readValue);
78
0
    return true;
79
0
  }
80
};
81
82
template<>
83
struct ParamTraits<mozilla::CopyableErrorResult>
84
{
85
  typedef mozilla::CopyableErrorResult paramType;
86
87
  static void Write(Message* aMsg, const paramType& aParam)
88
0
  {
89
0
    ParamTraits<mozilla::ErrorResult>::Write(aMsg, aParam);
90
0
  }
91
92
  static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
93
0
  {
94
0
    mozilla::ErrorResult& ref = static_cast<mozilla::ErrorResult&>(*aResult);
95
0
    return ParamTraits<mozilla::ErrorResult>::Read(aMsg, aIter, &ref);
96
0
  }
97
};
98
99
} // namespace IPC
100
101
#endif