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