| 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 "JSWebGPUBuffer.h" |
| 26 | |
| 27 | #include "JSDOMBinding.h" |
| 28 | #include "JSDOMConstructorNotConstructable.h" |
| 29 | #include "JSDOMConvertBufferSource.h" |
| 30 | #include "JSDOMConvertNumbers.h" |
| 31 | #include "JSDOMExceptionHandling.h" |
| 32 | #include "JSDOMOperation.h" |
| 33 | #include "JSDOMOperationReturningPromise.h" |
| 34 | #include "JSDOMWrapperCache.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 jsWebGPUBufferPrototypeFunctionSetSubData(JSC::ExecState*); |
| 50 | JSC::EncodedJSValue JSC_HOST_CALL jsWebGPUBufferPrototypeFunctionMapReadAsync(JSC::ExecState*); |
| 51 | JSC::EncodedJSValue JSC_HOST_CALL jsWebGPUBufferPrototypeFunctionMapWriteAsync(JSC::ExecState*); |
| 52 | JSC::EncodedJSValue JSC_HOST_CALL jsWebGPUBufferPrototypeFunctionUnmap(JSC::ExecState*); |
| 53 | JSC::EncodedJSValue JSC_HOST_CALL jsWebGPUBufferPrototypeFunctionDestroy(JSC::ExecState*); |
| 54 | |
| 55 | // Attributes |
| 56 | |
| 57 | JSC::EncodedJSValue jsWebGPUBufferConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 58 | bool setJSWebGPUBufferConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| 59 | |
| 60 | class JSWebGPUBufferPrototype : public JSC::JSNonFinalObject { |
| 61 | public: |
| 62 | using Base = JSC::JSNonFinalObject; |
| 63 | static JSWebGPUBufferPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) |
| 64 | { |
| 65 | JSWebGPUBufferPrototype* ptr = new (NotNull, JSC::allocateCell<JSWebGPUBufferPrototype>(vm.heap)) JSWebGPUBufferPrototype(vm, globalObject, structure); |
| 66 | ptr->finishCreation(vm); |
| 67 | return ptr; |
| 68 | } |
| 69 | |
| 70 | DECLARE_INFO; |
| 71 | static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
| 72 | { |
| 73 | return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
| 74 | } |
| 75 | |
| 76 | private: |
| 77 | JSWebGPUBufferPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
| 78 | : JSC::JSNonFinalObject(vm, structure) |
| 79 | { |
| 80 | } |
| 81 | |
| 82 | void finishCreation(JSC::VM&); |
| 83 | }; |
| 84 | |
| 85 | using JSWebGPUBufferConstructor = JSDOMConstructorNotConstructable<JSWebGPUBuffer>; |
| 86 | |
| 87 | template<> JSValue JSWebGPUBufferConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
| 88 | { |
| 89 | UNUSED_PARAM(vm); |
| 90 | return globalObject.functionPrototype(); |
| 91 | } |
| 92 | |
| 93 | template<> void JSWebGPUBufferConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
| 94 | { |
| 95 | putDirect(vm, vm.propertyNames->prototype, JSWebGPUBuffer::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 96 | putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("GPUBuffer"_s )), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 97 | putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 98 | } |
| 99 | |
| 100 | template<> const ClassInfo JSWebGPUBufferConstructor::s_info = { "GPUBuffer" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSWebGPUBufferConstructor) }; |
| 101 | |
| 102 | /* Hash table for prototype */ |
| 103 | |
| 104 | static const HashTableValue JSWebGPUBufferPrototypeTableValues[] = |
| 105 | { |
| 106 | { "constructor" , static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsWebGPUBufferConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSWebGPUBufferConstructor) } }, |
| 107 | { "setSubData" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsWebGPUBufferPrototypeFunctionSetSubData), (intptr_t) (2) } }, |
| 108 | { "mapReadAsync" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsWebGPUBufferPrototypeFunctionMapReadAsync), (intptr_t) (0) } }, |
| 109 | { "mapWriteAsync" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsWebGPUBufferPrototypeFunctionMapWriteAsync), (intptr_t) (0) } }, |
| 110 | { "unmap" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsWebGPUBufferPrototypeFunctionUnmap), (intptr_t) (0) } }, |
| 111 | { "destroy" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsWebGPUBufferPrototypeFunctionDestroy), (intptr_t) (0) } }, |
| 112 | }; |
| 113 | |
| 114 | const ClassInfo JSWebGPUBufferPrototype::s_info = { "GPUBufferPrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSWebGPUBufferPrototype) }; |
| 115 | |
| 116 | void JSWebGPUBufferPrototype::finishCreation(VM& vm) |
| 117 | { |
| 118 | Base::finishCreation(vm); |
| 119 | reifyStaticProperties(vm, JSWebGPUBuffer::info(), JSWebGPUBufferPrototypeTableValues, *this); |
| 120 | } |
| 121 | |
| 122 | const ClassInfo JSWebGPUBuffer::s_info = { "GPUBuffer" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSWebGPUBuffer) }; |
| 123 | |
| 124 | JSWebGPUBuffer::JSWebGPUBuffer(Structure* structure, JSDOMGlobalObject& globalObject, Ref<WebGPUBuffer>&& impl) |
| 125 | : JSDOMWrapper<WebGPUBuffer>(structure, globalObject, WTFMove(impl)) |
| 126 | { |
| 127 | } |
| 128 | |
| 129 | void JSWebGPUBuffer::finishCreation(VM& vm) |
| 130 | { |
| 131 | Base::finishCreation(vm); |
| 132 | ASSERT(inherits(vm, info())); |
| 133 | |
| 134 | } |
| 135 | |
| 136 | JSObject* JSWebGPUBuffer::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
| 137 | { |
| 138 | return JSWebGPUBufferPrototype::create(vm, &globalObject, JSWebGPUBufferPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype())); |
| 139 | } |
| 140 | |
| 141 | JSObject* JSWebGPUBuffer::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
| 142 | { |
| 143 | return getDOMPrototype<JSWebGPUBuffer>(vm, globalObject); |
| 144 | } |
| 145 | |
| 146 | JSValue JSWebGPUBuffer::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
| 147 | { |
| 148 | return getDOMConstructor<JSWebGPUBufferConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
| 149 | } |
| 150 | |
| 151 | void JSWebGPUBuffer::destroy(JSC::JSCell* cell) |
| 152 | { |
| 153 | JSWebGPUBuffer* thisObject = static_cast<JSWebGPUBuffer*>(cell); |
| 154 | thisObject->JSWebGPUBuffer::~JSWebGPUBuffer(); |
| 155 | } |
| 156 | |
| 157 | template<> inline JSWebGPUBuffer* IDLOperation<JSWebGPUBuffer>::cast(ExecState& state) |
| 158 | { |
| 159 | return jsDynamicCast<JSWebGPUBuffer*>(state.vm(), state.thisValue()); |
| 160 | } |
| 161 | |
| 162 | EncodedJSValue jsWebGPUBufferConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 163 | { |
| 164 | VM& vm = state->vm(); |
| 165 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 166 | auto* prototype = jsDynamicCast<JSWebGPUBufferPrototype*>(vm, JSValue::decode(thisValue)); |
| 167 | if (UNLIKELY(!prototype)) |
| 168 | return throwVMTypeError(state, throwScope); |
| 169 | return JSValue::encode(JSWebGPUBuffer::getConstructor(state->vm(), prototype->globalObject())); |
| 170 | } |
| 171 | |
| 172 | bool setJSWebGPUBufferConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| 173 | { |
| 174 | VM& vm = state->vm(); |
| 175 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 176 | auto* prototype = jsDynamicCast<JSWebGPUBufferPrototype*>(vm, JSValue::decode(thisValue)); |
| 177 | if (UNLIKELY(!prototype)) { |
| 178 | throwVMTypeError(state, throwScope); |
| 179 | return false; |
| 180 | } |
| 181 | // Shadowing a built-in constructor |
| 182 | return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue)); |
| 183 | } |
| 184 | |
| 185 | static inline JSC::EncodedJSValue jsWebGPUBufferPrototypeFunctionSetSubDataBody(JSC::ExecState* state, typename IDLOperation<JSWebGPUBuffer>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 186 | { |
| 187 | UNUSED_PARAM(state); |
| 188 | UNUSED_PARAM(throwScope); |
| 189 | auto& impl = castedThis->wrapped(); |
| 190 | if (UNLIKELY(state->argumentCount() < 2)) |
| 191 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| 192 | auto offset = convert<IDLUnsignedLongLong>(*state, state->uncheckedArgument(0)); |
| 193 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 194 | auto data = convert<IDLArrayBuffer>(*state, state->uncheckedArgument(1), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentTypeError(state, scope, 1, "data" , "GPUBuffer" , "setSubData" , "ArrayBuffer" ); }); |
| 195 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 196 | impl.setSubData(WTFMove(offset), *data); |
| 197 | return JSValue::encode(jsUndefined()); |
| 198 | } |
| 199 | |
| 200 | EncodedJSValue JSC_HOST_CALL jsWebGPUBufferPrototypeFunctionSetSubData(ExecState* state) |
| 201 | { |
| 202 | return IDLOperation<JSWebGPUBuffer>::call<jsWebGPUBufferPrototypeFunctionSetSubDataBody>(*state, "setSubData" ); |
| 203 | } |
| 204 | |
| 205 | static inline JSC::EncodedJSValue jsWebGPUBufferPrototypeFunctionMapReadAsyncBody(JSC::ExecState* state, typename IDLOperationReturningPromise<JSWebGPUBuffer>::ClassParameter castedThis, Ref<DeferredPromise>&& promise, JSC::ThrowScope& throwScope) |
| 206 | { |
| 207 | UNUSED_PARAM(state); |
| 208 | UNUSED_PARAM(throwScope); |
| 209 | auto& impl = castedThis->wrapped(); |
| 210 | impl.mapReadAsync(WTFMove(promise)); |
| 211 | return JSValue::encode(jsUndefined()); |
| 212 | } |
| 213 | |
| 214 | EncodedJSValue JSC_HOST_CALL jsWebGPUBufferPrototypeFunctionMapReadAsync(ExecState* state) |
| 215 | { |
| 216 | return IDLOperationReturningPromise<JSWebGPUBuffer>::call<jsWebGPUBufferPrototypeFunctionMapReadAsyncBody, PromiseExecutionScope::WindowOnly>(*state, "mapReadAsync" ); |
| 217 | } |
| 218 | |
| 219 | static inline JSC::EncodedJSValue jsWebGPUBufferPrototypeFunctionMapWriteAsyncBody(JSC::ExecState* state, typename IDLOperationReturningPromise<JSWebGPUBuffer>::ClassParameter castedThis, Ref<DeferredPromise>&& promise, JSC::ThrowScope& throwScope) |
| 220 | { |
| 221 | UNUSED_PARAM(state); |
| 222 | UNUSED_PARAM(throwScope); |
| 223 | auto& impl = castedThis->wrapped(); |
| 224 | impl.mapWriteAsync(WTFMove(promise)); |
| 225 | return JSValue::encode(jsUndefined()); |
| 226 | } |
| 227 | |
| 228 | EncodedJSValue JSC_HOST_CALL jsWebGPUBufferPrototypeFunctionMapWriteAsync(ExecState* state) |
| 229 | { |
| 230 | return IDLOperationReturningPromise<JSWebGPUBuffer>::call<jsWebGPUBufferPrototypeFunctionMapWriteAsyncBody, PromiseExecutionScope::WindowOnly>(*state, "mapWriteAsync" ); |
| 231 | } |
| 232 | |
| 233 | static inline JSC::EncodedJSValue jsWebGPUBufferPrototypeFunctionUnmapBody(JSC::ExecState* state, typename IDLOperation<JSWebGPUBuffer>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 234 | { |
| 235 | UNUSED_PARAM(state); |
| 236 | UNUSED_PARAM(throwScope); |
| 237 | auto& impl = castedThis->wrapped(); |
| 238 | impl.unmap(); |
| 239 | return JSValue::encode(jsUndefined()); |
| 240 | } |
| 241 | |
| 242 | EncodedJSValue JSC_HOST_CALL jsWebGPUBufferPrototypeFunctionUnmap(ExecState* state) |
| 243 | { |
| 244 | return IDLOperation<JSWebGPUBuffer>::call<jsWebGPUBufferPrototypeFunctionUnmapBody>(*state, "unmap" ); |
| 245 | } |
| 246 | |
| 247 | static inline JSC::EncodedJSValue jsWebGPUBufferPrototypeFunctionDestroyBody(JSC::ExecState* state, typename IDLOperation<JSWebGPUBuffer>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 248 | { |
| 249 | UNUSED_PARAM(state); |
| 250 | UNUSED_PARAM(throwScope); |
| 251 | auto& impl = castedThis->wrapped(); |
| 252 | impl.destroy(); |
| 253 | return JSValue::encode(jsUndefined()); |
| 254 | } |
| 255 | |
| 256 | EncodedJSValue JSC_HOST_CALL jsWebGPUBufferPrototypeFunctionDestroy(ExecState* state) |
| 257 | { |
| 258 | return IDLOperation<JSWebGPUBuffer>::call<jsWebGPUBufferPrototypeFunctionDestroyBody>(*state, "destroy" ); |
| 259 | } |
| 260 | |
| 261 | void JSWebGPUBuffer::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder) |
| 262 | { |
| 263 | auto* thisObject = jsCast<JSWebGPUBuffer*>(cell); |
| 264 | builder.setWrappedObjectForCell(cell, &thisObject->wrapped()); |
| 265 | if (thisObject->scriptExecutionContext()) |
| 266 | builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); |
| 267 | Base::heapSnapshot(cell, builder); |
| 268 | } |
| 269 | |
| 270 | bool JSWebGPUBufferOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason) |
| 271 | { |
| 272 | UNUSED_PARAM(handle); |
| 273 | UNUSED_PARAM(visitor); |
| 274 | UNUSED_PARAM(reason); |
| 275 | return false; |
| 276 | } |
| 277 | |
| 278 | void JSWebGPUBufferOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context) |
| 279 | { |
| 280 | auto* jsWebGPUBuffer = static_cast<JSWebGPUBuffer*>(handle.slot()->asCell()); |
| 281 | auto& world = *static_cast<DOMWrapperWorld*>(context); |
| 282 | uncacheWrapper(world, &jsWebGPUBuffer->wrapped(), jsWebGPUBuffer); |
| 283 | } |
| 284 | |
| 285 | JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<WebGPUBuffer>&& impl) |
| 286 | { |
| 287 | // If you hit this failure the interface definition has the ImplementationLacksVTable |
| 288 | // attribute. You should remove that attribute. If the class has subclasses |
| 289 | // that may be passed through this toJS() function you should use the SkipVTableValidation |
| 290 | // attribute to WebGPUBuffer. |
| 291 | static_assert(!std::is_polymorphic<WebGPUBuffer>::value, "WebGPUBuffer is polymorphic but the IDL claims it is not" ); |
| 292 | return createWrapper<WebGPUBuffer>(globalObject, WTFMove(impl)); |
| 293 | } |
| 294 | |
| 295 | JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, WebGPUBuffer& impl) |
| 296 | { |
| 297 | return wrap(state, globalObject, impl); |
| 298 | } |
| 299 | |
| 300 | WebGPUBuffer* JSWebGPUBuffer::toWrapped(JSC::VM& vm, JSC::JSValue value) |
| 301 | { |
| 302 | if (auto* wrapper = jsDynamicCast<JSWebGPUBuffer*>(vm, value)) |
| 303 | return &wrapper->wrapped(); |
| 304 | return nullptr; |
| 305 | } |
| 306 | |
| 307 | } |
| 308 | |
| 309 | #endif // ENABLE(WEBGPU) |
| 310 | |