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/. */
7 #include "mozilla/dom/Headers.h"
9 #include "mozilla/ErrorResult.h"
10 #include "mozilla/dom/WorkerPrivate.h"
11 #include "mozilla/Preferences.h"
13 namespace mozilla::dom
{
15 NS_IMPL_CYCLE_COLLECTING_ADDREF(Headers
)
16 NS_IMPL_CYCLE_COLLECTING_RELEASE(Headers
)
17 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Headers
, mOwner
)
19 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Headers
)
20 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
21 NS_INTERFACE_MAP_ENTRY(nsISupports
)
25 already_AddRefed
<Headers
> Headers::Constructor(
26 const GlobalObject
& aGlobal
,
27 const Optional
<ByteStringSequenceSequenceOrByteStringByteStringRecord
>&
30 RefPtr
<InternalHeaders
> ih
= new InternalHeaders();
31 RefPtr
<Headers
> headers
= new Headers(aGlobal
.GetAsSupports(), ih
);
33 if (!aInit
.WasPassed()) {
34 return headers
.forget();
37 if (aInit
.Value().IsByteStringSequenceSequence()) {
38 ih
->Fill(aInit
.Value().GetAsByteStringSequenceSequence(), aRv
);
39 } else if (aInit
.Value().IsByteStringByteStringRecord()) {
40 ih
->Fill(aInit
.Value().GetAsByteStringByteStringRecord(), aRv
);
47 return headers
.forget();
51 already_AddRefed
<Headers
> Headers::Constructor(
52 const GlobalObject
& aGlobal
,
53 const OwningByteStringSequenceSequenceOrByteStringByteStringRecord
& aInit
,
55 nsCOMPtr
<nsIGlobalObject
> global
= do_QueryInterface(aGlobal
.GetAsSupports());
56 return Create(global
, aInit
, aRv
);
60 already_AddRefed
<Headers
> Headers::Create(
61 nsIGlobalObject
* aGlobal
,
62 const OwningByteStringSequenceSequenceOrByteStringByteStringRecord
& aInit
,
64 RefPtr
<InternalHeaders
> ih
= new InternalHeaders();
65 RefPtr
<Headers
> headers
= new Headers(aGlobal
, ih
);
67 if (aInit
.IsByteStringSequenceSequence()) {
68 ih
->Fill(aInit
.GetAsByteStringSequenceSequence(), aRv
);
69 } else if (aInit
.IsByteStringByteStringRecord()) {
70 ih
->Fill(aInit
.GetAsByteStringByteStringRecord(), aRv
);
73 if (NS_WARN_IF(aRv
.Failed())) {
77 return headers
.forget();
80 JSObject
* Headers::WrapObject(JSContext
* aCx
,
81 JS::Handle
<JSObject
*> aGivenProto
) {
82 return mozilla::dom::Headers_Binding::Wrap(aCx
, this, aGivenProto
);
85 Headers::~Headers() = default;
87 } // namespace mozilla::dom