NeverDestroyed<String>(ASCIILiteral(...)) is not thread safe.
[WebKit-https.git] / Source / JavaScriptCore / replay / scripts / tests / expected / generate-enum-encoding-helpers.json-TestReplayInputs.cpp
1 /*
2  * Copyright (C) 2014 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1.  Redistributions of source code must retain the above copyright
9  *     notice, this list of conditions and the following disclaimer.
10  * 2.  Redistributions in binary form must reproduce the above copyright
11  *     notice, this list of conditions and the following disclaimer in the
12  *     documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
15  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
16  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
17  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
18  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26
27 // DO NOT EDIT THIS FILE. It is automatically generated from generate-enum-encoding-helpers.json
28 // by the script: JavaScriptCore/replay/scripts/CodeGeneratorReplayInputs.py
29
30 #include "config.h"
31 #include "generate-enum-encoding-helpers.json-TestReplayInputs.h"
32
33 #if ENABLE(WEB_REPLAY)
34 #include "InternalNamespaceImplIncludeDummy.h"
35 #include "NondeterministicInput.h"
36 #include "PlatformMouseEvent.h"
37 #include <platform/ExternalNamespaceImplIncludeDummy.h>
38
39 namespace Test {
40 SavedMouseButton::SavedMouseButton(MouseButton button)
41     : NondeterministicInput<SavedMouseButton>()
42     , m_button(button)
43 {
44 }
45
46 SavedMouseButton::~SavedMouseButton()
47 {
48 }
49 } // namespace Test
50
51 namespace JSC {
52 const String& InputTraits<Test::SavedMouseButton>::type()
53 {
54     static NeverDestroyed<const String> type(MAKE_STATIC_STRING_IMPL("SavedMouseButton"));
55     return type;
56 }
57
58 void InputTraits<Test::SavedMouseButton>::encode(EncodedValue& encodedValue, const Test::SavedMouseButton& input)
59 {
60     encodedValue.put<Test::MouseButton>(ASCIILiteral("button"), input.button());
61 }
62
63 bool InputTraits<Test::SavedMouseButton>::decode(EncodedValue& encodedValue, std::unique_ptr<Test::SavedMouseButton>& input)
64 {
65     Test::MouseButton button;
66     if (!encodedValue.get<Test::MouseButton>(ASCIILiteral("button"), button))
67         return false;
68
69     input = std::make_unique<Test::SavedMouseButton>(button);
70     return true;
71 }
72 EncodedValue EncodingTraits<Test::InputQueue>::encodeValue(const Test::InputQueue& enumValue)
73 {
74     switch (enumValue) {
75     case Test::InputQueue::EventLoopInput: return EncodedValue::createString("EventLoopInput");
76     case Test::InputQueue::LoaderMemoizedData: return EncodedValue::createString("LoaderMemoizedData");
77     case Test::InputQueue::ScriptMemoizedData: return EncodedValue::createString("ScriptMemoizedData");
78     default: ASSERT_NOT_REACHED(); return EncodedValue::createString("Error!");
79     }
80 }
81
82 bool EncodingTraits<Test::InputQueue>::decodeValue(EncodedValue& encodedValue, Test::InputQueue& enumValue)
83 {
84     String enumString = encodedValue.convertTo<String>();
85     if (enumString == "EventLoopInput") {
86         enumValue = Test::InputQueue::EventLoopInput;
87         return true;
88     }
89     if (enumString == "LoaderMemoizedData") {
90         enumValue = Test::InputQueue::LoaderMemoizedData;
91         return true;
92     }
93     if (enumString == "ScriptMemoizedData") {
94         enumValue = Test::InputQueue::ScriptMemoizedData;
95         return true;
96     }
97     return false;
98 }
99
100 EncodedValue EncodingTraits<Test::MouseButton>::encodeValue(const Test::MouseButton& enumValue)
101 {
102     EncodedValue encodedValue = EncodedValue::createArray();
103     if (enumValue & Test::NoButton) {
104         encodedValue.append<String>(ASCIILiteral("NoButton"));
105         if (enumValue == Test::NoButton)
106             return encodedValue;
107     }
108     if (enumValue & Test::LeftButton) {
109         encodedValue.append<String>(ASCIILiteral("LeftButton"));
110         if (enumValue == Test::LeftButton)
111             return encodedValue;
112     }
113     if (enumValue & Test::MiddleButton) {
114         encodedValue.append<String>(ASCIILiteral("MiddleButton"));
115         if (enumValue == Test::MiddleButton)
116             return encodedValue;
117     }
118     if (enumValue & Test::RightButton) {
119         encodedValue.append<String>(ASCIILiteral("RightButton"));
120         if (enumValue == Test::RightButton)
121             return encodedValue;
122     }
123     return encodedValue;
124 }
125
126 bool EncodingTraits<Test::MouseButton>::decodeValue(EncodedValue& encodedValue, Test::MouseButton& enumValue)
127 {
128     Vector<String> enumStrings;
129     if (!EncodingTraits<Vector<String>>::decodeValue(encodedValue, enumStrings))
130         return false;
131
132     for (const String& enumString : enumStrings) {
133         if (enumString == "NoButton")
134             enumValue = static_cast<Test::MouseButton>(enumValue | Test::NoButton);
135         else if (enumString == "LeftButton")
136             enumValue = static_cast<Test::MouseButton>(enumValue | Test::LeftButton);
137         else if (enumString == "MiddleButton")
138             enumValue = static_cast<Test::MouseButton>(enumValue | Test::MiddleButton);
139         else if (enumString == "RightButton")
140             enumValue = static_cast<Test::MouseButton>(enumValue | Test::RightButton);
141     }
142
143     return true;
144 }
145
146 EncodedValue EncodingTraits<Test::PlatformEvent::OtherType>::encodeValue(const OptionSet<Test::PlatformEvent::OtherType>& enumValue)
147 {
148     EncodedValue encodedValue = EncodedValue::createArray();
149     if (enumValue.contains(Test::PlatformEvent::OtherType::Mouse))
150         encodedValue.append<String>(ASCIILiteral("Mouse"));
151     if (enumValue.contains(Test::PlatformEvent::OtherType::Key))
152         encodedValue.append<String>(ASCIILiteral("Key"));
153     if (enumValue.contains(Test::PlatformEvent::OtherType::Touch))
154         encodedValue.append<String>(ASCIILiteral("Touch"));
155     if (enumValue.contains(Test::PlatformEvent::OtherType::Wheel))
156         encodedValue.append<String>(ASCIILiteral("Wheel"));
157
158     return encodedValue;
159 }
160
161 bool EncodingTraits<Test::PlatformEvent::OtherType>::decodeValue(EncodedValue& encodedValue, OptionSet<Test::PlatformEvent::OtherType>& enumValue)
162 {
163     Vector<String> enumStrings;
164     if (!EncodingTraits<Vector<String>>::decodeValue(encodedValue, enumStrings))
165         return false;
166
167     for (const String& enumString : enumStrings) {
168         if (enumString == "Mouse")
169             enumValue |= Test::PlatformEvent::OtherType::Mouse;
170         else if (enumString == "Key")
171             enumValue |= Test::PlatformEvent::OtherType::Key;
172         else if (enumString == "Touch")
173             enumValue |= Test::PlatformEvent::OtherType::Touch;
174         else if (enumString == "Wheel")
175             enumValue |= Test::PlatformEvent::OtherType::Wheel;
176     }
177
178     return true;
179 }
180
181 EncodedValue EncodingTraits<Test::PlatformEvent::Type>::encodeValue(const Test::PlatformEvent::Type& enumValue)
182 {
183     EncodedValue encodedValue = EncodedValue::createArray();
184     if (enumValue & Test::PlatformEvent::Mouse) {
185         encodedValue.append<String>(ASCIILiteral("Mouse"));
186         if (enumValue == Test::PlatformEvent::Mouse)
187             return encodedValue;
188     }
189     if (enumValue & Test::PlatformEvent::Key) {
190         encodedValue.append<String>(ASCIILiteral("Key"));
191         if (enumValue == Test::PlatformEvent::Key)
192             return encodedValue;
193     }
194     if (enumValue & Test::PlatformEvent::Touch) {
195         encodedValue.append<String>(ASCIILiteral("Touch"));
196         if (enumValue == Test::PlatformEvent::Touch)
197             return encodedValue;
198     }
199     if (enumValue & Test::PlatformEvent::Wheel) {
200         encodedValue.append<String>(ASCIILiteral("Wheel"));
201         if (enumValue == Test::PlatformEvent::Wheel)
202             return encodedValue;
203     }
204     return encodedValue;
205 }
206
207 bool EncodingTraits<Test::PlatformEvent::Type>::decodeValue(EncodedValue& encodedValue, Test::PlatformEvent::Type& enumValue)
208 {
209     Vector<String> enumStrings;
210     if (!EncodingTraits<Vector<String>>::decodeValue(encodedValue, enumStrings))
211         return false;
212
213     for (const String& enumString : enumStrings) {
214         if (enumString == "Mouse")
215             enumValue = static_cast<Test::PlatformEvent::Type>(enumValue | Test::PlatformEvent::Mouse);
216         else if (enumString == "Key")
217             enumValue = static_cast<Test::PlatformEvent::Type>(enumValue | Test::PlatformEvent::Key);
218         else if (enumString == "Touch")
219             enumValue = static_cast<Test::PlatformEvent::Type>(enumValue | Test::PlatformEvent::Touch);
220         else if (enumString == "Wheel")
221             enumValue = static_cast<Test::PlatformEvent::Type>(enumValue | Test::PlatformEvent::Wheel);
222     }
223
224     return true;
225 }
226 } // namespace JSC
227
228 #endif // ENABLE(WEB_REPLAY)