Headers.cpp (2678B)
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/Preferences.h" 11 #include "mozilla/dom/WorkerPrivate.h" 12 13 namespace mozilla::dom { 14 15 NS_IMPL_CYCLE_COLLECTING_ADDREF(Headers) 16 NS_IMPL_CYCLE_COLLECTING_RELEASE(Headers) 17 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Headers, mOwner) 18 19 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Headers) 20 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY 21 NS_INTERFACE_MAP_ENTRY(nsISupports) 22 NS_INTERFACE_MAP_END 23 24 // static 25 already_AddRefed<Headers> Headers::Constructor( 26 const GlobalObject& aGlobal, 27 const Optional<ByteStringSequenceSequenceOrByteStringByteStringRecord>& 28 aInit, 29 ErrorResult& aRv) { 30 RefPtr<InternalHeaders> ih = new InternalHeaders(); 31 RefPtr<Headers> headers = new Headers(aGlobal.GetAsSupports(), ih); 32 33 if (!aInit.WasPassed()) { 34 return headers.forget(); 35 } 36 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); 41 } 42 43 if (aRv.Failed()) { 44 return nullptr; 45 } 46 47 return headers.forget(); 48 } 49 50 // static 51 already_AddRefed<Headers> Headers::Constructor( 52 const GlobalObject& aGlobal, 53 const OwningByteStringSequenceSequenceOrByteStringByteStringRecord& aInit, 54 ErrorResult& aRv) { 55 nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports()); 56 return Create(global, aInit, aRv); 57 } 58 59 /* static */ 60 already_AddRefed<Headers> Headers::Create( 61 nsIGlobalObject* aGlobal, 62 const OwningByteStringSequenceSequenceOrByteStringByteStringRecord& aInit, 63 ErrorResult& aRv) { 64 RefPtr<InternalHeaders> ih = new InternalHeaders(); 65 RefPtr<Headers> headers = new Headers(aGlobal, ih); 66 67 if (aInit.IsByteStringSequenceSequence()) { 68 ih->Fill(aInit.GetAsByteStringSequenceSequence(), aRv); 69 } else if (aInit.IsByteStringByteStringRecord()) { 70 ih->Fill(aInit.GetAsByteStringByteStringRecord(), aRv); 71 } 72 73 if (NS_WARN_IF(aRv.Failed())) { 74 return nullptr; 75 } 76 77 return headers.forget(); 78 } 79 80 JSObject* Headers::WrapObject(JSContext* aCx, 81 JS::Handle<JSObject*> aGivenProto) { 82 return mozilla::dom::Headers_Binding::Wrap(aCx, this, aGivenProto); 83 } 84 85 Headers::~Headers() = default; 86 87 } // namespace mozilla::dom