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(MEDIA_STREAM)
24
25#include "JSMediaTrackConstraints.h"
26
27#include "JSDOMConvertBoolean.h"
28#include "JSDOMConvertNumbers.h"
29#include "JSDOMConvertSequences.h"
30#include "JSDOMConvertStrings.h"
31#include "JSDOMConvertUnion.h"
32#include "JSDOMGlobalObject.h"
33#include <JavaScriptCore/JSArray.h>
34#include <JavaScriptCore/JSCInlines.h>
35#include <JavaScriptCore/ObjectConstructor.h>
36#include <wtf/Variant.h>
37
38
39namespace WebCore {
40using namespace JSC;
41
42#if ENABLE(MEDIA_STREAM)
43
44template<> MediaTrackConstraints convertDictionary<MediaTrackConstraints>(ExecState& state, JSValue value)
45{
46 VM& vm = state.vm();
47 auto throwScope = DECLARE_THROW_SCOPE(vm);
48 bool isNullOrUndefined = value.isUndefinedOrNull();
49 auto* object = isNullOrUndefined ? nullptr : value.getObject();
50 if (UNLIKELY(!isNullOrUndefined && !object)) {
51 throwTypeError(&state, throwScope);
52 return { };
53 }
54 MediaTrackConstraints result;
55 JSValue aspectRatioValue;
56 if (isNullOrUndefined)
57 aspectRatioValue = jsUndefined();
58 else {
59 aspectRatioValue = object->get(&state, Identifier::fromString(&state, "aspectRatio"));
60 RETURN_IF_EXCEPTION(throwScope, { });
61 }
62 if (!aspectRatioValue.isUndefined()) {
63 result.aspectRatio = convert<IDLUnion<IDLDouble, IDLDictionary<ConstrainDoubleRange>>>(state, aspectRatioValue);
64 RETURN_IF_EXCEPTION(throwScope, { });
65 }
66 JSValue deviceIdValue;
67 if (isNullOrUndefined)
68 deviceIdValue = jsUndefined();
69 else {
70 deviceIdValue = object->get(&state, Identifier::fromString(&state, "deviceId"));
71 RETURN_IF_EXCEPTION(throwScope, { });
72 }
73 if (!deviceIdValue.isUndefined()) {
74 result.deviceId = convert<IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>, IDLDictionary<ConstrainDOMStringParameters>>>(state, deviceIdValue);
75 RETURN_IF_EXCEPTION(throwScope, { });
76 }
77 JSValue displaySurfaceValue;
78 if (isNullOrUndefined)
79 displaySurfaceValue = jsUndefined();
80 else {
81 displaySurfaceValue = object->get(&state, Identifier::fromString(&state, "displaySurface"));
82 RETURN_IF_EXCEPTION(throwScope, { });
83 }
84 if (!displaySurfaceValue.isUndefined()) {
85 result.displaySurface = convert<IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>, IDLDictionary<ConstrainDOMStringParameters>>>(state, displaySurfaceValue);
86 RETURN_IF_EXCEPTION(throwScope, { });
87 }
88 JSValue echoCancellationValue;
89 if (isNullOrUndefined)
90 echoCancellationValue = jsUndefined();
91 else {
92 echoCancellationValue = object->get(&state, Identifier::fromString(&state, "echoCancellation"));
93 RETURN_IF_EXCEPTION(throwScope, { });
94 }
95 if (!echoCancellationValue.isUndefined()) {
96 result.echoCancellation = convert<IDLUnion<IDLBoolean, IDLDictionary<ConstrainBooleanParameters>>>(state, echoCancellationValue);
97 RETURN_IF_EXCEPTION(throwScope, { });
98 }
99 JSValue facingModeValue;
100 if (isNullOrUndefined)
101 facingModeValue = jsUndefined();
102 else {
103 facingModeValue = object->get(&state, Identifier::fromString(&state, "facingMode"));
104 RETURN_IF_EXCEPTION(throwScope, { });
105 }
106 if (!facingModeValue.isUndefined()) {
107 result.facingMode = convert<IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>, IDLDictionary<ConstrainDOMStringParameters>>>(state, facingModeValue);
108 RETURN_IF_EXCEPTION(throwScope, { });
109 }
110 JSValue frameRateValue;
111 if (isNullOrUndefined)
112 frameRateValue = jsUndefined();
113 else {
114 frameRateValue = object->get(&state, Identifier::fromString(&state, "frameRate"));
115 RETURN_IF_EXCEPTION(throwScope, { });
116 }
117 if (!frameRateValue.isUndefined()) {
118 result.frameRate = convert<IDLUnion<IDLDouble, IDLDictionary<ConstrainDoubleRange>>>(state, frameRateValue);
119 RETURN_IF_EXCEPTION(throwScope, { });
120 }
121 JSValue groupIdValue;
122 if (isNullOrUndefined)
123 groupIdValue = jsUndefined();
124 else {
125 groupIdValue = object->get(&state, Identifier::fromString(&state, "groupId"));
126 RETURN_IF_EXCEPTION(throwScope, { });
127 }
128 if (!groupIdValue.isUndefined()) {
129 result.groupId = convert<IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>, IDLDictionary<ConstrainDOMStringParameters>>>(state, groupIdValue);
130 RETURN_IF_EXCEPTION(throwScope, { });
131 }
132 JSValue heightValue;
133 if (isNullOrUndefined)
134 heightValue = jsUndefined();
135 else {
136 heightValue = object->get(&state, Identifier::fromString(&state, "height"));
137 RETURN_IF_EXCEPTION(throwScope, { });
138 }
139 if (!heightValue.isUndefined()) {
140 result.height = convert<IDLUnion<IDLLong, IDLDictionary<ConstrainLongRange>>>(state, heightValue);
141 RETURN_IF_EXCEPTION(throwScope, { });
142 }
143 JSValue logicalSurfaceValue;
144 if (isNullOrUndefined)
145 logicalSurfaceValue = jsUndefined();
146 else {
147 logicalSurfaceValue = object->get(&state, Identifier::fromString(&state, "logicalSurface"));
148 RETURN_IF_EXCEPTION(throwScope, { });
149 }
150 if (!logicalSurfaceValue.isUndefined()) {
151 result.logicalSurface = convert<IDLUnion<IDLBoolean, IDLDictionary<ConstrainBooleanParameters>>>(state, logicalSurfaceValue);
152 RETURN_IF_EXCEPTION(throwScope, { });
153 }
154 JSValue sampleRateValue;
155 if (isNullOrUndefined)
156 sampleRateValue = jsUndefined();
157 else {
158 sampleRateValue = object->get(&state, Identifier::fromString(&state, "sampleRate"));
159 RETURN_IF_EXCEPTION(throwScope, { });
160 }
161 if (!sampleRateValue.isUndefined()) {
162 result.sampleRate = convert<IDLUnion<IDLLong, IDLDictionary<ConstrainLongRange>>>(state, sampleRateValue);
163 RETURN_IF_EXCEPTION(throwScope, { });
164 }
165 JSValue sampleSizeValue;
166 if (isNullOrUndefined)
167 sampleSizeValue = jsUndefined();
168 else {
169 sampleSizeValue = object->get(&state, Identifier::fromString(&state, "sampleSize"));
170 RETURN_IF_EXCEPTION(throwScope, { });
171 }
172 if (!sampleSizeValue.isUndefined()) {
173 result.sampleSize = convert<IDLUnion<IDLLong, IDLDictionary<ConstrainLongRange>>>(state, sampleSizeValue);
174 RETURN_IF_EXCEPTION(throwScope, { });
175 }
176 JSValue volumeValue;
177 if (isNullOrUndefined)
178 volumeValue = jsUndefined();
179 else {
180 volumeValue = object->get(&state, Identifier::fromString(&state, "volume"));
181 RETURN_IF_EXCEPTION(throwScope, { });
182 }
183 if (!volumeValue.isUndefined()) {
184 result.volume = convert<IDLUnion<IDLDouble, IDLDictionary<ConstrainDoubleRange>>>(state, volumeValue);
185 RETURN_IF_EXCEPTION(throwScope, { });
186 }
187 JSValue widthValue;
188 if (isNullOrUndefined)
189 widthValue = jsUndefined();
190 else {
191 widthValue = object->get(&state, Identifier::fromString(&state, "width"));
192 RETURN_IF_EXCEPTION(throwScope, { });
193 }
194 if (!widthValue.isUndefined()) {
195 result.width = convert<IDLUnion<IDLLong, IDLDictionary<ConstrainLongRange>>>(state, widthValue);
196 RETURN_IF_EXCEPTION(throwScope, { });
197 }
198 JSValue advancedValue;
199 if (isNullOrUndefined)
200 advancedValue = jsUndefined();
201 else {
202 advancedValue = object->get(&state, Identifier::fromString(&state, "advanced"));
203 RETURN_IF_EXCEPTION(throwScope, { });
204 }
205 if (!advancedValue.isUndefined()) {
206 result.advanced = convert<IDLSequence<IDLDictionary<MediaTrackConstraintSet>>>(state, advancedValue);
207 RETURN_IF_EXCEPTION(throwScope, { });
208 }
209 return result;
210}
211
212JSC::JSObject* convertDictionaryToJS(JSC::ExecState& state, JSDOMGlobalObject& globalObject, const MediaTrackConstraints& dictionary)
213{
214 auto& vm = state.vm();
215
216 auto result = constructEmptyObject(&state, globalObject.objectPrototype());
217
218 if (!IDLUnion<IDLDouble, IDLDictionary<ConstrainDoubleRange>>::isNullValue(dictionary.aspectRatio)) {
219 auto aspectRatioValue = toJS<IDLUnion<IDLDouble, IDLDictionary<ConstrainDoubleRange>>>(state, globalObject, IDLUnion<IDLDouble, IDLDictionary<ConstrainDoubleRange>>::extractValueFromNullable(dictionary.aspectRatio));
220 result->putDirect(vm, JSC::Identifier::fromString(&vm, "aspectRatio"), aspectRatioValue);
221 }
222 if (!IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>, IDLDictionary<ConstrainDOMStringParameters>>::isNullValue(dictionary.deviceId)) {
223 auto deviceIdValue = toJS<IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>, IDLDictionary<ConstrainDOMStringParameters>>>(state, globalObject, IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>, IDLDictionary<ConstrainDOMStringParameters>>::extractValueFromNullable(dictionary.deviceId));
224 result->putDirect(vm, JSC::Identifier::fromString(&vm, "deviceId"), deviceIdValue);
225 }
226 if (!IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>, IDLDictionary<ConstrainDOMStringParameters>>::isNullValue(dictionary.displaySurface)) {
227 auto displaySurfaceValue = toJS<IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>, IDLDictionary<ConstrainDOMStringParameters>>>(state, globalObject, IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>, IDLDictionary<ConstrainDOMStringParameters>>::extractValueFromNullable(dictionary.displaySurface));
228 result->putDirect(vm, JSC::Identifier::fromString(&vm, "displaySurface"), displaySurfaceValue);
229 }
230 if (!IDLUnion<IDLBoolean, IDLDictionary<ConstrainBooleanParameters>>::isNullValue(dictionary.echoCancellation)) {
231 auto echoCancellationValue = toJS<IDLUnion<IDLBoolean, IDLDictionary<ConstrainBooleanParameters>>>(state, globalObject, IDLUnion<IDLBoolean, IDLDictionary<ConstrainBooleanParameters>>::extractValueFromNullable(dictionary.echoCancellation));
232 result->putDirect(vm, JSC::Identifier::fromString(&vm, "echoCancellation"), echoCancellationValue);
233 }
234 if (!IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>, IDLDictionary<ConstrainDOMStringParameters>>::isNullValue(dictionary.facingMode)) {
235 auto facingModeValue = toJS<IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>, IDLDictionary<ConstrainDOMStringParameters>>>(state, globalObject, IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>, IDLDictionary<ConstrainDOMStringParameters>>::extractValueFromNullable(dictionary.facingMode));
236 result->putDirect(vm, JSC::Identifier::fromString(&vm, "facingMode"), facingModeValue);
237 }
238 if (!IDLUnion<IDLDouble, IDLDictionary<ConstrainDoubleRange>>::isNullValue(dictionary.frameRate)) {
239 auto frameRateValue = toJS<IDLUnion<IDLDouble, IDLDictionary<ConstrainDoubleRange>>>(state, globalObject, IDLUnion<IDLDouble, IDLDictionary<ConstrainDoubleRange>>::extractValueFromNullable(dictionary.frameRate));
240 result->putDirect(vm, JSC::Identifier::fromString(&vm, "frameRate"), frameRateValue);
241 }
242 if (!IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>, IDLDictionary<ConstrainDOMStringParameters>>::isNullValue(dictionary.groupId)) {
243 auto groupIdValue = toJS<IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>, IDLDictionary<ConstrainDOMStringParameters>>>(state, globalObject, IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>, IDLDictionary<ConstrainDOMStringParameters>>::extractValueFromNullable(dictionary.groupId));
244 result->putDirect(vm, JSC::Identifier::fromString(&vm, "groupId"), groupIdValue);
245 }
246 if (!IDLUnion<IDLLong, IDLDictionary<ConstrainLongRange>>::isNullValue(dictionary.height)) {
247 auto heightValue = toJS<IDLUnion<IDLLong, IDLDictionary<ConstrainLongRange>>>(state, globalObject, IDLUnion<IDLLong, IDLDictionary<ConstrainLongRange>>::extractValueFromNullable(dictionary.height));
248 result->putDirect(vm, JSC::Identifier::fromString(&vm, "height"), heightValue);
249 }
250 if (!IDLUnion<IDLBoolean, IDLDictionary<ConstrainBooleanParameters>>::isNullValue(dictionary.logicalSurface)) {
251 auto logicalSurfaceValue = toJS<IDLUnion<IDLBoolean, IDLDictionary<ConstrainBooleanParameters>>>(state, globalObject, IDLUnion<IDLBoolean, IDLDictionary<ConstrainBooleanParameters>>::extractValueFromNullable(dictionary.logicalSurface));
252 result->putDirect(vm, JSC::Identifier::fromString(&vm, "logicalSurface"), logicalSurfaceValue);
253 }
254 if (!IDLUnion<IDLLong, IDLDictionary<ConstrainLongRange>>::isNullValue(dictionary.sampleRate)) {
255 auto sampleRateValue = toJS<IDLUnion<IDLLong, IDLDictionary<ConstrainLongRange>>>(state, globalObject, IDLUnion<IDLLong, IDLDictionary<ConstrainLongRange>>::extractValueFromNullable(dictionary.sampleRate));
256 result->putDirect(vm, JSC::Identifier::fromString(&vm, "sampleRate"), sampleRateValue);
257 }
258 if (!IDLUnion<IDLLong, IDLDictionary<ConstrainLongRange>>::isNullValue(dictionary.sampleSize)) {
259 auto sampleSizeValue = toJS<IDLUnion<IDLLong, IDLDictionary<ConstrainLongRange>>>(state, globalObject, IDLUnion<IDLLong, IDLDictionary<ConstrainLongRange>>::extractValueFromNullable(dictionary.sampleSize));
260 result->putDirect(vm, JSC::Identifier::fromString(&vm, "sampleSize"), sampleSizeValue);
261 }
262 if (!IDLUnion<IDLDouble, IDLDictionary<ConstrainDoubleRange>>::isNullValue(dictionary.volume)) {
263 auto volumeValue = toJS<IDLUnion<IDLDouble, IDLDictionary<ConstrainDoubleRange>>>(state, globalObject, IDLUnion<IDLDouble, IDLDictionary<ConstrainDoubleRange>>::extractValueFromNullable(dictionary.volume));
264 result->putDirect(vm, JSC::Identifier::fromString(&vm, "volume"), volumeValue);
265 }
266 if (!IDLUnion<IDLLong, IDLDictionary<ConstrainLongRange>>::isNullValue(dictionary.width)) {
267 auto widthValue = toJS<IDLUnion<IDLLong, IDLDictionary<ConstrainLongRange>>>(state, globalObject, IDLUnion<IDLLong, IDLDictionary<ConstrainLongRange>>::extractValueFromNullable(dictionary.width));
268 result->putDirect(vm, JSC::Identifier::fromString(&vm, "width"), widthValue);
269 }
270 if (!IDLSequence<IDLDictionary<MediaTrackConstraintSet>>::isNullValue(dictionary.advanced)) {
271 auto advancedValue = toJS<IDLSequence<IDLDictionary<MediaTrackConstraintSet>>>(state, globalObject, IDLSequence<IDLDictionary<MediaTrackConstraintSet>>::extractValueFromNullable(dictionary.advanced));
272 result->putDirect(vm, JSC::Identifier::fromString(&vm, "advanced"), advancedValue);
273 }
274 return result;
275}
276
277#endif
278
279#if ENABLE(MEDIA_STREAM)
280
281template<> MediaTrackConstraintSet convertDictionary<MediaTrackConstraintSet>(ExecState& state, JSValue value)
282{
283 VM& vm = state.vm();
284 auto throwScope = DECLARE_THROW_SCOPE(vm);
285 bool isNullOrUndefined = value.isUndefinedOrNull();
286 auto* object = isNullOrUndefined ? nullptr : value.getObject();
287 if (UNLIKELY(!isNullOrUndefined && !object)) {
288 throwTypeError(&state, throwScope);
289 return { };
290 }
291 MediaTrackConstraintSet result;
292 JSValue aspectRatioValue;
293 if (isNullOrUndefined)
294 aspectRatioValue = jsUndefined();
295 else {
296 aspectRatioValue = object->get(&state, Identifier::fromString(&state, "aspectRatio"));
297 RETURN_IF_EXCEPTION(throwScope, { });
298 }
299 if (!aspectRatioValue.isUndefined()) {
300 result.aspectRatio = convert<IDLUnion<IDLDouble, IDLDictionary<ConstrainDoubleRange>>>(state, aspectRatioValue);
301 RETURN_IF_EXCEPTION(throwScope, { });
302 }
303 JSValue deviceIdValue;
304 if (isNullOrUndefined)
305 deviceIdValue = jsUndefined();
306 else {
307 deviceIdValue = object->get(&state, Identifier::fromString(&state, "deviceId"));
308 RETURN_IF_EXCEPTION(throwScope, { });
309 }
310 if (!deviceIdValue.isUndefined()) {
311 result.deviceId = convert<IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>, IDLDictionary<ConstrainDOMStringParameters>>>(state, deviceIdValue);
312 RETURN_IF_EXCEPTION(throwScope, { });
313 }
314 JSValue displaySurfaceValue;
315 if (isNullOrUndefined)
316 displaySurfaceValue = jsUndefined();
317 else {
318 displaySurfaceValue = object->get(&state, Identifier::fromString(&state, "displaySurface"));
319 RETURN_IF_EXCEPTION(throwScope, { });
320 }
321 if (!displaySurfaceValue.isUndefined()) {
322 result.displaySurface = convert<IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>, IDLDictionary<ConstrainDOMStringParameters>>>(state, displaySurfaceValue);
323 RETURN_IF_EXCEPTION(throwScope, { });
324 }
325 JSValue echoCancellationValue;
326 if (isNullOrUndefined)
327 echoCancellationValue = jsUndefined();
328 else {
329 echoCancellationValue = object->get(&state, Identifier::fromString(&state, "echoCancellation"));
330 RETURN_IF_EXCEPTION(throwScope, { });
331 }
332 if (!echoCancellationValue.isUndefined()) {
333 result.echoCancellation = convert<IDLUnion<IDLBoolean, IDLDictionary<ConstrainBooleanParameters>>>(state, echoCancellationValue);
334 RETURN_IF_EXCEPTION(throwScope, { });
335 }
336 JSValue facingModeValue;
337 if (isNullOrUndefined)
338 facingModeValue = jsUndefined();
339 else {
340 facingModeValue = object->get(&state, Identifier::fromString(&state, "facingMode"));
341 RETURN_IF_EXCEPTION(throwScope, { });
342 }
343 if (!facingModeValue.isUndefined()) {
344 result.facingMode = convert<IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>, IDLDictionary<ConstrainDOMStringParameters>>>(state, facingModeValue);
345 RETURN_IF_EXCEPTION(throwScope, { });
346 }
347 JSValue frameRateValue;
348 if (isNullOrUndefined)
349 frameRateValue = jsUndefined();
350 else {
351 frameRateValue = object->get(&state, Identifier::fromString(&state, "frameRate"));
352 RETURN_IF_EXCEPTION(throwScope, { });
353 }
354 if (!frameRateValue.isUndefined()) {
355 result.frameRate = convert<IDLUnion<IDLDouble, IDLDictionary<ConstrainDoubleRange>>>(state, frameRateValue);
356 RETURN_IF_EXCEPTION(throwScope, { });
357 }
358 JSValue groupIdValue;
359 if (isNullOrUndefined)
360 groupIdValue = jsUndefined();
361 else {
362 groupIdValue = object->get(&state, Identifier::fromString(&state, "groupId"));
363 RETURN_IF_EXCEPTION(throwScope, { });
364 }
365 if (!groupIdValue.isUndefined()) {
366 result.groupId = convert<IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>, IDLDictionary<ConstrainDOMStringParameters>>>(state, groupIdValue);
367 RETURN_IF_EXCEPTION(throwScope, { });
368 }
369 JSValue heightValue;
370 if (isNullOrUndefined)
371 heightValue = jsUndefined();
372 else {
373 heightValue = object->get(&state, Identifier::fromString(&state, "height"));
374 RETURN_IF_EXCEPTION(throwScope, { });
375 }
376 if (!heightValue.isUndefined()) {
377 result.height = convert<IDLUnion<IDLLong, IDLDictionary<ConstrainLongRange>>>(state, heightValue);
378 RETURN_IF_EXCEPTION(throwScope, { });
379 }
380 JSValue logicalSurfaceValue;
381 if (isNullOrUndefined)
382 logicalSurfaceValue = jsUndefined();
383 else {
384 logicalSurfaceValue = object->get(&state, Identifier::fromString(&state, "logicalSurface"));
385 RETURN_IF_EXCEPTION(throwScope, { });
386 }
387 if (!logicalSurfaceValue.isUndefined()) {
388 result.logicalSurface = convert<IDLUnion<IDLBoolean, IDLDictionary<ConstrainBooleanParameters>>>(state, logicalSurfaceValue);
389 RETURN_IF_EXCEPTION(throwScope, { });
390 }
391 JSValue sampleRateValue;
392 if (isNullOrUndefined)
393 sampleRateValue = jsUndefined();
394 else {
395 sampleRateValue = object->get(&state, Identifier::fromString(&state, "sampleRate"));
396 RETURN_IF_EXCEPTION(throwScope, { });
397 }
398 if (!sampleRateValue.isUndefined()) {
399 result.sampleRate = convert<IDLUnion<IDLLong, IDLDictionary<ConstrainLongRange>>>(state, sampleRateValue);
400 RETURN_IF_EXCEPTION(throwScope, { });
401 }
402 JSValue sampleSizeValue;
403 if (isNullOrUndefined)
404 sampleSizeValue = jsUndefined();
405 else {
406 sampleSizeValue = object->get(&state, Identifier::fromString(&state, "sampleSize"));
407 RETURN_IF_EXCEPTION(throwScope, { });
408 }
409 if (!sampleSizeValue.isUndefined()) {
410 result.sampleSize = convert<IDLUnion<IDLLong, IDLDictionary<ConstrainLongRange>>>(state, sampleSizeValue);
411 RETURN_IF_EXCEPTION(throwScope, { });
412 }
413 JSValue volumeValue;
414 if (isNullOrUndefined)
415 volumeValue = jsUndefined();
416 else {
417 volumeValue = object->get(&state, Identifier::fromString(&state, "volume"));
418 RETURN_IF_EXCEPTION(throwScope, { });
419 }
420 if (!volumeValue.isUndefined()) {
421 result.volume = convert<IDLUnion<IDLDouble, IDLDictionary<ConstrainDoubleRange>>>(state, volumeValue);
422 RETURN_IF_EXCEPTION(throwScope, { });
423 }
424 JSValue widthValue;
425 if (isNullOrUndefined)
426 widthValue = jsUndefined();
427 else {
428 widthValue = object->get(&state, Identifier::fromString(&state, "width"));
429 RETURN_IF_EXCEPTION(throwScope, { });
430 }
431 if (!widthValue.isUndefined()) {
432 result.width = convert<IDLUnion<IDLLong, IDLDictionary<ConstrainLongRange>>>(state, widthValue);
433 RETURN_IF_EXCEPTION(throwScope, { });
434 }
435 return result;
436}
437
438JSC::JSObject* convertDictionaryToJS(JSC::ExecState& state, JSDOMGlobalObject& globalObject, const MediaTrackConstraintSet& dictionary)
439{
440 auto& vm = state.vm();
441
442 auto result = constructEmptyObject(&state, globalObject.objectPrototype());
443
444 if (!IDLUnion<IDLDouble, IDLDictionary<ConstrainDoubleRange>>::isNullValue(dictionary.aspectRatio)) {
445 auto aspectRatioValue = toJS<IDLUnion<IDLDouble, IDLDictionary<ConstrainDoubleRange>>>(state, globalObject, IDLUnion<IDLDouble, IDLDictionary<ConstrainDoubleRange>>::extractValueFromNullable(dictionary.aspectRatio));
446 result->putDirect(vm, JSC::Identifier::fromString(&vm, "aspectRatio"), aspectRatioValue);
447 }
448 if (!IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>, IDLDictionary<ConstrainDOMStringParameters>>::isNullValue(dictionary.deviceId)) {
449 auto deviceIdValue = toJS<IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>, IDLDictionary<ConstrainDOMStringParameters>>>(state, globalObject, IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>, IDLDictionary<ConstrainDOMStringParameters>>::extractValueFromNullable(dictionary.deviceId));
450 result->putDirect(vm, JSC::Identifier::fromString(&vm, "deviceId"), deviceIdValue);
451 }
452 if (!IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>, IDLDictionary<ConstrainDOMStringParameters>>::isNullValue(dictionary.displaySurface)) {
453 auto displaySurfaceValue = toJS<IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>, IDLDictionary<ConstrainDOMStringParameters>>>(state, globalObject, IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>, IDLDictionary<ConstrainDOMStringParameters>>::extractValueFromNullable(dictionary.displaySurface));
454 result->putDirect(vm, JSC::Identifier::fromString(&vm, "displaySurface"), displaySurfaceValue);
455 }
456 if (!IDLUnion<IDLBoolean, IDLDictionary<ConstrainBooleanParameters>>::isNullValue(dictionary.echoCancellation)) {
457 auto echoCancellationValue = toJS<IDLUnion<IDLBoolean, IDLDictionary<ConstrainBooleanParameters>>>(state, globalObject, IDLUnion<IDLBoolean, IDLDictionary<ConstrainBooleanParameters>>::extractValueFromNullable(dictionary.echoCancellation));
458 result->putDirect(vm, JSC::Identifier::fromString(&vm, "echoCancellation"), echoCancellationValue);
459 }
460 if (!IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>, IDLDictionary<ConstrainDOMStringParameters>>::isNullValue(dictionary.facingMode)) {
461 auto facingModeValue = toJS<IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>, IDLDictionary<ConstrainDOMStringParameters>>>(state, globalObject, IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>, IDLDictionary<ConstrainDOMStringParameters>>::extractValueFromNullable(dictionary.facingMode));
462 result->putDirect(vm, JSC::Identifier::fromString(&vm, "facingMode"), facingModeValue);
463 }
464 if (!IDLUnion<IDLDouble, IDLDictionary<ConstrainDoubleRange>>::isNullValue(dictionary.frameRate)) {
465 auto frameRateValue = toJS<IDLUnion<IDLDouble, IDLDictionary<ConstrainDoubleRange>>>(state, globalObject, IDLUnion<IDLDouble, IDLDictionary<ConstrainDoubleRange>>::extractValueFromNullable(dictionary.frameRate));
466 result->putDirect(vm, JSC::Identifier::fromString(&vm, "frameRate"), frameRateValue);
467 }
468 if (!IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>, IDLDictionary<ConstrainDOMStringParameters>>::isNullValue(dictionary.groupId)) {
469 auto groupIdValue = toJS<IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>, IDLDictionary<ConstrainDOMStringParameters>>>(state, globalObject, IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>, IDLDictionary<ConstrainDOMStringParameters>>::extractValueFromNullable(dictionary.groupId));
470 result->putDirect(vm, JSC::Identifier::fromString(&vm, "groupId"), groupIdValue);
471 }
472 if (!IDLUnion<IDLLong, IDLDictionary<ConstrainLongRange>>::isNullValue(dictionary.height)) {
473 auto heightValue = toJS<IDLUnion<IDLLong, IDLDictionary<ConstrainLongRange>>>(state, globalObject, IDLUnion<IDLLong, IDLDictionary<ConstrainLongRange>>::extractValueFromNullable(dictionary.height));
474 result->putDirect(vm, JSC::Identifier::fromString(&vm, "height"), heightValue);
475 }
476 if (!IDLUnion<IDLBoolean, IDLDictionary<ConstrainBooleanParameters>>::isNullValue(dictionary.logicalSurface)) {
477 auto logicalSurfaceValue = toJS<IDLUnion<IDLBoolean, IDLDictionary<ConstrainBooleanParameters>>>(state, globalObject, IDLUnion<IDLBoolean, IDLDictionary<ConstrainBooleanParameters>>::extractValueFromNullable(dictionary.logicalSurface));
478 result->putDirect(vm, JSC::Identifier::fromString(&vm, "logicalSurface"), logicalSurfaceValue);
479 }
480 if (!IDLUnion<IDLLong, IDLDictionary<ConstrainLongRange>>::isNullValue(dictionary.sampleRate)) {
481 auto sampleRateValue = toJS<IDLUnion<IDLLong, IDLDictionary<ConstrainLongRange>>>(state, globalObject, IDLUnion<IDLLong, IDLDictionary<ConstrainLongRange>>::extractValueFromNullable(dictionary.sampleRate));
482 result->putDirect(vm, JSC::Identifier::fromString(&vm, "sampleRate"), sampleRateValue);
483 }
484 if (!IDLUnion<IDLLong, IDLDictionary<ConstrainLongRange>>::isNullValue(dictionary.sampleSize)) {
485 auto sampleSizeValue = toJS<IDLUnion<IDLLong, IDLDictionary<ConstrainLongRange>>>(state, globalObject, IDLUnion<IDLLong, IDLDictionary<ConstrainLongRange>>::extractValueFromNullable(dictionary.sampleSize));
486 result->putDirect(vm, JSC::Identifier::fromString(&vm, "sampleSize"), sampleSizeValue);
487 }
488 if (!IDLUnion<IDLDouble, IDLDictionary<ConstrainDoubleRange>>::isNullValue(dictionary.volume)) {
489 auto volumeValue = toJS<IDLUnion<IDLDouble, IDLDictionary<ConstrainDoubleRange>>>(state, globalObject, IDLUnion<IDLDouble, IDLDictionary<ConstrainDoubleRange>>::extractValueFromNullable(dictionary.volume));
490 result->putDirect(vm, JSC::Identifier::fromString(&vm, "volume"), volumeValue);
491 }
492 if (!IDLUnion<IDLLong, IDLDictionary<ConstrainLongRange>>::isNullValue(dictionary.width)) {
493 auto widthValue = toJS<IDLUnion<IDLLong, IDLDictionary<ConstrainLongRange>>>(state, globalObject, IDLUnion<IDLLong, IDLDictionary<ConstrainLongRange>>::extractValueFromNullable(dictionary.width));
494 result->putDirect(vm, JSC::Identifier::fromString(&vm, "width"), widthValue);
495 }
496 return result;
497}
498
499#endif
500
501#if ENABLE(MEDIA_STREAM)
502
503template<> ConstrainBooleanParameters convertDictionary<ConstrainBooleanParameters>(ExecState& state, JSValue value)
504{
505 VM& vm = state.vm();
506 auto throwScope = DECLARE_THROW_SCOPE(vm);
507 bool isNullOrUndefined = value.isUndefinedOrNull();
508 auto* object = isNullOrUndefined ? nullptr : value.getObject();
509 if (UNLIKELY(!isNullOrUndefined && !object)) {
510 throwTypeError(&state, throwScope);
511 return { };
512 }
513 ConstrainBooleanParameters result;
514 JSValue exactValue;
515 if (isNullOrUndefined)
516 exactValue = jsUndefined();
517 else {
518 exactValue = object->get(&state, Identifier::fromString(&state, "exact"));
519 RETURN_IF_EXCEPTION(throwScope, { });
520 }
521 if (!exactValue.isUndefined()) {
522 result.exact = convert<IDLBoolean>(state, exactValue);
523 RETURN_IF_EXCEPTION(throwScope, { });
524 }
525 JSValue idealValue;
526 if (isNullOrUndefined)
527 idealValue = jsUndefined();
528 else {
529 idealValue = object->get(&state, Identifier::fromString(&state, "ideal"));
530 RETURN_IF_EXCEPTION(throwScope, { });
531 }
532 if (!idealValue.isUndefined()) {
533 result.ideal = convert<IDLBoolean>(state, idealValue);
534 RETURN_IF_EXCEPTION(throwScope, { });
535 }
536 return result;
537}
538
539JSC::JSObject* convertDictionaryToJS(JSC::ExecState& state, JSDOMGlobalObject& globalObject, const ConstrainBooleanParameters& dictionary)
540{
541 auto& vm = state.vm();
542
543 auto result = constructEmptyObject(&state, globalObject.objectPrototype());
544
545 if (!IDLBoolean::isNullValue(dictionary.exact)) {
546 auto exactValue = toJS<IDLBoolean>(IDLBoolean::extractValueFromNullable(dictionary.exact));
547 result->putDirect(vm, JSC::Identifier::fromString(&vm, "exact"), exactValue);
548 }
549 if (!IDLBoolean::isNullValue(dictionary.ideal)) {
550 auto idealValue = toJS<IDLBoolean>(IDLBoolean::extractValueFromNullable(dictionary.ideal));
551 result->putDirect(vm, JSC::Identifier::fromString(&vm, "ideal"), idealValue);
552 }
553 return result;
554}
555
556#endif
557
558#if ENABLE(MEDIA_STREAM)
559
560template<> ConstrainDOMStringParameters convertDictionary<ConstrainDOMStringParameters>(ExecState& state, JSValue value)
561{
562 VM& vm = state.vm();
563 auto throwScope = DECLARE_THROW_SCOPE(vm);
564 bool isNullOrUndefined = value.isUndefinedOrNull();
565 auto* object = isNullOrUndefined ? nullptr : value.getObject();
566 if (UNLIKELY(!isNullOrUndefined && !object)) {
567 throwTypeError(&state, throwScope);
568 return { };
569 }
570 ConstrainDOMStringParameters result;
571 JSValue exactValue;
572 if (isNullOrUndefined)
573 exactValue = jsUndefined();
574 else {
575 exactValue = object->get(&state, Identifier::fromString(&state, "exact"));
576 RETURN_IF_EXCEPTION(throwScope, { });
577 }
578 if (!exactValue.isUndefined()) {
579 result.exact = convert<IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>>>(state, exactValue);
580 RETURN_IF_EXCEPTION(throwScope, { });
581 }
582 JSValue idealValue;
583 if (isNullOrUndefined)
584 idealValue = jsUndefined();
585 else {
586 idealValue = object->get(&state, Identifier::fromString(&state, "ideal"));
587 RETURN_IF_EXCEPTION(throwScope, { });
588 }
589 if (!idealValue.isUndefined()) {
590 result.ideal = convert<IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>>>(state, idealValue);
591 RETURN_IF_EXCEPTION(throwScope, { });
592 }
593 return result;
594}
595
596JSC::JSObject* convertDictionaryToJS(JSC::ExecState& state, JSDOMGlobalObject& globalObject, const ConstrainDOMStringParameters& dictionary)
597{
598 auto& vm = state.vm();
599
600 auto result = constructEmptyObject(&state, globalObject.objectPrototype());
601
602 if (!IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>>::isNullValue(dictionary.exact)) {
603 auto exactValue = toJS<IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>>>(state, globalObject, IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>>::extractValueFromNullable(dictionary.exact));
604 result->putDirect(vm, JSC::Identifier::fromString(&vm, "exact"), exactValue);
605 }
606 if (!IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>>::isNullValue(dictionary.ideal)) {
607 auto idealValue = toJS<IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>>>(state, globalObject, IDLUnion<IDLDOMString, IDLSequence<IDLDOMString>>::extractValueFromNullable(dictionary.ideal));
608 result->putDirect(vm, JSC::Identifier::fromString(&vm, "ideal"), idealValue);
609 }
610 return result;
611}
612
613#endif
614
615#if ENABLE(MEDIA_STREAM)
616
617template<> ConstrainDoubleRange convertDictionary<ConstrainDoubleRange>(ExecState& state, JSValue value)
618{
619 VM& vm = state.vm();
620 auto throwScope = DECLARE_THROW_SCOPE(vm);
621 bool isNullOrUndefined = value.isUndefinedOrNull();
622 auto* object = isNullOrUndefined ? nullptr : value.getObject();
623 if (UNLIKELY(!isNullOrUndefined && !object)) {
624 throwTypeError(&state, throwScope);
625 return { };
626 }
627 ConstrainDoubleRange result;
628 JSValue maxValue;
629 if (isNullOrUndefined)
630 maxValue = jsUndefined();
631 else {
632 maxValue = object->get(&state, Identifier::fromString(&state, "max"));
633 RETURN_IF_EXCEPTION(throwScope, { });
634 }
635 if (!maxValue.isUndefined()) {
636 result.max = convert<IDLDouble>(state, maxValue);
637 RETURN_IF_EXCEPTION(throwScope, { });
638 }
639 JSValue minValue;
640 if (isNullOrUndefined)
641 minValue = jsUndefined();
642 else {
643 minValue = object->get(&state, Identifier::fromString(&state, "min"));
644 RETURN_IF_EXCEPTION(throwScope, { });
645 }
646 if (!minValue.isUndefined()) {
647 result.min = convert<IDLDouble>(state, minValue);
648 RETURN_IF_EXCEPTION(throwScope, { });
649 }
650 JSValue exactValue;
651 if (isNullOrUndefined)
652 exactValue = jsUndefined();
653 else {
654 exactValue = object->get(&state, Identifier::fromString(&state, "exact"));
655 RETURN_IF_EXCEPTION(throwScope, { });
656 }
657 if (!exactValue.isUndefined()) {
658 result.exact = convert<IDLDouble>(state, exactValue);
659 RETURN_IF_EXCEPTION(throwScope, { });
660 }
661 JSValue idealValue;
662 if (isNullOrUndefined)
663 idealValue = jsUndefined();
664 else {
665 idealValue = object->get(&state, Identifier::fromString(&state, "ideal"));
666 RETURN_IF_EXCEPTION(throwScope, { });
667 }
668 if (!idealValue.isUndefined()) {
669 result.ideal = convert<IDLDouble>(state, idealValue);
670 RETURN_IF_EXCEPTION(throwScope, { });
671 }
672 return result;
673}
674
675JSC::JSObject* convertDictionaryToJS(JSC::ExecState& state, JSDOMGlobalObject& globalObject, const ConstrainDoubleRange& dictionary)
676{
677 auto& vm = state.vm();
678
679 auto result = constructEmptyObject(&state, globalObject.objectPrototype());
680
681 if (!IDLDouble::isNullValue(dictionary.max)) {
682 auto maxValue = toJS<IDLDouble>(IDLDouble::extractValueFromNullable(dictionary.max));
683 result->putDirect(vm, JSC::Identifier::fromString(&vm, "max"), maxValue);
684 }
685 if (!IDLDouble::isNullValue(dictionary.min)) {
686 auto minValue = toJS<IDLDouble>(IDLDouble::extractValueFromNullable(dictionary.min));
687 result->putDirect(vm, JSC::Identifier::fromString(&vm, "min"), minValue);
688 }
689 if (!IDLDouble::isNullValue(dictionary.exact)) {
690 auto exactValue = toJS<IDLDouble>(IDLDouble::extractValueFromNullable(dictionary.exact));
691 result->putDirect(vm, JSC::Identifier::fromString(&vm, "exact"), exactValue);
692 }
693 if (!IDLDouble::isNullValue(dictionary.ideal)) {
694 auto idealValue = toJS<IDLDouble>(IDLDouble::extractValueFromNullable(dictionary.ideal));
695 result->putDirect(vm, JSC::Identifier::fromString(&vm, "ideal"), idealValue);
696 }
697 return result;
698}
699
700#endif
701
702#if ENABLE(MEDIA_STREAM)
703
704template<> ConstrainLongRange convertDictionary<ConstrainLongRange>(ExecState& state, JSValue value)
705{
706 VM& vm = state.vm();
707 auto throwScope = DECLARE_THROW_SCOPE(vm);
708 bool isNullOrUndefined = value.isUndefinedOrNull();
709 auto* object = isNullOrUndefined ? nullptr : value.getObject();
710 if (UNLIKELY(!isNullOrUndefined && !object)) {
711 throwTypeError(&state, throwScope);
712 return { };
713 }
714 ConstrainLongRange result;
715 JSValue maxValue;
716 if (isNullOrUndefined)
717 maxValue = jsUndefined();
718 else {
719 maxValue = object->get(&state, Identifier::fromString(&state, "max"));
720 RETURN_IF_EXCEPTION(throwScope, { });
721 }
722 if (!maxValue.isUndefined()) {
723 result.max = convert<IDLLong>(state, maxValue);
724 RETURN_IF_EXCEPTION(throwScope, { });
725 }
726 JSValue minValue;
727 if (isNullOrUndefined)
728 minValue = jsUndefined();
729 else {
730 minValue = object->get(&state, Identifier::fromString(&state, "min"));
731 RETURN_IF_EXCEPTION(throwScope, { });
732 }
733 if (!minValue.isUndefined()) {
734 result.min = convert<IDLLong>(state, minValue);
735 RETURN_IF_EXCEPTION(throwScope, { });
736 }
737 JSValue exactValue;
738 if (isNullOrUndefined)
739 exactValue = jsUndefined();
740 else {
741 exactValue = object->get(&state, Identifier::fromString(&state, "exact"));
742 RETURN_IF_EXCEPTION(throwScope, { });
743 }
744 if (!exactValue.isUndefined()) {
745 result.exact = convert<IDLLong>(state, exactValue);
746 RETURN_IF_EXCEPTION(throwScope, { });
747 }
748 JSValue idealValue;
749 if (isNullOrUndefined)
750 idealValue = jsUndefined();
751 else {
752 idealValue = object->get(&state, Identifier::fromString(&state, "ideal"));
753 RETURN_IF_EXCEPTION(throwScope, { });
754 }
755 if (!idealValue.isUndefined()) {
756 result.ideal = convert<IDLLong>(state, idealValue);
757 RETURN_IF_EXCEPTION(throwScope, { });
758 }
759 return result;
760}
761
762JSC::JSObject* convertDictionaryToJS(JSC::ExecState& state, JSDOMGlobalObject& globalObject, const ConstrainLongRange& dictionary)
763{
764 auto& vm = state.vm();
765
766 auto result = constructEmptyObject(&state, globalObject.objectPrototype());
767
768 if (!IDLLong::isNullValue(dictionary.max)) {
769 auto maxValue = toJS<IDLLong>(IDLLong::extractValueFromNullable(dictionary.max));
770 result->putDirect(vm, JSC::Identifier::fromString(&vm, "max"), maxValue);
771 }
772 if (!IDLLong::isNullValue(dictionary.min)) {
773 auto minValue = toJS<IDLLong>(IDLLong::extractValueFromNullable(dictionary.min));
774 result->putDirect(vm, JSC::Identifier::fromString(&vm, "min"), minValue);
775 }
776 if (!IDLLong::isNullValue(dictionary.exact)) {
777 auto exactValue = toJS<IDLLong>(IDLLong::extractValueFromNullable(dictionary.exact));
778 result->putDirect(vm, JSC::Identifier::fromString(&vm, "exact"), exactValue);
779 }
780 if (!IDLLong::isNullValue(dictionary.ideal)) {
781 auto idealValue = toJS<IDLLong>(IDLLong::extractValueFromNullable(dictionary.ideal));
782 result->putDirect(vm, JSC::Identifier::fromString(&vm, "ideal"), idealValue);
783 }
784 return result;
785}
786
787#endif
788
789} // namespace WebCore
790
791#endif // ENABLE(MEDIA_STREAM)
792