| 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(WEB_RTC) |
| 24 | |
| 25 | #include "JSRTCRtpCapabilities.h" |
| 26 | |
| 27 | #include "JSDOMConvertNumbers.h" |
| 28 | #include "JSDOMConvertSequences.h" |
| 29 | #include "JSDOMConvertStrings.h" |
| 30 | #include "JSDOMGlobalObject.h" |
| 31 | #include <JavaScriptCore/JSArray.h> |
| 32 | #include <JavaScriptCore/JSCInlines.h> |
| 33 | #include <JavaScriptCore/ObjectConstructor.h> |
| 34 | |
| 35 | |
| 36 | namespace WebCore { |
| 37 | using namespace JSC; |
| 38 | |
| 39 | #if ENABLE(WEB_RTC) |
| 40 | |
| 41 | template<> RTCRtpCapabilities convertDictionary<RTCRtpCapabilities>(ExecState& state, JSValue value) |
| 42 | { |
| 43 | VM& vm = state.vm(); |
| 44 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 45 | bool isNullOrUndefined = value.isUndefinedOrNull(); |
| 46 | auto* object = isNullOrUndefined ? nullptr : value.getObject(); |
| 47 | if (UNLIKELY(!isNullOrUndefined && !object)) { |
| 48 | throwTypeError(&state, throwScope); |
| 49 | return { }; |
| 50 | } |
| 51 | RTCRtpCapabilities result; |
| 52 | JSValue codecsValue; |
| 53 | if (isNullOrUndefined) |
| 54 | codecsValue = jsUndefined(); |
| 55 | else { |
| 56 | codecsValue = object->get(&state, Identifier::fromString(&state, "codecs" )); |
| 57 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 58 | } |
| 59 | if (!codecsValue.isUndefined()) { |
| 60 | result.codecs = convert<IDLSequence<IDLDictionary<RTCRtpCapabilities::CodecCapability>>>(state, codecsValue); |
| 61 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 62 | } else { |
| 63 | throwRequiredMemberTypeError(state, throwScope, "codecs" , "RTCRtpCapabilities" , "sequence" ); |
| 64 | return { }; |
| 65 | } |
| 66 | JSValue ; |
| 67 | if (isNullOrUndefined) |
| 68 | headerExtensionsValue = jsUndefined(); |
| 69 | else { |
| 70 | headerExtensionsValue = object->get(&state, Identifier::fromString(&state, "headerExtensions" )); |
| 71 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 72 | } |
| 73 | if (!headerExtensionsValue.isUndefined()) { |
| 74 | result.headerExtensions = convert<IDLSequence<IDLDictionary<RTCRtpCapabilities::HeaderExtensionCapability>>>(state, headerExtensionsValue); |
| 75 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 76 | } else { |
| 77 | throwRequiredMemberTypeError(state, throwScope, "headerExtensions" , "RTCRtpCapabilities" , "sequence" ); |
| 78 | return { }; |
| 79 | } |
| 80 | return result; |
| 81 | } |
| 82 | |
| 83 | JSC::JSObject* convertDictionaryToJS(JSC::ExecState& state, JSDOMGlobalObject& globalObject, const RTCRtpCapabilities& dictionary) |
| 84 | { |
| 85 | auto& vm = state.vm(); |
| 86 | |
| 87 | auto result = constructEmptyObject(&state, globalObject.objectPrototype()); |
| 88 | |
| 89 | auto codecsValue = toJS<IDLSequence<IDLDictionary<RTCRtpCapabilities::CodecCapability>>>(state, globalObject, dictionary.codecs); |
| 90 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "codecs" ), codecsValue); |
| 91 | auto = toJS<IDLSequence<IDLDictionary<RTCRtpCapabilities::HeaderExtensionCapability>>>(state, globalObject, dictionary.headerExtensions); |
| 92 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "headerExtensions" ), headerExtensionsValue); |
| 93 | return result; |
| 94 | } |
| 95 | |
| 96 | #endif |
| 97 | |
| 98 | #if ENABLE(WEB_RTC) |
| 99 | |
| 100 | template<> RTCRtpCapabilities::CodecCapability convertDictionary<RTCRtpCapabilities::CodecCapability>(ExecState& state, JSValue value) |
| 101 | { |
| 102 | VM& vm = state.vm(); |
| 103 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 104 | bool isNullOrUndefined = value.isUndefinedOrNull(); |
| 105 | auto* object = isNullOrUndefined ? nullptr : value.getObject(); |
| 106 | if (UNLIKELY(!isNullOrUndefined && !object)) { |
| 107 | throwTypeError(&state, throwScope); |
| 108 | return { }; |
| 109 | } |
| 110 | RTCRtpCapabilities::CodecCapability result; |
| 111 | JSValue channelsValue; |
| 112 | if (isNullOrUndefined) |
| 113 | channelsValue = jsUndefined(); |
| 114 | else { |
| 115 | channelsValue = object->get(&state, Identifier::fromString(&state, "channels" )); |
| 116 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 117 | } |
| 118 | if (!channelsValue.isUndefined()) { |
| 119 | result.channels = convert<IDLUnsignedShort>(state, channelsValue); |
| 120 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 121 | } |
| 122 | JSValue clockRateValue; |
| 123 | if (isNullOrUndefined) |
| 124 | clockRateValue = jsUndefined(); |
| 125 | else { |
| 126 | clockRateValue = object->get(&state, Identifier::fromString(&state, "clockRate" )); |
| 127 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 128 | } |
| 129 | if (!clockRateValue.isUndefined()) { |
| 130 | result.clockRate = convert<IDLUnsignedLong>(state, clockRateValue); |
| 131 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 132 | } else { |
| 133 | throwRequiredMemberTypeError(state, throwScope, "clockRate" , "RTCRtpCodecCapability" , "unsigned long" ); |
| 134 | return { }; |
| 135 | } |
| 136 | JSValue mimeTypeValue; |
| 137 | if (isNullOrUndefined) |
| 138 | mimeTypeValue = jsUndefined(); |
| 139 | else { |
| 140 | mimeTypeValue = object->get(&state, Identifier::fromString(&state, "mimeType" )); |
| 141 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 142 | } |
| 143 | if (!mimeTypeValue.isUndefined()) { |
| 144 | result.mimeType = convert<IDLDOMString>(state, mimeTypeValue); |
| 145 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 146 | } else { |
| 147 | throwRequiredMemberTypeError(state, throwScope, "mimeType" , "RTCRtpCodecCapability" , "DOMString" ); |
| 148 | return { }; |
| 149 | } |
| 150 | JSValue sdpFmtpLineValue; |
| 151 | if (isNullOrUndefined) |
| 152 | sdpFmtpLineValue = jsUndefined(); |
| 153 | else { |
| 154 | sdpFmtpLineValue = object->get(&state, Identifier::fromString(&state, "sdpFmtpLine" )); |
| 155 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 156 | } |
| 157 | if (!sdpFmtpLineValue.isUndefined()) { |
| 158 | result.sdpFmtpLine = convert<IDLDOMString>(state, sdpFmtpLineValue); |
| 159 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 160 | } |
| 161 | return result; |
| 162 | } |
| 163 | |
| 164 | JSC::JSObject* convertDictionaryToJS(JSC::ExecState& state, JSDOMGlobalObject& globalObject, const RTCRtpCapabilities::CodecCapability& dictionary) |
| 165 | { |
| 166 | auto& vm = state.vm(); |
| 167 | |
| 168 | auto result = constructEmptyObject(&state, globalObject.objectPrototype()); |
| 169 | |
| 170 | if (!IDLUnsignedShort::isNullValue(dictionary.channels)) { |
| 171 | auto channelsValue = toJS<IDLUnsignedShort>(IDLUnsignedShort::extractValueFromNullable(dictionary.channels)); |
| 172 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "channels" ), channelsValue); |
| 173 | } |
| 174 | auto clockRateValue = toJS<IDLUnsignedLong>(dictionary.clockRate); |
| 175 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "clockRate" ), clockRateValue); |
| 176 | auto mimeTypeValue = toJS<IDLDOMString>(state, dictionary.mimeType); |
| 177 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "mimeType" ), mimeTypeValue); |
| 178 | if (!IDLDOMString::isNullValue(dictionary.sdpFmtpLine)) { |
| 179 | auto sdpFmtpLineValue = toJS<IDLDOMString>(state, IDLDOMString::extractValueFromNullable(dictionary.sdpFmtpLine)); |
| 180 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "sdpFmtpLine" ), sdpFmtpLineValue); |
| 181 | } |
| 182 | return result; |
| 183 | } |
| 184 | |
| 185 | #endif |
| 186 | |
| 187 | #if ENABLE(WEB_RTC) |
| 188 | |
| 189 | template<> RTCRtpCapabilities::HeaderExtensionCapability convertDictionary<RTCRtpCapabilities::HeaderExtensionCapability>(ExecState& state, JSValue value) |
| 190 | { |
| 191 | VM& vm = state.vm(); |
| 192 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 193 | bool isNullOrUndefined = value.isUndefinedOrNull(); |
| 194 | auto* object = isNullOrUndefined ? nullptr : value.getObject(); |
| 195 | if (UNLIKELY(!isNullOrUndefined && !object)) { |
| 196 | throwTypeError(&state, throwScope); |
| 197 | return { }; |
| 198 | } |
| 199 | RTCRtpCapabilities::HeaderExtensionCapability result; |
| 200 | JSValue uriValue; |
| 201 | if (isNullOrUndefined) |
| 202 | uriValue = jsUndefined(); |
| 203 | else { |
| 204 | uriValue = object->get(&state, Identifier::fromString(&state, "uri" )); |
| 205 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 206 | } |
| 207 | if (!uriValue.isUndefined()) { |
| 208 | result.uri = convert<IDLDOMString>(state, uriValue); |
| 209 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 210 | } |
| 211 | return result; |
| 212 | } |
| 213 | |
| 214 | JSC::JSObject* (JSC::ExecState& state, JSDOMGlobalObject& globalObject, const RTCRtpCapabilities::HeaderExtensionCapability& dictionary) |
| 215 | { |
| 216 | auto& vm = state.vm(); |
| 217 | |
| 218 | auto result = constructEmptyObject(&state, globalObject.objectPrototype()); |
| 219 | |
| 220 | if (!IDLDOMString::isNullValue(dictionary.uri)) { |
| 221 | auto uriValue = toJS<IDLDOMString>(state, IDLDOMString::extractValueFromNullable(dictionary.uri)); |
| 222 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "uri" ), uriValue); |
| 223 | } |
| 224 | return result; |
| 225 | } |
| 226 | |
| 227 | #endif |
| 228 | |
| 229 | } // namespace WebCore |
| 230 | |
| 231 | #endif // ENABLE(WEB_RTC) |
| 232 | |