Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/fetch/Headers.cpp
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
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include "mozilla/dom/Headers.h"
8
9
#include "mozilla/ErrorResult.h"
10
#include "mozilla/dom/WorkerPrivate.h"
11
#include "mozilla/Preferences.h"
12
13
namespace mozilla {
14
namespace dom {
15
16
NS_IMPL_CYCLE_COLLECTING_ADDREF(Headers)
17
NS_IMPL_CYCLE_COLLECTING_RELEASE(Headers)
18
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Headers, mOwner)
19
20
0
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Headers)
21
0
  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
22
0
  NS_INTERFACE_MAP_ENTRY(nsISupports)
23
0
NS_INTERFACE_MAP_END
24
25
// static
26
already_AddRefed<Headers>
27
Headers::Constructor(const GlobalObject& aGlobal,
28
                     const Optional<HeadersOrByteStringSequenceSequenceOrByteStringByteStringRecord>& aInit,
29
                     ErrorResult& aRv)
30
0
{
31
0
  RefPtr<InternalHeaders> ih = new InternalHeaders();
32
0
  RefPtr<Headers> headers = new Headers(aGlobal.GetAsSupports(), ih);
33
0
34
0
  if (!aInit.WasPassed()) {
35
0
    return headers.forget();
36
0
  }
37
0
38
0
  if (aInit.Value().IsHeaders()) {
39
0
    ih->Fill(*aInit.Value().GetAsHeaders().mInternalHeaders, aRv);
40
0
  } else if (aInit.Value().IsByteStringSequenceSequence()) {
41
0
    ih->Fill(aInit.Value().GetAsByteStringSequenceSequence(), aRv);
42
0
  } else if (aInit.Value().IsByteStringByteStringRecord()) {
43
0
    ih->Fill(aInit.Value().GetAsByteStringByteStringRecord(), aRv);
44
0
  }
45
0
46
0
  if (aRv.Failed()) {
47
0
    return nullptr;
48
0
  }
49
0
50
0
  return headers.forget();
51
0
}
52
53
// static
54
already_AddRefed<Headers>
55
Headers::Constructor(const GlobalObject& aGlobal,
56
                     const OwningHeadersOrByteStringSequenceSequenceOrByteStringByteStringRecord& aInit,
57
                     ErrorResult& aRv)
58
0
{
59
0
  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
60
0
  return Create(global, aInit, aRv);
61
0
}
62
63
/* static */ already_AddRefed<Headers>
64
Headers::Create(nsIGlobalObject* aGlobal,
65
                const OwningHeadersOrByteStringSequenceSequenceOrByteStringByteStringRecord& aInit,
66
                ErrorResult& aRv)
67
0
{
68
0
  RefPtr<InternalHeaders> ih = new InternalHeaders();
69
0
  RefPtr<Headers> headers = new Headers(aGlobal, ih);
70
0
71
0
  if (aInit.IsHeaders()) {
72
0
    ih->Fill(*(aInit.GetAsHeaders().get()->mInternalHeaders), aRv);
73
0
  } else if (aInit.IsByteStringSequenceSequence()) {
74
0
    ih->Fill(aInit.GetAsByteStringSequenceSequence(), aRv);
75
0
  } else if (aInit.IsByteStringByteStringRecord()) {
76
0
    ih->Fill(aInit.GetAsByteStringByteStringRecord(), aRv);
77
0
  }
78
0
79
0
  if (NS_WARN_IF(aRv.Failed())) {
80
0
    return nullptr;
81
0
  }
82
0
83
0
  return headers.forget();
84
0
}
85
86
JSObject*
87
Headers::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
88
0
{
89
0
  return mozilla::dom::Headers_Binding::Wrap(aCx, this, aGivenProto);
90
0
}
91
92
Headers::~Headers()
93
0
{
94
0
}
95
96
} // namespace dom
97
} // namespace mozilla