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 "JSGPUCanvasContext.h"
26
27#include "JSDOMAttribute.h"
28#include "JSDOMBinding.h"
29#include "JSDOMConstructorNotConstructable.h"
30#include "JSDOMConvertEnumeration.h"
31#include "JSDOMConvertInterface.h"
32#include "JSDOMConvertNumbers.h"
33#include "JSDOMExceptionHandling.h"
34#include "JSDOMGlobalObject.h"
35#include "JSDOMOperation.h"
36#include "JSDOMWrapperCache.h"
37#include "JSGPUTextureFormat.h"
38#include "JSHTMLCanvasElement.h"
39#include "JSWebGPUDevice.h"
40#include "JSWebGPUSwapChain.h"
41#include "ScriptExecutionContext.h"
42#include <JavaScriptCore/FunctionPrototype.h>
43#include <JavaScriptCore/HeapSnapshotBuilder.h>
44#include <JavaScriptCore/JSCInlines.h>
45#include <wtf/GetPtr.h>
46#include <wtf/PointerPreparations.h>
47#include <wtf/URL.h>
48
49
50namespace WebCore {
51using namespace JSC;
52
53#if ENABLE(WEBGPU)
54
55template<> WebGPUSwapChainDescriptor convertDictionary<WebGPUSwapChainDescriptor>(ExecState& state, JSValue value)
56{
57 VM& vm = state.vm();
58 auto throwScope = DECLARE_THROW_SCOPE(vm);
59 bool isNullOrUndefined = value.isUndefinedOrNull();
60 auto* object = isNullOrUndefined ? nullptr : value.getObject();
61 if (UNLIKELY(!isNullOrUndefined && !object)) {
62 throwTypeError(&state, throwScope);
63 return { };
64 }
65 WebGPUSwapChainDescriptor result;
66 JSValue deviceValue;
67 if (isNullOrUndefined)
68 deviceValue = jsUndefined();
69 else {
70 deviceValue = object->get(&state, Identifier::fromString(&state, "device"));
71 RETURN_IF_EXCEPTION(throwScope, { });
72 }
73 if (!deviceValue.isUndefined()) {
74 result.device = convert<IDLInterface<WebGPUDevice>>(state, deviceValue);
75 RETURN_IF_EXCEPTION(throwScope, { });
76 } else {
77 throwRequiredMemberTypeError(state, throwScope, "device", "WebGPUSwapChainDescriptor", "WebGPUDevice");
78 return { };
79 }
80 JSValue formatValue;
81 if (isNullOrUndefined)
82 formatValue = jsUndefined();
83 else {
84 formatValue = object->get(&state, Identifier::fromString(&state, "format"));
85 RETURN_IF_EXCEPTION(throwScope, { });
86 }
87 if (!formatValue.isUndefined()) {
88 result.format = convert<IDLEnumeration<GPUTextureFormat>>(state, formatValue);
89 RETURN_IF_EXCEPTION(throwScope, { });
90 } else {
91 throwRequiredMemberTypeError(state, throwScope, "format", "WebGPUSwapChainDescriptor", "GPUTextureFormat");
92 return { };
93 }
94 JSValue usageValue;
95 if (isNullOrUndefined)
96 usageValue = jsUndefined();
97 else {
98 usageValue = object->get(&state, Identifier::fromString(&state, "usage"));
99 RETURN_IF_EXCEPTION(throwScope, { });
100 }
101 if (!usageValue.isUndefined()) {
102 result.usage = convert<IDLUnsignedLong>(state, usageValue);
103 RETURN_IF_EXCEPTION(throwScope, { });
104 }
105 return result;
106}
107
108#endif
109
110// Functions
111
112JSC::EncodedJSValue JSC_HOST_CALL jsGPUCanvasContextPrototypeFunctionConfigureSwapChain(JSC::ExecState*);
113
114// Attributes
115
116JSC::EncodedJSValue jsGPUCanvasContextConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
117bool setJSGPUCanvasContextConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
118JSC::EncodedJSValue jsGPUCanvasContextCanvas(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
119
120class JSGPUCanvasContextPrototype : public JSC::JSNonFinalObject {
121public:
122 using Base = JSC::JSNonFinalObject;
123 static JSGPUCanvasContextPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
124 {
125 JSGPUCanvasContextPrototype* ptr = new (NotNull, JSC::allocateCell<JSGPUCanvasContextPrototype>(vm.heap)) JSGPUCanvasContextPrototype(vm, globalObject, structure);
126 ptr->finishCreation(vm);
127 return ptr;
128 }
129
130 DECLARE_INFO;
131 static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
132 {
133 return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
134 }
135
136private:
137 JSGPUCanvasContextPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
138 : JSC::JSNonFinalObject(vm, structure)
139 {
140 }
141
142 void finishCreation(JSC::VM&);
143};
144
145using JSGPUCanvasContextConstructor = JSDOMConstructorNotConstructable<JSGPUCanvasContext>;
146
147template<> JSValue JSGPUCanvasContextConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
148{
149 UNUSED_PARAM(vm);
150 return globalObject.functionPrototype();
151}
152
153template<> void JSGPUCanvasContextConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
154{
155 putDirect(vm, vm.propertyNames->prototype, JSGPUCanvasContext::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
156 putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("GPUCanvasContext"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
157 putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
158}
159
160template<> const ClassInfo JSGPUCanvasContextConstructor::s_info = { "GPUCanvasContext", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSGPUCanvasContextConstructor) };
161
162/* Hash table for prototype */
163
164static const HashTableValue JSGPUCanvasContextPrototypeTableValues[] =
165{
166 { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsGPUCanvasContextConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSGPUCanvasContextConstructor) } },
167 { "canvas", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsGPUCanvasContextCanvas), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
168 { "configureSwapChain", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsGPUCanvasContextPrototypeFunctionConfigureSwapChain), (intptr_t) (1) } },
169};
170
171const ClassInfo JSGPUCanvasContextPrototype::s_info = { "GPUCanvasContextPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSGPUCanvasContextPrototype) };
172
173void JSGPUCanvasContextPrototype::finishCreation(VM& vm)
174{
175 Base::finishCreation(vm);
176 reifyStaticProperties(vm, JSGPUCanvasContext::info(), JSGPUCanvasContextPrototypeTableValues, *this);
177}
178
179const ClassInfo JSGPUCanvasContext::s_info = { "GPUCanvasContext", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSGPUCanvasContext) };
180
181JSGPUCanvasContext::JSGPUCanvasContext(Structure* structure, JSDOMGlobalObject& globalObject, Ref<GPUCanvasContext>&& impl)
182 : JSDOMWrapper<GPUCanvasContext>(structure, globalObject, WTFMove(impl))
183{
184}
185
186void JSGPUCanvasContext::finishCreation(VM& vm)
187{
188 Base::finishCreation(vm);
189 ASSERT(inherits(vm, info()));
190
191}
192
193JSObject* JSGPUCanvasContext::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
194{
195 return JSGPUCanvasContextPrototype::create(vm, &globalObject, JSGPUCanvasContextPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype()));
196}
197
198JSObject* JSGPUCanvasContext::prototype(VM& vm, JSDOMGlobalObject& globalObject)
199{
200 return getDOMPrototype<JSGPUCanvasContext>(vm, globalObject);
201}
202
203JSValue JSGPUCanvasContext::getConstructor(VM& vm, const JSGlobalObject* globalObject)
204{
205 return getDOMConstructor<JSGPUCanvasContextConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
206}
207
208void JSGPUCanvasContext::destroy(JSC::JSCell* cell)
209{
210 JSGPUCanvasContext* thisObject = static_cast<JSGPUCanvasContext*>(cell);
211 thisObject->JSGPUCanvasContext::~JSGPUCanvasContext();
212}
213
214template<> inline JSGPUCanvasContext* IDLAttribute<JSGPUCanvasContext>::cast(ExecState& state, EncodedJSValue thisValue)
215{
216 return jsDynamicCast<JSGPUCanvasContext*>(state.vm(), JSValue::decode(thisValue));
217}
218
219template<> inline JSGPUCanvasContext* IDLOperation<JSGPUCanvasContext>::cast(ExecState& state)
220{
221 return jsDynamicCast<JSGPUCanvasContext*>(state.vm(), state.thisValue());
222}
223
224EncodedJSValue jsGPUCanvasContextConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
225{
226 VM& vm = state->vm();
227 auto throwScope = DECLARE_THROW_SCOPE(vm);
228 auto* prototype = jsDynamicCast<JSGPUCanvasContextPrototype*>(vm, JSValue::decode(thisValue));
229 if (UNLIKELY(!prototype))
230 return throwVMTypeError(state, throwScope);
231 return JSValue::encode(JSGPUCanvasContext::getConstructor(state->vm(), prototype->globalObject()));
232}
233
234bool setJSGPUCanvasContextConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
235{
236 VM& vm = state->vm();
237 auto throwScope = DECLARE_THROW_SCOPE(vm);
238 auto* prototype = jsDynamicCast<JSGPUCanvasContextPrototype*>(vm, JSValue::decode(thisValue));
239 if (UNLIKELY(!prototype)) {
240 throwVMTypeError(state, throwScope);
241 return false;
242 }
243 // Shadowing a built-in constructor
244 return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
245}
246
247static inline JSValue jsGPUCanvasContextCanvasGetter(ExecState& state, JSGPUCanvasContext& thisObject, ThrowScope& throwScope)
248{
249 UNUSED_PARAM(throwScope);
250 UNUSED_PARAM(state);
251 auto& impl = thisObject.wrapped();
252 JSValue result = toJS<IDLInterface<HTMLCanvasElement>>(state, *thisObject.globalObject(), throwScope, impl.canvas());
253 return result;
254}
255
256EncodedJSValue jsGPUCanvasContextCanvas(ExecState* state, EncodedJSValue thisValue, PropertyName)
257{
258 return IDLAttribute<JSGPUCanvasContext>::get<jsGPUCanvasContextCanvasGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "canvas");
259}
260
261static inline JSC::EncodedJSValue jsGPUCanvasContextPrototypeFunctionConfigureSwapChainBody(JSC::ExecState* state, typename IDLOperation<JSGPUCanvasContext>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
262{
263 UNUSED_PARAM(state);
264 UNUSED_PARAM(throwScope);
265 auto& impl = castedThis->wrapped();
266 if (UNLIKELY(state->argumentCount() < 1))
267 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
268 auto descriptor = convert<IDLDictionary<WebGPUSwapChainDescriptor>>(*state, state->uncheckedArgument(0));
269 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
270 return JSValue::encode(toJS<IDLInterface<WebGPUSwapChain>>(*state, *castedThis->globalObject(), impl.configureSwapChain(WTFMove(descriptor))));
271}
272
273EncodedJSValue JSC_HOST_CALL jsGPUCanvasContextPrototypeFunctionConfigureSwapChain(ExecState* state)
274{
275 return IDLOperation<JSGPUCanvasContext>::call<jsGPUCanvasContextPrototypeFunctionConfigureSwapChainBody>(*state, "configureSwapChain");
276}
277
278void JSGPUCanvasContext::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
279{
280 auto* thisObject = jsCast<JSGPUCanvasContext*>(cell);
281 builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
282 if (thisObject->scriptExecutionContext())
283 builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
284 Base::heapSnapshot(cell, builder);
285}
286
287bool JSGPUCanvasContextOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
288{
289 UNUSED_PARAM(handle);
290 UNUSED_PARAM(visitor);
291 UNUSED_PARAM(reason);
292 return false;
293}
294
295void JSGPUCanvasContextOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
296{
297 auto* jsGPUCanvasContext = static_cast<JSGPUCanvasContext*>(handle.slot()->asCell());
298 auto& world = *static_cast<DOMWrapperWorld*>(context);
299 uncacheWrapper(world, &jsGPUCanvasContext->wrapped(), jsGPUCanvasContext);
300}
301
302#if ENABLE(BINDING_INTEGRITY)
303#if PLATFORM(WIN)
304#pragma warning(disable: 4483)
305extern "C" { extern void (*const __identifier("??_7GPUCanvasContext@WebCore@@6B@")[])(); }
306#else
307extern "C" { extern void* _ZTVN7WebCore16GPUCanvasContextE[]; }
308#endif
309#endif
310
311JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<GPUCanvasContext>&& impl)
312{
313
314#if ENABLE(BINDING_INTEGRITY)
315 void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
316#if PLATFORM(WIN)
317 void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7GPUCanvasContext@WebCore@@6B@"));
318#else
319 void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore16GPUCanvasContextE[2]);
320#endif
321
322 // If this fails GPUCanvasContext does not have a vtable, so you need to add the
323 // ImplementationLacksVTable attribute to the interface definition
324 static_assert(std::is_polymorphic<GPUCanvasContext>::value, "GPUCanvasContext is not polymorphic");
325
326 // If you hit this assertion you either have a use after free bug, or
327 // GPUCanvasContext has subclasses. If GPUCanvasContext has subclasses that get passed
328 // to toJS() we currently require GPUCanvasContext you to opt out of binding hardening
329 // by adding the SkipVTableValidation attribute to the interface IDL definition
330 RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
331#endif
332 return createWrapper<GPUCanvasContext>(globalObject, WTFMove(impl));
333}
334
335JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, GPUCanvasContext& impl)
336{
337 return wrap(state, globalObject, impl);
338}
339
340GPUCanvasContext* JSGPUCanvasContext::toWrapped(JSC::VM& vm, JSC::JSValue value)
341{
342 if (auto* wrapper = jsDynamicCast<JSGPUCanvasContext*>(vm, value))
343 return &wrapper->wrapped();
344 return nullptr;
345}
346
347}
348
349#endif // ENABLE(WEBGPU)
350