]> git.saurik.com Git - apple/javascriptcore.git/blob - replay/scripts/tests/expected/generate-enum-encoding-helpers.json-TestReplayInputs.cpp
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / 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(ASCIILiteral("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::Type>::encodeValue(const Test::PlatformEvent::Type& enumValue)
147 {
148 EncodedValue encodedValue = EncodedValue::createArray();
149 if (enumValue & Test::PlatformEvent::Mouse) {
150 encodedValue.append<String>(ASCIILiteral("Mouse"));
151 if (enumValue == Test::PlatformEvent::Mouse)
152 return encodedValue;
153 }
154 if (enumValue & Test::PlatformEvent::Key) {
155 encodedValue.append<String>(ASCIILiteral("Key"));
156 if (enumValue == Test::PlatformEvent::Key)
157 return encodedValue;
158 }
159 if (enumValue & Test::PlatformEvent::Touch) {
160 encodedValue.append<String>(ASCIILiteral("Touch"));
161 if (enumValue == Test::PlatformEvent::Touch)
162 return encodedValue;
163 }
164 if (enumValue & Test::PlatformEvent::Wheel) {
165 encodedValue.append<String>(ASCIILiteral("Wheel"));
166 if (enumValue == Test::PlatformEvent::Wheel)
167 return encodedValue;
168 }
169 return encodedValue;
170 }
171
172 bool EncodingTraits<Test::PlatformEvent::Type>::decodeValue(EncodedValue& encodedValue, Test::PlatformEvent::Type& enumValue)
173 {
174 Vector<String> enumStrings;
175 if (!EncodingTraits<Vector<String>>::decodeValue(encodedValue, enumStrings))
176 return false;
177
178 for (const String& enumString : enumStrings) {
179 if (enumString == "Mouse")
180 enumValue = static_cast<Test::PlatformEvent::Type>(enumValue | Test::PlatformEvent::Mouse);
181 else if (enumString == "Key")
182 enumValue = static_cast<Test::PlatformEvent::Type>(enumValue | Test::PlatformEvent::Key);
183 else if (enumString == "Touch")
184 enumValue = static_cast<Test::PlatformEvent::Type>(enumValue | Test::PlatformEvent::Touch);
185 else if (enumString == "Wheel")
186 enumValue = static_cast<Test::PlatformEvent::Type>(enumValue | Test::PlatformEvent::Wheel);
187 }
188
189 return true;
190 }
191 } // namespace JSC
192
193 #endif // ENABLE(WEB_REPLAY)