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(WEBGPU)
24
25#include "JSWebGPUAdapter.h"
26
27#include "JSDOMBinding.h"
28#include "JSDOMConstructorNotConstructable.h"
29#include "JSDOMExceptionHandling.h"
30#include "JSDOMOperation.h"
31#include "JSDOMOperationReturningPromise.h"
32#include "JSDOMWrapperCache.h"
33#include "ScriptExecutionContext.h"
34#include <JavaScriptCore/FunctionPrototype.h>
35#include <JavaScriptCore/HeapSnapshotBuilder.h>
36#include <JavaScriptCore/JSCInlines.h>
37#include <wtf/GetPtr.h>
38#include <wtf/PointerPreparations.h>
39#include <wtf/URL.h>
40
41
42namespace WebCore {
43using namespace JSC;
44
45// Functions
46
47JSC::EncodedJSValue JSC_HOST_CALL jsWebGPUAdapterPrototypeFunctionRequestDevice(JSC::ExecState*);
48
49// Attributes
50
51JSC::EncodedJSValue jsWebGPUAdapterConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
52bool setJSWebGPUAdapterConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
53
54class JSWebGPUAdapterPrototype : public JSC::JSNonFinalObject {
55public:
56 using Base = JSC::JSNonFinalObject;
57 static JSWebGPUAdapterPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
58 {
59 JSWebGPUAdapterPrototype* ptr = new (NotNull, JSC::allocateCell<JSWebGPUAdapterPrototype>(vm.heap)) JSWebGPUAdapterPrototype(vm, globalObject, structure);
60 ptr->finishCreation(vm);
61 return ptr;
62 }
63
64 DECLARE_INFO;
65 static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
66 {
67 return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
68 }
69
70private:
71 JSWebGPUAdapterPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
72 : JSC::JSNonFinalObject(vm, structure)
73 {
74 }
75
76 void finishCreation(JSC::VM&);
77};
78
79using JSWebGPUAdapterConstructor = JSDOMConstructorNotConstructable<JSWebGPUAdapter>;
80
81template<> JSValue JSWebGPUAdapterConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
82{
83 UNUSED_PARAM(vm);
84 return globalObject.functionPrototype();
85}
86
87template<> void JSWebGPUAdapterConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
88{
89 putDirect(vm, vm.propertyNames->prototype, JSWebGPUAdapter::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
90 putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("GPUAdapter"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
91 putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
92}
93
94template<> const ClassInfo JSWebGPUAdapterConstructor::s_info = { "GPUAdapter", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSWebGPUAdapterConstructor) };
95
96/* Hash table for prototype */
97
98static const HashTableValue JSWebGPUAdapterPrototypeTableValues[] =
99{
100 { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsWebGPUAdapterConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSWebGPUAdapterConstructor) } },
101 { "requestDevice", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsWebGPUAdapterPrototypeFunctionRequestDevice), (intptr_t) (0) } },
102};
103
104const ClassInfo JSWebGPUAdapterPrototype::s_info = { "GPUAdapterPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSWebGPUAdapterPrototype) };
105
106void JSWebGPUAdapterPrototype::finishCreation(VM& vm)
107{
108 Base::finishCreation(vm);
109 reifyStaticProperties(vm, JSWebGPUAdapter::info(), JSWebGPUAdapterPrototypeTableValues, *this);
110}
111
112const ClassInfo JSWebGPUAdapter::s_info = { "GPUAdapter", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSWebGPUAdapter) };
113
114JSWebGPUAdapter::JSWebGPUAdapter(Structure* structure, JSDOMGlobalObject& globalObject, Ref<WebGPUAdapter>&& impl)
115 : JSDOMWrapper<WebGPUAdapter>(structure, globalObject, WTFMove(impl))
116{
117}
118
119void JSWebGPUAdapter::finishCreation(VM& vm)
120{
121 Base::finishCreation(vm);
122 ASSERT(inherits(vm, info()));
123
124}
125
126JSObject* JSWebGPUAdapter::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
127{
128 return JSWebGPUAdapterPrototype::create(vm, &globalObject, JSWebGPUAdapterPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype()));
129}
130
131JSObject* JSWebGPUAdapter::prototype(VM& vm, JSDOMGlobalObject& globalObject)
132{
133 return getDOMPrototype<JSWebGPUAdapter>(vm, globalObject);
134}
135
136JSValue JSWebGPUAdapter::getConstructor(VM& vm, const JSGlobalObject* globalObject)
137{
138 return getDOMConstructor<JSWebGPUAdapterConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
139}
140
141void JSWebGPUAdapter::destroy(JSC::JSCell* cell)
142{
143 JSWebGPUAdapter* thisObject = static_cast<JSWebGPUAdapter*>(cell);
144 thisObject->JSWebGPUAdapter::~JSWebGPUAdapter();
145}
146
147template<> inline JSWebGPUAdapter* IDLOperation<JSWebGPUAdapter>::cast(ExecState& state)
148{
149 return jsDynamicCast<JSWebGPUAdapter*>(state.vm(), state.thisValue());
150}
151
152EncodedJSValue jsWebGPUAdapterConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
153{
154 VM& vm = state->vm();
155 auto throwScope = DECLARE_THROW_SCOPE(vm);
156 auto* prototype = jsDynamicCast<JSWebGPUAdapterPrototype*>(vm, JSValue::decode(thisValue));
157 if (UNLIKELY(!prototype))
158 return throwVMTypeError(state, throwScope);
159 return JSValue::encode(JSWebGPUAdapter::getConstructor(state->vm(), prototype->globalObject()));
160}
161
162bool setJSWebGPUAdapterConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
163{
164 VM& vm = state->vm();
165 auto throwScope = DECLARE_THROW_SCOPE(vm);
166 auto* prototype = jsDynamicCast<JSWebGPUAdapterPrototype*>(vm, JSValue::decode(thisValue));
167 if (UNLIKELY(!prototype)) {
168 throwVMTypeError(state, throwScope);
169 return false;
170 }
171 // Shadowing a built-in constructor
172 return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
173}
174
175static inline JSC::EncodedJSValue jsWebGPUAdapterPrototypeFunctionRequestDeviceBody(JSC::ExecState* state, typename IDLOperationReturningPromise<JSWebGPUAdapter>::ClassParameter castedThis, Ref<DeferredPromise>&& promise, JSC::ThrowScope& throwScope)
176{
177 UNUSED_PARAM(state);
178 UNUSED_PARAM(throwScope);
179 auto& impl = castedThis->wrapped();
180 impl.requestDevice(WTFMove(promise));
181 return JSValue::encode(jsUndefined());
182}
183
184EncodedJSValue JSC_HOST_CALL jsWebGPUAdapterPrototypeFunctionRequestDevice(ExecState* state)
185{
186 return IDLOperationReturningPromise<JSWebGPUAdapter>::call<jsWebGPUAdapterPrototypeFunctionRequestDeviceBody, PromiseExecutionScope::WindowOnly>(*state, "requestDevice");
187}
188
189void JSWebGPUAdapter::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
190{
191 auto* thisObject = jsCast<JSWebGPUAdapter*>(cell);
192 builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
193 if (thisObject->scriptExecutionContext())
194 builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
195 Base::heapSnapshot(cell, builder);
196}
197
198bool JSWebGPUAdapterOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
199{
200 UNUSED_PARAM(handle);
201 UNUSED_PARAM(visitor);
202 UNUSED_PARAM(reason);
203 return false;
204}
205
206void JSWebGPUAdapterOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
207{
208 auto* jsWebGPUAdapter = static_cast<JSWebGPUAdapter*>(handle.slot()->asCell());
209 auto& world = *static_cast<DOMWrapperWorld*>(context);
210 uncacheWrapper(world, &jsWebGPUAdapter->wrapped(), jsWebGPUAdapter);
211}
212
213JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<WebGPUAdapter>&& impl)
214{
215 // If you hit this failure the interface definition has the ImplementationLacksVTable
216 // attribute. You should remove that attribute. If the class has subclasses
217 // that may be passed through this toJS() function you should use the SkipVTableValidation
218 // attribute to WebGPUAdapter.
219 static_assert(!std::is_polymorphic<WebGPUAdapter>::value, "WebGPUAdapter is polymorphic but the IDL claims it is not");
220 return createWrapper<WebGPUAdapter>(globalObject, WTFMove(impl));
221}
222
223JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, WebGPUAdapter& impl)
224{
225 return wrap(state, globalObject, impl);
226}
227
228WebGPUAdapter* JSWebGPUAdapter::toWrapped(JSC::VM& vm, JSC::JSValue value)
229{
230 if (auto* wrapper = jsDynamicCast<JSWebGPUAdapter*>(vm, value))
231 return &wrapper->wrapped();
232 return nullptr;
233}
234
235}
236
237#endif // ENABLE(WEBGPU)
238