1 | /* |
2 | This file is part of the WebKit open source project. |
3 | This file has been generated by generate-bindings.pl. DO NOT MODIFY! |
4 | |
5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. |
9 | |
10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 | Boston, MA 02110-1301, USA. |
19 | */ |
20 | |
21 | #include "config.h" |
22 | |
23 | #if ENABLE(WEB_RTC) |
24 | |
25 | #include "JSRTCConfiguration.h" |
26 | |
27 | #include "JSDOMConvertInterface.h" |
28 | #include "JSDOMConvertNumbers.h" |
29 | #include "JSDOMConvertSequences.h" |
30 | #include "JSDOMGlobalObject.h" |
31 | #include "JSRTCCertificate.h" |
32 | #include "JSRTCIceServer.h" |
33 | #include <JavaScriptCore/JSArray.h> |
34 | #include <JavaScriptCore/JSCInlines.h> |
35 | #include <JavaScriptCore/JSString.h> |
36 | #include <JavaScriptCore/ObjectConstructor.h> |
37 | #include <wtf/NeverDestroyed.h> |
38 | |
39 | |
40 | namespace WebCore { |
41 | using namespace JSC; |
42 | |
43 | #if ENABLE(WEB_RTC) |
44 | |
45 | template<> RTCConfiguration convertDictionary<RTCConfiguration>(ExecState& state, JSValue value) |
46 | { |
47 | VM& vm = state.vm(); |
48 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
49 | bool isNullOrUndefined = value.isUndefinedOrNull(); |
50 | auto* object = isNullOrUndefined ? nullptr : value.getObject(); |
51 | if (UNLIKELY(!isNullOrUndefined && !object)) { |
52 | throwTypeError(&state, throwScope); |
53 | return { }; |
54 | } |
55 | RTCConfiguration result; |
56 | JSValue bundlePolicyValue; |
57 | if (isNullOrUndefined) |
58 | bundlePolicyValue = jsUndefined(); |
59 | else { |
60 | bundlePolicyValue = object->get(&state, Identifier::fromString(&state, "bundlePolicy" )); |
61 | RETURN_IF_EXCEPTION(throwScope, { }); |
62 | } |
63 | if (!bundlePolicyValue.isUndefined()) { |
64 | result.bundlePolicy = convert<IDLEnumeration<RTCBundlePolicy>>(state, bundlePolicyValue); |
65 | RETURN_IF_EXCEPTION(throwScope, { }); |
66 | } else |
67 | result.bundlePolicy = RTCBundlePolicy::Balanced; |
68 | JSValue certificatesValue; |
69 | if (isNullOrUndefined) |
70 | certificatesValue = jsUndefined(); |
71 | else { |
72 | certificatesValue = object->get(&state, Identifier::fromString(&state, "certificates" )); |
73 | RETURN_IF_EXCEPTION(throwScope, { }); |
74 | } |
75 | if (!certificatesValue.isUndefined()) { |
76 | result.certificates = convert<IDLSequence<IDLInterface<RTCCertificate>>>(state, certificatesValue); |
77 | RETURN_IF_EXCEPTION(throwScope, { }); |
78 | } |
79 | JSValue iceCandidatePoolSizeValue; |
80 | if (isNullOrUndefined) |
81 | iceCandidatePoolSizeValue = jsUndefined(); |
82 | else { |
83 | iceCandidatePoolSizeValue = object->get(&state, Identifier::fromString(&state, "iceCandidatePoolSize" )); |
84 | RETURN_IF_EXCEPTION(throwScope, { }); |
85 | } |
86 | if (!iceCandidatePoolSizeValue.isUndefined()) { |
87 | result.iceCandidatePoolSize = convert<IDLEnforceRangeAdaptor<IDLOctet>>(state, iceCandidatePoolSizeValue); |
88 | RETURN_IF_EXCEPTION(throwScope, { }); |
89 | } else |
90 | result.iceCandidatePoolSize = 0; |
91 | JSValue iceServersValue; |
92 | if (isNullOrUndefined) |
93 | iceServersValue = jsUndefined(); |
94 | else { |
95 | iceServersValue = object->get(&state, Identifier::fromString(&state, "iceServers" )); |
96 | RETURN_IF_EXCEPTION(throwScope, { }); |
97 | } |
98 | if (!iceServersValue.isUndefined()) { |
99 | result.iceServers = convert<IDLSequence<IDLDictionary<RTCIceServer>>>(state, iceServersValue); |
100 | RETURN_IF_EXCEPTION(throwScope, { }); |
101 | } |
102 | JSValue iceTransportPolicyValue; |
103 | if (isNullOrUndefined) |
104 | iceTransportPolicyValue = jsUndefined(); |
105 | else { |
106 | iceTransportPolicyValue = object->get(&state, Identifier::fromString(&state, "iceTransportPolicy" )); |
107 | RETURN_IF_EXCEPTION(throwScope, { }); |
108 | } |
109 | if (!iceTransportPolicyValue.isUndefined()) { |
110 | result.iceTransportPolicy = convert<IDLEnumeration<RTCIceTransportPolicy>>(state, iceTransportPolicyValue); |
111 | RETURN_IF_EXCEPTION(throwScope, { }); |
112 | } else |
113 | result.iceTransportPolicy = RTCIceTransportPolicy::All; |
114 | JSValue rtcpMuxPolicyValue; |
115 | if (isNullOrUndefined) |
116 | rtcpMuxPolicyValue = jsUndefined(); |
117 | else { |
118 | rtcpMuxPolicyValue = object->get(&state, Identifier::fromString(&state, "rtcpMuxPolicy" )); |
119 | RETURN_IF_EXCEPTION(throwScope, { }); |
120 | } |
121 | if (!rtcpMuxPolicyValue.isUndefined()) { |
122 | result.rtcpMuxPolicy = convert<IDLEnumeration<RTCPMuxPolicy>>(state, rtcpMuxPolicyValue); |
123 | RETURN_IF_EXCEPTION(throwScope, { }); |
124 | } else |
125 | result.rtcpMuxPolicy = RTCPMuxPolicy::Require; |
126 | return result; |
127 | } |
128 | |
129 | JSC::JSObject* convertDictionaryToJS(JSC::ExecState& state, JSDOMGlobalObject& globalObject, const RTCConfiguration& dictionary) |
130 | { |
131 | auto& vm = state.vm(); |
132 | |
133 | auto result = constructEmptyObject(&state, globalObject.objectPrototype()); |
134 | |
135 | auto bundlePolicyValue = toJS<IDLEnumeration<RTCBundlePolicy>>(state, dictionary.bundlePolicy); |
136 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "bundlePolicy" ), bundlePolicyValue); |
137 | if (!IDLSequence<IDLInterface<RTCCertificate>>::isNullValue(dictionary.certificates)) { |
138 | auto certificatesValue = toJS<IDLSequence<IDLInterface<RTCCertificate>>>(state, globalObject, IDLSequence<IDLInterface<RTCCertificate>>::extractValueFromNullable(dictionary.certificates)); |
139 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "certificates" ), certificatesValue); |
140 | } |
141 | auto iceCandidatePoolSizeValue = toJS<IDLEnforceRangeAdaptor<IDLOctet>>(dictionary.iceCandidatePoolSize); |
142 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "iceCandidatePoolSize" ), iceCandidatePoolSizeValue); |
143 | if (!IDLSequence<IDLDictionary<RTCIceServer>>::isNullValue(dictionary.iceServers)) { |
144 | auto iceServersValue = toJS<IDLSequence<IDLDictionary<RTCIceServer>>>(state, globalObject, IDLSequence<IDLDictionary<RTCIceServer>>::extractValueFromNullable(dictionary.iceServers)); |
145 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "iceServers" ), iceServersValue); |
146 | } |
147 | auto iceTransportPolicyValue = toJS<IDLEnumeration<RTCIceTransportPolicy>>(state, dictionary.iceTransportPolicy); |
148 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "iceTransportPolicy" ), iceTransportPolicyValue); |
149 | auto rtcpMuxPolicyValue = toJS<IDLEnumeration<RTCPMuxPolicy>>(state, dictionary.rtcpMuxPolicy); |
150 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "rtcpMuxPolicy" ), rtcpMuxPolicyValue); |
151 | return result; |
152 | } |
153 | |
154 | #endif |
155 | |
156 | #if ENABLE(WEB_RTC) |
157 | |
158 | String convertEnumerationToString(RTCIceTransportPolicy enumerationValue) |
159 | { |
160 | static const NeverDestroyed<String> values[] = { |
161 | MAKE_STATIC_STRING_IMPL("relay" ), |
162 | MAKE_STATIC_STRING_IMPL("all" ), |
163 | }; |
164 | static_assert(static_cast<size_t>(RTCIceTransportPolicy::Relay) == 0, "RTCIceTransportPolicy::Relay is not 0 as expected" ); |
165 | static_assert(static_cast<size_t>(RTCIceTransportPolicy::All) == 1, "RTCIceTransportPolicy::All is not 1 as expected" ); |
166 | ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values)); |
167 | return values[static_cast<size_t>(enumerationValue)]; |
168 | } |
169 | |
170 | template<> JSString* convertEnumerationToJS(ExecState& state, RTCIceTransportPolicy enumerationValue) |
171 | { |
172 | return jsStringWithCache(&state, convertEnumerationToString(enumerationValue)); |
173 | } |
174 | |
175 | template<> Optional<RTCIceTransportPolicy> parseEnumeration<RTCIceTransportPolicy>(ExecState& state, JSValue value) |
176 | { |
177 | auto stringValue = value.toWTFString(&state); |
178 | if (stringValue == "relay" ) |
179 | return RTCIceTransportPolicy::Relay; |
180 | if (stringValue == "all" ) |
181 | return RTCIceTransportPolicy::All; |
182 | return WTF::nullopt; |
183 | } |
184 | |
185 | template<> const char* expectedEnumerationValues<RTCIceTransportPolicy>() |
186 | { |
187 | return "\"relay\", \"all\"" ; |
188 | } |
189 | |
190 | #endif |
191 | |
192 | #if ENABLE(WEB_RTC) |
193 | |
194 | String convertEnumerationToString(RTCBundlePolicy enumerationValue) |
195 | { |
196 | static const NeverDestroyed<String> values[] = { |
197 | MAKE_STATIC_STRING_IMPL("balanced" ), |
198 | MAKE_STATIC_STRING_IMPL("max-compat" ), |
199 | MAKE_STATIC_STRING_IMPL("max-bundle" ), |
200 | }; |
201 | static_assert(static_cast<size_t>(RTCBundlePolicy::Balanced) == 0, "RTCBundlePolicy::Balanced is not 0 as expected" ); |
202 | static_assert(static_cast<size_t>(RTCBundlePolicy::MaxCompat) == 1, "RTCBundlePolicy::MaxCompat is not 1 as expected" ); |
203 | static_assert(static_cast<size_t>(RTCBundlePolicy::MaxBundle) == 2, "RTCBundlePolicy::MaxBundle is not 2 as expected" ); |
204 | ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values)); |
205 | return values[static_cast<size_t>(enumerationValue)]; |
206 | } |
207 | |
208 | template<> JSString* convertEnumerationToJS(ExecState& state, RTCBundlePolicy enumerationValue) |
209 | { |
210 | return jsStringWithCache(&state, convertEnumerationToString(enumerationValue)); |
211 | } |
212 | |
213 | template<> Optional<RTCBundlePolicy> parseEnumeration<RTCBundlePolicy>(ExecState& state, JSValue value) |
214 | { |
215 | auto stringValue = value.toWTFString(&state); |
216 | if (stringValue == "balanced" ) |
217 | return RTCBundlePolicy::Balanced; |
218 | if (stringValue == "max-compat" ) |
219 | return RTCBundlePolicy::MaxCompat; |
220 | if (stringValue == "max-bundle" ) |
221 | return RTCBundlePolicy::MaxBundle; |
222 | return WTF::nullopt; |
223 | } |
224 | |
225 | template<> const char* expectedEnumerationValues<RTCBundlePolicy>() |
226 | { |
227 | return "\"balanced\", \"max-compat\", \"max-bundle\"" ; |
228 | } |
229 | |
230 | #endif |
231 | |
232 | #if ENABLE(WEB_RTC) |
233 | |
234 | String convertEnumerationToString(RTCPMuxPolicy enumerationValue) |
235 | { |
236 | static const NeverDestroyed<String> values[] = { |
237 | MAKE_STATIC_STRING_IMPL("negotiate" ), |
238 | MAKE_STATIC_STRING_IMPL("require" ), |
239 | }; |
240 | static_assert(static_cast<size_t>(RTCPMuxPolicy::Negotiate) == 0, "RTCPMuxPolicy::Negotiate is not 0 as expected" ); |
241 | static_assert(static_cast<size_t>(RTCPMuxPolicy::Require) == 1, "RTCPMuxPolicy::Require is not 1 as expected" ); |
242 | ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values)); |
243 | return values[static_cast<size_t>(enumerationValue)]; |
244 | } |
245 | |
246 | template<> JSString* convertEnumerationToJS(ExecState& state, RTCPMuxPolicy enumerationValue) |
247 | { |
248 | return jsStringWithCache(&state, convertEnumerationToString(enumerationValue)); |
249 | } |
250 | |
251 | template<> Optional<RTCPMuxPolicy> parseEnumeration<RTCPMuxPolicy>(ExecState& state, JSValue value) |
252 | { |
253 | auto stringValue = value.toWTFString(&state); |
254 | if (stringValue == "negotiate" ) |
255 | return RTCPMuxPolicy::Negotiate; |
256 | if (stringValue == "require" ) |
257 | return RTCPMuxPolicy::Require; |
258 | return WTF::nullopt; |
259 | } |
260 | |
261 | template<> const char* expectedEnumerationValues<RTCPMuxPolicy>() |
262 | { |
263 | return "\"negotiate\", \"require\"" ; |
264 | } |
265 | |
266 | #endif |
267 | |
268 | } // namespace WebCore |
269 | |
270 | #endif // ENABLE(WEB_RTC) |
271 | |