| 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 | |
| 50 | namespace WebCore { |
| 51 | using namespace JSC; |
| 52 | |
| 53 | #if ENABLE(WEBGPU) |
| 54 | |
| 55 | template<> 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 | |
| 112 | JSC::EncodedJSValue JSC_HOST_CALL jsGPUCanvasContextPrototypeFunctionConfigureSwapChain(JSC::ExecState*); |
| 113 | |
| 114 | // Attributes |
| 115 | |
| 116 | JSC::EncodedJSValue jsGPUCanvasContextConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 117 | bool setJSGPUCanvasContextConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| 118 | JSC::EncodedJSValue jsGPUCanvasContextCanvas(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 119 | |
| 120 | class JSGPUCanvasContextPrototype : public JSC::JSNonFinalObject { |
| 121 | public: |
| 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 | |
| 136 | private: |
| 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 | |
| 145 | using JSGPUCanvasContextConstructor = JSDOMConstructorNotConstructable<JSGPUCanvasContext>; |
| 146 | |
| 147 | template<> JSValue JSGPUCanvasContextConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
| 148 | { |
| 149 | UNUSED_PARAM(vm); |
| 150 | return globalObject.functionPrototype(); |
| 151 | } |
| 152 | |
| 153 | template<> 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 | |
| 160 | template<> const ClassInfo JSGPUCanvasContextConstructor::s_info = { "GPUCanvasContext" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSGPUCanvasContextConstructor) }; |
| 161 | |
| 162 | /* Hash table for prototype */ |
| 163 | |
| 164 | static 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 | |
| 171 | const ClassInfo JSGPUCanvasContextPrototype::s_info = { "GPUCanvasContextPrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSGPUCanvasContextPrototype) }; |
| 172 | |
| 173 | void JSGPUCanvasContextPrototype::finishCreation(VM& vm) |
| 174 | { |
| 175 | Base::finishCreation(vm); |
| 176 | reifyStaticProperties(vm, JSGPUCanvasContext::info(), JSGPUCanvasContextPrototypeTableValues, *this); |
| 177 | } |
| 178 | |
| 179 | const ClassInfo JSGPUCanvasContext::s_info = { "GPUCanvasContext" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSGPUCanvasContext) }; |
| 180 | |
| 181 | JSGPUCanvasContext::JSGPUCanvasContext(Structure* structure, JSDOMGlobalObject& globalObject, Ref<GPUCanvasContext>&& impl) |
| 182 | : JSDOMWrapper<GPUCanvasContext>(structure, globalObject, WTFMove(impl)) |
| 183 | { |
| 184 | } |
| 185 | |
| 186 | void JSGPUCanvasContext::finishCreation(VM& vm) |
| 187 | { |
| 188 | Base::finishCreation(vm); |
| 189 | ASSERT(inherits(vm, info())); |
| 190 | |
| 191 | } |
| 192 | |
| 193 | JSObject* JSGPUCanvasContext::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
| 194 | { |
| 195 | return JSGPUCanvasContextPrototype::create(vm, &globalObject, JSGPUCanvasContextPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype())); |
| 196 | } |
| 197 | |
| 198 | JSObject* JSGPUCanvasContext::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
| 199 | { |
| 200 | return getDOMPrototype<JSGPUCanvasContext>(vm, globalObject); |
| 201 | } |
| 202 | |
| 203 | JSValue JSGPUCanvasContext::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
| 204 | { |
| 205 | return getDOMConstructor<JSGPUCanvasContextConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
| 206 | } |
| 207 | |
| 208 | void JSGPUCanvasContext::destroy(JSC::JSCell* cell) |
| 209 | { |
| 210 | JSGPUCanvasContext* thisObject = static_cast<JSGPUCanvasContext*>(cell); |
| 211 | thisObject->JSGPUCanvasContext::~JSGPUCanvasContext(); |
| 212 | } |
| 213 | |
| 214 | template<> inline JSGPUCanvasContext* IDLAttribute<JSGPUCanvasContext>::cast(ExecState& state, EncodedJSValue thisValue) |
| 215 | { |
| 216 | return jsDynamicCast<JSGPUCanvasContext*>(state.vm(), JSValue::decode(thisValue)); |
| 217 | } |
| 218 | |
| 219 | template<> inline JSGPUCanvasContext* IDLOperation<JSGPUCanvasContext>::cast(ExecState& state) |
| 220 | { |
| 221 | return jsDynamicCast<JSGPUCanvasContext*>(state.vm(), state.thisValue()); |
| 222 | } |
| 223 | |
| 224 | EncodedJSValue 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 | |
| 234 | bool 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 | |
| 247 | static 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 | |
| 256 | EncodedJSValue jsGPUCanvasContextCanvas(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 257 | { |
| 258 | return IDLAttribute<JSGPUCanvasContext>::get<jsGPUCanvasContextCanvasGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "canvas" ); |
| 259 | } |
| 260 | |
| 261 | static 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 | |
| 273 | EncodedJSValue JSC_HOST_CALL jsGPUCanvasContextPrototypeFunctionConfigureSwapChain(ExecState* state) |
| 274 | { |
| 275 | return IDLOperation<JSGPUCanvasContext>::call<jsGPUCanvasContextPrototypeFunctionConfigureSwapChainBody>(*state, "configureSwapChain" ); |
| 276 | } |
| 277 | |
| 278 | void 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 | |
| 287 | bool 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 | |
| 295 | void 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) |
| 305 | extern "C" { extern void (*const __identifier("??_7GPUCanvasContext@WebCore@@6B@" )[])(); } |
| 306 | #else |
| 307 | extern "C" { extern void* _ZTVN7WebCore16GPUCanvasContextE[]; } |
| 308 | #endif |
| 309 | #endif |
| 310 | |
| 311 | JSC::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 | |
| 335 | JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, GPUCanvasContext& impl) |
| 336 | { |
| 337 | return wrap(state, globalObject, impl); |
| 338 | } |
| 339 | |
| 340 | GPUCanvasContext* 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 | |