| 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 "JSFetchRequestInit.h" |
| 23 | |
| 24 | #include "JSBlob.h" |
| 25 | #include "JSDOMConvertAny.h" |
| 26 | #include "JSDOMConvertBoolean.h" |
| 27 | #include "JSDOMConvertBufferSource.h" |
| 28 | #include "JSDOMConvertEnumeration.h" |
| 29 | #include "JSDOMConvertInterface.h" |
| 30 | #include "JSDOMConvertNullable.h" |
| 31 | #include "JSDOMConvertRecord.h" |
| 32 | #include "JSDOMConvertSequences.h" |
| 33 | #include "JSDOMConvertStrings.h" |
| 34 | #include "JSDOMConvertUnion.h" |
| 35 | #include "JSDOMFormData.h" |
| 36 | #include "JSFetchReferrerPolicy.h" |
| 37 | #include "JSFetchRequestCache.h" |
| 38 | #include "JSFetchRequestCredentials.h" |
| 39 | #include "JSFetchRequestMode.h" |
| 40 | #include "JSFetchRequestRedirect.h" |
| 41 | #include "JSReadableStream.h" |
| 42 | #include "JSURLSearchParams.h" |
| 43 | #include <JavaScriptCore/JSArray.h> |
| 44 | #include <JavaScriptCore/JSCInlines.h> |
| 45 | #include <wtf/Variant.h> |
| 46 | #include <wtf/Vector.h> |
| 47 | |
| 48 | |
| 49 | namespace WebCore { |
| 50 | using namespace JSC; |
| 51 | |
| 52 | template<> FetchRequestInit convertDictionary<FetchRequestInit>(ExecState& state, JSValue value) |
| 53 | { |
| 54 | VM& vm = state.vm(); |
| 55 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 56 | bool isNullOrUndefined = value.isUndefinedOrNull(); |
| 57 | auto* object = isNullOrUndefined ? nullptr : value.getObject(); |
| 58 | if (UNLIKELY(!isNullOrUndefined && !object)) { |
| 59 | throwTypeError(&state, throwScope); |
| 60 | return { }; |
| 61 | } |
| 62 | FetchRequestInit result; |
| 63 | JSValue bodyValue; |
| 64 | if (isNullOrUndefined) |
| 65 | bodyValue = jsUndefined(); |
| 66 | else { |
| 67 | bodyValue = object->get(&state, Identifier::fromString(&state, "body" )); |
| 68 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 69 | } |
| 70 | if (!bodyValue.isUndefined()) { |
| 71 | result.body = convert<IDLNullable<IDLUnion<IDLInterface<Blob>, IDLArrayBufferView, IDLArrayBuffer, IDLInterface<DOMFormData>, IDLInterface<URLSearchParams>, IDLInterface<ReadableStream>, IDLUSVString>>>(state, bodyValue); |
| 72 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 73 | } |
| 74 | JSValue cacheValue; |
| 75 | if (isNullOrUndefined) |
| 76 | cacheValue = jsUndefined(); |
| 77 | else { |
| 78 | cacheValue = object->get(&state, Identifier::fromString(&state, "cache" )); |
| 79 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 80 | } |
| 81 | if (!cacheValue.isUndefined()) { |
| 82 | result.cache = convert<IDLEnumeration<FetchRequestCache>>(state, cacheValue); |
| 83 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 84 | } |
| 85 | JSValue credentialsValue; |
| 86 | if (isNullOrUndefined) |
| 87 | credentialsValue = jsUndefined(); |
| 88 | else { |
| 89 | credentialsValue = object->get(&state, Identifier::fromString(&state, "credentials" )); |
| 90 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 91 | } |
| 92 | if (!credentialsValue.isUndefined()) { |
| 93 | result.credentials = convert<IDLEnumeration<FetchRequestCredentials>>(state, credentialsValue); |
| 94 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 95 | } |
| 96 | JSValue ; |
| 97 | if (isNullOrUndefined) |
| 98 | headersValue = jsUndefined(); |
| 99 | else { |
| 100 | headersValue = object->get(&state, Identifier::fromString(&state, "headers" )); |
| 101 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 102 | } |
| 103 | if (!headersValue.isUndefined()) { |
| 104 | result.headers = convert<IDLUnion<IDLSequence<IDLSequence<IDLByteString>>, IDLRecord<IDLByteString, IDLByteString>>>(state, headersValue); |
| 105 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 106 | } |
| 107 | JSValue integrityValue; |
| 108 | if (isNullOrUndefined) |
| 109 | integrityValue = jsUndefined(); |
| 110 | else { |
| 111 | integrityValue = object->get(&state, Identifier::fromString(&state, "integrity" )); |
| 112 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 113 | } |
| 114 | if (!integrityValue.isUndefined()) { |
| 115 | result.integrity = convert<IDLDOMString>(state, integrityValue); |
| 116 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 117 | } |
| 118 | JSValue keepaliveValue; |
| 119 | if (isNullOrUndefined) |
| 120 | keepaliveValue = jsUndefined(); |
| 121 | else { |
| 122 | keepaliveValue = object->get(&state, Identifier::fromString(&state, "keepalive" )); |
| 123 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 124 | } |
| 125 | if (!keepaliveValue.isUndefined()) { |
| 126 | result.keepalive = convert<IDLBoolean>(state, keepaliveValue); |
| 127 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 128 | } |
| 129 | JSValue methodValue; |
| 130 | if (isNullOrUndefined) |
| 131 | methodValue = jsUndefined(); |
| 132 | else { |
| 133 | methodValue = object->get(&state, Identifier::fromString(&state, "method" )); |
| 134 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 135 | } |
| 136 | if (!methodValue.isUndefined()) { |
| 137 | result.method = convert<IDLByteString>(state, methodValue); |
| 138 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 139 | } |
| 140 | JSValue modeValue; |
| 141 | if (isNullOrUndefined) |
| 142 | modeValue = jsUndefined(); |
| 143 | else { |
| 144 | modeValue = object->get(&state, Identifier::fromString(&state, "mode" )); |
| 145 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 146 | } |
| 147 | if (!modeValue.isUndefined()) { |
| 148 | result.mode = convert<IDLEnumeration<FetchRequestMode>>(state, modeValue); |
| 149 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 150 | } |
| 151 | JSValue redirectValue; |
| 152 | if (isNullOrUndefined) |
| 153 | redirectValue = jsUndefined(); |
| 154 | else { |
| 155 | redirectValue = object->get(&state, Identifier::fromString(&state, "redirect" )); |
| 156 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 157 | } |
| 158 | if (!redirectValue.isUndefined()) { |
| 159 | result.redirect = convert<IDLEnumeration<FetchRequestRedirect>>(state, redirectValue); |
| 160 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 161 | } |
| 162 | JSValue referrerValue; |
| 163 | if (isNullOrUndefined) |
| 164 | referrerValue = jsUndefined(); |
| 165 | else { |
| 166 | referrerValue = object->get(&state, Identifier::fromString(&state, "referrer" )); |
| 167 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 168 | } |
| 169 | if (!referrerValue.isUndefined()) { |
| 170 | result.referrer = convert<IDLUSVString>(state, referrerValue); |
| 171 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 172 | } |
| 173 | JSValue referrerPolicyValue; |
| 174 | if (isNullOrUndefined) |
| 175 | referrerPolicyValue = jsUndefined(); |
| 176 | else { |
| 177 | referrerPolicyValue = object->get(&state, Identifier::fromString(&state, "referrerPolicy" )); |
| 178 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 179 | } |
| 180 | if (!referrerPolicyValue.isUndefined()) { |
| 181 | result.referrerPolicy = convert<IDLEnumeration<FetchReferrerPolicy>>(state, referrerPolicyValue); |
| 182 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 183 | } |
| 184 | JSValue signalValue; |
| 185 | if (isNullOrUndefined) |
| 186 | signalValue = jsUndefined(); |
| 187 | else { |
| 188 | signalValue = object->get(&state, Identifier::fromString(&state, "signal" )); |
| 189 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 190 | } |
| 191 | if (!signalValue.isUndefined()) { |
| 192 | result.signal = convert<IDLAny>(state, signalValue); |
| 193 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 194 | } else |
| 195 | result.signal = jsUndefined(); |
| 196 | JSValue windowValue; |
| 197 | if (isNullOrUndefined) |
| 198 | windowValue = jsUndefined(); |
| 199 | else { |
| 200 | windowValue = object->get(&state, Identifier::fromString(&state, "window" )); |
| 201 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 202 | } |
| 203 | if (!windowValue.isUndefined()) { |
| 204 | result.window = convert<IDLAny>(state, windowValue); |
| 205 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 206 | } else |
| 207 | result.window = jsUndefined(); |
| 208 | return result; |
| 209 | } |
| 210 | |
| 211 | } // namespace WebCore |
| 212 | |