| 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 "JSGPURequestAdapterOptions.h" |
| 26 | |
| 27 | #include "JSDOMConvertNullable.h" |
| 28 | #include <JavaScriptCore/JSCInlines.h> |
| 29 | #include <JavaScriptCore/JSString.h> |
| 30 | #include <wtf/NeverDestroyed.h> |
| 31 | |
| 32 | |
| 33 | namespace WebCore { |
| 34 | using namespace JSC; |
| 35 | |
| 36 | #if ENABLE(WEBGPU) |
| 37 | |
| 38 | template<> GPURequestAdapterOptions convertDictionary<GPURequestAdapterOptions>(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 | GPURequestAdapterOptions result; |
| 49 | JSValue powerPreferenceValue; |
| 50 | if (isNullOrUndefined) |
| 51 | powerPreferenceValue = jsUndefined(); |
| 52 | else { |
| 53 | powerPreferenceValue = object->get(&state, Identifier::fromString(&state, "powerPreference" )); |
| 54 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 55 | } |
| 56 | if (!powerPreferenceValue.isUndefined()) { |
| 57 | result.powerPreference = convert<IDLNullable<IDLEnumeration<GPUPowerPreference>>>(state, powerPreferenceValue); |
| 58 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 59 | } |
| 60 | return result; |
| 61 | } |
| 62 | |
| 63 | #endif |
| 64 | |
| 65 | String convertEnumerationToString(GPUPowerPreference enumerationValue) |
| 66 | { |
| 67 | static const NeverDestroyed<String> values[] = { |
| 68 | MAKE_STATIC_STRING_IMPL("low-power" ), |
| 69 | MAKE_STATIC_STRING_IMPL("high-performance" ), |
| 70 | }; |
| 71 | static_assert(static_cast<size_t>(GPUPowerPreference::LowPower) == 0, "GPUPowerPreference::LowPower is not 0 as expected" ); |
| 72 | static_assert(static_cast<size_t>(GPUPowerPreference::HighPerformance) == 1, "GPUPowerPreference::HighPerformance is not 1 as expected" ); |
| 73 | ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values)); |
| 74 | return values[static_cast<size_t>(enumerationValue)]; |
| 75 | } |
| 76 | |
| 77 | template<> JSString* convertEnumerationToJS(ExecState& state, GPUPowerPreference enumerationValue) |
| 78 | { |
| 79 | return jsStringWithCache(&state, convertEnumerationToString(enumerationValue)); |
| 80 | } |
| 81 | |
| 82 | template<> Optional<GPUPowerPreference> parseEnumeration<GPUPowerPreference>(ExecState& state, JSValue value) |
| 83 | { |
| 84 | auto stringValue = value.toWTFString(&state); |
| 85 | if (stringValue == "low-power" ) |
| 86 | return GPUPowerPreference::LowPower; |
| 87 | if (stringValue == "high-performance" ) |
| 88 | return GPUPowerPreference::HighPerformance; |
| 89 | return WTF::nullopt; |
| 90 | } |
| 91 | |
| 92 | template<> const char* expectedEnumerationValues<GPUPowerPreference>() |
| 93 | { |
| 94 | return "\"low-power\", \"high-performance\"" ; |
| 95 | } |
| 96 | |
| 97 | } // namespace WebCore |
| 98 | |
| 99 | #endif // ENABLE(WEBGPU) |
| 100 | |