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