| 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 "JSXMLHttpRequest.h" |
| 23 | |
| 24 | #include "EventNames.h" |
| 25 | #include "JSBlob.h" |
| 26 | #include "JSDOMAttribute.h" |
| 27 | #include "JSDOMBinding.h" |
| 28 | #include "JSDOMConstructor.h" |
| 29 | #include "JSDOMConvertBoolean.h" |
| 30 | #include "JSDOMConvertBufferSource.h" |
| 31 | #include "JSDOMConvertInterface.h" |
| 32 | #include "JSDOMConvertNullable.h" |
| 33 | #include "JSDOMConvertNumbers.h" |
| 34 | #include "JSDOMConvertStrings.h" |
| 35 | #include "JSDOMConvertUnion.h" |
| 36 | #include "JSDOMExceptionHandling.h" |
| 37 | #include "JSDOMFormData.h" |
| 38 | #include "JSDOMGlobalObject.h" |
| 39 | #include "JSDOMOperation.h" |
| 40 | #include "JSDOMWrapperCache.h" |
| 41 | #include "JSDocument.h" |
| 42 | #include "JSEventListener.h" |
| 43 | #include "JSXMLHttpRequestUpload.h" |
| 44 | #include "ScriptExecutionContext.h" |
| 45 | #include <JavaScriptCore/HeapSnapshotBuilder.h> |
| 46 | #include <JavaScriptCore/JSCInlines.h> |
| 47 | #include <JavaScriptCore/JSString.h> |
| 48 | #include <wtf/GetPtr.h> |
| 49 | #include <wtf/PointerPreparations.h> |
| 50 | #include <wtf/URL.h> |
| 51 | #include <wtf/Variant.h> |
| 52 | |
| 53 | |
| 54 | namespace WebCore { |
| 55 | using namespace JSC; |
| 56 | |
| 57 | String convertEnumerationToString(XMLHttpRequest::ResponseType enumerationValue) |
| 58 | { |
| 59 | static const NeverDestroyed<String> values[] = { |
| 60 | emptyString(), |
| 61 | MAKE_STATIC_STRING_IMPL("arraybuffer" ), |
| 62 | MAKE_STATIC_STRING_IMPL("blob" ), |
| 63 | MAKE_STATIC_STRING_IMPL("document" ), |
| 64 | MAKE_STATIC_STRING_IMPL("json" ), |
| 65 | MAKE_STATIC_STRING_IMPL("text" ), |
| 66 | }; |
| 67 | static_assert(static_cast<size_t>(XMLHttpRequest::ResponseType::EmptyString) == 0, "XMLHttpRequest::ResponseType::EmptyString is not 0 as expected" ); |
| 68 | static_assert(static_cast<size_t>(XMLHttpRequest::ResponseType::Arraybuffer) == 1, "XMLHttpRequest::ResponseType::Arraybuffer is not 1 as expected" ); |
| 69 | static_assert(static_cast<size_t>(XMLHttpRequest::ResponseType::Blob) == 2, "XMLHttpRequest::ResponseType::Blob is not 2 as expected" ); |
| 70 | static_assert(static_cast<size_t>(XMLHttpRequest::ResponseType::Document) == 3, "XMLHttpRequest::ResponseType::Document is not 3 as expected" ); |
| 71 | static_assert(static_cast<size_t>(XMLHttpRequest::ResponseType::Json) == 4, "XMLHttpRequest::ResponseType::Json is not 4 as expected" ); |
| 72 | static_assert(static_cast<size_t>(XMLHttpRequest::ResponseType::Text) == 5, "XMLHttpRequest::ResponseType::Text is not 5 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, XMLHttpRequest::ResponseType enumerationValue) |
| 78 | { |
| 79 | return jsStringWithCache(&state, convertEnumerationToString(enumerationValue)); |
| 80 | } |
| 81 | |
| 82 | template<> Optional<XMLHttpRequest::ResponseType> parseEnumeration<XMLHttpRequest::ResponseType>(ExecState& state, JSValue value) |
| 83 | { |
| 84 | auto stringValue = value.toWTFString(&state); |
| 85 | if (stringValue.isEmpty()) |
| 86 | return XMLHttpRequest::ResponseType::EmptyString; |
| 87 | if (stringValue == "arraybuffer" ) |
| 88 | return XMLHttpRequest::ResponseType::Arraybuffer; |
| 89 | if (stringValue == "blob" ) |
| 90 | return XMLHttpRequest::ResponseType::Blob; |
| 91 | if (stringValue == "document" ) |
| 92 | return XMLHttpRequest::ResponseType::Document; |
| 93 | if (stringValue == "json" ) |
| 94 | return XMLHttpRequest::ResponseType::Json; |
| 95 | if (stringValue == "text" ) |
| 96 | return XMLHttpRequest::ResponseType::Text; |
| 97 | return WTF::nullopt; |
| 98 | } |
| 99 | |
| 100 | template<> const char* expectedEnumerationValues<XMLHttpRequest::ResponseType>() |
| 101 | { |
| 102 | return "\"\", \"arraybuffer\", \"blob\", \"document\", \"json\", \"text\"" ; |
| 103 | } |
| 104 | |
| 105 | // Functions |
| 106 | |
| 107 | JSC::EncodedJSValue JSC_HOST_CALL jsXMLHttpRequestPrototypeFunctionOpen(JSC::ExecState*); |
| 108 | JSC::EncodedJSValue JSC_HOST_CALL jsXMLHttpRequestPrototypeFunctionSetRequestHeader(JSC::ExecState*); |
| 109 | JSC::EncodedJSValue JSC_HOST_CALL jsXMLHttpRequestPrototypeFunctionSend(JSC::ExecState*); |
| 110 | JSC::EncodedJSValue JSC_HOST_CALL jsXMLHttpRequestPrototypeFunctionAbort(JSC::ExecState*); |
| 111 | JSC::EncodedJSValue JSC_HOST_CALL jsXMLHttpRequestPrototypeFunctionGetResponseHeader(JSC::ExecState*); |
| 112 | JSC::EncodedJSValue JSC_HOST_CALL jsXMLHttpRequestPrototypeFunctionGetAllResponseHeaders(JSC::ExecState*); |
| 113 | JSC::EncodedJSValue JSC_HOST_CALL jsXMLHttpRequestPrototypeFunctionOverrideMimeType(JSC::ExecState*); |
| 114 | |
| 115 | // Attributes |
| 116 | |
| 117 | JSC::EncodedJSValue jsXMLHttpRequestConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 118 | bool setJSXMLHttpRequestConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| 119 | JSC::EncodedJSValue jsXMLHttpRequestOnreadystatechange(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 120 | bool setJSXMLHttpRequestOnreadystatechange(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| 121 | JSC::EncodedJSValue jsXMLHttpRequestReadyState(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 122 | JSC::EncodedJSValue jsXMLHttpRequestTimeout(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 123 | bool setJSXMLHttpRequestTimeout(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| 124 | JSC::EncodedJSValue jsXMLHttpRequestWithCredentials(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 125 | bool setJSXMLHttpRequestWithCredentials(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| 126 | JSC::EncodedJSValue jsXMLHttpRequestUpload(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 127 | JSC::EncodedJSValue jsXMLHttpRequestResponseURL(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 128 | JSC::EncodedJSValue jsXMLHttpRequestStatus(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 129 | JSC::EncodedJSValue jsXMLHttpRequestStatusText(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 130 | JSC::EncodedJSValue jsXMLHttpRequestResponseType(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 131 | bool setJSXMLHttpRequestResponseType(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| 132 | JSC::EncodedJSValue jsXMLHttpRequestResponse(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 133 | JSC::EncodedJSValue jsXMLHttpRequestResponseText(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 134 | JSC::EncodedJSValue jsXMLHttpRequestResponseXML(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 135 | |
| 136 | class JSXMLHttpRequestPrototype : public JSC::JSNonFinalObject { |
| 137 | public: |
| 138 | using Base = JSC::JSNonFinalObject; |
| 139 | static JSXMLHttpRequestPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) |
| 140 | { |
| 141 | JSXMLHttpRequestPrototype* ptr = new (NotNull, JSC::allocateCell<JSXMLHttpRequestPrototype>(vm.heap)) JSXMLHttpRequestPrototype(vm, globalObject, structure); |
| 142 | ptr->finishCreation(vm); |
| 143 | return ptr; |
| 144 | } |
| 145 | |
| 146 | DECLARE_INFO; |
| 147 | static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
| 148 | { |
| 149 | return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
| 150 | } |
| 151 | |
| 152 | private: |
| 153 | JSXMLHttpRequestPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
| 154 | : JSC::JSNonFinalObject(vm, structure) |
| 155 | { |
| 156 | } |
| 157 | |
| 158 | void finishCreation(JSC::VM&); |
| 159 | }; |
| 160 | |
| 161 | using JSXMLHttpRequestConstructor = JSDOMConstructor<JSXMLHttpRequest>; |
| 162 | |
| 163 | /* Hash table for constructor */ |
| 164 | |
| 165 | static const HashTableValue JSXMLHttpRequestConstructorTableValues[] = |
| 166 | { |
| 167 | { "UNSENT" , JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(0) } }, |
| 168 | { "OPENED" , JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(1) } }, |
| 169 | { "HEADERS_RECEIVED" , JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(2) } }, |
| 170 | { "LOADING" , JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(3) } }, |
| 171 | { "DONE" , JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(4) } }, |
| 172 | }; |
| 173 | |
| 174 | static_assert(XMLHttpRequest::UNSENT == 0, "UNSENT in XMLHttpRequest does not match value from IDL" ); |
| 175 | static_assert(XMLHttpRequest::OPENED == 1, "OPENED in XMLHttpRequest does not match value from IDL" ); |
| 176 | static_assert(XMLHttpRequest::HEADERS_RECEIVED == 2, "HEADERS_RECEIVED in XMLHttpRequest does not match value from IDL" ); |
| 177 | static_assert(XMLHttpRequest::LOADING == 3, "LOADING in XMLHttpRequest does not match value from IDL" ); |
| 178 | static_assert(XMLHttpRequest::DONE == 4, "DONE in XMLHttpRequest does not match value from IDL" ); |
| 179 | |
| 180 | template<> EncodedJSValue JSC_HOST_CALL JSXMLHttpRequestConstructor::construct(ExecState* state) |
| 181 | { |
| 182 | VM& vm = state->vm(); |
| 183 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 184 | UNUSED_PARAM(throwScope); |
| 185 | auto* castedThis = jsCast<JSXMLHttpRequestConstructor*>(state->jsCallee()); |
| 186 | ASSERT(castedThis); |
| 187 | auto* context = castedThis->scriptExecutionContext(); |
| 188 | if (UNLIKELY(!context)) |
| 189 | return throwConstructorScriptExecutionContextUnavailableError(*state, throwScope, "XMLHttpRequest" ); |
| 190 | auto object = XMLHttpRequest::create(*context); |
| 191 | return JSValue::encode(toJSNewlyCreated<IDLInterface<XMLHttpRequest>>(*state, *castedThis->globalObject(), WTFMove(object))); |
| 192 | } |
| 193 | |
| 194 | template<> JSValue JSXMLHttpRequestConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
| 195 | { |
| 196 | return JSXMLHttpRequestEventTarget::getConstructor(vm, &globalObject); |
| 197 | } |
| 198 | |
| 199 | template<> void JSXMLHttpRequestConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
| 200 | { |
| 201 | putDirect(vm, vm.propertyNames->prototype, JSXMLHttpRequest::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 202 | putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("XMLHttpRequest"_s )), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 203 | putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 204 | reifyStaticProperties(vm, JSXMLHttpRequest::info(), JSXMLHttpRequestConstructorTableValues, *this); |
| 205 | } |
| 206 | |
| 207 | template<> const ClassInfo JSXMLHttpRequestConstructor::s_info = { "XMLHttpRequest" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSXMLHttpRequestConstructor) }; |
| 208 | |
| 209 | /* Hash table for prototype */ |
| 210 | |
| 211 | static const HashTableValue JSXMLHttpRequestPrototypeTableValues[] = |
| 212 | { |
| 213 | { "constructor" , static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsXMLHttpRequestConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSXMLHttpRequestConstructor) } }, |
| 214 | { "onreadystatechange" , static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsXMLHttpRequestOnreadystatechange), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSXMLHttpRequestOnreadystatechange) } }, |
| 215 | { "readyState" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsXMLHttpRequestReadyState), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| 216 | { "timeout" , static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsXMLHttpRequestTimeout), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSXMLHttpRequestTimeout) } }, |
| 217 | { "withCredentials" , static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsXMLHttpRequestWithCredentials), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSXMLHttpRequestWithCredentials) } }, |
| 218 | { "upload" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsXMLHttpRequestUpload), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| 219 | { "responseURL" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsXMLHttpRequestResponseURL), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| 220 | { "status" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsXMLHttpRequestStatus), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| 221 | { "statusText" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsXMLHttpRequestStatusText), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| 222 | { "responseType" , static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsXMLHttpRequestResponseType), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSXMLHttpRequestResponseType) } }, |
| 223 | { "response" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsXMLHttpRequestResponse), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| 224 | { "responseText" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsXMLHttpRequestResponseText), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| 225 | { "responseXML" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsXMLHttpRequestResponseXML), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| 226 | { "open" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsXMLHttpRequestPrototypeFunctionOpen), (intptr_t) (2) } }, |
| 227 | { "setRequestHeader" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsXMLHttpRequestPrototypeFunctionSetRequestHeader), (intptr_t) (2) } }, |
| 228 | { "send" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsXMLHttpRequestPrototypeFunctionSend), (intptr_t) (0) } }, |
| 229 | { "abort" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsXMLHttpRequestPrototypeFunctionAbort), (intptr_t) (0) } }, |
| 230 | { "getResponseHeader" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsXMLHttpRequestPrototypeFunctionGetResponseHeader), (intptr_t) (1) } }, |
| 231 | { "getAllResponseHeaders" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsXMLHttpRequestPrototypeFunctionGetAllResponseHeaders), (intptr_t) (0) } }, |
| 232 | { "overrideMimeType" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsXMLHttpRequestPrototypeFunctionOverrideMimeType), (intptr_t) (1) } }, |
| 233 | { "UNSENT" , JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(0) } }, |
| 234 | { "OPENED" , JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(1) } }, |
| 235 | { "HEADERS_RECEIVED" , JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(2) } }, |
| 236 | { "LOADING" , JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(3) } }, |
| 237 | { "DONE" , JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(4) } }, |
| 238 | }; |
| 239 | |
| 240 | const ClassInfo JSXMLHttpRequestPrototype::s_info = { "XMLHttpRequestPrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSXMLHttpRequestPrototype) }; |
| 241 | |
| 242 | void JSXMLHttpRequestPrototype::finishCreation(VM& vm) |
| 243 | { |
| 244 | Base::finishCreation(vm); |
| 245 | reifyStaticProperties(vm, JSXMLHttpRequest::info(), JSXMLHttpRequestPrototypeTableValues, *this); |
| 246 | bool hasDisabledRuntimeProperties = false; |
| 247 | if (!jsCast<JSDOMGlobalObject*>(globalObject())->scriptExecutionContext()->isDocument()) { |
| 248 | hasDisabledRuntimeProperties = true; |
| 249 | auto propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("responseXML" ), strlen("responseXML" )); |
| 250 | VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable); |
| 251 | JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName); |
| 252 | } |
| 253 | if (hasDisabledRuntimeProperties && structure()->isDictionary()) |
| 254 | flattenDictionaryObject(vm); |
| 255 | } |
| 256 | |
| 257 | const ClassInfo JSXMLHttpRequest::s_info = { "XMLHttpRequest" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSXMLHttpRequest) }; |
| 258 | |
| 259 | JSXMLHttpRequest::JSXMLHttpRequest(Structure* structure, JSDOMGlobalObject& globalObject, Ref<XMLHttpRequest>&& impl) |
| 260 | : JSXMLHttpRequestEventTarget(structure, globalObject, WTFMove(impl)) |
| 261 | { |
| 262 | } |
| 263 | |
| 264 | void JSXMLHttpRequest::finishCreation(VM& vm) |
| 265 | { |
| 266 | Base::finishCreation(vm); |
| 267 | ASSERT(inherits(vm, info())); |
| 268 | |
| 269 | } |
| 270 | |
| 271 | JSObject* JSXMLHttpRequest::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
| 272 | { |
| 273 | return JSXMLHttpRequestPrototype::create(vm, &globalObject, JSXMLHttpRequestPrototype::createStructure(vm, &globalObject, JSXMLHttpRequestEventTarget::prototype(vm, globalObject))); |
| 274 | } |
| 275 | |
| 276 | JSObject* JSXMLHttpRequest::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
| 277 | { |
| 278 | return getDOMPrototype<JSXMLHttpRequest>(vm, globalObject); |
| 279 | } |
| 280 | |
| 281 | JSValue JSXMLHttpRequest::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
| 282 | { |
| 283 | return getDOMConstructor<JSXMLHttpRequestConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
| 284 | } |
| 285 | |
| 286 | template<> inline JSXMLHttpRequest* IDLAttribute<JSXMLHttpRequest>::cast(ExecState& state, EncodedJSValue thisValue) |
| 287 | { |
| 288 | return jsDynamicCast<JSXMLHttpRequest*>(state.vm(), JSValue::decode(thisValue)); |
| 289 | } |
| 290 | |
| 291 | template<> inline JSXMLHttpRequest* IDLOperation<JSXMLHttpRequest>::cast(ExecState& state) |
| 292 | { |
| 293 | return jsDynamicCast<JSXMLHttpRequest*>(state.vm(), state.thisValue()); |
| 294 | } |
| 295 | |
| 296 | EncodedJSValue jsXMLHttpRequestConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 297 | { |
| 298 | VM& vm = state->vm(); |
| 299 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 300 | auto* prototype = jsDynamicCast<JSXMLHttpRequestPrototype*>(vm, JSValue::decode(thisValue)); |
| 301 | if (UNLIKELY(!prototype)) |
| 302 | return throwVMTypeError(state, throwScope); |
| 303 | return JSValue::encode(JSXMLHttpRequest::getConstructor(state->vm(), prototype->globalObject())); |
| 304 | } |
| 305 | |
| 306 | bool setJSXMLHttpRequestConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| 307 | { |
| 308 | VM& vm = state->vm(); |
| 309 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 310 | auto* prototype = jsDynamicCast<JSXMLHttpRequestPrototype*>(vm, JSValue::decode(thisValue)); |
| 311 | if (UNLIKELY(!prototype)) { |
| 312 | throwVMTypeError(state, throwScope); |
| 313 | return false; |
| 314 | } |
| 315 | // Shadowing a built-in constructor |
| 316 | return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue)); |
| 317 | } |
| 318 | |
| 319 | static inline JSValue jsXMLHttpRequestOnreadystatechangeGetter(ExecState& state, JSXMLHttpRequest& thisObject, ThrowScope& throwScope) |
| 320 | { |
| 321 | UNUSED_PARAM(throwScope); |
| 322 | UNUSED_PARAM(state); |
| 323 | return eventHandlerAttribute(thisObject.wrapped(), eventNames().readystatechangeEvent, worldForDOMObject(thisObject)); |
| 324 | } |
| 325 | |
| 326 | EncodedJSValue jsXMLHttpRequestOnreadystatechange(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 327 | { |
| 328 | return IDLAttribute<JSXMLHttpRequest>::get<jsXMLHttpRequestOnreadystatechangeGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "onreadystatechange" ); |
| 329 | } |
| 330 | |
| 331 | static inline bool setJSXMLHttpRequestOnreadystatechangeSetter(ExecState& state, JSXMLHttpRequest& thisObject, JSValue value, ThrowScope& throwScope) |
| 332 | { |
| 333 | UNUSED_PARAM(throwScope); |
| 334 | setEventHandlerAttribute(state, thisObject, thisObject.wrapped(), eventNames().readystatechangeEvent, value); |
| 335 | return true; |
| 336 | } |
| 337 | |
| 338 | bool setJSXMLHttpRequestOnreadystatechange(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| 339 | { |
| 340 | return IDLAttribute<JSXMLHttpRequest>::set<setJSXMLHttpRequestOnreadystatechangeSetter>(*state, thisValue, encodedValue, "onreadystatechange" ); |
| 341 | } |
| 342 | |
| 343 | static inline JSValue jsXMLHttpRequestReadyStateGetter(ExecState& state, JSXMLHttpRequest& thisObject, ThrowScope& throwScope) |
| 344 | { |
| 345 | UNUSED_PARAM(throwScope); |
| 346 | UNUSED_PARAM(state); |
| 347 | auto& impl = thisObject.wrapped(); |
| 348 | JSValue result = toJS<IDLUnsignedShort>(state, throwScope, impl.readyState()); |
| 349 | return result; |
| 350 | } |
| 351 | |
| 352 | EncodedJSValue jsXMLHttpRequestReadyState(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 353 | { |
| 354 | return IDLAttribute<JSXMLHttpRequest>::get<jsXMLHttpRequestReadyStateGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "readyState" ); |
| 355 | } |
| 356 | |
| 357 | static inline JSValue jsXMLHttpRequestTimeoutGetter(ExecState& state, JSXMLHttpRequest& thisObject, ThrowScope& throwScope) |
| 358 | { |
| 359 | UNUSED_PARAM(throwScope); |
| 360 | UNUSED_PARAM(state); |
| 361 | auto& impl = thisObject.wrapped(); |
| 362 | JSValue result = toJS<IDLUnsignedLong>(state, throwScope, impl.timeout()); |
| 363 | return result; |
| 364 | } |
| 365 | |
| 366 | EncodedJSValue jsXMLHttpRequestTimeout(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 367 | { |
| 368 | return IDLAttribute<JSXMLHttpRequest>::get<jsXMLHttpRequestTimeoutGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "timeout" ); |
| 369 | } |
| 370 | |
| 371 | static inline bool setJSXMLHttpRequestTimeoutSetter(ExecState& state, JSXMLHttpRequest& thisObject, JSValue value, ThrowScope& throwScope) |
| 372 | { |
| 373 | UNUSED_PARAM(throwScope); |
| 374 | auto& impl = thisObject.wrapped(); |
| 375 | auto nativeValue = convert<IDLUnsignedLong>(state, value); |
| 376 | RETURN_IF_EXCEPTION(throwScope, false); |
| 377 | AttributeSetter::call(state, throwScope, [&] { |
| 378 | return impl.setTimeout(WTFMove(nativeValue)); |
| 379 | }); |
| 380 | return true; |
| 381 | } |
| 382 | |
| 383 | bool setJSXMLHttpRequestTimeout(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| 384 | { |
| 385 | return IDLAttribute<JSXMLHttpRequest>::set<setJSXMLHttpRequestTimeoutSetter>(*state, thisValue, encodedValue, "timeout" ); |
| 386 | } |
| 387 | |
| 388 | static inline JSValue jsXMLHttpRequestWithCredentialsGetter(ExecState& state, JSXMLHttpRequest& thisObject, ThrowScope& throwScope) |
| 389 | { |
| 390 | UNUSED_PARAM(throwScope); |
| 391 | UNUSED_PARAM(state); |
| 392 | auto& impl = thisObject.wrapped(); |
| 393 | JSValue result = toJS<IDLBoolean>(state, throwScope, impl.withCredentials()); |
| 394 | return result; |
| 395 | } |
| 396 | |
| 397 | EncodedJSValue jsXMLHttpRequestWithCredentials(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 398 | { |
| 399 | return IDLAttribute<JSXMLHttpRequest>::get<jsXMLHttpRequestWithCredentialsGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "withCredentials" ); |
| 400 | } |
| 401 | |
| 402 | static inline bool setJSXMLHttpRequestWithCredentialsSetter(ExecState& state, JSXMLHttpRequest& thisObject, JSValue value, ThrowScope& throwScope) |
| 403 | { |
| 404 | UNUSED_PARAM(throwScope); |
| 405 | auto& impl = thisObject.wrapped(); |
| 406 | auto nativeValue = convert<IDLBoolean>(state, value); |
| 407 | RETURN_IF_EXCEPTION(throwScope, false); |
| 408 | AttributeSetter::call(state, throwScope, [&] { |
| 409 | return impl.setWithCredentials(WTFMove(nativeValue)); |
| 410 | }); |
| 411 | return true; |
| 412 | } |
| 413 | |
| 414 | bool setJSXMLHttpRequestWithCredentials(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| 415 | { |
| 416 | return IDLAttribute<JSXMLHttpRequest>::set<setJSXMLHttpRequestWithCredentialsSetter>(*state, thisValue, encodedValue, "withCredentials" ); |
| 417 | } |
| 418 | |
| 419 | static inline JSValue jsXMLHttpRequestUploadGetter(ExecState& state, JSXMLHttpRequest& thisObject, ThrowScope& throwScope) |
| 420 | { |
| 421 | UNUSED_PARAM(throwScope); |
| 422 | UNUSED_PARAM(state); |
| 423 | auto& impl = thisObject.wrapped(); |
| 424 | JSValue result = toJS<IDLInterface<XMLHttpRequestUpload>>(state, *thisObject.globalObject(), throwScope, impl.upload()); |
| 425 | return result; |
| 426 | } |
| 427 | |
| 428 | EncodedJSValue jsXMLHttpRequestUpload(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 429 | { |
| 430 | return IDLAttribute<JSXMLHttpRequest>::get<jsXMLHttpRequestUploadGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "upload" ); |
| 431 | } |
| 432 | |
| 433 | static inline JSValue jsXMLHttpRequestResponseURLGetter(ExecState& state, JSXMLHttpRequest& thisObject, ThrowScope& throwScope) |
| 434 | { |
| 435 | UNUSED_PARAM(throwScope); |
| 436 | UNUSED_PARAM(state); |
| 437 | auto& impl = thisObject.wrapped(); |
| 438 | JSValue result = toJS<IDLUSVString>(state, throwScope, impl.responseURL()); |
| 439 | return result; |
| 440 | } |
| 441 | |
| 442 | EncodedJSValue jsXMLHttpRequestResponseURL(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 443 | { |
| 444 | return IDLAttribute<JSXMLHttpRequest>::get<jsXMLHttpRequestResponseURLGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "responseURL" ); |
| 445 | } |
| 446 | |
| 447 | static inline JSValue jsXMLHttpRequestStatusGetter(ExecState& state, JSXMLHttpRequest& thisObject, ThrowScope& throwScope) |
| 448 | { |
| 449 | UNUSED_PARAM(throwScope); |
| 450 | UNUSED_PARAM(state); |
| 451 | auto& impl = thisObject.wrapped(); |
| 452 | JSValue result = toJS<IDLUnsignedShort>(state, throwScope, impl.status()); |
| 453 | return result; |
| 454 | } |
| 455 | |
| 456 | EncodedJSValue jsXMLHttpRequestStatus(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 457 | { |
| 458 | return IDLAttribute<JSXMLHttpRequest>::get<jsXMLHttpRequestStatusGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "status" ); |
| 459 | } |
| 460 | |
| 461 | static inline JSValue jsXMLHttpRequestStatusTextGetter(ExecState& state, JSXMLHttpRequest& thisObject, ThrowScope& throwScope) |
| 462 | { |
| 463 | UNUSED_PARAM(throwScope); |
| 464 | UNUSED_PARAM(state); |
| 465 | auto& impl = thisObject.wrapped(); |
| 466 | JSValue result = toJS<IDLByteString>(state, throwScope, impl.statusText()); |
| 467 | return result; |
| 468 | } |
| 469 | |
| 470 | EncodedJSValue jsXMLHttpRequestStatusText(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 471 | { |
| 472 | return IDLAttribute<JSXMLHttpRequest>::get<jsXMLHttpRequestStatusTextGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "statusText" ); |
| 473 | } |
| 474 | |
| 475 | static inline JSValue jsXMLHttpRequestResponseTypeGetter(ExecState& state, JSXMLHttpRequest& thisObject, ThrowScope& throwScope) |
| 476 | { |
| 477 | UNUSED_PARAM(throwScope); |
| 478 | UNUSED_PARAM(state); |
| 479 | auto& impl = thisObject.wrapped(); |
| 480 | JSValue result = toJS<IDLEnumeration<XMLHttpRequest::ResponseType>>(state, throwScope, impl.responseType()); |
| 481 | return result; |
| 482 | } |
| 483 | |
| 484 | EncodedJSValue jsXMLHttpRequestResponseType(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 485 | { |
| 486 | return IDLAttribute<JSXMLHttpRequest>::get<jsXMLHttpRequestResponseTypeGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "responseType" ); |
| 487 | } |
| 488 | |
| 489 | static inline bool setJSXMLHttpRequestResponseTypeSetter(ExecState& state, JSXMLHttpRequest& thisObject, JSValue value, ThrowScope& throwScope) |
| 490 | { |
| 491 | UNUSED_PARAM(throwScope); |
| 492 | auto& impl = thisObject.wrapped(); |
| 493 | auto optionalNativeValue = parseEnumeration<XMLHttpRequest::ResponseType>(state, value); |
| 494 | RETURN_IF_EXCEPTION(throwScope, false); |
| 495 | if (UNLIKELY(!optionalNativeValue)) |
| 496 | return false; |
| 497 | auto nativeValue = optionalNativeValue.value(); |
| 498 | AttributeSetter::call(state, throwScope, [&] { |
| 499 | return impl.setResponseType(WTFMove(nativeValue)); |
| 500 | }); |
| 501 | return true; |
| 502 | } |
| 503 | |
| 504 | bool setJSXMLHttpRequestResponseType(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| 505 | { |
| 506 | return IDLAttribute<JSXMLHttpRequest>::set<setJSXMLHttpRequestResponseTypeSetter>(*state, thisValue, encodedValue, "responseType" ); |
| 507 | } |
| 508 | |
| 509 | static inline JSValue jsXMLHttpRequestResponseGetter(ExecState& state, JSXMLHttpRequest& thisObject, ThrowScope& throwScope) |
| 510 | { |
| 511 | UNUSED_PARAM(throwScope); |
| 512 | UNUSED_PARAM(state); |
| 513 | return thisObject.response(state); |
| 514 | } |
| 515 | |
| 516 | EncodedJSValue jsXMLHttpRequestResponse(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 517 | { |
| 518 | return IDLAttribute<JSXMLHttpRequest>::get<jsXMLHttpRequestResponseGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "response" ); |
| 519 | } |
| 520 | |
| 521 | static inline JSValue jsXMLHttpRequestResponseTextGetter(ExecState& state, JSXMLHttpRequest& thisObject, ThrowScope& throwScope) |
| 522 | { |
| 523 | UNUSED_PARAM(throwScope); |
| 524 | UNUSED_PARAM(state); |
| 525 | auto& impl = thisObject.wrapped(); |
| 526 | JSValue result = toJS<IDLUSVString>(state, throwScope, impl.responseText()); |
| 527 | return result; |
| 528 | } |
| 529 | |
| 530 | EncodedJSValue jsXMLHttpRequestResponseText(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 531 | { |
| 532 | return IDLAttribute<JSXMLHttpRequest>::get<jsXMLHttpRequestResponseTextGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "responseText" ); |
| 533 | } |
| 534 | |
| 535 | static inline JSValue jsXMLHttpRequestResponseXMLGetter(ExecState& state, JSXMLHttpRequest& thisObject, ThrowScope& throwScope) |
| 536 | { |
| 537 | UNUSED_PARAM(throwScope); |
| 538 | UNUSED_PARAM(state); |
| 539 | auto& impl = thisObject.wrapped(); |
| 540 | JSValue result = toJS<IDLNullable<IDLInterface<Document>>>(state, *thisObject.globalObject(), throwScope, impl.responseXML()); |
| 541 | return result; |
| 542 | } |
| 543 | |
| 544 | EncodedJSValue jsXMLHttpRequestResponseXML(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 545 | { |
| 546 | return IDLAttribute<JSXMLHttpRequest>::get<jsXMLHttpRequestResponseXMLGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "responseXML" ); |
| 547 | } |
| 548 | |
| 549 | static inline JSC::EncodedJSValue jsXMLHttpRequestPrototypeFunctionOpen1Body(JSC::ExecState* state, typename IDLOperation<JSXMLHttpRequest>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 550 | { |
| 551 | UNUSED_PARAM(state); |
| 552 | UNUSED_PARAM(throwScope); |
| 553 | auto& impl = castedThis->wrapped(); |
| 554 | auto method = convert<IDLByteString>(*state, state->uncheckedArgument(0)); |
| 555 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 556 | auto url = convert<IDLDOMString>(*state, state->uncheckedArgument(1)); |
| 557 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 558 | propagateException(*state, throwScope, impl.open(WTFMove(method), WTFMove(url))); |
| 559 | return JSValue::encode(jsUndefined()); |
| 560 | } |
| 561 | |
| 562 | static inline JSC::EncodedJSValue jsXMLHttpRequestPrototypeFunctionOpen2Body(JSC::ExecState* state, typename IDLOperation<JSXMLHttpRequest>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 563 | { |
| 564 | UNUSED_PARAM(state); |
| 565 | UNUSED_PARAM(throwScope); |
| 566 | auto& impl = castedThis->wrapped(); |
| 567 | auto method = convert<IDLByteString>(*state, state->uncheckedArgument(0)); |
| 568 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 569 | auto url = convert<IDLDOMString>(*state, state->uncheckedArgument(1)); |
| 570 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 571 | auto async = convert<IDLBoolean>(*state, state->uncheckedArgument(2)); |
| 572 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 573 | auto user = state->argument(3).isUndefined() ? String() : convert<IDLNullable<IDLDOMString>>(*state, state->uncheckedArgument(3)); |
| 574 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 575 | auto password = state->argument(4).isUndefined() ? String() : convert<IDLNullable<IDLDOMString>>(*state, state->uncheckedArgument(4)); |
| 576 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 577 | propagateException(*state, throwScope, impl.open(WTFMove(method), WTFMove(url), WTFMove(async), WTFMove(user), WTFMove(password))); |
| 578 | return JSValue::encode(jsUndefined()); |
| 579 | } |
| 580 | |
| 581 | static inline JSC::EncodedJSValue jsXMLHttpRequestPrototypeFunctionOpenOverloadDispatcher(JSC::ExecState* state, typename IDLOperation<JSXMLHttpRequest>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 582 | { |
| 583 | UNUSED_PARAM(state); |
| 584 | UNUSED_PARAM(throwScope); |
| 585 | VM& vm = state->vm(); |
| 586 | UNUSED_PARAM(vm); |
| 587 | size_t argsCount = std::min<size_t>(5, state->argumentCount()); |
| 588 | if (argsCount == 2) { |
| 589 | return jsXMLHttpRequestPrototypeFunctionOpen1Body(state, castedThis, throwScope); |
| 590 | } |
| 591 | if (argsCount == 3) { |
| 592 | return jsXMLHttpRequestPrototypeFunctionOpen2Body(state, castedThis, throwScope); |
| 593 | } |
| 594 | if (argsCount == 4) { |
| 595 | return jsXMLHttpRequestPrototypeFunctionOpen2Body(state, castedThis, throwScope); |
| 596 | } |
| 597 | if (argsCount == 5) { |
| 598 | return jsXMLHttpRequestPrototypeFunctionOpen2Body(state, castedThis, throwScope); |
| 599 | } |
| 600 | return argsCount < 2 ? throwVMError(state, throwScope, createNotEnoughArgumentsError(state)) : throwVMTypeError(state, throwScope); |
| 601 | } |
| 602 | |
| 603 | EncodedJSValue JSC_HOST_CALL jsXMLHttpRequestPrototypeFunctionOpen(ExecState* state) |
| 604 | { |
| 605 | return IDLOperation<JSXMLHttpRequest>::call<jsXMLHttpRequestPrototypeFunctionOpenOverloadDispatcher>(*state, "open" ); |
| 606 | } |
| 607 | |
| 608 | static inline JSC::EncodedJSValue jsXMLHttpRequestPrototypeFunctionSetRequestHeaderBody(JSC::ExecState* state, typename IDLOperation<JSXMLHttpRequest>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 609 | { |
| 610 | UNUSED_PARAM(state); |
| 611 | UNUSED_PARAM(throwScope); |
| 612 | auto& impl = castedThis->wrapped(); |
| 613 | if (UNLIKELY(state->argumentCount() < 2)) |
| 614 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| 615 | auto = convert<IDLByteString>(*state, state->uncheckedArgument(0)); |
| 616 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 617 | auto value = convert<IDLByteString>(*state, state->uncheckedArgument(1)); |
| 618 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 619 | propagateException(*state, throwScope, impl.setRequestHeader(WTFMove(header), WTFMove(value))); |
| 620 | return JSValue::encode(jsUndefined()); |
| 621 | } |
| 622 | |
| 623 | EncodedJSValue JSC_HOST_CALL (ExecState* state) |
| 624 | { |
| 625 | return IDLOperation<JSXMLHttpRequest>::call<jsXMLHttpRequestPrototypeFunctionSetRequestHeaderBody>(*state, "setRequestHeader" ); |
| 626 | } |
| 627 | |
| 628 | static inline JSC::EncodedJSValue jsXMLHttpRequestPrototypeFunctionSendBody(JSC::ExecState* state, typename IDLOperation<JSXMLHttpRequest>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 629 | { |
| 630 | UNUSED_PARAM(state); |
| 631 | UNUSED_PARAM(throwScope); |
| 632 | auto& impl = castedThis->wrapped(); |
| 633 | auto body = state->argument(0).isUndefined() ? WTF::nullopt : convert<IDLNullable<IDLUnion<IDLInterface<Document>, IDLInterface<Blob>, IDLArrayBufferView, IDLArrayBuffer, IDLInterface<DOMFormData>, IDLUSVString>>>(*state, state->uncheckedArgument(0)); |
| 634 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 635 | propagateException(*state, throwScope, impl.send(WTFMove(body))); |
| 636 | return JSValue::encode(jsUndefined()); |
| 637 | } |
| 638 | |
| 639 | EncodedJSValue JSC_HOST_CALL jsXMLHttpRequestPrototypeFunctionSend(ExecState* state) |
| 640 | { |
| 641 | return IDLOperation<JSXMLHttpRequest>::call<jsXMLHttpRequestPrototypeFunctionSendBody>(*state, "send" ); |
| 642 | } |
| 643 | |
| 644 | static inline JSC::EncodedJSValue jsXMLHttpRequestPrototypeFunctionAbortBody(JSC::ExecState* state, typename IDLOperation<JSXMLHttpRequest>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 645 | { |
| 646 | UNUSED_PARAM(state); |
| 647 | UNUSED_PARAM(throwScope); |
| 648 | auto& impl = castedThis->wrapped(); |
| 649 | impl.abort(); |
| 650 | return JSValue::encode(jsUndefined()); |
| 651 | } |
| 652 | |
| 653 | EncodedJSValue JSC_HOST_CALL jsXMLHttpRequestPrototypeFunctionAbort(ExecState* state) |
| 654 | { |
| 655 | return IDLOperation<JSXMLHttpRequest>::call<jsXMLHttpRequestPrototypeFunctionAbortBody>(*state, "abort" ); |
| 656 | } |
| 657 | |
| 658 | static inline JSC::EncodedJSValue jsXMLHttpRequestPrototypeFunctionGetResponseHeaderBody(JSC::ExecState* state, typename IDLOperation<JSXMLHttpRequest>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 659 | { |
| 660 | UNUSED_PARAM(state); |
| 661 | UNUSED_PARAM(throwScope); |
| 662 | auto& impl = castedThis->wrapped(); |
| 663 | if (UNLIKELY(state->argumentCount() < 1)) |
| 664 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| 665 | auto name = convert<IDLByteString>(*state, state->uncheckedArgument(0)); |
| 666 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 667 | return JSValue::encode(toJS<IDLNullable<IDLByteString>>(*state, impl.getResponseHeader(WTFMove(name)))); |
| 668 | } |
| 669 | |
| 670 | EncodedJSValue JSC_HOST_CALL (ExecState* state) |
| 671 | { |
| 672 | return IDLOperation<JSXMLHttpRequest>::call<jsXMLHttpRequestPrototypeFunctionGetResponseHeaderBody>(*state, "getResponseHeader" ); |
| 673 | } |
| 674 | |
| 675 | static inline JSC::EncodedJSValue jsXMLHttpRequestPrototypeFunctionGetAllResponseHeadersBody(JSC::ExecState* state, typename IDLOperation<JSXMLHttpRequest>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 676 | { |
| 677 | UNUSED_PARAM(state); |
| 678 | UNUSED_PARAM(throwScope); |
| 679 | auto& impl = castedThis->wrapped(); |
| 680 | return JSValue::encode(toJS<IDLByteString>(*state, impl.getAllResponseHeaders())); |
| 681 | } |
| 682 | |
| 683 | EncodedJSValue JSC_HOST_CALL (ExecState* state) |
| 684 | { |
| 685 | return IDLOperation<JSXMLHttpRequest>::call<jsXMLHttpRequestPrototypeFunctionGetAllResponseHeadersBody>(*state, "getAllResponseHeaders" ); |
| 686 | } |
| 687 | |
| 688 | static inline JSC::EncodedJSValue jsXMLHttpRequestPrototypeFunctionOverrideMimeTypeBody(JSC::ExecState* state, typename IDLOperation<JSXMLHttpRequest>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 689 | { |
| 690 | UNUSED_PARAM(state); |
| 691 | UNUSED_PARAM(throwScope); |
| 692 | auto& impl = castedThis->wrapped(); |
| 693 | if (UNLIKELY(state->argumentCount() < 1)) |
| 694 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
| 695 | auto mime = convert<IDLDOMString>(*state, state->uncheckedArgument(0)); |
| 696 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 697 | propagateException(*state, throwScope, impl.overrideMimeType(WTFMove(mime))); |
| 698 | return JSValue::encode(jsUndefined()); |
| 699 | } |
| 700 | |
| 701 | EncodedJSValue JSC_HOST_CALL jsXMLHttpRequestPrototypeFunctionOverrideMimeType(ExecState* state) |
| 702 | { |
| 703 | return IDLOperation<JSXMLHttpRequest>::call<jsXMLHttpRequestPrototypeFunctionOverrideMimeTypeBody>(*state, "overrideMimeType" ); |
| 704 | } |
| 705 | |
| 706 | void JSXMLHttpRequest::visitChildren(JSCell* cell, SlotVisitor& visitor) |
| 707 | { |
| 708 | auto* thisObject = jsCast<JSXMLHttpRequest*>(cell); |
| 709 | ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
| 710 | Base::visitChildren(thisObject, visitor); |
| 711 | thisObject->visitAdditionalChildren(visitor); |
| 712 | visitor.reportExtraMemoryVisited(thisObject->wrapped().memoryCost()); |
| 713 | visitor.append(thisObject->m_response); |
| 714 | } |
| 715 | |
| 716 | void JSXMLHttpRequest::visitOutputConstraints(JSCell* cell, SlotVisitor& visitor) |
| 717 | { |
| 718 | auto* thisObject = jsCast<JSXMLHttpRequest*>(cell); |
| 719 | ASSERT_GC_OBJECT_INHERITS(thisObject, info()); |
| 720 | Base::visitOutputConstraints(thisObject, visitor); |
| 721 | thisObject->visitAdditionalChildren(visitor); |
| 722 | } |
| 723 | |
| 724 | size_t JSXMLHttpRequest::estimatedSize(JSCell* cell, VM& vm) |
| 725 | { |
| 726 | auto* thisObject = jsCast<JSXMLHttpRequest*>(cell); |
| 727 | return Base::estimatedSize(thisObject, vm) + thisObject->wrapped().memoryCost(); |
| 728 | } |
| 729 | |
| 730 | void JSXMLHttpRequest::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder) |
| 731 | { |
| 732 | auto* thisObject = jsCast<JSXMLHttpRequest*>(cell); |
| 733 | builder.setWrappedObjectForCell(cell, &thisObject->wrapped()); |
| 734 | if (thisObject->scriptExecutionContext()) |
| 735 | builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); |
| 736 | Base::heapSnapshot(cell, builder); |
| 737 | } |
| 738 | |
| 739 | bool JSXMLHttpRequestOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason) |
| 740 | { |
| 741 | auto* jsXMLHttpRequest = jsCast<JSXMLHttpRequest*>(handle.slot()->asCell()); |
| 742 | if (jsXMLHttpRequest->wrapped().hasPendingActivity()) { |
| 743 | if (UNLIKELY(reason)) |
| 744 | *reason = "ActiveDOMObject with pending activity" ; |
| 745 | return true; |
| 746 | } |
| 747 | if (jsXMLHttpRequest->wrapped().isFiringEventListeners()) { |
| 748 | if (UNLIKELY(reason)) |
| 749 | *reason = "EventTarget firing event listeners" ; |
| 750 | return true; |
| 751 | } |
| 752 | UNUSED_PARAM(visitor); |
| 753 | UNUSED_PARAM(reason); |
| 754 | return false; |
| 755 | } |
| 756 | |
| 757 | void JSXMLHttpRequestOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context) |
| 758 | { |
| 759 | auto* jsXMLHttpRequest = static_cast<JSXMLHttpRequest*>(handle.slot()->asCell()); |
| 760 | auto& world = *static_cast<DOMWrapperWorld*>(context); |
| 761 | uncacheWrapper(world, &jsXMLHttpRequest->wrapped(), jsXMLHttpRequest); |
| 762 | } |
| 763 | |
| 764 | #if ENABLE(BINDING_INTEGRITY) |
| 765 | #if PLATFORM(WIN) |
| 766 | #pragma warning(disable: 4483) |
| 767 | extern "C" { extern void (*const __identifier("??_7XMLHttpRequest@WebCore@@6B@" )[])(); } |
| 768 | #else |
| 769 | extern "C" { extern void* _ZTVN7WebCore14XMLHttpRequestE[]; } |
| 770 | #endif |
| 771 | #endif |
| 772 | |
| 773 | JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<XMLHttpRequest>&& impl) |
| 774 | { |
| 775 | |
| 776 | #if ENABLE(BINDING_INTEGRITY) |
| 777 | void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr())); |
| 778 | #if PLATFORM(WIN) |
| 779 | void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7XMLHttpRequest@WebCore@@6B@" )); |
| 780 | #else |
| 781 | void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore14XMLHttpRequestE[2]); |
| 782 | #endif |
| 783 | |
| 784 | // If this fails XMLHttpRequest does not have a vtable, so you need to add the |
| 785 | // ImplementationLacksVTable attribute to the interface definition |
| 786 | static_assert(std::is_polymorphic<XMLHttpRequest>::value, "XMLHttpRequest is not polymorphic" ); |
| 787 | |
| 788 | // If you hit this assertion you either have a use after free bug, or |
| 789 | // XMLHttpRequest has subclasses. If XMLHttpRequest has subclasses that get passed |
| 790 | // to toJS() we currently require XMLHttpRequest you to opt out of binding hardening |
| 791 | // by adding the SkipVTableValidation attribute to the interface IDL definition |
| 792 | RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer); |
| 793 | #endif |
| 794 | globalObject->vm().heap.reportExtraMemoryAllocated(impl->memoryCost()); |
| 795 | return createWrapper<XMLHttpRequest>(globalObject, WTFMove(impl)); |
| 796 | } |
| 797 | |
| 798 | JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, XMLHttpRequest& impl) |
| 799 | { |
| 800 | return wrap(state, globalObject, impl); |
| 801 | } |
| 802 | |
| 803 | XMLHttpRequest* JSXMLHttpRequest::toWrapped(JSC::VM& vm, JSC::JSValue value) |
| 804 | { |
| 805 | if (auto* wrapper = jsDynamicCast<JSXMLHttpRequest*>(vm, value)) |
| 806 | return &wrapper->wrapped(); |
| 807 | return nullptr; |
| 808 | } |
| 809 | |
| 810 | } |
| 811 | |