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 "JSGPUInputStateDescriptor.h"
26
27#include "JSDOMConvertNullable.h"
28#include "JSDOMConvertSequences.h"
29#include "JSGPUVertexAttributeDescriptor.h"
30#include "JSGPUVertexInputDescriptor.h"
31#include <JavaScriptCore/JSArray.h>
32#include <JavaScriptCore/JSCInlines.h>
33#include <JavaScriptCore/JSString.h>
34#include <wtf/NeverDestroyed.h>
35
36
37namespace WebCore {
38using namespace JSC;
39
40#if ENABLE(WEBGPU)
41
42template<> GPUInputStateDescriptor convertDictionary<GPUInputStateDescriptor>(ExecState& state, JSValue value)
43{
44 VM& vm = state.vm();
45 auto throwScope = DECLARE_THROW_SCOPE(vm);
46 bool isNullOrUndefined = value.isUndefinedOrNull();
47 auto* object = isNullOrUndefined ? nullptr : value.getObject();
48 if (UNLIKELY(!isNullOrUndefined && !object)) {
49 throwTypeError(&state, throwScope);
50 return { };
51 }
52 GPUInputStateDescriptor result;
53 JSValue attributesValue;
54 if (isNullOrUndefined)
55 attributesValue = jsUndefined();
56 else {
57 attributesValue = object->get(&state, Identifier::fromString(&state, "attributes"));
58 RETURN_IF_EXCEPTION(throwScope, { });
59 }
60 if (!attributesValue.isUndefined()) {
61 result.attributes = convert<IDLSequence<IDLDictionary<GPUVertexAttributeDescriptor>>>(state, attributesValue);
62 RETURN_IF_EXCEPTION(throwScope, { });
63 } else {
64 throwRequiredMemberTypeError(state, throwScope, "attributes", "GPUInputStateDescriptor", "sequence");
65 return { };
66 }
67 JSValue indexFormatValue;
68 if (isNullOrUndefined)
69 indexFormatValue = jsUndefined();
70 else {
71 indexFormatValue = object->get(&state, Identifier::fromString(&state, "indexFormat"));
72 RETURN_IF_EXCEPTION(throwScope, { });
73 }
74 if (!indexFormatValue.isUndefined()) {
75 result.indexFormat = convert<IDLNullable<IDLEnumeration<GPUIndexFormat>>>(state, indexFormatValue);
76 RETURN_IF_EXCEPTION(throwScope, { });
77 }
78 JSValue inputsValue;
79 if (isNullOrUndefined)
80 inputsValue = jsUndefined();
81 else {
82 inputsValue = object->get(&state, Identifier::fromString(&state, "inputs"));
83 RETURN_IF_EXCEPTION(throwScope, { });
84 }
85 if (!inputsValue.isUndefined()) {
86 result.inputs = convert<IDLSequence<IDLDictionary<GPUVertexInputDescriptor>>>(state, inputsValue);
87 RETURN_IF_EXCEPTION(throwScope, { });
88 } else {
89 throwRequiredMemberTypeError(state, throwScope, "inputs", "GPUInputStateDescriptor", "sequence");
90 return { };
91 }
92 return result;
93}
94
95#endif
96
97String convertEnumerationToString(GPUIndexFormat enumerationValue)
98{
99 static const NeverDestroyed<String> values[] = {
100 MAKE_STATIC_STRING_IMPL("uint16"),
101 MAKE_STATIC_STRING_IMPL("uint32"),
102 };
103 static_assert(static_cast<size_t>(GPUIndexFormat::Uint16) == 0, "GPUIndexFormat::Uint16 is not 0 as expected");
104 static_assert(static_cast<size_t>(GPUIndexFormat::Uint32) == 1, "GPUIndexFormat::Uint32 is not 1 as expected");
105 ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values));
106 return values[static_cast<size_t>(enumerationValue)];
107}
108
109template<> JSString* convertEnumerationToJS(ExecState& state, GPUIndexFormat enumerationValue)
110{
111 return jsStringWithCache(&state, convertEnumerationToString(enumerationValue));
112}
113
114template<> Optional<GPUIndexFormat> parseEnumeration<GPUIndexFormat>(ExecState& state, JSValue value)
115{
116 auto stringValue = value.toWTFString(&state);
117 if (stringValue == "uint16")
118 return GPUIndexFormat::Uint16;
119 if (stringValue == "uint32")
120 return GPUIndexFormat::Uint32;
121 return WTF::nullopt;
122}
123
124template<> const char* expectedEnumerationValues<GPUIndexFormat>()
125{
126 return "\"uint16\", \"uint32\"";
127}
128
129} // namespace WebCore
130
131#endif // ENABLE(WEBGPU)
132