Bug 1941046 - Part 4: Send a callback request for impression and clicks of MARS Top...
[gecko.git] / dom / bindings / test / TestReflectedHTMLAttribute.cpp
blobb2a73788ccebf345a3183d35c65e324638a61dc8
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/. */
7 #include "mozilla/dom/TestReflectedHTMLAttribute.h"
8 #include "mozilla/dom/TestFunctionsBinding.h"
10 namespace mozilla::dom {
12 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(TestReflectedHTMLAttribute,
13 mCachedElements, mNewElements)
15 /* static */
16 already_AddRefed<TestReflectedHTMLAttribute>
17 TestReflectedHTMLAttribute::Constructor(GlobalObject& aGlobal) {
18 return MakeAndAddRef<TestReflectedHTMLAttribute>();
21 template <typename ArrayLike>
22 static void AssignElements(const ArrayLike& aFrom,
23 Nullable<nsTArray<RefPtr<Element>>>& aTo) {
24 if (aTo.IsNull()) {
25 aTo.SetValue();
26 } else {
27 aTo.Value().Clear();
29 aTo.Value().AppendElements(aFrom);
32 void TestReflectedHTMLAttribute::GetReflectedHTMLAttribute(
33 bool* aUseCachedValue, Nullable<nsTArray<RefPtr<Element>>>& aResult) {
34 if (aUseCachedValue) {
35 if (mCachedElements == mNewElements) {
36 *aUseCachedValue = true;
37 return;
40 *aUseCachedValue = false;
43 if (mNewElements.IsNull()) {
44 mCachedElements.SetNull();
45 aResult.SetNull();
46 } else {
47 AssignElements(mNewElements.Value(), mCachedElements);
48 aResult.SetValue(mCachedElements.Value().Clone());
52 void TestReflectedHTMLAttribute::SetReflectedHTMLAttribute(
53 const Nullable<Sequence<OwningNonNull<Element>>>& aValue) {
54 // We're just testing getters, so do nothing. But this would either clear or
55 // set the "explicitly set attr-elements".
58 void TestReflectedHTMLAttribute::SetReflectedHTMLAttributeValue(
59 const Sequence<OwningNonNull<Element>>& aElements) {
60 AssignElements(aElements, mNewElements);
63 JSObject* TestReflectedHTMLAttribute::WrapObject(
64 JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
65 return TestReflectedHTMLAttribute_Binding::Wrap(aCx, this, aGivenProto);
68 } // namespace mozilla::dom