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 "JSGPUBindGroupLayoutBinding.h"
26
27#include "JSDOMConvertNumbers.h"
28#include <JavaScriptCore/JSCInlines.h>
29#include <JavaScriptCore/JSString.h>
30#include <wtf/NeverDestroyed.h>
31
32
33namespace WebCore {
34using namespace JSC;
35
36#if ENABLE(WEBGPU)
37
38template<> GPUBindGroupLayoutBinding convertDictionary<GPUBindGroupLayoutBinding>(ExecState& state, JSValue value)
39{
40 VM& vm = state.vm();
41 auto throwScope = DECLARE_THROW_SCOPE(vm);
42 bool isNullOrUndefined = value.isUndefinedOrNull();
43 auto* object = isNullOrUndefined ? nullptr : value.getObject();
44 if (UNLIKELY(!isNullOrUndefined && !object)) {
45 throwTypeError(&state, throwScope);
46 return { };
47 }
48 GPUBindGroupLayoutBinding result;
49 JSValue bindingValue;
50 if (isNullOrUndefined)
51 bindingValue = jsUndefined();
52 else {
53 bindingValue = object->get(&state, Identifier::fromString(&state, "binding"));
54 RETURN_IF_EXCEPTION(throwScope, { });
55 }
56 if (!bindingValue.isUndefined()) {
57 result.binding = convert<IDLUnsignedLong>(state, bindingValue);
58 RETURN_IF_EXCEPTION(throwScope, { });
59 } else {
60 throwRequiredMemberTypeError(state, throwScope, "binding", "GPUBindGroupLayoutBinding", "unsigned long");
61 return { };
62 }
63 JSValue typeValue;
64 if (isNullOrUndefined)
65 typeValue = jsUndefined();
66 else {
67 typeValue = object->get(&state, Identifier::fromString(&state, "type"));
68 RETURN_IF_EXCEPTION(throwScope, { });
69 }
70 if (!typeValue.isUndefined()) {
71 result.type = convert<IDLEnumeration<GPUBindingType>>(state, typeValue);
72 RETURN_IF_EXCEPTION(throwScope, { });
73 } else {
74 throwRequiredMemberTypeError(state, throwScope, "type", "GPUBindGroupLayoutBinding", "GPUBindingType");
75 return { };
76 }
77 JSValue visibilityValue;
78 if (isNullOrUndefined)
79 visibilityValue = jsUndefined();
80 else {
81 visibilityValue = object->get(&state, Identifier::fromString(&state, "visibility"));
82 RETURN_IF_EXCEPTION(throwScope, { });
83 }
84 if (!visibilityValue.isUndefined()) {
85 result.visibility = convert<IDLUnsignedLong>(state, visibilityValue);
86 RETURN_IF_EXCEPTION(throwScope, { });
87 } else {
88 throwRequiredMemberTypeError(state, throwScope, "visibility", "GPUBindGroupLayoutBinding", "unsigned long");
89 return { };
90 }
91 return result;
92}
93
94#endif
95
96String convertEnumerationToString(GPUBindingType enumerationValue)
97{
98 static const NeverDestroyed<String> values[] = {
99 MAKE_STATIC_STRING_IMPL("uniform-buffer"),
100 MAKE_STATIC_STRING_IMPL("dynamic-uniform-buffer"),
101 MAKE_STATIC_STRING_IMPL("sampler"),
102 MAKE_STATIC_STRING_IMPL("sampled-texture"),
103 MAKE_STATIC_STRING_IMPL("storage-buffer"),
104 MAKE_STATIC_STRING_IMPL("dynamic-storage-buffer"),
105 };
106 static_assert(static_cast<size_t>(GPUBindingType::UniformBuffer) == 0, "GPUBindingType::UniformBuffer is not 0 as expected");
107 static_assert(static_cast<size_t>(GPUBindingType::DynamicUniformBuffer) == 1, "GPUBindingType::DynamicUniformBuffer is not 1 as expected");
108 static_assert(static_cast<size_t>(GPUBindingType::Sampler) == 2, "GPUBindingType::Sampler is not 2 as expected");
109 static_assert(static_cast<size_t>(GPUBindingType::SampledTexture) == 3, "GPUBindingType::SampledTexture is not 3 as expected");
110 static_assert(static_cast<size_t>(GPUBindingType::StorageBuffer) == 4, "GPUBindingType::StorageBuffer is not 4 as expected");
111 static_assert(static_cast<size_t>(GPUBindingType::DynamicStorageBuffer) == 5, "GPUBindingType::DynamicStorageBuffer is not 5 as expected");
112 ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values));
113 return values[static_cast<size_t>(enumerationValue)];
114}
115
116template<> JSString* convertEnumerationToJS(ExecState& state, GPUBindingType enumerationValue)
117{
118 return jsStringWithCache(&state, convertEnumerationToString(enumerationValue));
119}
120
121template<> Optional<GPUBindingType> parseEnumeration<GPUBindingType>(ExecState& state, JSValue value)
122{
123 auto stringValue = value.toWTFString(&state);
124 if (stringValue == "uniform-buffer")
125 return GPUBindingType::UniformBuffer;
126 if (stringValue == "dynamic-uniform-buffer")
127 return GPUBindingType::DynamicUniformBuffer;
128 if (stringValue == "sampler")
129 return GPUBindingType::Sampler;
130 if (stringValue == "sampled-texture")
131 return GPUBindingType::SampledTexture;
132 if (stringValue == "storage-buffer")
133 return GPUBindingType::StorageBuffer;
134 if (stringValue == "dynamic-storage-buffer")
135 return GPUBindingType::DynamicStorageBuffer;
136 return WTF::nullopt;
137}
138
139template<> const char* expectedEnumerationValues<GPUBindingType>()
140{
141 return "\"uniform-buffer\", \"dynamic-uniform-buffer\", \"sampler\", \"sampled-texture\", \"storage-buffer\", \"dynamic-storage-buffer\"";
142}
143
144} // namespace WebCore
145
146#endif // ENABLE(WEBGPU)
147