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 "JSPublicKeyCredential.h"
26
27#include "Document.h"
28#include "JSAuthenticatorResponse.h"
29#include "JSDOMAttribute.h"
30#include "JSDOMBinding.h"
31#include "JSDOMConstructorNotConstructable.h"
32#include "JSDOMConvertBoolean.h"
33#include "JSDOMConvertBufferSource.h"
34#include "JSDOMConvertInterface.h"
35#include "JSDOMExceptionHandling.h"
36#include "JSDOMGlobalObject.h"
37#include "JSDOMOperation.h"
38#include "JSDOMOperationReturningPromise.h"
39#include "JSDOMWrapperCache.h"
40#include "ScriptExecutionContext.h"
41#include <JavaScriptCore/HeapSnapshotBuilder.h>
42#include <JavaScriptCore/JSCInlines.h>
43#include <JavaScriptCore/ObjectConstructor.h>
44#include <wtf/GetPtr.h>
45#include <wtf/PointerPreparations.h>
46#include <wtf/URL.h>
47
48
49namespace WebCore {
50using namespace JSC;
51
52#if ENABLE(WEB_AUTHN)
53
54template<> PublicKeyCredential::AuthenticationExtensionsClientOutputs convertDictionary<PublicKeyCredential::AuthenticationExtensionsClientOutputs>(ExecState& state, JSValue value)
55{
56 VM& vm = state.vm();
57 auto throwScope = DECLARE_THROW_SCOPE(vm);
58 bool isNullOrUndefined = value.isUndefinedOrNull();
59 auto* object = isNullOrUndefined ? nullptr : value.getObject();
60 if (UNLIKELY(!isNullOrUndefined && !object)) {
61 throwTypeError(&state, throwScope);
62 return { };
63 }
64 PublicKeyCredential::AuthenticationExtensionsClientOutputs result;
65 JSValue appidValue;
66 if (isNullOrUndefined)
67 appidValue = jsUndefined();
68 else {
69 appidValue = object->get(&state, Identifier::fromString(&state, "appid"));
70 RETURN_IF_EXCEPTION(throwScope, { });
71 }
72 if (!appidValue.isUndefined()) {
73 result.appid = convert<IDLBoolean>(state, appidValue);
74 RETURN_IF_EXCEPTION(throwScope, { });
75 }
76 return result;
77}
78
79JSC::JSObject* convertDictionaryToJS(JSC::ExecState& state, JSDOMGlobalObject& globalObject, const PublicKeyCredential::AuthenticationExtensionsClientOutputs& dictionary)
80{
81 auto& vm = state.vm();
82
83 auto result = constructEmptyObject(&state, globalObject.objectPrototype());
84
85 if (!IDLBoolean::isNullValue(dictionary.appid)) {
86 auto appidValue = toJS<IDLBoolean>(IDLBoolean::extractValueFromNullable(dictionary.appid));
87 result->putDirect(vm, JSC::Identifier::fromString(&vm, "appid"), appidValue);
88 }
89 return result;
90}
91
92#endif
93
94// Functions
95
96JSC::EncodedJSValue JSC_HOST_CALL jsPublicKeyCredentialPrototypeFunctionGetClientExtensionResults(JSC::ExecState*);
97JSC::EncodedJSValue JSC_HOST_CALL jsPublicKeyCredentialConstructorFunctionIsUserVerifyingPlatformAuthenticatorAvailable(JSC::ExecState*);
98
99// Attributes
100
101JSC::EncodedJSValue jsPublicKeyCredentialConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
102bool setJSPublicKeyCredentialConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
103JSC::EncodedJSValue jsPublicKeyCredentialRawId(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
104JSC::EncodedJSValue jsPublicKeyCredentialResponse(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
105
106class JSPublicKeyCredentialPrototype : public JSC::JSNonFinalObject {
107public:
108 using Base = JSC::JSNonFinalObject;
109 static JSPublicKeyCredentialPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
110 {
111 JSPublicKeyCredentialPrototype* ptr = new (NotNull, JSC::allocateCell<JSPublicKeyCredentialPrototype>(vm.heap)) JSPublicKeyCredentialPrototype(vm, globalObject, structure);
112 ptr->finishCreation(vm);
113 return ptr;
114 }
115
116 DECLARE_INFO;
117 static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
118 {
119 return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
120 }
121
122private:
123 JSPublicKeyCredentialPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
124 : JSC::JSNonFinalObject(vm, structure)
125 {
126 }
127
128 void finishCreation(JSC::VM&);
129};
130
131using JSPublicKeyCredentialConstructor = JSDOMConstructorNotConstructable<JSPublicKeyCredential>;
132
133/* Hash table for constructor */
134
135static const HashTableValue JSPublicKeyCredentialConstructorTableValues[] =
136{
137 { "isUserVerifyingPlatformAuthenticatorAvailable", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsPublicKeyCredentialConstructorFunctionIsUserVerifyingPlatformAuthenticatorAvailable), (intptr_t) (0) } },
138};
139
140template<> JSValue JSPublicKeyCredentialConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
141{
142 return JSBasicCredential::getConstructor(vm, &globalObject);
143}
144
145template<> void JSPublicKeyCredentialConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
146{
147 putDirect(vm, vm.propertyNames->prototype, JSPublicKeyCredential::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
148 putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("PublicKeyCredential"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
149 putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
150 reifyStaticProperties(vm, JSPublicKeyCredential::info(), JSPublicKeyCredentialConstructorTableValues, *this);
151}
152
153template<> const ClassInfo JSPublicKeyCredentialConstructor::s_info = { "PublicKeyCredential", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSPublicKeyCredentialConstructor) };
154
155/* Hash table for prototype */
156
157static const HashTableValue JSPublicKeyCredentialPrototypeTableValues[] =
158{
159 { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsPublicKeyCredentialConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSPublicKeyCredentialConstructor) } },
160 { "rawId", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsPublicKeyCredentialRawId), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
161 { "response", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsPublicKeyCredentialResponse), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
162 { "getClientExtensionResults", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsPublicKeyCredentialPrototypeFunctionGetClientExtensionResults), (intptr_t) (0) } },
163};
164
165const ClassInfo JSPublicKeyCredentialPrototype::s_info = { "PublicKeyCredentialPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSPublicKeyCredentialPrototype) };
166
167void JSPublicKeyCredentialPrototype::finishCreation(VM& vm)
168{
169 Base::finishCreation(vm);
170 reifyStaticProperties(vm, JSPublicKeyCredential::info(), JSPublicKeyCredentialPrototypeTableValues, *this);
171}
172
173const ClassInfo JSPublicKeyCredential::s_info = { "PublicKeyCredential", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSPublicKeyCredential) };
174
175JSPublicKeyCredential::JSPublicKeyCredential(Structure* structure, JSDOMGlobalObject& globalObject, Ref<PublicKeyCredential>&& impl)
176 : JSBasicCredential(structure, globalObject, WTFMove(impl))
177{
178}
179
180void JSPublicKeyCredential::finishCreation(VM& vm)
181{
182 Base::finishCreation(vm);
183 ASSERT(inherits(vm, info()));
184
185}
186
187JSObject* JSPublicKeyCredential::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
188{
189 return JSPublicKeyCredentialPrototype::create(vm, &globalObject, JSPublicKeyCredentialPrototype::createStructure(vm, &globalObject, JSBasicCredential::prototype(vm, globalObject)));
190}
191
192JSObject* JSPublicKeyCredential::prototype(VM& vm, JSDOMGlobalObject& globalObject)
193{
194 return getDOMPrototype<JSPublicKeyCredential>(vm, globalObject);
195}
196
197JSValue JSPublicKeyCredential::getConstructor(VM& vm, const JSGlobalObject* globalObject)
198{
199 return getDOMConstructor<JSPublicKeyCredentialConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
200}
201
202template<> inline JSPublicKeyCredential* IDLAttribute<JSPublicKeyCredential>::cast(ExecState& state, EncodedJSValue thisValue)
203{
204 return jsDynamicCast<JSPublicKeyCredential*>(state.vm(), JSValue::decode(thisValue));
205}
206
207template<> inline JSPublicKeyCredential* IDLOperation<JSPublicKeyCredential>::cast(ExecState& state)
208{
209 return jsDynamicCast<JSPublicKeyCredential*>(state.vm(), state.thisValue());
210}
211
212EncodedJSValue jsPublicKeyCredentialConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
213{
214 VM& vm = state->vm();
215 auto throwScope = DECLARE_THROW_SCOPE(vm);
216 auto* prototype = jsDynamicCast<JSPublicKeyCredentialPrototype*>(vm, JSValue::decode(thisValue));
217 if (UNLIKELY(!prototype))
218 return throwVMTypeError(state, throwScope);
219 return JSValue::encode(JSPublicKeyCredential::getConstructor(state->vm(), prototype->globalObject()));
220}
221
222bool setJSPublicKeyCredentialConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
223{
224 VM& vm = state->vm();
225 auto throwScope = DECLARE_THROW_SCOPE(vm);
226 auto* prototype = jsDynamicCast<JSPublicKeyCredentialPrototype*>(vm, JSValue::decode(thisValue));
227 if (UNLIKELY(!prototype)) {
228 throwVMTypeError(state, throwScope);
229 return false;
230 }
231 // Shadowing a built-in constructor
232 return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
233}
234
235static inline JSValue jsPublicKeyCredentialRawIdGetter(ExecState& state, JSPublicKeyCredential& thisObject, ThrowScope& throwScope)
236{
237 UNUSED_PARAM(throwScope);
238 UNUSED_PARAM(state);
239 auto& impl = thisObject.wrapped();
240 JSValue result = toJS<IDLArrayBuffer>(state, *thisObject.globalObject(), throwScope, impl.rawId());
241 return result;
242}
243
244EncodedJSValue jsPublicKeyCredentialRawId(ExecState* state, EncodedJSValue thisValue, PropertyName)
245{
246 return IDLAttribute<JSPublicKeyCredential>::get<jsPublicKeyCredentialRawIdGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "rawId");
247}
248
249static inline JSValue jsPublicKeyCredentialResponseGetter(ExecState& state, JSPublicKeyCredential& thisObject, ThrowScope& throwScope)
250{
251 UNUSED_PARAM(throwScope);
252 UNUSED_PARAM(state);
253 auto& impl = thisObject.wrapped();
254 JSValue result = toJS<IDLInterface<AuthenticatorResponse>>(state, *thisObject.globalObject(), throwScope, impl.response());
255 return result;
256}
257
258EncodedJSValue jsPublicKeyCredentialResponse(ExecState* state, EncodedJSValue thisValue, PropertyName)
259{
260 return IDLAttribute<JSPublicKeyCredential>::get<jsPublicKeyCredentialResponseGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "response");
261}
262
263static inline JSC::EncodedJSValue jsPublicKeyCredentialPrototypeFunctionGetClientExtensionResultsBody(JSC::ExecState* state, typename IDLOperation<JSPublicKeyCredential>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
264{
265 UNUSED_PARAM(state);
266 UNUSED_PARAM(throwScope);
267 auto& impl = castedThis->wrapped();
268 return JSValue::encode(toJS<IDLDictionary<PublicKeyCredential::AuthenticationExtensionsClientOutputs>>(*state, *castedThis->globalObject(), impl.getClientExtensionResults()));
269}
270
271EncodedJSValue JSC_HOST_CALL jsPublicKeyCredentialPrototypeFunctionGetClientExtensionResults(ExecState* state)
272{
273 return IDLOperation<JSPublicKeyCredential>::call<jsPublicKeyCredentialPrototypeFunctionGetClientExtensionResultsBody>(*state, "getClientExtensionResults");
274}
275
276static inline JSC::EncodedJSValue jsPublicKeyCredentialConstructorFunctionIsUserVerifyingPlatformAuthenticatorAvailableBody(JSC::ExecState* state, Ref<DeferredPromise>&& promise, JSC::ThrowScope& throwScope)
277{
278 UNUSED_PARAM(state);
279 UNUSED_PARAM(throwScope);
280 auto* context = jsCast<JSDOMGlobalObject*>(state->lexicalGlobalObject())->scriptExecutionContext();
281 if (UNLIKELY(!context))
282 return JSValue::encode(jsUndefined());
283 ASSERT(context->isDocument());
284 auto& document = downcast<Document>(*context);
285 PublicKeyCredential::isUserVerifyingPlatformAuthenticatorAvailable(document, WTFMove(promise));
286 return JSValue::encode(jsUndefined());
287}
288
289EncodedJSValue JSC_HOST_CALL jsPublicKeyCredentialConstructorFunctionIsUserVerifyingPlatformAuthenticatorAvailable(ExecState* state)
290{
291 return IDLOperationReturningPromise<JSPublicKeyCredential>::callStatic<jsPublicKeyCredentialConstructorFunctionIsUserVerifyingPlatformAuthenticatorAvailableBody, PromiseExecutionScope::WindowOrWorker>(*state, "isUserVerifyingPlatformAuthenticatorAvailable");
292}
293
294void JSPublicKeyCredential::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
295{
296 auto* thisObject = jsCast<JSPublicKeyCredential*>(cell);
297 builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
298 if (thisObject->scriptExecutionContext())
299 builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
300 Base::heapSnapshot(cell, builder);
301}
302
303
304}
305
306#endif // ENABLE(WEB_AUTHN)
307