blob: 21172713f0ff38197ca9f75840ba95ad60084540 [file] [log] [blame]
/*
This file is part of the WebKit open source project.
This file has been generated by generate-bindings.pl. DO NOT MODIFY!
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "JSXMLHttpRequest.h"
#include "EventNames.h"
#include "ExceptionCode.h"
#include "JSDOMBinding.h"
#include "JSDOMConstructor.h"
#include "JSDOMConvert.h"
#include "JSDocument.h"
#include "JSEventListener.h"
#include "JSXMLHttpRequestUpload.h"
#include "URL.h"
#include "WebCoreJSClientData.h"
#include "XMLHttpRequestBuiltins.h"
#include <runtime/Error.h>
#include <runtime/JSString.h>
#include <wtf/GetPtr.h>
using namespace JSC;
namespace WebCore {
template<typename T> Optional<T> parse(ExecState&, JSValue);
template<typename T> const char* expectedEnumerationValues();
JSString* jsStringWithCache(ExecState*, XMLHttpRequest::ResponseType);
JSString* jsStringWithCache(ExecState* state, XMLHttpRequest::ResponseType enumerationValue)
{
static NeverDestroyed<const String> values[] = {
emptyString(),
ASCIILiteral("arraybuffer"),
ASCIILiteral("blob"),
ASCIILiteral("document"),
ASCIILiteral("json"),
ASCIILiteral("text"),
};
static_assert(static_cast<size_t>(XMLHttpRequest::ResponseType::EmptyString) == 0, "XMLHttpRequest::ResponseType::EmptyString is not 0 as expected");
static_assert(static_cast<size_t>(XMLHttpRequest::ResponseType::Arraybuffer) == 1, "XMLHttpRequest::ResponseType::Arraybuffer is not 1 as expected");
static_assert(static_cast<size_t>(XMLHttpRequest::ResponseType::Blob) == 2, "XMLHttpRequest::ResponseType::Blob is not 2 as expected");
static_assert(static_cast<size_t>(XMLHttpRequest::ResponseType::Document) == 3, "XMLHttpRequest::ResponseType::Document is not 3 as expected");
static_assert(static_cast<size_t>(XMLHttpRequest::ResponseType::Json) == 4, "XMLHttpRequest::ResponseType::Json is not 4 as expected");
static_assert(static_cast<size_t>(XMLHttpRequest::ResponseType::Text) == 5, "XMLHttpRequest::ResponseType::Text is not 5 as expected");
ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values));
return jsStringWithCache(state, values[static_cast<size_t>(enumerationValue)]);
}
template<> struct JSValueTraits<XMLHttpRequest::ResponseType> {
static JSString* arrayJSValue(ExecState* state, JSDOMGlobalObject*, XMLHttpRequest::ResponseType value) { return jsStringWithCache(state, value); }
};
template<> Optional<XMLHttpRequest::ResponseType> parse<XMLHttpRequest::ResponseType>(ExecState& state, JSValue value)
{
auto stringValue = value.toWTFString(&state);
if (stringValue.isEmpty())
return XMLHttpRequest::ResponseType::EmptyString;
if (stringValue == "arraybuffer")
return XMLHttpRequest::ResponseType::Arraybuffer;
if (stringValue == "blob")
return XMLHttpRequest::ResponseType::Blob;
if (stringValue == "document")
return XMLHttpRequest::ResponseType::Document;
if (stringValue == "json")
return XMLHttpRequest::ResponseType::Json;
if (stringValue == "text")
return XMLHttpRequest::ResponseType::Text;
return Nullopt;
}
template<> XMLHttpRequest::ResponseType convert<XMLHttpRequest::ResponseType>(ExecState& state, JSValue value)
{
VM& vm = state.vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
auto result = parse<XMLHttpRequest::ResponseType>(state, value);
if (UNLIKELY(!result)) {
throwTypeError(&state, throwScope);
return { };
}
return result.value();
}
template<> inline const char* expectedEnumerationValues<XMLHttpRequest::ResponseType>()
{
return "\"\", \"arraybuffer\", \"blob\", \"document\", \"json\", \"text\"";
}
// Functions
JSC::EncodedJSValue JSC_HOST_CALL jsXMLHttpRequestPrototypeFunctionOpen(JSC::ExecState*);
JSC::EncodedJSValue JSC_HOST_CALL jsXMLHttpRequestPrototypeFunctionSetRequestHeader(JSC::ExecState*);
JSC::EncodedJSValue JSC_HOST_CALL jsXMLHttpRequestPrototypeFunctionSend(JSC::ExecState*);
JSC::EncodedJSValue JSC_HOST_CALL jsXMLHttpRequestPrototypeFunctionAbort(JSC::ExecState*);
JSC::EncodedJSValue JSC_HOST_CALL jsXMLHttpRequestPrototypeFunctionGetAllResponseHeaders(JSC::ExecState*);
JSC::EncodedJSValue JSC_HOST_CALL jsXMLHttpRequestPrototypeFunctionGetResponseHeader(JSC::ExecState*);
JSC::EncodedJSValue JSC_HOST_CALL jsXMLHttpRequestPrototypeFunctionResponseCacheIsValid(JSC::ExecState*);
JSC::EncodedJSValue JSC_HOST_CALL jsXMLHttpRequestPrototypeFunctionRetrieveResponse(JSC::ExecState*);
JSC::EncodedJSValue JSC_HOST_CALL jsXMLHttpRequestPrototypeFunctionOverrideMimeType(JSC::ExecState*);
// Attributes
JSC::EncodedJSValue jsXMLHttpRequestOnreadystatechange(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
bool setJSXMLHttpRequestOnreadystatechange(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
JSC::EncodedJSValue jsXMLHttpRequestTimeout(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
bool setJSXMLHttpRequestTimeout(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
JSC::EncodedJSValue jsXMLHttpRequestReadyState(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
JSC::EncodedJSValue jsXMLHttpRequestWithCredentials(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
bool setJSXMLHttpRequestWithCredentials(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
JSC::EncodedJSValue jsXMLHttpRequestUpload(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
JSC::EncodedJSValue jsXMLHttpRequestResponseText(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
JSC::EncodedJSValue jsXMLHttpRequestResponseXML(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
JSC::EncodedJSValue jsXMLHttpRequestResponseType(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
bool setJSXMLHttpRequestResponseType(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
JSC::EncodedJSValue jsXMLHttpRequestStatus(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
JSC::EncodedJSValue jsXMLHttpRequestStatusText(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
JSC::EncodedJSValue jsXMLHttpRequestResponseURL(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
JSC::EncodedJSValue jsXMLHttpRequestConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
bool setJSXMLHttpRequestConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
class JSXMLHttpRequestPrototype : public JSC::JSNonFinalObject {
public:
typedef JSC::JSNonFinalObject Base;
static JSXMLHttpRequestPrototype* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure)
{
JSXMLHttpRequestPrototype* ptr = new (NotNull, JSC::allocateCell<JSXMLHttpRequestPrototype>(vm.heap)) JSXMLHttpRequestPrototype(vm, globalObject, structure);
ptr->finishCreation(vm);
return ptr;
}
DECLARE_INFO;
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
}
private:
JSXMLHttpRequestPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
: JSC::JSNonFinalObject(vm, structure)
{
}
void finishCreation(JSC::VM&);
};
typedef JSDOMConstructor<JSXMLHttpRequest> JSXMLHttpRequestConstructor;
/* Hash table for constructor */
static const HashTableValue JSXMLHttpRequestConstructorTableValues[] =
{
{ "UNSENT", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(0) } },
{ "OPENED", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(1) } },
{ "HEADERS_RECEIVED", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(2) } },
{ "LOADING", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(3) } },
{ "DONE", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(4) } },
};
static_assert(XMLHttpRequest::UNSENT == 0, "UNSENT in XMLHttpRequest does not match value from IDL");
static_assert(XMLHttpRequest::OPENED == 1, "OPENED in XMLHttpRequest does not match value from IDL");
static_assert(XMLHttpRequest::HEADERS_RECEIVED == 2, "HEADERS_RECEIVED in XMLHttpRequest does not match value from IDL");
static_assert(XMLHttpRequest::LOADING == 3, "LOADING in XMLHttpRequest does not match value from IDL");
static_assert(XMLHttpRequest::DONE == 4, "DONE in XMLHttpRequest does not match value from IDL");
template<> EncodedJSValue JSC_HOST_CALL JSXMLHttpRequestConstructor::construct(ExecState* state)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
auto* castedThis = jsCast<JSXMLHttpRequestConstructor*>(state->callee());
ASSERT(castedThis);
ScriptExecutionContext* context = castedThis->scriptExecutionContext();
if (UNLIKELY(!context))
return throwConstructorScriptExecutionContextUnavailableError(*state, throwScope, "XMLHttpRequest");
auto object = XMLHttpRequest::create(*context);
return JSValue::encode(toJSNewlyCreated(state, castedThis->globalObject(), WTFMove(object)));
}
template<> JSValue JSXMLHttpRequestConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
{
return JSXMLHttpRequestEventTarget::getConstructor(vm, &globalObject);
}
template<> void JSXMLHttpRequestConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
{
putDirect(vm, vm.propertyNames->prototype, JSXMLHttpRequest::prototype(vm, &globalObject), DontDelete | ReadOnly | DontEnum);
putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String(ASCIILiteral("XMLHttpRequest"))), ReadOnly | DontEnum);
putDirect(vm, vm.propertyNames->length, jsNumber(0), ReadOnly | DontEnum);
reifyStaticProperties(vm, JSXMLHttpRequestConstructorTableValues, *this);
}
template<> const ClassInfo JSXMLHttpRequestConstructor::s_info = { "XMLHttpRequest", &Base::s_info, 0, CREATE_METHOD_TABLE(JSXMLHttpRequestConstructor) };
/* Hash table for prototype */
static const HashTableValue JSXMLHttpRequestPrototypeTableValues[] =
{
{ "constructor", DontEnum, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsXMLHttpRequestConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSXMLHttpRequestConstructor) } },
{ "onreadystatechange", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsXMLHttpRequestOnreadystatechange), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSXMLHttpRequestOnreadystatechange) } },
{ "timeout", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsXMLHttpRequestTimeout), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSXMLHttpRequestTimeout) } },
{ "readyState", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsXMLHttpRequestReadyState), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
{ "withCredentials", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsXMLHttpRequestWithCredentials), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSXMLHttpRequestWithCredentials) } },
{ "upload", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsXMLHttpRequestUpload), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
{ "responseText", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsXMLHttpRequestResponseText), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
{ "responseXML", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsXMLHttpRequestResponseXML), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
{ "responseType", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsXMLHttpRequestResponseType), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSXMLHttpRequestResponseType) } },
{ "response", ReadOnly | Accessor | Builtin, NoIntrinsic, { (intptr_t)static_cast<BuiltinGenerator>(xmlHttpRequestResponseCodeGenerator), (intptr_t) (0) } },
{ "status", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsXMLHttpRequestStatus), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
{ "statusText", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsXMLHttpRequestStatusText), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
{ "responseURL", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsXMLHttpRequestResponseURL), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
{ "open", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsXMLHttpRequestPrototypeFunctionOpen), (intptr_t) (2) } },
{ "setRequestHeader", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsXMLHttpRequestPrototypeFunctionSetRequestHeader), (intptr_t) (2) } },
{ "send", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsXMLHttpRequestPrototypeFunctionSend), (intptr_t) (0) } },
{ "abort", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsXMLHttpRequestPrototypeFunctionAbort), (intptr_t) (0) } },
{ "getAllResponseHeaders", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsXMLHttpRequestPrototypeFunctionGetAllResponseHeaders), (intptr_t) (0) } },
{ "getResponseHeader", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsXMLHttpRequestPrototypeFunctionGetResponseHeader), (intptr_t) (1) } },
{ "overrideMimeType", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsXMLHttpRequestPrototypeFunctionOverrideMimeType), (intptr_t) (1) } },
{ "UNSENT", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(0) } },
{ "OPENED", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(1) } },
{ "HEADERS_RECEIVED", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(2) } },
{ "LOADING", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(3) } },
{ "DONE", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, { (long long)(4) } },
};
const ClassInfo JSXMLHttpRequestPrototype::s_info = { "XMLHttpRequestPrototype", &Base::s_info, 0, CREATE_METHOD_TABLE(JSXMLHttpRequestPrototype) };
void JSXMLHttpRequestPrototype::finishCreation(VM& vm)
{
Base::finishCreation(vm);
reifyStaticProperties(vm, JSXMLHttpRequestPrototypeTableValues, *this);
JSVMClientData& clientData = *static_cast<JSVMClientData*>(vm.clientData);
putDirect(vm, clientData.builtinNames().responseCacheIsValidPrivateName(), JSFunction::create(vm, globalObject(), 0, String(), jsXMLHttpRequestPrototypeFunctionResponseCacheIsValid), ReadOnly | DontEnum);
putDirect(vm, clientData.builtinNames().retrieveResponsePrivateName(), JSFunction::create(vm, globalObject(), 0, String(), jsXMLHttpRequestPrototypeFunctionRetrieveResponse), ReadOnly | DontEnum);
}
const ClassInfo JSXMLHttpRequest::s_info = { "XMLHttpRequest", &Base::s_info, 0, CREATE_METHOD_TABLE(JSXMLHttpRequest) };
JSXMLHttpRequest::JSXMLHttpRequest(Structure* structure, JSDOMGlobalObject& globalObject, Ref<XMLHttpRequest>&& impl)
: JSXMLHttpRequestEventTarget(structure, globalObject, WTFMove(impl))
{
}
JSObject* JSXMLHttpRequest::createPrototype(VM& vm, JSGlobalObject* globalObject)
{
return JSXMLHttpRequestPrototype::create(vm, globalObject, JSXMLHttpRequestPrototype::createStructure(vm, globalObject, JSXMLHttpRequestEventTarget::prototype(vm, globalObject)));
}
JSObject* JSXMLHttpRequest::prototype(VM& vm, JSGlobalObject* globalObject)
{
return getDOMPrototype<JSXMLHttpRequest>(vm, globalObject);
}
EncodedJSValue jsXMLHttpRequestOnreadystatechange(ExecState* state, EncodedJSValue thisValue, PropertyName)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
UNUSED_PARAM(thisValue);
JSValue decodedThisValue = JSValue::decode(thisValue);
auto* castedThis = jsDynamicCast<JSXMLHttpRequest*>(decodedThisValue);
if (UNLIKELY(!castedThis)) {
return throwGetterTypeError(*state, throwScope, "XMLHttpRequest", "onreadystatechange");
}
UNUSED_PARAM(state);
return JSValue::encode(eventHandlerAttribute(castedThis->wrapped(), eventNames().readystatechangeEvent));
}
EncodedJSValue jsXMLHttpRequestTimeout(ExecState* state, EncodedJSValue thisValue, PropertyName)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
UNUSED_PARAM(thisValue);
JSValue decodedThisValue = JSValue::decode(thisValue);
auto* castedThis = jsDynamicCast<JSXMLHttpRequest*>(decodedThisValue);
if (UNLIKELY(!castedThis)) {
return throwGetterTypeError(*state, throwScope, "XMLHttpRequest", "timeout");
}
auto& impl = castedThis->wrapped();
JSValue result = jsNumber(impl.timeout());
return JSValue::encode(result);
}
EncodedJSValue jsXMLHttpRequestReadyState(ExecState* state, EncodedJSValue thisValue, PropertyName)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
UNUSED_PARAM(thisValue);
JSValue decodedThisValue = JSValue::decode(thisValue);
auto* castedThis = jsDynamicCast<JSXMLHttpRequest*>(decodedThisValue);
if (UNLIKELY(!castedThis)) {
return throwGetterTypeError(*state, throwScope, "XMLHttpRequest", "readyState");
}
auto& impl = castedThis->wrapped();
JSValue result = jsNumber(impl.readyState());
return JSValue::encode(result);
}
EncodedJSValue jsXMLHttpRequestWithCredentials(ExecState* state, EncodedJSValue thisValue, PropertyName)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
UNUSED_PARAM(thisValue);
JSValue decodedThisValue = JSValue::decode(thisValue);
auto* castedThis = jsDynamicCast<JSXMLHttpRequest*>(decodedThisValue);
if (UNLIKELY(!castedThis)) {
return throwGetterTypeError(*state, throwScope, "XMLHttpRequest", "withCredentials");
}
auto& impl = castedThis->wrapped();
JSValue result = jsBoolean(impl.withCredentials());
return JSValue::encode(result);
}
EncodedJSValue jsXMLHttpRequestUpload(ExecState* state, EncodedJSValue thisValue, PropertyName)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
UNUSED_PARAM(thisValue);
JSValue decodedThisValue = JSValue::decode(thisValue);
auto* castedThis = jsDynamicCast<JSXMLHttpRequest*>(decodedThisValue);
if (UNLIKELY(!castedThis)) {
return throwGetterTypeError(*state, throwScope, "XMLHttpRequest", "upload");
}
auto& impl = castedThis->wrapped();
JSValue result = toJS(state, castedThis->globalObject(), impl.upload());
return JSValue::encode(result);
}
EncodedJSValue jsXMLHttpRequestResponseText(ExecState* state, EncodedJSValue thisValue, PropertyName)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
UNUSED_PARAM(thisValue);
JSValue decodedThisValue = JSValue::decode(thisValue);
auto* castedThis = jsDynamicCast<JSXMLHttpRequest*>(decodedThisValue);
if (UNLIKELY(!castedThis)) {
return throwGetterTypeError(*state, throwScope, "XMLHttpRequest", "responseText");
}
return JSValue::encode(castedThis->responseText(*state));
}
EncodedJSValue jsXMLHttpRequestResponseXML(ExecState* state, EncodedJSValue thisValue, PropertyName)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
UNUSED_PARAM(thisValue);
JSValue decodedThisValue = JSValue::decode(thisValue);
auto* castedThis = jsDynamicCast<JSXMLHttpRequest*>(decodedThisValue);
if (UNLIKELY(!castedThis)) {
return throwGetterTypeError(*state, throwScope, "XMLHttpRequest", "responseXML");
}
ExceptionCode ec = 0;
auto& impl = castedThis->wrapped();
JSValue result = toJS(state, castedThis->globalObject(), impl.responseXML(ec));
setDOMException(state, throwScope, ec);
return JSValue::encode(result);
}
EncodedJSValue jsXMLHttpRequestResponseType(ExecState* state, EncodedJSValue thisValue, PropertyName)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
UNUSED_PARAM(thisValue);
JSValue decodedThisValue = JSValue::decode(thisValue);
auto* castedThis = jsDynamicCast<JSXMLHttpRequest*>(decodedThisValue);
if (UNLIKELY(!castedThis)) {
return throwGetterTypeError(*state, throwScope, "XMLHttpRequest", "responseType");
}
auto& impl = castedThis->wrapped();
JSValue result = jsStringWithCache(state, impl.responseType());
return JSValue::encode(result);
}
EncodedJSValue jsXMLHttpRequestStatus(ExecState* state, EncodedJSValue thisValue, PropertyName)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
UNUSED_PARAM(thisValue);
JSValue decodedThisValue = JSValue::decode(thisValue);
auto* castedThis = jsDynamicCast<JSXMLHttpRequest*>(decodedThisValue);
if (UNLIKELY(!castedThis)) {
return throwGetterTypeError(*state, throwScope, "XMLHttpRequest", "status");
}
auto& impl = castedThis->wrapped();
JSValue result = jsNumber(impl.status());
return JSValue::encode(result);
}
EncodedJSValue jsXMLHttpRequestStatusText(ExecState* state, EncodedJSValue thisValue, PropertyName)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
UNUSED_PARAM(thisValue);
JSValue decodedThisValue = JSValue::decode(thisValue);
auto* castedThis = jsDynamicCast<JSXMLHttpRequest*>(decodedThisValue);
if (UNLIKELY(!castedThis)) {
return throwGetterTypeError(*state, throwScope, "XMLHttpRequest", "statusText");
}
auto& impl = castedThis->wrapped();
JSValue result = jsStringWithCache(state, impl.statusText());
return JSValue::encode(result);
}
EncodedJSValue jsXMLHttpRequestResponseURL(ExecState* state, EncodedJSValue thisValue, PropertyName)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
UNUSED_PARAM(thisValue);
JSValue decodedThisValue = JSValue::decode(thisValue);
auto* castedThis = jsDynamicCast<JSXMLHttpRequest*>(decodedThisValue);
if (UNLIKELY(!castedThis)) {
return throwGetterTypeError(*state, throwScope, "XMLHttpRequest", "responseURL");
}
auto& impl = castedThis->wrapped();
JSValue result = jsStringWithCache(state, impl.responseURL());
return JSValue::encode(result);
}
EncodedJSValue jsXMLHttpRequestConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
JSXMLHttpRequestPrototype* domObject = jsDynamicCast<JSXMLHttpRequestPrototype*>(JSValue::decode(thisValue));
if (UNLIKELY(!domObject))
return throwVMTypeError(state, throwScope);
return JSValue::encode(JSXMLHttpRequest::getConstructor(state->vm(), domObject->globalObject()));
}
bool setJSXMLHttpRequestConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
JSValue value = JSValue::decode(encodedValue);
JSXMLHttpRequestPrototype* domObject = jsDynamicCast<JSXMLHttpRequestPrototype*>(JSValue::decode(thisValue));
if (UNLIKELY(!domObject)) {
throwVMTypeError(state, throwScope);
return false;
}
// Shadowing a built-in constructor
return domObject->putDirect(state->vm(), state->propertyNames().constructor, value);
}
bool setJSXMLHttpRequestOnreadystatechange(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
JSValue value = JSValue::decode(encodedValue);
UNUSED_PARAM(thisValue);
JSXMLHttpRequest* castedThis = jsDynamicCast<JSXMLHttpRequest*>(JSValue::decode(thisValue));
if (UNLIKELY(!castedThis)) {
return throwSetterTypeError(*state, throwScope, "XMLHttpRequest", "onreadystatechange");
}
setEventHandlerAttribute(*state, *castedThis, castedThis->wrapped(), eventNames().readystatechangeEvent, value);
return true;
}
bool setJSXMLHttpRequestTimeout(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
JSValue value = JSValue::decode(encodedValue);
UNUSED_PARAM(thisValue);
JSXMLHttpRequest* castedThis = jsDynamicCast<JSXMLHttpRequest*>(JSValue::decode(thisValue));
if (UNLIKELY(!castedThis)) {
return throwSetterTypeError(*state, throwScope, "XMLHttpRequest", "timeout");
}
auto& impl = castedThis->wrapped();
ExceptionCode ec = 0;
auto nativeValue = convert<uint32_t>(*state, value, NormalConversion);
RETURN_IF_EXCEPTION(throwScope, false);
impl.setTimeout(WTFMove(nativeValue), ec);
setDOMException(state, throwScope, ec);
return true;
}
bool setJSXMLHttpRequestWithCredentials(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
JSValue value = JSValue::decode(encodedValue);
UNUSED_PARAM(thisValue);
JSXMLHttpRequest* castedThis = jsDynamicCast<JSXMLHttpRequest*>(JSValue::decode(thisValue));
if (UNLIKELY(!castedThis)) {
return throwSetterTypeError(*state, throwScope, "XMLHttpRequest", "withCredentials");
}
auto& impl = castedThis->wrapped();
ExceptionCode ec = 0;
auto nativeValue = value.toBoolean(state);
RETURN_IF_EXCEPTION(throwScope, false);
impl.setWithCredentials(WTFMove(nativeValue), ec);
setDOMException(state, throwScope, ec);
return true;
}
bool setJSXMLHttpRequestResponseType(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
JSValue value = JSValue::decode(encodedValue);
UNUSED_PARAM(thisValue);
JSXMLHttpRequest* castedThis = jsDynamicCast<JSXMLHttpRequest*>(JSValue::decode(thisValue));
if (UNLIKELY(!castedThis)) {
return throwSetterTypeError(*state, throwScope, "XMLHttpRequest", "responseType");
}
auto& impl = castedThis->wrapped();
ExceptionCode ec = 0;
auto nativeValue = parse<XMLHttpRequest::ResponseType>(*state, value);
RETURN_IF_EXCEPTION(throwScope, false);
if (UNLIKELY(!nativeValue))
return false;
impl.setResponseType(nativeValue.value(), ec);
setDOMException(state, throwScope, ec);
return true;
}
JSValue JSXMLHttpRequest::getConstructor(VM& vm, const JSGlobalObject* globalObject)
{
return getDOMConstructor<JSXMLHttpRequestConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
}
static inline EncodedJSValue jsXMLHttpRequestPrototypeFunctionOpen1(ExecState* state)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
JSValue thisValue = state->thisValue();
auto castedThis = jsDynamicCast<JSXMLHttpRequest*>(thisValue);
if (UNLIKELY(!castedThis))
return throwThisTypeError(*state, throwScope, "XMLHttpRequest", "open");
ASSERT_GC_OBJECT_INHERITS(castedThis, JSXMLHttpRequest::info());
auto& impl = castedThis->wrapped();
if (UNLIKELY(state->argumentCount() < 2))
return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
ExceptionCode ec = 0;
auto method = state->uncheckedArgument(0).toWTFString(state);
RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
auto url = state->uncheckedArgument(1).toWTFString(state);
RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
impl.open(WTFMove(method), WTFMove(url), ec);
setDOMException(state, throwScope, ec);
return JSValue::encode(jsUndefined());
}
static inline EncodedJSValue jsXMLHttpRequestPrototypeFunctionOpen2(ExecState* state)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
JSValue thisValue = state->thisValue();
auto castedThis = jsDynamicCast<JSXMLHttpRequest*>(thisValue);
if (UNLIKELY(!castedThis))
return throwThisTypeError(*state, throwScope, "XMLHttpRequest", "open");
ASSERT_GC_OBJECT_INHERITS(castedThis, JSXMLHttpRequest::info());
auto& impl = castedThis->wrapped();
if (UNLIKELY(state->argumentCount() < 3))
return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
ExceptionCode ec = 0;
auto method = state->uncheckedArgument(0).toWTFString(state);
RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
auto url = state->uncheckedArgument(1).toWTFString(state);
RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
auto async = state->uncheckedArgument(2).toBoolean(state);
RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
auto user = state->argument(3).isUndefined() ? String() : valueToStringWithUndefinedOrNullCheck(state, state->uncheckedArgument(3));
RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
auto password = state->argument(4).isUndefined() ? String() : valueToStringWithUndefinedOrNullCheck(state, state->uncheckedArgument(4));
RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
impl.open(WTFMove(method), WTFMove(url), WTFMove(async), WTFMove(user), WTFMove(password), ec);
setDOMException(state, throwScope, ec);
return JSValue::encode(jsUndefined());
}
EncodedJSValue JSC_HOST_CALL jsXMLHttpRequestPrototypeFunctionOpen(ExecState* state)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
size_t argsCount = std::min<size_t>(5, state->argumentCount());
if (argsCount == 2) {
return jsXMLHttpRequestPrototypeFunctionOpen1(state);
}
if (argsCount == 3) {
return jsXMLHttpRequestPrototypeFunctionOpen2(state);
}
if (argsCount == 4) {
return jsXMLHttpRequestPrototypeFunctionOpen2(state);
}
if (argsCount == 5) {
return jsXMLHttpRequestPrototypeFunctionOpen2(state);
}
return argsCount < 2 ? throwVMError(state, throwScope, createNotEnoughArgumentsError(state)) : throwVMTypeError(state, throwScope);
}
EncodedJSValue JSC_HOST_CALL jsXMLHttpRequestPrototypeFunctionSetRequestHeader(ExecState* state)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
JSValue thisValue = state->thisValue();
auto castedThis = jsDynamicCast<JSXMLHttpRequest*>(thisValue);
if (UNLIKELY(!castedThis))
return throwThisTypeError(*state, throwScope, "XMLHttpRequest", "setRequestHeader");
ASSERT_GC_OBJECT_INHERITS(castedThis, JSXMLHttpRequest::info());
auto& impl = castedThis->wrapped();
if (UNLIKELY(state->argumentCount() < 2))
return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
ExceptionCode ec = 0;
auto header = state->uncheckedArgument(0).toWTFString(state);
RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
auto value = state->uncheckedArgument(1).toWTFString(state);
RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
impl.setRequestHeader(WTFMove(header), WTFMove(value), ec);
setDOMException(state, throwScope, ec);
return JSValue::encode(jsUndefined());
}
EncodedJSValue JSC_HOST_CALL jsXMLHttpRequestPrototypeFunctionSend(ExecState* state)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
JSValue thisValue = state->thisValue();
auto castedThis = jsDynamicCast<JSXMLHttpRequest*>(thisValue);
if (UNLIKELY(!castedThis))
return throwThisTypeError(*state, throwScope, "XMLHttpRequest", "send");
ASSERT_GC_OBJECT_INHERITS(castedThis, JSXMLHttpRequest::info());
return JSValue::encode(castedThis->send(*state));
}
EncodedJSValue JSC_HOST_CALL jsXMLHttpRequestPrototypeFunctionAbort(ExecState* state)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
JSValue thisValue = state->thisValue();
auto castedThis = jsDynamicCast<JSXMLHttpRequest*>(thisValue);
if (UNLIKELY(!castedThis))
return throwThisTypeError(*state, throwScope, "XMLHttpRequest", "abort");
ASSERT_GC_OBJECT_INHERITS(castedThis, JSXMLHttpRequest::info());
auto& impl = castedThis->wrapped();
impl.abort();
return JSValue::encode(jsUndefined());
}
EncodedJSValue JSC_HOST_CALL jsXMLHttpRequestPrototypeFunctionGetAllResponseHeaders(ExecState* state)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
JSValue thisValue = state->thisValue();
auto castedThis = jsDynamicCast<JSXMLHttpRequest*>(thisValue);
if (UNLIKELY(!castedThis))
return throwThisTypeError(*state, throwScope, "XMLHttpRequest", "getAllResponseHeaders");
ASSERT_GC_OBJECT_INHERITS(castedThis, JSXMLHttpRequest::info());
auto& impl = castedThis->wrapped();
JSValue result = jsStringWithCache(state, impl.getAllResponseHeaders());
return JSValue::encode(result);
}
EncodedJSValue JSC_HOST_CALL jsXMLHttpRequestPrototypeFunctionGetResponseHeader(ExecState* state)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
JSValue thisValue = state->thisValue();
auto castedThis = jsDynamicCast<JSXMLHttpRequest*>(thisValue);
if (UNLIKELY(!castedThis))
return throwThisTypeError(*state, throwScope, "XMLHttpRequest", "getResponseHeader");
ASSERT_GC_OBJECT_INHERITS(castedThis, JSXMLHttpRequest::info());
auto& impl = castedThis->wrapped();
if (UNLIKELY(state->argumentCount() < 1))
return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
auto header = state->uncheckedArgument(0).toWTFString(state);
RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
JSValue result = jsStringOrNull(state, impl.getResponseHeader(WTFMove(header)));
return JSValue::encode(result);
}
EncodedJSValue JSC_HOST_CALL jsXMLHttpRequestPrototypeFunctionResponseCacheIsValid(ExecState* state)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
JSValue thisValue = state->thisValue();
auto castedThis = jsDynamicCast<JSXMLHttpRequest*>(thisValue);
if (UNLIKELY(!castedThis))
return throwThisTypeError(*state, throwScope, "XMLHttpRequest", "responseCacheIsValid");
ASSERT_GC_OBJECT_INHERITS(castedThis, JSXMLHttpRequest::info());
auto& impl = castedThis->wrapped();
JSValue result = jsBoolean(impl.responseCacheIsValid());
return JSValue::encode(result);
}
EncodedJSValue JSC_HOST_CALL jsXMLHttpRequestPrototypeFunctionRetrieveResponse(ExecState* state)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
JSValue thisValue = state->thisValue();
auto castedThis = jsDynamicCast<JSXMLHttpRequest*>(thisValue);
if (UNLIKELY(!castedThis))
return throwThisTypeError(*state, throwScope, "XMLHttpRequest", "retrieveResponse");
ASSERT_GC_OBJECT_INHERITS(castedThis, JSXMLHttpRequest::info());
return JSValue::encode(castedThis->retrieveResponse(*state));
}
EncodedJSValue JSC_HOST_CALL jsXMLHttpRequestPrototypeFunctionOverrideMimeType(ExecState* state)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
JSValue thisValue = state->thisValue();
auto castedThis = jsDynamicCast<JSXMLHttpRequest*>(thisValue);
if (UNLIKELY(!castedThis))
return throwThisTypeError(*state, throwScope, "XMLHttpRequest", "overrideMimeType");
ASSERT_GC_OBJECT_INHERITS(castedThis, JSXMLHttpRequest::info());
auto& impl = castedThis->wrapped();
if (UNLIKELY(state->argumentCount() < 1))
return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
ExceptionCode ec = 0;
auto override = state->uncheckedArgument(0).toWTFString(state);
RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
impl.overrideMimeType(WTFMove(override), ec);
setDOMException(state, throwScope, ec);
return JSValue::encode(jsUndefined());
}
void JSXMLHttpRequest::visitChildren(JSCell* cell, SlotVisitor& visitor)
{
auto* thisObject = jsCast<JSXMLHttpRequest*>(cell);
ASSERT_GC_OBJECT_INHERITS(thisObject, info());
Base::visitChildren(thisObject, visitor);
thisObject->wrapped().visitJSEventListeners(visitor);
thisObject->visitAdditionalChildren(visitor);
}
bool JSXMLHttpRequestOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor)
{
auto* jsXMLHttpRequest = jsCast<JSXMLHttpRequest*>(handle.slot()->asCell());
if (jsXMLHttpRequest->wrapped().hasPendingActivity())
return true;
if (jsXMLHttpRequest->wrapped().isFiringEventListeners())
return true;
UNUSED_PARAM(visitor);
return false;
}
void JSXMLHttpRequestOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
{
auto* jsXMLHttpRequest = jsCast<JSXMLHttpRequest*>(handle.slot()->asCell());
auto& world = *static_cast<DOMWrapperWorld*>(context);
uncacheWrapper(world, &jsXMLHttpRequest->wrapped(), jsXMLHttpRequest);
}
#if ENABLE(BINDING_INTEGRITY)
#if PLATFORM(WIN)
#pragma warning(disable: 4483)
extern "C" { extern void (*const __identifier("??_7XMLHttpRequest@WebCore@@6B@")[])(); }
#else
extern "C" { extern void* _ZTVN7WebCore14XMLHttpRequestE[]; }
#endif
#endif
JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<XMLHttpRequest>&& impl)
{
#if ENABLE(BINDING_INTEGRITY)
void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
#if PLATFORM(WIN)
void* expectedVTablePointer = reinterpret_cast<void*>(__identifier("??_7XMLHttpRequest@WebCore@@6B@"));
#else
void* expectedVTablePointer = &_ZTVN7WebCore14XMLHttpRequestE[2];
#if COMPILER(CLANG)
// If this fails XMLHttpRequest does not have a vtable, so you need to add the
// ImplementationLacksVTable attribute to the interface definition
static_assert(__is_polymorphic(XMLHttpRequest), "XMLHttpRequest is not polymorphic");
#endif
#endif
// If you hit this assertion you either have a use after free bug, or
// XMLHttpRequest has subclasses. If XMLHttpRequest has subclasses that get passed
// to toJS() we currently require XMLHttpRequest you to opt out of binding hardening
// by adding the SkipVTableValidation attribute to the interface IDL definition
RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
#endif
return createWrapper<XMLHttpRequest>(globalObject, WTFMove(impl));
}
JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, XMLHttpRequest& impl)
{
return wrap(state, globalObject, impl);
}
XMLHttpRequest* JSXMLHttpRequest::toWrapped(JSC::JSValue value)
{
if (auto* wrapper = jsDynamicCast<JSXMLHttpRequest*>(value))
return &wrapper->wrapped();
return nullptr;
}
}