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 "JSCredentialRequestOptions.h" |
26 | |
27 | #include "JSAbortSignal.h" |
28 | #include "JSDOMConvertInterface.h" |
29 | #include "JSPublicKeyCredentialRequestOptions.h" |
30 | #include <JavaScriptCore/JSCInlines.h> |
31 | #include <JavaScriptCore/JSString.h> |
32 | #include <wtf/NeverDestroyed.h> |
33 | |
34 | |
35 | namespace WebCore { |
36 | using namespace JSC; |
37 | |
38 | #if ENABLE(WEB_AUTHN) |
39 | |
40 | template<> CredentialRequestOptions convertDictionary<CredentialRequestOptions>(ExecState& state, JSValue value) |
41 | { |
42 | VM& vm = state.vm(); |
43 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
44 | bool isNullOrUndefined = value.isUndefinedOrNull(); |
45 | auto* object = isNullOrUndefined ? nullptr : value.getObject(); |
46 | if (UNLIKELY(!isNullOrUndefined && !object)) { |
47 | throwTypeError(&state, throwScope); |
48 | return { }; |
49 | } |
50 | CredentialRequestOptions result; |
51 | JSValue mediationValue; |
52 | if (isNullOrUndefined) |
53 | mediationValue = jsUndefined(); |
54 | else { |
55 | mediationValue = object->get(&state, Identifier::fromString(&state, "mediation" )); |
56 | RETURN_IF_EXCEPTION(throwScope, { }); |
57 | } |
58 | if (!mediationValue.isUndefined()) { |
59 | result.mediation = convert<IDLEnumeration<CredentialRequestOptions::MediationRequirement>>(state, mediationValue); |
60 | RETURN_IF_EXCEPTION(throwScope, { }); |
61 | } else |
62 | result.mediation = CredentialRequestOptions::MediationRequirement::Optional; |
63 | JSValue publicKeyValue; |
64 | if (isNullOrUndefined) |
65 | publicKeyValue = jsUndefined(); |
66 | else { |
67 | publicKeyValue = object->get(&state, Identifier::fromString(&state, "publicKey" )); |
68 | RETURN_IF_EXCEPTION(throwScope, { }); |
69 | } |
70 | if (!publicKeyValue.isUndefined()) { |
71 | result.publicKey = convert<IDLDictionary<PublicKeyCredentialRequestOptions>>(state, publicKeyValue); |
72 | RETURN_IF_EXCEPTION(throwScope, { }); |
73 | } |
74 | JSValue signalValue; |
75 | if (isNullOrUndefined) |
76 | signalValue = jsUndefined(); |
77 | else { |
78 | signalValue = object->get(&state, Identifier::fromString(&state, "signal" )); |
79 | RETURN_IF_EXCEPTION(throwScope, { }); |
80 | } |
81 | if (!signalValue.isUndefined()) { |
82 | result.signal = convert<IDLInterface<AbortSignal>>(state, signalValue); |
83 | RETURN_IF_EXCEPTION(throwScope, { }); |
84 | } |
85 | return result; |
86 | } |
87 | |
88 | #endif |
89 | |
90 | #if ENABLE(WEB_AUTHN) |
91 | |
92 | String convertEnumerationToString(CredentialRequestOptions::MediationRequirement enumerationValue) |
93 | { |
94 | static const NeverDestroyed<String> values[] = { |
95 | MAKE_STATIC_STRING_IMPL("silent" ), |
96 | MAKE_STATIC_STRING_IMPL("optional" ), |
97 | MAKE_STATIC_STRING_IMPL("required" ), |
98 | }; |
99 | static_assert(static_cast<size_t>(CredentialRequestOptions::MediationRequirement::Silent) == 0, "CredentialRequestOptions::MediationRequirement::Silent is not 0 as expected" ); |
100 | static_assert(static_cast<size_t>(CredentialRequestOptions::MediationRequirement::Optional) == 1, "CredentialRequestOptions::MediationRequirement::Optional is not 1 as expected" ); |
101 | static_assert(static_cast<size_t>(CredentialRequestOptions::MediationRequirement::Required) == 2, "CredentialRequestOptions::MediationRequirement::Required is not 2 as expected" ); |
102 | ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values)); |
103 | return values[static_cast<size_t>(enumerationValue)]; |
104 | } |
105 | |
106 | template<> JSString* convertEnumerationToJS(ExecState& state, CredentialRequestOptions::MediationRequirement enumerationValue) |
107 | { |
108 | return jsStringWithCache(&state, convertEnumerationToString(enumerationValue)); |
109 | } |
110 | |
111 | template<> Optional<CredentialRequestOptions::MediationRequirement> parseEnumeration<CredentialRequestOptions::MediationRequirement>(ExecState& state, JSValue value) |
112 | { |
113 | auto stringValue = value.toWTFString(&state); |
114 | if (stringValue == "silent" ) |
115 | return CredentialRequestOptions::MediationRequirement::Silent; |
116 | if (stringValue == "optional" ) |
117 | return CredentialRequestOptions::MediationRequirement::Optional; |
118 | if (stringValue == "required" ) |
119 | return CredentialRequestOptions::MediationRequirement::Required; |
120 | return WTF::nullopt; |
121 | } |
122 | |
123 | template<> const char* expectedEnumerationValues<CredentialRequestOptions::MediationRequirement>() |
124 | { |
125 | return "\"silent\", \"optional\", \"required\"" ; |
126 | } |
127 | |
128 | #endif |
129 | |
130 | } // namespace WebCore |
131 | |
132 | #endif // ENABLE(WEB_AUTHN) |
133 | |