mirror of
https://github.com/RGBCube/serenity
synced 2025-05-19 02:55:07 +00:00
LibWeb: Generate JS bindings for XMLHttpRequest from IDL :^)
Remove the hand-written XHR bindings in favor of generated ones.
This commit is contained in:
parent
25056830f0
commit
8363b3ae99
13 changed files with 38 additions and 431 deletions
|
@ -93,9 +93,6 @@ void WindowObject::initialize()
|
|||
|
||||
ADD_WINDOW_OBJECT_INTERFACES;
|
||||
|
||||
m_xhr_prototype = heap().allocate<XMLHttpRequestPrototype>(*this, *this);
|
||||
add_constructor("XMLHttpRequest", m_xhr_constructor, m_xhr_prototype);
|
||||
|
||||
m_range_prototype = heap().allocate<RangePrototype>(*this, *this);
|
||||
add_constructor("Range", m_range_constructor, m_range_prototype);
|
||||
}
|
||||
|
@ -107,8 +104,6 @@ WindowObject::~WindowObject()
|
|||
void WindowObject::visit_edges(Visitor& visitor)
|
||||
{
|
||||
GlobalObject::visit_edges(visitor);
|
||||
visitor.visit(m_xhr_constructor);
|
||||
visitor.visit(m_xhr_prototype);
|
||||
visitor.visit(m_range_constructor);
|
||||
visitor.visit(m_range_prototype);
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -47,9 +47,6 @@ public:
|
|||
|
||||
Origin origin() const;
|
||||
|
||||
XMLHttpRequestPrototype* xhr_prototype() { return m_xhr_prototype; }
|
||||
XMLHttpRequestConstructor* xhr_constructor() { return m_xhr_constructor; }
|
||||
|
||||
RangePrototype* range_prototype() { return m_range_prototype; }
|
||||
RangeConstructor* range_constructor() { return m_range_constructor; }
|
||||
|
||||
|
@ -103,9 +100,6 @@ private:
|
|||
|
||||
NonnullRefPtr<DOM::Window> m_impl;
|
||||
|
||||
XMLHttpRequestConstructor* m_xhr_constructor { nullptr };
|
||||
XMLHttpRequestPrototype* m_xhr_prototype { nullptr };
|
||||
|
||||
RangePrototype* m_range_prototype { nullptr };
|
||||
RangeConstructor* m_range_constructor { nullptr };
|
||||
|
||||
|
|
|
@ -218,6 +218,8 @@
|
|||
#include <LibWeb/Bindings/TextPrototype.h>
|
||||
#include <LibWeb/Bindings/UIEventConstructor.h>
|
||||
#include <LibWeb/Bindings/UIEventPrototype.h>
|
||||
#include <LibWeb/Bindings/XMLHttpRequestConstructor.h>
|
||||
#include <LibWeb/Bindings/XMLHttpRequestPrototype.h>
|
||||
|
||||
#define ADD_WINDOW_OBJECT_INTERFACE(name) \
|
||||
{ \
|
||||
|
@ -319,4 +321,5 @@
|
|||
ADD_WINDOW_OBJECT_INTERFACE(SVGPathElement) \
|
||||
ADD_WINDOW_OBJECT_INTERFACE(SVGSVGElement) \
|
||||
ADD_WINDOW_OBJECT_INTERFACE(Text) \
|
||||
ADD_WINDOW_OBJECT_INTERFACE(UIEvent)
|
||||
ADD_WINDOW_OBJECT_INTERFACE(UIEvent) \
|
||||
ADD_WINDOW_OBJECT_INTERFACE(XMLHttpRequest)
|
||||
|
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <LibJS/Heap/Heap.h>
|
||||
#include <LibJS/Runtime/GlobalObject.h>
|
||||
#include <LibWeb/Bindings/WindowObject.h>
|
||||
#include <LibWeb/Bindings/XMLHttpRequestConstructor.h>
|
||||
#include <LibWeb/Bindings/XMLHttpRequestPrototype.h>
|
||||
#include <LibWeb/Bindings/XMLHttpRequestWrapper.h>
|
||||
#include <LibWeb/XHR/XMLHttpRequest.h>
|
||||
|
||||
namespace Web::Bindings {
|
||||
|
||||
XMLHttpRequestConstructor::XMLHttpRequestConstructor(JS::GlobalObject& global_object)
|
||||
: NativeFunction(*global_object.function_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
void XMLHttpRequestConstructor::initialize(JS::GlobalObject& global_object)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
NativeFunction::initialize(global_object);
|
||||
auto& window = static_cast<WindowObject&>(global_object);
|
||||
define_property(vm.names.prototype, window.xhr_prototype(), 0);
|
||||
define_property(vm.names.length, JS::Value(1), JS::Attribute::Configurable);
|
||||
|
||||
define_property("UNSENT", JS::Value((i32)XHR::XMLHttpRequest::ReadyState::Unsent), JS::Attribute::Enumerable);
|
||||
define_property("OPENED", JS::Value((i32)XHR::XMLHttpRequest::ReadyState::Opened), JS::Attribute::Enumerable);
|
||||
define_property("HEADERS_RECEIVED", JS::Value((i32)XHR::XMLHttpRequest::ReadyState::HeadersReceived), JS::Attribute::Enumerable);
|
||||
define_property("LOADING", JS::Value((i32)XHR::XMLHttpRequest::ReadyState::Loading), JS::Attribute::Enumerable);
|
||||
define_property("DONE", JS::Value((i32)XHR::XMLHttpRequest::ReadyState::Done), JS::Attribute::Enumerable);
|
||||
}
|
||||
|
||||
XMLHttpRequestConstructor::~XMLHttpRequestConstructor()
|
||||
{
|
||||
}
|
||||
|
||||
JS::Value XMLHttpRequestConstructor::call()
|
||||
{
|
||||
vm().throw_exception<JS::TypeError>(global_object(), JS::ErrorType::ConstructorWithoutNew, "XMLHttpRequest");
|
||||
return {};
|
||||
}
|
||||
|
||||
JS::Value XMLHttpRequestConstructor::construct(Function&)
|
||||
{
|
||||
auto& window = static_cast<WindowObject&>(global_object());
|
||||
return heap().allocate<XMLHttpRequestWrapper>(window, window, XHR::XMLHttpRequest::create(window.impl()));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibJS/Runtime/NativeFunction.h>
|
||||
|
||||
namespace Web::Bindings {
|
||||
|
||||
class XMLHttpRequestConstructor final : public JS::NativeFunction {
|
||||
public:
|
||||
explicit XMLHttpRequestConstructor(JS::GlobalObject&);
|
||||
virtual void initialize(JS::GlobalObject&) override;
|
||||
virtual ~XMLHttpRequestConstructor() override;
|
||||
|
||||
virtual JS::Value call() override;
|
||||
virtual JS::Value construct(JS::Function& new_target) override;
|
||||
|
||||
private:
|
||||
virtual bool has_constructor() const override { return true; }
|
||||
virtual const char* class_name() const override { return "XMLHttpRequestConstructor"; }
|
||||
};
|
||||
|
||||
}
|
|
@ -1,128 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <AK/Function.h>
|
||||
#include <LibJS/Runtime/Error.h>
|
||||
#include <LibJS/Runtime/GlobalObject.h>
|
||||
#include <LibWeb/Bindings/XMLHttpRequestPrototype.h>
|
||||
#include <LibWeb/Bindings/XMLHttpRequestWrapper.h>
|
||||
#include <LibWeb/XHR/XMLHttpRequest.h>
|
||||
|
||||
namespace Web::Bindings {
|
||||
|
||||
XMLHttpRequestPrototype::XMLHttpRequestPrototype(JS::GlobalObject& global_object)
|
||||
: Object(*global_object.object_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
void XMLHttpRequestPrototype::initialize(JS::GlobalObject& global_object)
|
||||
{
|
||||
Object::initialize(global_object);
|
||||
define_native_function("open", open, 2);
|
||||
define_native_function("send", send, 0);
|
||||
define_native_function("setRequestHeader", set_request_header, 2);
|
||||
define_native_property("readyState", ready_state_getter, nullptr, JS::Attribute::Enumerable | JS::Attribute::Configurable);
|
||||
define_native_property("responseText", response_text_getter, nullptr, JS::Attribute::Enumerable | JS::Attribute::Configurable);
|
||||
|
||||
define_property("UNSENT", JS::Value((i32)XHR::XMLHttpRequest::ReadyState::Unsent), JS::Attribute::Enumerable);
|
||||
define_property("OPENED", JS::Value((i32)XHR::XMLHttpRequest::ReadyState::Opened), JS::Attribute::Enumerable);
|
||||
define_property("HEADERS_RECEIVED", JS::Value((i32)XHR::XMLHttpRequest::ReadyState::HeadersReceived), JS::Attribute::Enumerable);
|
||||
define_property("LOADING", JS::Value((i32)XHR::XMLHttpRequest::ReadyState::Loading), JS::Attribute::Enumerable);
|
||||
define_property("DONE", JS::Value((i32)XHR::XMLHttpRequest::ReadyState::Done), JS::Attribute::Enumerable);
|
||||
}
|
||||
|
||||
XMLHttpRequestPrototype::~XMLHttpRequestPrototype()
|
||||
{
|
||||
}
|
||||
|
||||
static XHR::XMLHttpRequest* impl_from(JS::VM& vm, JS::GlobalObject& global_object)
|
||||
{
|
||||
auto* this_object = vm.this_value(global_object).to_object(global_object);
|
||||
if (!this_object)
|
||||
return nullptr;
|
||||
if (!is<XMLHttpRequestWrapper>(this_object)) {
|
||||
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotA, "XMLHttpRequest");
|
||||
return nullptr;
|
||||
}
|
||||
return &static_cast<XMLHttpRequestWrapper*>(this_object)->impl();
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(XMLHttpRequestPrototype::open)
|
||||
{
|
||||
auto* impl = impl_from(vm, global_object);
|
||||
if (!impl)
|
||||
return {};
|
||||
auto arg0 = vm.argument(0).to_string(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
auto arg1 = vm.argument(1).to_string(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
impl->open(arg0, arg1);
|
||||
return JS::js_undefined();
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(XMLHttpRequestPrototype::send)
|
||||
{
|
||||
auto* impl = impl_from(vm, global_object);
|
||||
if (!impl)
|
||||
return {};
|
||||
impl->send();
|
||||
return JS::js_undefined();
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(XMLHttpRequestPrototype::set_request_header)
|
||||
{
|
||||
auto* impl = impl_from(vm, global_object);
|
||||
if (!impl)
|
||||
return {};
|
||||
auto arg0 = vm.argument(0).to_string(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
auto arg1 = vm.argument(1).to_string(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
impl->set_request_header(arg0, arg1);
|
||||
return JS::js_undefined();
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_GETTER(XMLHttpRequestPrototype::ready_state_getter)
|
||||
{
|
||||
auto* impl = impl_from(vm, global_object);
|
||||
if (!impl)
|
||||
return {};
|
||||
return JS::Value((i32)impl->ready_state());
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_GETTER(XMLHttpRequestPrototype::response_text_getter)
|
||||
{
|
||||
auto* impl = impl_from(vm, global_object);
|
||||
if (!impl)
|
||||
return {};
|
||||
return JS::js_string(vm, impl->response_text());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibJS/Runtime/Object.h>
|
||||
|
||||
namespace Web::Bindings {
|
||||
|
||||
class XMLHttpRequestPrototype final : public JS::Object {
|
||||
JS_OBJECT(XMLHttpRequestPrototype, JS::Object);
|
||||
|
||||
public:
|
||||
explicit XMLHttpRequestPrototype(JS::GlobalObject&);
|
||||
virtual void initialize(JS::GlobalObject&) override;
|
||||
virtual ~XMLHttpRequestPrototype() override;
|
||||
|
||||
private:
|
||||
JS_DECLARE_NATIVE_FUNCTION(open);
|
||||
JS_DECLARE_NATIVE_FUNCTION(send);
|
||||
JS_DECLARE_NATIVE_FUNCTION(set_request_header);
|
||||
|
||||
JS_DECLARE_NATIVE_GETTER(ready_state_getter);
|
||||
JS_DECLARE_NATIVE_GETTER(response_text_getter);
|
||||
};
|
||||
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <AK/FlyString.h>
|
||||
#include <LibJS/Runtime/GlobalObject.h>
|
||||
#include <LibJS/Runtime/Value.h>
|
||||
#include <LibWeb/Bindings/WindowObject.h>
|
||||
#include <LibWeb/Bindings/XMLHttpRequestPrototype.h>
|
||||
#include <LibWeb/Bindings/XMLHttpRequestWrapper.h>
|
||||
#include <LibWeb/XHR/XMLHttpRequest.h>
|
||||
|
||||
namespace Web::Bindings {
|
||||
|
||||
XMLHttpRequestWrapper* wrap(JS::GlobalObject& global_object, XHR::XMLHttpRequest& impl)
|
||||
{
|
||||
return static_cast<XMLHttpRequestWrapper*>(wrap_impl(global_object, impl));
|
||||
}
|
||||
|
||||
XMLHttpRequestWrapper::XMLHttpRequestWrapper(JS::GlobalObject& global_object, XHR::XMLHttpRequest& impl)
|
||||
: EventTargetWrapper(global_object, impl)
|
||||
{
|
||||
set_prototype(static_cast<WindowObject&>(global_object).xhr_prototype());
|
||||
}
|
||||
|
||||
XMLHttpRequestWrapper::~XMLHttpRequestWrapper()
|
||||
{
|
||||
}
|
||||
|
||||
XHR::XMLHttpRequest& XMLHttpRequestWrapper::impl()
|
||||
{
|
||||
return static_cast<XHR::XMLHttpRequest&>(EventTargetWrapper::impl());
|
||||
}
|
||||
|
||||
const XHR::XMLHttpRequest& XMLHttpRequestWrapper::impl() const
|
||||
{
|
||||
return static_cast<const XHR::XMLHttpRequest&>(EventTargetWrapper::impl());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/Bindings/EventTargetWrapper.h>
|
||||
|
||||
namespace Web::Bindings {
|
||||
|
||||
class XMLHttpRequestWrapper final : public EventTargetWrapper {
|
||||
public:
|
||||
XMLHttpRequestWrapper(JS::GlobalObject&, XHR::XMLHttpRequest&);
|
||||
virtual ~XMLHttpRequestWrapper() override;
|
||||
|
||||
XHR::XMLHttpRequest& impl();
|
||||
const XHR::XMLHttpRequest& impl() const;
|
||||
|
||||
private:
|
||||
virtual const char* class_name() const override { return "XMLHttpRequestWrapper"; }
|
||||
};
|
||||
|
||||
XMLHttpRequestWrapper* wrap(JS::GlobalObject&, XHR::XMLHttpRequest&);
|
||||
|
||||
}
|
|
@ -8,9 +8,6 @@ set(SOURCES
|
|||
Bindings/ScriptExecutionContext.cpp
|
||||
Bindings/WindowObject.cpp
|
||||
Bindings/Wrappable.cpp
|
||||
Bindings/XMLHttpRequestConstructor.cpp
|
||||
Bindings/XMLHttpRequestPrototype.cpp
|
||||
Bindings/XMLHttpRequestWrapper.cpp
|
||||
Bindings/RangeConstructor.cpp
|
||||
Bindings/RangePrototype.cpp
|
||||
Bindings/RangeWrapper.cpp
|
||||
|
@ -375,6 +372,7 @@ libweb_js_wrapper(SVG/SVGPathElement)
|
|||
libweb_js_wrapper(SVG/SVGSVGElement)
|
||||
libweb_js_wrapper(UIEvents/MouseEvent)
|
||||
libweb_js_wrapper(UIEvents/UIEvent)
|
||||
libweb_js_wrapper(XHR/XMLHttpRequest)
|
||||
|
||||
get_property(WRAPPER_SOURCES GLOBAL PROPERTY wrapper_sources)
|
||||
set(SOURCES ${SOURCES} ${WRAPPER_SOURCES})
|
||||
|
|
|
@ -232,6 +232,7 @@ static OwnPtr<Interface> parse_interface(StringView filename, const StringView&
|
|||
consume_whitespace();
|
||||
auto name = lexer.consume_until([](auto ch) { return isspace(ch) || ch == ';'; });
|
||||
consume_whitespace();
|
||||
|
||||
assert_specific(';');
|
||||
Attribute attribute;
|
||||
attribute.readonly = readonly;
|
||||
|
@ -397,7 +398,7 @@ int main(int argc, char** argv)
|
|||
return 1;
|
||||
}
|
||||
|
||||
if (namespace_.is_one_of("DOM", "HTML", "UIEvents", "HighResolutionTime", "NavigationTiming", "SVG")) {
|
||||
if (namespace_.is_one_of("DOM", "HTML", "UIEvents", "HighResolutionTime", "NavigationTiming", "SVG", "XHR")) {
|
||||
StringBuilder builder;
|
||||
builder.append(namespace_);
|
||||
builder.append("::");
|
||||
|
@ -519,6 +520,8 @@ static void generate_header(const IDL::Interface& interface)
|
|||
# include <LibWeb/NavigationTiming/@name@.h>
|
||||
#elif __has_include(<LibWeb/SVG/@name@.h>)
|
||||
# include <LibWeb/SVG/@name@.h>
|
||||
#elif __has_include(<LibWeb/XHR/@name@.h>)
|
||||
# include <LibWeb/XHR/@name@.h>
|
||||
#endif
|
||||
)~~~");
|
||||
|
||||
|
@ -739,6 +742,8 @@ void generate_constructor_implementation(const IDL::Interface& interface)
|
|||
# include <LibWeb/NavigationTiming/@name@.h>
|
||||
#elif __has_include(<LibWeb/SVG/@name@.h>)
|
||||
# include <LibWeb/SVG/@name@.h>
|
||||
#elif __has_include(<LibWeb/XHR/@name@.h>)
|
||||
# include <LibWeb/XHR/@name@.h>
|
||||
#endif
|
||||
|
||||
// FIXME: This is a total hack until we can figure out the namespace for a given type somehow.
|
||||
|
@ -920,12 +925,15 @@ void generate_prototype_implementation(const IDL::Interface& interface)
|
|||
# include <LibWeb/NavigationTiming/@name@.h>
|
||||
#elif __has_include(<LibWeb/SVG/@name@.h>)
|
||||
# include <LibWeb/SVG/@name@.h>
|
||||
#elif __has_include(<LibWeb/XHR/@name@.h>)
|
||||
# include <LibWeb/XHR/@name@.h>
|
||||
#endif
|
||||
|
||||
// FIXME: This is a total hack until we can figure out the namespace for a given type somehow.
|
||||
using namespace Web::DOM;
|
||||
using namespace Web::HTML;
|
||||
using namespace Web::NavigationTiming;
|
||||
using namespace Web::XHR;
|
||||
|
||||
namespace Web::Bindings {
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -40,12 +40,12 @@ class XMLHttpRequest final
|
|||
, public DOM::EventTarget
|
||||
, public Bindings::Wrappable {
|
||||
public:
|
||||
enum class ReadyState {
|
||||
Unsent,
|
||||
Opened,
|
||||
HeadersReceived,
|
||||
Loading,
|
||||
Done,
|
||||
enum class ReadyState : u16 {
|
||||
Unsent = 0,
|
||||
Opened = 1,
|
||||
HeadersReceived = 2,
|
||||
Loading = 3,
|
||||
Done = 4,
|
||||
};
|
||||
|
||||
using WrapperType = Bindings::XMLHttpRequestWrapper;
|
||||
|
|
16
Userland/Libraries/LibWeb/XHR/XMLHttpRequest.idl
Normal file
16
Userland/Libraries/LibWeb/XHR/XMLHttpRequest.idl
Normal file
|
@ -0,0 +1,16 @@
|
|||
interface XMLHttpRequest : EventTarget {
|
||||
|
||||
const unsigned short UNSENT = 0;
|
||||
const unsigned short OPENED = 1;
|
||||
const unsigned short HEADERS_RECEIVED = 2;
|
||||
const unsigned short LOADING = 3;
|
||||
const unsigned short DONE = 4;
|
||||
|
||||
readonly attribute unsigned short readyState;
|
||||
readonly attribute DOMString responseText;
|
||||
|
||||
undefined open(DOMString method, DOMString url);
|
||||
undefined setRequestHeader(DOMString name, DOMString value);
|
||||
undefined send();
|
||||
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue