| 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 | #include "JSImageBitmapOptions.h" |
| 23 | |
| 24 | #include "JSDOMConvertNumbers.h" |
| 25 | #include <JavaScriptCore/JSCInlines.h> |
| 26 | #include <JavaScriptCore/JSString.h> |
| 27 | #include <wtf/NeverDestroyed.h> |
| 28 | |
| 29 | |
| 30 | namespace WebCore { |
| 31 | using namespace JSC; |
| 32 | |
| 33 | template<> ImageBitmapOptions convertDictionary<ImageBitmapOptions>(ExecState& state, JSValue value) |
| 34 | { |
| 35 | VM& vm = state.vm(); |
| 36 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 37 | bool isNullOrUndefined = value.isUndefinedOrNull(); |
| 38 | auto* object = isNullOrUndefined ? nullptr : value.getObject(); |
| 39 | if (UNLIKELY(!isNullOrUndefined && !object)) { |
| 40 | throwTypeError(&state, throwScope); |
| 41 | return { }; |
| 42 | } |
| 43 | ImageBitmapOptions result; |
| 44 | JSValue colorSpaceConversionValue; |
| 45 | if (isNullOrUndefined) |
| 46 | colorSpaceConversionValue = jsUndefined(); |
| 47 | else { |
| 48 | colorSpaceConversionValue = object->get(&state, Identifier::fromString(&state, "colorSpaceConversion" )); |
| 49 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 50 | } |
| 51 | if (!colorSpaceConversionValue.isUndefined()) { |
| 52 | result.colorSpaceConversion = convert<IDLEnumeration<ImageBitmapOptions::ColorSpaceConversion>>(state, colorSpaceConversionValue); |
| 53 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 54 | } else |
| 55 | result.colorSpaceConversion = ImageBitmapOptions::ColorSpaceConversion::Default; |
| 56 | JSValue imageOrientationValue; |
| 57 | if (isNullOrUndefined) |
| 58 | imageOrientationValue = jsUndefined(); |
| 59 | else { |
| 60 | imageOrientationValue = object->get(&state, Identifier::fromString(&state, "imageOrientation" )); |
| 61 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 62 | } |
| 63 | if (!imageOrientationValue.isUndefined()) { |
| 64 | result.imageOrientation = convert<IDLEnumeration<ImageBitmapOptions::Orientation>>(state, imageOrientationValue); |
| 65 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 66 | } else |
| 67 | result.imageOrientation = ImageBitmapOptions::Orientation::None; |
| 68 | JSValue premultiplyAlphaValue; |
| 69 | if (isNullOrUndefined) |
| 70 | premultiplyAlphaValue = jsUndefined(); |
| 71 | else { |
| 72 | premultiplyAlphaValue = object->get(&state, Identifier::fromString(&state, "premultiplyAlpha" )); |
| 73 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 74 | } |
| 75 | if (!premultiplyAlphaValue.isUndefined()) { |
| 76 | result.premultiplyAlpha = convert<IDLEnumeration<ImageBitmapOptions::PremultiplyAlpha>>(state, premultiplyAlphaValue); |
| 77 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 78 | } else |
| 79 | result.premultiplyAlpha = ImageBitmapOptions::PremultiplyAlpha::Default; |
| 80 | JSValue resizeHeightValue; |
| 81 | if (isNullOrUndefined) |
| 82 | resizeHeightValue = jsUndefined(); |
| 83 | else { |
| 84 | resizeHeightValue = object->get(&state, Identifier::fromString(&state, "resizeHeight" )); |
| 85 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 86 | } |
| 87 | if (!resizeHeightValue.isUndefined()) { |
| 88 | result.resizeHeight = convert<IDLEnforceRangeAdaptor<IDLUnsignedLong>>(state, resizeHeightValue); |
| 89 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 90 | } |
| 91 | JSValue resizeQualityValue; |
| 92 | if (isNullOrUndefined) |
| 93 | resizeQualityValue = jsUndefined(); |
| 94 | else { |
| 95 | resizeQualityValue = object->get(&state, Identifier::fromString(&state, "resizeQuality" )); |
| 96 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 97 | } |
| 98 | if (!resizeQualityValue.isUndefined()) { |
| 99 | result.resizeQuality = convert<IDLEnumeration<ImageBitmapOptions::ResizeQuality>>(state, resizeQualityValue); |
| 100 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 101 | } else |
| 102 | result.resizeQuality = ImageBitmapOptions::ResizeQuality::Low; |
| 103 | JSValue resizeWidthValue; |
| 104 | if (isNullOrUndefined) |
| 105 | resizeWidthValue = jsUndefined(); |
| 106 | else { |
| 107 | resizeWidthValue = object->get(&state, Identifier::fromString(&state, "resizeWidth" )); |
| 108 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 109 | } |
| 110 | if (!resizeWidthValue.isUndefined()) { |
| 111 | result.resizeWidth = convert<IDLEnforceRangeAdaptor<IDLUnsignedLong>>(state, resizeWidthValue); |
| 112 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 113 | } |
| 114 | return result; |
| 115 | } |
| 116 | |
| 117 | String convertEnumerationToString(ImageBitmapOptions::Orientation enumerationValue) |
| 118 | { |
| 119 | static const NeverDestroyed<String> values[] = { |
| 120 | MAKE_STATIC_STRING_IMPL("none" ), |
| 121 | MAKE_STATIC_STRING_IMPL("flipY" ), |
| 122 | }; |
| 123 | static_assert(static_cast<size_t>(ImageBitmapOptions::Orientation::None) == 0, "ImageBitmapOptions::Orientation::None is not 0 as expected" ); |
| 124 | static_assert(static_cast<size_t>(ImageBitmapOptions::Orientation::FlipY) == 1, "ImageBitmapOptions::Orientation::FlipY is not 1 as expected" ); |
| 125 | ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values)); |
| 126 | return values[static_cast<size_t>(enumerationValue)]; |
| 127 | } |
| 128 | |
| 129 | template<> JSString* convertEnumerationToJS(ExecState& state, ImageBitmapOptions::Orientation enumerationValue) |
| 130 | { |
| 131 | return jsStringWithCache(&state, convertEnumerationToString(enumerationValue)); |
| 132 | } |
| 133 | |
| 134 | template<> Optional<ImageBitmapOptions::Orientation> parseEnumeration<ImageBitmapOptions::Orientation>(ExecState& state, JSValue value) |
| 135 | { |
| 136 | auto stringValue = value.toWTFString(&state); |
| 137 | if (stringValue == "none" ) |
| 138 | return ImageBitmapOptions::Orientation::None; |
| 139 | if (stringValue == "flipY" ) |
| 140 | return ImageBitmapOptions::Orientation::FlipY; |
| 141 | return WTF::nullopt; |
| 142 | } |
| 143 | |
| 144 | template<> const char* expectedEnumerationValues<ImageBitmapOptions::Orientation>() |
| 145 | { |
| 146 | return "\"none\", \"flipY\"" ; |
| 147 | } |
| 148 | |
| 149 | String convertEnumerationToString(ImageBitmapOptions::PremultiplyAlpha enumerationValue) |
| 150 | { |
| 151 | static const NeverDestroyed<String> values[] = { |
| 152 | MAKE_STATIC_STRING_IMPL("none" ), |
| 153 | MAKE_STATIC_STRING_IMPL("premultiply" ), |
| 154 | MAKE_STATIC_STRING_IMPL("default" ), |
| 155 | }; |
| 156 | static_assert(static_cast<size_t>(ImageBitmapOptions::PremultiplyAlpha::None) == 0, "ImageBitmapOptions::PremultiplyAlpha::None is not 0 as expected" ); |
| 157 | static_assert(static_cast<size_t>(ImageBitmapOptions::PremultiplyAlpha::Premultiply) == 1, "ImageBitmapOptions::PremultiplyAlpha::Premultiply is not 1 as expected" ); |
| 158 | static_assert(static_cast<size_t>(ImageBitmapOptions::PremultiplyAlpha::Default) == 2, "ImageBitmapOptions::PremultiplyAlpha::Default is not 2 as expected" ); |
| 159 | ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values)); |
| 160 | return values[static_cast<size_t>(enumerationValue)]; |
| 161 | } |
| 162 | |
| 163 | template<> JSString* convertEnumerationToJS(ExecState& state, ImageBitmapOptions::PremultiplyAlpha enumerationValue) |
| 164 | { |
| 165 | return jsStringWithCache(&state, convertEnumerationToString(enumerationValue)); |
| 166 | } |
| 167 | |
| 168 | template<> Optional<ImageBitmapOptions::PremultiplyAlpha> parseEnumeration<ImageBitmapOptions::PremultiplyAlpha>(ExecState& state, JSValue value) |
| 169 | { |
| 170 | auto stringValue = value.toWTFString(&state); |
| 171 | if (stringValue == "none" ) |
| 172 | return ImageBitmapOptions::PremultiplyAlpha::None; |
| 173 | if (stringValue == "premultiply" ) |
| 174 | return ImageBitmapOptions::PremultiplyAlpha::Premultiply; |
| 175 | if (stringValue == "default" ) |
| 176 | return ImageBitmapOptions::PremultiplyAlpha::Default; |
| 177 | return WTF::nullopt; |
| 178 | } |
| 179 | |
| 180 | template<> const char* expectedEnumerationValues<ImageBitmapOptions::PremultiplyAlpha>() |
| 181 | { |
| 182 | return "\"none\", \"premultiply\", \"default\"" ; |
| 183 | } |
| 184 | |
| 185 | String convertEnumerationToString(ImageBitmapOptions::ColorSpaceConversion enumerationValue) |
| 186 | { |
| 187 | static const NeverDestroyed<String> values[] = { |
| 188 | MAKE_STATIC_STRING_IMPL("none" ), |
| 189 | MAKE_STATIC_STRING_IMPL("default" ), |
| 190 | }; |
| 191 | static_assert(static_cast<size_t>(ImageBitmapOptions::ColorSpaceConversion::None) == 0, "ImageBitmapOptions::ColorSpaceConversion::None is not 0 as expected" ); |
| 192 | static_assert(static_cast<size_t>(ImageBitmapOptions::ColorSpaceConversion::Default) == 1, "ImageBitmapOptions::ColorSpaceConversion::Default is not 1 as expected" ); |
| 193 | ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values)); |
| 194 | return values[static_cast<size_t>(enumerationValue)]; |
| 195 | } |
| 196 | |
| 197 | template<> JSString* convertEnumerationToJS(ExecState& state, ImageBitmapOptions::ColorSpaceConversion enumerationValue) |
| 198 | { |
| 199 | return jsStringWithCache(&state, convertEnumerationToString(enumerationValue)); |
| 200 | } |
| 201 | |
| 202 | template<> Optional<ImageBitmapOptions::ColorSpaceConversion> parseEnumeration<ImageBitmapOptions::ColorSpaceConversion>(ExecState& state, JSValue value) |
| 203 | { |
| 204 | auto stringValue = value.toWTFString(&state); |
| 205 | if (stringValue == "none" ) |
| 206 | return ImageBitmapOptions::ColorSpaceConversion::None; |
| 207 | if (stringValue == "default" ) |
| 208 | return ImageBitmapOptions::ColorSpaceConversion::Default; |
| 209 | return WTF::nullopt; |
| 210 | } |
| 211 | |
| 212 | template<> const char* expectedEnumerationValues<ImageBitmapOptions::ColorSpaceConversion>() |
| 213 | { |
| 214 | return "\"none\", \"default\"" ; |
| 215 | } |
| 216 | |
| 217 | String convertEnumerationToString(ImageBitmapOptions::ResizeQuality enumerationValue) |
| 218 | { |
| 219 | static const NeverDestroyed<String> values[] = { |
| 220 | MAKE_STATIC_STRING_IMPL("pixelated" ), |
| 221 | MAKE_STATIC_STRING_IMPL("low" ), |
| 222 | MAKE_STATIC_STRING_IMPL("medium" ), |
| 223 | MAKE_STATIC_STRING_IMPL("high" ), |
| 224 | }; |
| 225 | static_assert(static_cast<size_t>(ImageBitmapOptions::ResizeQuality::Pixelated) == 0, "ImageBitmapOptions::ResizeQuality::Pixelated is not 0 as expected" ); |
| 226 | static_assert(static_cast<size_t>(ImageBitmapOptions::ResizeQuality::Low) == 1, "ImageBitmapOptions::ResizeQuality::Low is not 1 as expected" ); |
| 227 | static_assert(static_cast<size_t>(ImageBitmapOptions::ResizeQuality::Medium) == 2, "ImageBitmapOptions::ResizeQuality::Medium is not 2 as expected" ); |
| 228 | static_assert(static_cast<size_t>(ImageBitmapOptions::ResizeQuality::High) == 3, "ImageBitmapOptions::ResizeQuality::High is not 3 as expected" ); |
| 229 | ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values)); |
| 230 | return values[static_cast<size_t>(enumerationValue)]; |
| 231 | } |
| 232 | |
| 233 | template<> JSString* convertEnumerationToJS(ExecState& state, ImageBitmapOptions::ResizeQuality enumerationValue) |
| 234 | { |
| 235 | return jsStringWithCache(&state, convertEnumerationToString(enumerationValue)); |
| 236 | } |
| 237 | |
| 238 | template<> Optional<ImageBitmapOptions::ResizeQuality> parseEnumeration<ImageBitmapOptions::ResizeQuality>(ExecState& state, JSValue value) |
| 239 | { |
| 240 | auto stringValue = value.toWTFString(&state); |
| 241 | if (stringValue == "pixelated" ) |
| 242 | return ImageBitmapOptions::ResizeQuality::Pixelated; |
| 243 | if (stringValue == "low" ) |
| 244 | return ImageBitmapOptions::ResizeQuality::Low; |
| 245 | if (stringValue == "medium" ) |
| 246 | return ImageBitmapOptions::ResizeQuality::Medium; |
| 247 | if (stringValue == "high" ) |
| 248 | return ImageBitmapOptions::ResizeQuality::High; |
| 249 | return WTF::nullopt; |
| 250 | } |
| 251 | |
| 252 | template<> const char* expectedEnumerationValues<ImageBitmapOptions::ResizeQuality>() |
| 253 | { |
| 254 | return "\"pixelated\", \"low\", \"medium\", \"high\"" ; |
| 255 | } |
| 256 | |
| 257 | } // namespace WebCore |
| 258 | |