| 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(WEBGL) |
| 24 | |
| 25 | #include "JSWebGLContextAttributes.h" |
| 26 | |
| 27 | #include "JSDOMConvertBoolean.h" |
| 28 | #include "JSDOMGlobalObject.h" |
| 29 | #include <JavaScriptCore/JSCInlines.h> |
| 30 | #include <JavaScriptCore/JSString.h> |
| 31 | #include <JavaScriptCore/ObjectConstructor.h> |
| 32 | #include <wtf/NeverDestroyed.h> |
| 33 | |
| 34 | |
| 35 | namespace WebCore { |
| 36 | using namespace JSC; |
| 37 | |
| 38 | #if ENABLE(WEBGL) |
| 39 | |
| 40 | template<> WebGLContextAttributes convertDictionary<WebGLContextAttributes>(ExecState& state, JSValue value) |
| 41 | { |
| 42 | VM& vm = state.vm(); |
| 43 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 44 | bool isNullOrUndefined = value.isUndefinedOrNull(); |
| 45 | auto* object = isNullOrUndefined ? nullptr : value.getObject(); |
| 46 | if (UNLIKELY(!isNullOrUndefined && !object)) { |
| 47 | throwTypeError(&state, throwScope); |
| 48 | return { }; |
| 49 | } |
| 50 | WebGLContextAttributes result; |
| 51 | JSValue alphaValue; |
| 52 | if (isNullOrUndefined) |
| 53 | alphaValue = jsUndefined(); |
| 54 | else { |
| 55 | alphaValue = object->get(&state, Identifier::fromString(&state, "alpha" )); |
| 56 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 57 | } |
| 58 | if (!alphaValue.isUndefined()) { |
| 59 | result.alpha = convert<IDLBoolean>(state, alphaValue); |
| 60 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 61 | } else |
| 62 | result.alpha = true; |
| 63 | JSValue antialiasValue; |
| 64 | if (isNullOrUndefined) |
| 65 | antialiasValue = jsUndefined(); |
| 66 | else { |
| 67 | antialiasValue = object->get(&state, Identifier::fromString(&state, "antialias" )); |
| 68 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 69 | } |
| 70 | if (!antialiasValue.isUndefined()) { |
| 71 | result.antialias = convert<IDLBoolean>(state, antialiasValue); |
| 72 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 73 | } else |
| 74 | result.antialias = true; |
| 75 | JSValue depthValue; |
| 76 | if (isNullOrUndefined) |
| 77 | depthValue = jsUndefined(); |
| 78 | else { |
| 79 | depthValue = object->get(&state, Identifier::fromString(&state, "depth" )); |
| 80 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 81 | } |
| 82 | if (!depthValue.isUndefined()) { |
| 83 | result.depth = convert<IDLBoolean>(state, depthValue); |
| 84 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 85 | } else |
| 86 | result.depth = true; |
| 87 | JSValue failIfMajorPerformanceCaveatValue; |
| 88 | if (isNullOrUndefined) |
| 89 | failIfMajorPerformanceCaveatValue = jsUndefined(); |
| 90 | else { |
| 91 | failIfMajorPerformanceCaveatValue = object->get(&state, Identifier::fromString(&state, "failIfMajorPerformanceCaveat" )); |
| 92 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 93 | } |
| 94 | if (!failIfMajorPerformanceCaveatValue.isUndefined()) { |
| 95 | result.failIfMajorPerformanceCaveat = convert<IDLBoolean>(state, failIfMajorPerformanceCaveatValue); |
| 96 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 97 | } else |
| 98 | result.failIfMajorPerformanceCaveat = false; |
| 99 | JSValue powerPreferenceValue; |
| 100 | if (isNullOrUndefined) |
| 101 | powerPreferenceValue = jsUndefined(); |
| 102 | else { |
| 103 | powerPreferenceValue = object->get(&state, Identifier::fromString(&state, "powerPreference" )); |
| 104 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 105 | } |
| 106 | if (!powerPreferenceValue.isUndefined()) { |
| 107 | result.powerPreference = convert<IDLEnumeration<WebGLContextAttributes::PowerPreference>>(state, powerPreferenceValue); |
| 108 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 109 | } else |
| 110 | result.powerPreference = WebGLContextAttributes::PowerPreference::Default; |
| 111 | JSValue premultipliedAlphaValue; |
| 112 | if (isNullOrUndefined) |
| 113 | premultipliedAlphaValue = jsUndefined(); |
| 114 | else { |
| 115 | premultipliedAlphaValue = object->get(&state, Identifier::fromString(&state, "premultipliedAlpha" )); |
| 116 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 117 | } |
| 118 | if (!premultipliedAlphaValue.isUndefined()) { |
| 119 | result.premultipliedAlpha = convert<IDLBoolean>(state, premultipliedAlphaValue); |
| 120 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 121 | } else |
| 122 | result.premultipliedAlpha = true; |
| 123 | JSValue preserveDrawingBufferValue; |
| 124 | if (isNullOrUndefined) |
| 125 | preserveDrawingBufferValue = jsUndefined(); |
| 126 | else { |
| 127 | preserveDrawingBufferValue = object->get(&state, Identifier::fromString(&state, "preserveDrawingBuffer" )); |
| 128 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 129 | } |
| 130 | if (!preserveDrawingBufferValue.isUndefined()) { |
| 131 | result.preserveDrawingBuffer = convert<IDLBoolean>(state, preserveDrawingBufferValue); |
| 132 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 133 | } else |
| 134 | result.preserveDrawingBuffer = false; |
| 135 | JSValue stencilValue; |
| 136 | if (isNullOrUndefined) |
| 137 | stencilValue = jsUndefined(); |
| 138 | else { |
| 139 | stencilValue = object->get(&state, Identifier::fromString(&state, "stencil" )); |
| 140 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 141 | } |
| 142 | if (!stencilValue.isUndefined()) { |
| 143 | result.stencil = convert<IDLBoolean>(state, stencilValue); |
| 144 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 145 | } else |
| 146 | result.stencil = false; |
| 147 | return result; |
| 148 | } |
| 149 | |
| 150 | JSC::JSObject* convertDictionaryToJS(JSC::ExecState& state, JSDOMGlobalObject& globalObject, const WebGLContextAttributes& dictionary) |
| 151 | { |
| 152 | auto& vm = state.vm(); |
| 153 | |
| 154 | auto result = constructEmptyObject(&state, globalObject.objectPrototype()); |
| 155 | |
| 156 | auto alphaValue = toJS<IDLBoolean>(dictionary.alpha); |
| 157 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "alpha" ), alphaValue); |
| 158 | auto antialiasValue = toJS<IDLBoolean>(dictionary.antialias); |
| 159 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "antialias" ), antialiasValue); |
| 160 | auto depthValue = toJS<IDLBoolean>(dictionary.depth); |
| 161 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "depth" ), depthValue); |
| 162 | auto failIfMajorPerformanceCaveatValue = toJS<IDLBoolean>(dictionary.failIfMajorPerformanceCaveat); |
| 163 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "failIfMajorPerformanceCaveat" ), failIfMajorPerformanceCaveatValue); |
| 164 | auto powerPreferenceValue = toJS<IDLEnumeration<WebGLContextAttributes::PowerPreference>>(state, dictionary.powerPreference); |
| 165 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "powerPreference" ), powerPreferenceValue); |
| 166 | auto premultipliedAlphaValue = toJS<IDLBoolean>(dictionary.premultipliedAlpha); |
| 167 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "premultipliedAlpha" ), premultipliedAlphaValue); |
| 168 | auto preserveDrawingBufferValue = toJS<IDLBoolean>(dictionary.preserveDrawingBuffer); |
| 169 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "preserveDrawingBuffer" ), preserveDrawingBufferValue); |
| 170 | auto stencilValue = toJS<IDLBoolean>(dictionary.stencil); |
| 171 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "stencil" ), stencilValue); |
| 172 | return result; |
| 173 | } |
| 174 | |
| 175 | #endif |
| 176 | |
| 177 | String convertEnumerationToString(WebGLContextAttributes::PowerPreference enumerationValue) |
| 178 | { |
| 179 | static const NeverDestroyed<String> values[] = { |
| 180 | MAKE_STATIC_STRING_IMPL("default" ), |
| 181 | MAKE_STATIC_STRING_IMPL("low-power" ), |
| 182 | MAKE_STATIC_STRING_IMPL("high-performance" ), |
| 183 | }; |
| 184 | static_assert(static_cast<size_t>(WebGLContextAttributes::PowerPreference::Default) == 0, "WebGLContextAttributes::PowerPreference::Default is not 0 as expected" ); |
| 185 | static_assert(static_cast<size_t>(WebGLContextAttributes::PowerPreference::LowPower) == 1, "WebGLContextAttributes::PowerPreference::LowPower is not 1 as expected" ); |
| 186 | static_assert(static_cast<size_t>(WebGLContextAttributes::PowerPreference::HighPerformance) == 2, "WebGLContextAttributes::PowerPreference::HighPerformance is not 2 as expected" ); |
| 187 | ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values)); |
| 188 | return values[static_cast<size_t>(enumerationValue)]; |
| 189 | } |
| 190 | |
| 191 | template<> JSString* convertEnumerationToJS(ExecState& state, WebGLContextAttributes::PowerPreference enumerationValue) |
| 192 | { |
| 193 | return jsStringWithCache(&state, convertEnumerationToString(enumerationValue)); |
| 194 | } |
| 195 | |
| 196 | template<> Optional<WebGLContextAttributes::PowerPreference> parseEnumeration<WebGLContextAttributes::PowerPreference>(ExecState& state, JSValue value) |
| 197 | { |
| 198 | auto stringValue = value.toWTFString(&state); |
| 199 | if (stringValue == "default" ) |
| 200 | return WebGLContextAttributes::PowerPreference::Default; |
| 201 | if (stringValue == "low-power" ) |
| 202 | return WebGLContextAttributes::PowerPreference::LowPower; |
| 203 | if (stringValue == "high-performance" ) |
| 204 | return WebGLContextAttributes::PowerPreference::HighPerformance; |
| 205 | return WTF::nullopt; |
| 206 | } |
| 207 | |
| 208 | template<> const char* expectedEnumerationValues<WebGLContextAttributes::PowerPreference>() |
| 209 | { |
| 210 | return "\"default\", \"low-power\", \"high-performance\"" ; |
| 211 | } |
| 212 | |
| 213 | } // namespace WebCore |
| 214 | |
| 215 | #endif // ENABLE(WEBGL) |
| 216 | |