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 "JSGPUVertexAttributeDescriptor.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<> GPUVertexAttributeDescriptor convertDictionary<GPUVertexAttributeDescriptor>(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 GPUVertexAttributeDescriptor result;
49 JSValue formatValue;
50 if (isNullOrUndefined)
51 formatValue = jsUndefined();
52 else {
53 formatValue = object->get(&state, Identifier::fromString(&state, "format"));
54 RETURN_IF_EXCEPTION(throwScope, { });
55 }
56 if (!formatValue.isUndefined()) {
57 result.format = convert<IDLEnumeration<GPUVertexFormat>>(state, formatValue);
58 RETURN_IF_EXCEPTION(throwScope, { });
59 } else {
60 throwRequiredMemberTypeError(state, throwScope, "format", "GPUVertexAttributeDescriptor", "GPUVertexFormat");
61 return { };
62 }
63 JSValue inputSlotValue;
64 if (isNullOrUndefined)
65 inputSlotValue = jsUndefined();
66 else {
67 inputSlotValue = object->get(&state, Identifier::fromString(&state, "inputSlot"));
68 RETURN_IF_EXCEPTION(throwScope, { });
69 }
70 if (!inputSlotValue.isUndefined()) {
71 result.inputSlot = convert<IDLUnsignedLong>(state, inputSlotValue);
72 RETURN_IF_EXCEPTION(throwScope, { });
73 } else {
74 throwRequiredMemberTypeError(state, throwScope, "inputSlot", "GPUVertexAttributeDescriptor", "unsigned long");
75 return { };
76 }
77 JSValue offsetValue;
78 if (isNullOrUndefined)
79 offsetValue = jsUndefined();
80 else {
81 offsetValue = object->get(&state, Identifier::fromString(&state, "offset"));
82 RETURN_IF_EXCEPTION(throwScope, { });
83 }
84 if (!offsetValue.isUndefined()) {
85 result.offset = convert<IDLUnsignedLongLong>(state, offsetValue);
86 RETURN_IF_EXCEPTION(throwScope, { });
87 } else
88 result.offset = 0;
89 JSValue shaderLocationValue;
90 if (isNullOrUndefined)
91 shaderLocationValue = jsUndefined();
92 else {
93 shaderLocationValue = object->get(&state, Identifier::fromString(&state, "shaderLocation"));
94 RETURN_IF_EXCEPTION(throwScope, { });
95 }
96 if (!shaderLocationValue.isUndefined()) {
97 result.shaderLocation = convert<IDLUnsignedLong>(state, shaderLocationValue);
98 RETURN_IF_EXCEPTION(throwScope, { });
99 } else {
100 throwRequiredMemberTypeError(state, throwScope, "shaderLocation", "GPUVertexAttributeDescriptor", "unsigned long");
101 return { };
102 }
103 return result;
104}
105
106#endif
107
108String convertEnumerationToString(GPUVertexFormat enumerationValue)
109{
110 static const NeverDestroyed<String> values[] = {
111 MAKE_STATIC_STRING_IMPL("float"),
112 MAKE_STATIC_STRING_IMPL("float2"),
113 MAKE_STATIC_STRING_IMPL("float3"),
114 MAKE_STATIC_STRING_IMPL("float4"),
115 };
116 static_assert(static_cast<size_t>(GPUVertexFormat::Float) == 0, "GPUVertexFormat::Float is not 0 as expected");
117 static_assert(static_cast<size_t>(GPUVertexFormat::Float2) == 1, "GPUVertexFormat::Float2 is not 1 as expected");
118 static_assert(static_cast<size_t>(GPUVertexFormat::Float3) == 2, "GPUVertexFormat::Float3 is not 2 as expected");
119 static_assert(static_cast<size_t>(GPUVertexFormat::Float4) == 3, "GPUVertexFormat::Float4 is not 3 as expected");
120 ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values));
121 return values[static_cast<size_t>(enumerationValue)];
122}
123
124template<> JSString* convertEnumerationToJS(ExecState& state, GPUVertexFormat enumerationValue)
125{
126 return jsStringWithCache(&state, convertEnumerationToString(enumerationValue));
127}
128
129template<> Optional<GPUVertexFormat> parseEnumeration<GPUVertexFormat>(ExecState& state, JSValue value)
130{
131 auto stringValue = value.toWTFString(&state);
132 if (stringValue == "float")
133 return GPUVertexFormat::Float;
134 if (stringValue == "float2")
135 return GPUVertexFormat::Float2;
136 if (stringValue == "float3")
137 return GPUVertexFormat::Float3;
138 if (stringValue == "float4")
139 return GPUVertexFormat::Float4;
140 return WTF::nullopt;
141}
142
143template<> const char* expectedEnumerationValues<GPUVertexFormat>()
144{
145 return "\"float\", \"float2\", \"float3\", \"float4\"";
146}
147
148} // namespace WebCore
149
150#endif // ENABLE(WEBGPU)
151