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_AUTHN) |
24 | |
25 | #include "JSPublicKeyCredentialCreationOptions.h" |
26 | |
27 | #include "JSAuthenticationExtensionsClientInputs.h" |
28 | #include "JSDOMConvertBoolean.h" |
29 | #include "JSDOMConvertBufferSource.h" |
30 | #include "JSDOMConvertNumbers.h" |
31 | #include "JSDOMConvertSequences.h" |
32 | #include "JSDOMConvertStrings.h" |
33 | #include "JSDOMConvertUnion.h" |
34 | #include "JSPublicKeyCredentialDescriptor.h" |
35 | #include "JSPublicKeyCredentialType.h" |
36 | #include "JSUserVerificationRequirement.h" |
37 | #include <JavaScriptCore/JSArray.h> |
38 | #include <JavaScriptCore/JSCInlines.h> |
39 | #include <JavaScriptCore/JSString.h> |
40 | #include <wtf/NeverDestroyed.h> |
41 | #include <wtf/Variant.h> |
42 | |
43 | |
44 | namespace WebCore { |
45 | using namespace JSC; |
46 | |
47 | #if ENABLE(WEB_AUTHN) |
48 | |
49 | template<> PublicKeyCredentialCreationOptions convertDictionary<PublicKeyCredentialCreationOptions>(ExecState& state, JSValue value) |
50 | { |
51 | VM& vm = state.vm(); |
52 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
53 | bool isNullOrUndefined = value.isUndefinedOrNull(); |
54 | auto* object = isNullOrUndefined ? nullptr : value.getObject(); |
55 | if (UNLIKELY(!isNullOrUndefined && !object)) { |
56 | throwTypeError(&state, throwScope); |
57 | return { }; |
58 | } |
59 | PublicKeyCredentialCreationOptions result; |
60 | JSValue authenticatorSelectionValue; |
61 | if (isNullOrUndefined) |
62 | authenticatorSelectionValue = jsUndefined(); |
63 | else { |
64 | authenticatorSelectionValue = object->get(&state, Identifier::fromString(&state, "authenticatorSelection" )); |
65 | RETURN_IF_EXCEPTION(throwScope, { }); |
66 | } |
67 | if (!authenticatorSelectionValue.isUndefined()) { |
68 | result.authenticatorSelection = convert<IDLDictionary<PublicKeyCredentialCreationOptions::AuthenticatorSelectionCriteria>>(state, authenticatorSelectionValue); |
69 | RETURN_IF_EXCEPTION(throwScope, { }); |
70 | } |
71 | JSValue challengeValue; |
72 | if (isNullOrUndefined) |
73 | challengeValue = jsUndefined(); |
74 | else { |
75 | challengeValue = object->get(&state, Identifier::fromString(&state, "challenge" )); |
76 | RETURN_IF_EXCEPTION(throwScope, { }); |
77 | } |
78 | if (!challengeValue.isUndefined()) { |
79 | result.challenge = convert<IDLUnion<IDLArrayBufferView, IDLArrayBuffer>>(state, challengeValue); |
80 | RETURN_IF_EXCEPTION(throwScope, { }); |
81 | } else { |
82 | throwRequiredMemberTypeError(state, throwScope, "challenge" , "PublicKeyCredentialCreationOptions" , "(ArrayBufferView or ArrayBuffer)" ); |
83 | return { }; |
84 | } |
85 | JSValue excludeCredentialsValue; |
86 | if (isNullOrUndefined) |
87 | excludeCredentialsValue = jsUndefined(); |
88 | else { |
89 | excludeCredentialsValue = object->get(&state, Identifier::fromString(&state, "excludeCredentials" )); |
90 | RETURN_IF_EXCEPTION(throwScope, { }); |
91 | } |
92 | if (!excludeCredentialsValue.isUndefined()) { |
93 | result.excludeCredentials = convert<IDLSequence<IDLDictionary<PublicKeyCredentialDescriptor>>>(state, excludeCredentialsValue); |
94 | RETURN_IF_EXCEPTION(throwScope, { }); |
95 | } else |
96 | result.excludeCredentials = Converter<IDLSequence<IDLDictionary<PublicKeyCredentialDescriptor>>>::ReturnType{ }; |
97 | JSValue extensionsValue; |
98 | if (isNullOrUndefined) |
99 | extensionsValue = jsUndefined(); |
100 | else { |
101 | extensionsValue = object->get(&state, Identifier::fromString(&state, "extensions" )); |
102 | RETURN_IF_EXCEPTION(throwScope, { }); |
103 | } |
104 | if (!extensionsValue.isUndefined()) { |
105 | result.extensions = convert<IDLDictionary<AuthenticationExtensionsClientInputs>>(state, extensionsValue); |
106 | RETURN_IF_EXCEPTION(throwScope, { }); |
107 | } |
108 | JSValue pubKeyCredParamsValue; |
109 | if (isNullOrUndefined) |
110 | pubKeyCredParamsValue = jsUndefined(); |
111 | else { |
112 | pubKeyCredParamsValue = object->get(&state, Identifier::fromString(&state, "pubKeyCredParams" )); |
113 | RETURN_IF_EXCEPTION(throwScope, { }); |
114 | } |
115 | if (!pubKeyCredParamsValue.isUndefined()) { |
116 | result.pubKeyCredParams = convert<IDLSequence<IDLDictionary<PublicKeyCredentialCreationOptions::Parameters>>>(state, pubKeyCredParamsValue); |
117 | RETURN_IF_EXCEPTION(throwScope, { }); |
118 | } else { |
119 | throwRequiredMemberTypeError(state, throwScope, "pubKeyCredParams" , "PublicKeyCredentialCreationOptions" , "sequence" ); |
120 | return { }; |
121 | } |
122 | JSValue rpValue; |
123 | if (isNullOrUndefined) |
124 | rpValue = jsUndefined(); |
125 | else { |
126 | rpValue = object->get(&state, Identifier::fromString(&state, "rp" )); |
127 | RETURN_IF_EXCEPTION(throwScope, { }); |
128 | } |
129 | if (!rpValue.isUndefined()) { |
130 | result.rp = convert<IDLDictionary<PublicKeyCredentialCreationOptions::RpEntity>>(state, rpValue); |
131 | RETURN_IF_EXCEPTION(throwScope, { }); |
132 | } else { |
133 | throwRequiredMemberTypeError(state, throwScope, "rp" , "PublicKeyCredentialCreationOptions" , "PublicKeyCredentialRpEntity" ); |
134 | return { }; |
135 | } |
136 | JSValue timeoutValue; |
137 | if (isNullOrUndefined) |
138 | timeoutValue = jsUndefined(); |
139 | else { |
140 | timeoutValue = object->get(&state, Identifier::fromString(&state, "timeout" )); |
141 | RETURN_IF_EXCEPTION(throwScope, { }); |
142 | } |
143 | if (!timeoutValue.isUndefined()) { |
144 | result.timeout = convert<IDLUnsignedLong>(state, timeoutValue); |
145 | RETURN_IF_EXCEPTION(throwScope, { }); |
146 | } |
147 | JSValue userValue; |
148 | if (isNullOrUndefined) |
149 | userValue = jsUndefined(); |
150 | else { |
151 | userValue = object->get(&state, Identifier::fromString(&state, "user" )); |
152 | RETURN_IF_EXCEPTION(throwScope, { }); |
153 | } |
154 | if (!userValue.isUndefined()) { |
155 | result.user = convert<IDLDictionary<PublicKeyCredentialCreationOptions::UserEntity>>(state, userValue); |
156 | RETURN_IF_EXCEPTION(throwScope, { }); |
157 | } else { |
158 | throwRequiredMemberTypeError(state, throwScope, "user" , "PublicKeyCredentialCreationOptions" , "PublicKeyCredentialUserEntity" ); |
159 | return { }; |
160 | } |
161 | return result; |
162 | } |
163 | |
164 | #endif |
165 | |
166 | #if ENABLE(WEB_AUTHN) |
167 | |
168 | String convertEnumerationToString(PublicKeyCredentialCreationOptions::AuthenticatorAttachment enumerationValue) |
169 | { |
170 | static const NeverDestroyed<String> values[] = { |
171 | MAKE_STATIC_STRING_IMPL("platform" ), |
172 | MAKE_STATIC_STRING_IMPL("cross-platform" ), |
173 | }; |
174 | static_assert(static_cast<size_t>(PublicKeyCredentialCreationOptions::AuthenticatorAttachment::Platform) == 0, "PublicKeyCredentialCreationOptions::AuthenticatorAttachment::Platform is not 0 as expected" ); |
175 | static_assert(static_cast<size_t>(PublicKeyCredentialCreationOptions::AuthenticatorAttachment::CrossPlatform) == 1, "PublicKeyCredentialCreationOptions::AuthenticatorAttachment::CrossPlatform is not 1 as expected" ); |
176 | ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values)); |
177 | return values[static_cast<size_t>(enumerationValue)]; |
178 | } |
179 | |
180 | template<> JSString* convertEnumerationToJS(ExecState& state, PublicKeyCredentialCreationOptions::AuthenticatorAttachment enumerationValue) |
181 | { |
182 | return jsStringWithCache(&state, convertEnumerationToString(enumerationValue)); |
183 | } |
184 | |
185 | template<> Optional<PublicKeyCredentialCreationOptions::AuthenticatorAttachment> parseEnumeration<PublicKeyCredentialCreationOptions::AuthenticatorAttachment>(ExecState& state, JSValue value) |
186 | { |
187 | auto stringValue = value.toWTFString(&state); |
188 | if (stringValue == "platform" ) |
189 | return PublicKeyCredentialCreationOptions::AuthenticatorAttachment::Platform; |
190 | if (stringValue == "cross-platform" ) |
191 | return PublicKeyCredentialCreationOptions::AuthenticatorAttachment::CrossPlatform; |
192 | return WTF::nullopt; |
193 | } |
194 | |
195 | template<> const char* expectedEnumerationValues<PublicKeyCredentialCreationOptions::AuthenticatorAttachment>() |
196 | { |
197 | return "\"platform\", \"cross-platform\"" ; |
198 | } |
199 | |
200 | #endif |
201 | |
202 | #if ENABLE(WEB_AUTHN) |
203 | |
204 | template<> PublicKeyCredentialCreationOptions::Entity convertDictionary<PublicKeyCredentialCreationOptions::Entity>(ExecState& state, JSValue value) |
205 | { |
206 | VM& vm = state.vm(); |
207 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
208 | bool isNullOrUndefined = value.isUndefinedOrNull(); |
209 | auto* object = isNullOrUndefined ? nullptr : value.getObject(); |
210 | if (UNLIKELY(!isNullOrUndefined && !object)) { |
211 | throwTypeError(&state, throwScope); |
212 | return { }; |
213 | } |
214 | PublicKeyCredentialCreationOptions::Entity result; |
215 | JSValue iconValue; |
216 | if (isNullOrUndefined) |
217 | iconValue = jsUndefined(); |
218 | else { |
219 | iconValue = object->get(&state, Identifier::fromString(&state, "icon" )); |
220 | RETURN_IF_EXCEPTION(throwScope, { }); |
221 | } |
222 | if (!iconValue.isUndefined()) { |
223 | result.icon = convert<IDLUSVString>(state, iconValue); |
224 | RETURN_IF_EXCEPTION(throwScope, { }); |
225 | } |
226 | JSValue nameValue; |
227 | if (isNullOrUndefined) |
228 | nameValue = jsUndefined(); |
229 | else { |
230 | nameValue = object->get(&state, Identifier::fromString(&state, "name" )); |
231 | RETURN_IF_EXCEPTION(throwScope, { }); |
232 | } |
233 | if (!nameValue.isUndefined()) { |
234 | result.name = convert<IDLDOMString>(state, nameValue); |
235 | RETURN_IF_EXCEPTION(throwScope, { }); |
236 | } else { |
237 | throwRequiredMemberTypeError(state, throwScope, "name" , "PublicKeyCredentialEntity" , "DOMString" ); |
238 | return { }; |
239 | } |
240 | return result; |
241 | } |
242 | |
243 | #endif |
244 | |
245 | #if ENABLE(WEB_AUTHN) |
246 | |
247 | template<> PublicKeyCredentialCreationOptions::RpEntity convertDictionary<PublicKeyCredentialCreationOptions::RpEntity>(ExecState& state, JSValue value) |
248 | { |
249 | VM& vm = state.vm(); |
250 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
251 | bool isNullOrUndefined = value.isUndefinedOrNull(); |
252 | auto* object = isNullOrUndefined ? nullptr : value.getObject(); |
253 | if (UNLIKELY(!isNullOrUndefined && !object)) { |
254 | throwTypeError(&state, throwScope); |
255 | return { }; |
256 | } |
257 | PublicKeyCredentialCreationOptions::RpEntity result; |
258 | JSValue iconValue; |
259 | if (isNullOrUndefined) |
260 | iconValue = jsUndefined(); |
261 | else { |
262 | iconValue = object->get(&state, Identifier::fromString(&state, "icon" )); |
263 | RETURN_IF_EXCEPTION(throwScope, { }); |
264 | } |
265 | if (!iconValue.isUndefined()) { |
266 | result.icon = convert<IDLUSVString>(state, iconValue); |
267 | RETURN_IF_EXCEPTION(throwScope, { }); |
268 | } |
269 | JSValue nameValue; |
270 | if (isNullOrUndefined) |
271 | nameValue = jsUndefined(); |
272 | else { |
273 | nameValue = object->get(&state, Identifier::fromString(&state, "name" )); |
274 | RETURN_IF_EXCEPTION(throwScope, { }); |
275 | } |
276 | if (!nameValue.isUndefined()) { |
277 | result.name = convert<IDLDOMString>(state, nameValue); |
278 | RETURN_IF_EXCEPTION(throwScope, { }); |
279 | } else { |
280 | throwRequiredMemberTypeError(state, throwScope, "name" , "PublicKeyCredentialRpEntity" , "DOMString" ); |
281 | return { }; |
282 | } |
283 | JSValue idValue; |
284 | if (isNullOrUndefined) |
285 | idValue = jsUndefined(); |
286 | else { |
287 | idValue = object->get(&state, Identifier::fromString(&state, "id" )); |
288 | RETURN_IF_EXCEPTION(throwScope, { }); |
289 | } |
290 | if (!idValue.isUndefined()) { |
291 | result.id = convert<IDLDOMString>(state, idValue); |
292 | RETURN_IF_EXCEPTION(throwScope, { }); |
293 | } |
294 | return result; |
295 | } |
296 | |
297 | #endif |
298 | |
299 | #if ENABLE(WEB_AUTHN) |
300 | |
301 | template<> PublicKeyCredentialCreationOptions::UserEntity convertDictionary<PublicKeyCredentialCreationOptions::UserEntity>(ExecState& state, JSValue value) |
302 | { |
303 | VM& vm = state.vm(); |
304 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
305 | bool isNullOrUndefined = value.isUndefinedOrNull(); |
306 | auto* object = isNullOrUndefined ? nullptr : value.getObject(); |
307 | if (UNLIKELY(!isNullOrUndefined && !object)) { |
308 | throwTypeError(&state, throwScope); |
309 | return { }; |
310 | } |
311 | PublicKeyCredentialCreationOptions::UserEntity result; |
312 | JSValue iconValue; |
313 | if (isNullOrUndefined) |
314 | iconValue = jsUndefined(); |
315 | else { |
316 | iconValue = object->get(&state, Identifier::fromString(&state, "icon" )); |
317 | RETURN_IF_EXCEPTION(throwScope, { }); |
318 | } |
319 | if (!iconValue.isUndefined()) { |
320 | result.icon = convert<IDLUSVString>(state, iconValue); |
321 | RETURN_IF_EXCEPTION(throwScope, { }); |
322 | } |
323 | JSValue nameValue; |
324 | if (isNullOrUndefined) |
325 | nameValue = jsUndefined(); |
326 | else { |
327 | nameValue = object->get(&state, Identifier::fromString(&state, "name" )); |
328 | RETURN_IF_EXCEPTION(throwScope, { }); |
329 | } |
330 | if (!nameValue.isUndefined()) { |
331 | result.name = convert<IDLDOMString>(state, nameValue); |
332 | RETURN_IF_EXCEPTION(throwScope, { }); |
333 | } else { |
334 | throwRequiredMemberTypeError(state, throwScope, "name" , "PublicKeyCredentialUserEntity" , "DOMString" ); |
335 | return { }; |
336 | } |
337 | JSValue displayNameValue; |
338 | if (isNullOrUndefined) |
339 | displayNameValue = jsUndefined(); |
340 | else { |
341 | displayNameValue = object->get(&state, Identifier::fromString(&state, "displayName" )); |
342 | RETURN_IF_EXCEPTION(throwScope, { }); |
343 | } |
344 | if (!displayNameValue.isUndefined()) { |
345 | result.displayName = convert<IDLDOMString>(state, displayNameValue); |
346 | RETURN_IF_EXCEPTION(throwScope, { }); |
347 | } else { |
348 | throwRequiredMemberTypeError(state, throwScope, "displayName" , "PublicKeyCredentialUserEntity" , "DOMString" ); |
349 | return { }; |
350 | } |
351 | JSValue idValue; |
352 | if (isNullOrUndefined) |
353 | idValue = jsUndefined(); |
354 | else { |
355 | idValue = object->get(&state, Identifier::fromString(&state, "id" )); |
356 | RETURN_IF_EXCEPTION(throwScope, { }); |
357 | } |
358 | if (!idValue.isUndefined()) { |
359 | result.id = convert<IDLUnion<IDLArrayBufferView, IDLArrayBuffer>>(state, idValue); |
360 | RETURN_IF_EXCEPTION(throwScope, { }); |
361 | } else { |
362 | throwRequiredMemberTypeError(state, throwScope, "id" , "PublicKeyCredentialUserEntity" , "(ArrayBufferView or ArrayBuffer)" ); |
363 | return { }; |
364 | } |
365 | return result; |
366 | } |
367 | |
368 | #endif |
369 | |
370 | #if ENABLE(WEB_AUTHN) |
371 | |
372 | template<> PublicKeyCredentialCreationOptions::Parameters convertDictionary<PublicKeyCredentialCreationOptions::Parameters>(ExecState& state, JSValue value) |
373 | { |
374 | VM& vm = state.vm(); |
375 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
376 | bool isNullOrUndefined = value.isUndefinedOrNull(); |
377 | auto* object = isNullOrUndefined ? nullptr : value.getObject(); |
378 | if (UNLIKELY(!isNullOrUndefined && !object)) { |
379 | throwTypeError(&state, throwScope); |
380 | return { }; |
381 | } |
382 | PublicKeyCredentialCreationOptions::Parameters result; |
383 | JSValue algValue; |
384 | if (isNullOrUndefined) |
385 | algValue = jsUndefined(); |
386 | else { |
387 | algValue = object->get(&state, Identifier::fromString(&state, "alg" )); |
388 | RETURN_IF_EXCEPTION(throwScope, { }); |
389 | } |
390 | if (!algValue.isUndefined()) { |
391 | result.alg = convert<IDLLong>(state, algValue); |
392 | RETURN_IF_EXCEPTION(throwScope, { }); |
393 | } else { |
394 | throwRequiredMemberTypeError(state, throwScope, "alg" , "PublicKeyCredentialParameters" , "long" ); |
395 | return { }; |
396 | } |
397 | JSValue typeValue; |
398 | if (isNullOrUndefined) |
399 | typeValue = jsUndefined(); |
400 | else { |
401 | typeValue = object->get(&state, Identifier::fromString(&state, "type" )); |
402 | RETURN_IF_EXCEPTION(throwScope, { }); |
403 | } |
404 | if (!typeValue.isUndefined()) { |
405 | result.type = convert<IDLEnumeration<PublicKeyCredentialType>>(state, typeValue); |
406 | RETURN_IF_EXCEPTION(throwScope, { }); |
407 | } else { |
408 | throwRequiredMemberTypeError(state, throwScope, "type" , "PublicKeyCredentialParameters" , "PublicKeyCredentialType" ); |
409 | return { }; |
410 | } |
411 | return result; |
412 | } |
413 | |
414 | #endif |
415 | |
416 | #if ENABLE(WEB_AUTHN) |
417 | |
418 | template<> PublicKeyCredentialCreationOptions::AuthenticatorSelectionCriteria convertDictionary<PublicKeyCredentialCreationOptions::AuthenticatorSelectionCriteria>(ExecState& state, JSValue value) |
419 | { |
420 | VM& vm = state.vm(); |
421 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
422 | bool isNullOrUndefined = value.isUndefinedOrNull(); |
423 | auto* object = isNullOrUndefined ? nullptr : value.getObject(); |
424 | if (UNLIKELY(!isNullOrUndefined && !object)) { |
425 | throwTypeError(&state, throwScope); |
426 | return { }; |
427 | } |
428 | PublicKeyCredentialCreationOptions::AuthenticatorSelectionCriteria result; |
429 | JSValue authenticatorAttachmentValue; |
430 | if (isNullOrUndefined) |
431 | authenticatorAttachmentValue = jsUndefined(); |
432 | else { |
433 | authenticatorAttachmentValue = object->get(&state, Identifier::fromString(&state, "authenticatorAttachment" )); |
434 | RETURN_IF_EXCEPTION(throwScope, { }); |
435 | } |
436 | if (!authenticatorAttachmentValue.isUndefined()) { |
437 | result.authenticatorAttachment = convert<IDLEnumeration<PublicKeyCredentialCreationOptions::AuthenticatorAttachment>>(state, authenticatorAttachmentValue); |
438 | RETURN_IF_EXCEPTION(throwScope, { }); |
439 | } |
440 | JSValue requireResidentKeyValue; |
441 | if (isNullOrUndefined) |
442 | requireResidentKeyValue = jsUndefined(); |
443 | else { |
444 | requireResidentKeyValue = object->get(&state, Identifier::fromString(&state, "requireResidentKey" )); |
445 | RETURN_IF_EXCEPTION(throwScope, { }); |
446 | } |
447 | if (!requireResidentKeyValue.isUndefined()) { |
448 | result.requireResidentKey = convert<IDLBoolean>(state, requireResidentKeyValue); |
449 | RETURN_IF_EXCEPTION(throwScope, { }); |
450 | } else |
451 | result.requireResidentKey = false; |
452 | JSValue userVerificationValue; |
453 | if (isNullOrUndefined) |
454 | userVerificationValue = jsUndefined(); |
455 | else { |
456 | userVerificationValue = object->get(&state, Identifier::fromString(&state, "userVerification" )); |
457 | RETURN_IF_EXCEPTION(throwScope, { }); |
458 | } |
459 | if (!userVerificationValue.isUndefined()) { |
460 | result.userVerification = convert<IDLEnumeration<UserVerificationRequirement>>(state, userVerificationValue); |
461 | RETURN_IF_EXCEPTION(throwScope, { }); |
462 | } else |
463 | result.userVerification = UserVerificationRequirement::Preferred; |
464 | return result; |
465 | } |
466 | |
467 | #endif |
468 | |
469 | } // namespace WebCore |
470 | |
471 | #endif // ENABLE(WEB_AUTHN) |
472 | |