diff --git a/Userland/Libraries/LibWeb/Bindings/LocationConstructor.cpp b/Userland/Libraries/LibWeb/Bindings/LocationConstructor.cpp new file mode 100644 index 0000000000..5517e15b3f --- /dev/null +++ b/Userland/Libraries/LibWeb/Bindings/LocationConstructor.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2022, the SerenityOS developers. + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include +#include + +namespace Web::Bindings { + +LocationConstructor::LocationConstructor(JS::GlobalObject& global_object) + : NativeFunction(*global_object.function_prototype()) +{ +} + +LocationConstructor::~LocationConstructor() = default; + +JS::ThrowCompletionOr LocationConstructor::call() +{ + return vm().throw_completion(global_object(), JS::ErrorType::ConstructorWithoutNew, "Location"); +} + +JS::ThrowCompletionOr LocationConstructor::construct(FunctionObject&) +{ + return vm().throw_completion(global_object(), JS::ErrorType::NotAConstructor, "Location"); +} + +void LocationConstructor::initialize(JS::GlobalObject& global_object) +{ + auto& vm = this->vm(); + auto& window = static_cast(global_object); + + NativeFunction::initialize(global_object); + define_direct_property(vm.names.prototype, &window.ensure_web_prototype("Location"), 0); + define_direct_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable); +} + +} diff --git a/Userland/Libraries/LibWeb/Bindings/LocationConstructor.h b/Userland/Libraries/LibWeb/Bindings/LocationConstructor.h new file mode 100644 index 0000000000..4d35774851 --- /dev/null +++ b/Userland/Libraries/LibWeb/Bindings/LocationConstructor.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2022, the SerenityOS developers. + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace Web::Bindings { + +class LocationConstructor : public JS::NativeFunction { + JS_OBJECT(LocationConstructor, JS::NativeFunction); + +public: + explicit LocationConstructor(JS::GlobalObject&); + virtual void initialize(JS::GlobalObject&) override; + virtual ~LocationConstructor() override; + + virtual JS::ThrowCompletionOr call() override; + virtual JS::ThrowCompletionOr construct(JS::FunctionObject& new_target) override; + +private: + virtual bool has_constructor() const override { return true; } +}; + +} diff --git a/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp b/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp index 1c152169d4..6bff5f40c3 100644 --- a/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp +++ b/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -23,7 +24,7 @@ namespace Web::Bindings { // https://html.spec.whatwg.org/multipage/history.html#the-location-interface LocationObject::LocationObject(JS::GlobalObject& global_object) - : Object(*global_object.object_prototype()) + : Object(static_cast(global_object).ensure_web_prototype("Location")) , m_default_properties(heap()) { } diff --git a/Userland/Libraries/LibWeb/Bindings/LocationPrototype.h b/Userland/Libraries/LibWeb/Bindings/LocationPrototype.h new file mode 100644 index 0000000000..c4303742ac --- /dev/null +++ b/Userland/Libraries/LibWeb/Bindings/LocationPrototype.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2022, the SerenityOS developers. + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include +#include +#include + +namespace Web::Bindings { + +class LocationPrototype final : public JS::Object { + JS_OBJECT(LocationPrototype, JS::Object); + +public: + explicit LocationPrototype(JS::GlobalObject& global_object) + : JS::Object(*global_object.object_prototype()) + { + } +}; + +} diff --git a/Userland/Libraries/LibWeb/Bindings/NavigatorConstructor.cpp b/Userland/Libraries/LibWeb/Bindings/NavigatorConstructor.cpp new file mode 100644 index 0000000000..a248df808f --- /dev/null +++ b/Userland/Libraries/LibWeb/Bindings/NavigatorConstructor.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2022, the SerenityOS developers. + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include +#include + +namespace Web::Bindings { + +NavigatorConstructor::NavigatorConstructor(JS::GlobalObject& global_object) + : NativeFunction(*global_object.function_prototype()) +{ +} + +NavigatorConstructor::~NavigatorConstructor() = default; + +JS::ThrowCompletionOr NavigatorConstructor::call() +{ + return vm().throw_completion(global_object(), JS::ErrorType::ConstructorWithoutNew, "Navigator"); +} + +JS::ThrowCompletionOr NavigatorConstructor::construct(FunctionObject&) +{ + return vm().throw_completion(global_object(), JS::ErrorType::NotAConstructor, "Navigator"); +} + +void NavigatorConstructor::initialize(JS::GlobalObject& global_object) +{ + auto& vm = this->vm(); + auto& window = static_cast(global_object); + + NativeFunction::initialize(global_object); + define_direct_property(vm.names.prototype, &window.ensure_web_prototype("Navigator"), 0); + define_direct_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable); +} + +} diff --git a/Userland/Libraries/LibWeb/Bindings/NavigatorConstructor.h b/Userland/Libraries/LibWeb/Bindings/NavigatorConstructor.h new file mode 100644 index 0000000000..b98347db74 --- /dev/null +++ b/Userland/Libraries/LibWeb/Bindings/NavigatorConstructor.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2022, the SerenityOS developers. + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace Web::Bindings { + +class NavigatorConstructor : public JS::NativeFunction { + JS_OBJECT(NavigatorConstructor, JS::NativeFunction); + +public: + explicit NavigatorConstructor(JS::GlobalObject&); + virtual void initialize(JS::GlobalObject&) override; + virtual ~NavigatorConstructor() override; + + virtual JS::ThrowCompletionOr call() override; + virtual JS::ThrowCompletionOr construct(JS::FunctionObject& new_target) override; + +private: + virtual bool has_constructor() const override { return true; } +}; + +} diff --git a/Userland/Libraries/LibWeb/Bindings/NavigatorObject.cpp b/Userland/Libraries/LibWeb/Bindings/NavigatorObject.cpp index deb7e7a295..479467f955 100644 --- a/Userland/Libraries/LibWeb/Bindings/NavigatorObject.cpp +++ b/Userland/Libraries/LibWeb/Bindings/NavigatorObject.cpp @@ -7,13 +7,14 @@ #include #include #include +#include #include namespace Web { namespace Bindings { NavigatorObject::NavigatorObject(JS::GlobalObject& global_object) - : Object(*global_object.object_prototype()) + : Object(static_cast(global_object).ensure_web_prototype("Navigator")) { } diff --git a/Userland/Libraries/LibWeb/Bindings/NavigatorPrototype.h b/Userland/Libraries/LibWeb/Bindings/NavigatorPrototype.h new file mode 100644 index 0000000000..b213b77ef3 --- /dev/null +++ b/Userland/Libraries/LibWeb/Bindings/NavigatorPrototype.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2022, the SerenityOS developers. + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include +#include +#include + +namespace Web::Bindings { + +class NavigatorPrototype final : public JS::Object { + JS_OBJECT(NavigatorPrototype, JS::Object); + +public: + explicit NavigatorPrototype(JS::GlobalObject& global_object) + : JS::Object(*global_object.object_prototype()) + { + } +}; + +} diff --git a/Userland/Libraries/LibWeb/Bindings/WindowConstructor.cpp b/Userland/Libraries/LibWeb/Bindings/WindowConstructor.cpp new file mode 100644 index 0000000000..87ad5904f1 --- /dev/null +++ b/Userland/Libraries/LibWeb/Bindings/WindowConstructor.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2022, the SerenityOS developers. + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include +#include + +namespace Web::Bindings { + +WindowConstructor::WindowConstructor(JS::GlobalObject& global_object) + : NativeFunction(*global_object.function_prototype()) +{ +} + +WindowConstructor::~WindowConstructor() = default; + +JS::ThrowCompletionOr WindowConstructor::call() +{ + return vm().throw_completion(global_object(), JS::ErrorType::ConstructorWithoutNew, "Window"); +} + +JS::ThrowCompletionOr WindowConstructor::construct(FunctionObject&) +{ + return vm().throw_completion(global_object(), JS::ErrorType::NotAConstructor, "Window"); +} + +void WindowConstructor::initialize(JS::GlobalObject& global_object) +{ + auto& vm = this->vm(); + auto& window = static_cast(global_object); + + NativeFunction::initialize(global_object); + define_direct_property(vm.names.prototype, &window.ensure_web_prototype("Window"), 0); + define_direct_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable); +} + +} diff --git a/Userland/Libraries/LibWeb/Bindings/WindowConstructor.h b/Userland/Libraries/LibWeb/Bindings/WindowConstructor.h new file mode 100644 index 0000000000..3a2493e4c3 --- /dev/null +++ b/Userland/Libraries/LibWeb/Bindings/WindowConstructor.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2022, the SerenityOS developers. + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace Web::Bindings { + +class WindowConstructor : public JS::NativeFunction { + JS_OBJECT(WindowConstructor, JS::NativeFunction); + +public: + explicit WindowConstructor(JS::GlobalObject&); + virtual void initialize(JS::GlobalObject&) override; + virtual ~WindowConstructor() override; + + virtual JS::ThrowCompletionOr call() override; + virtual JS::ThrowCompletionOr construct(JS::FunctionObject& new_target) override; + +private: + virtual bool has_constructor() const override { return true; } +}; + +} diff --git a/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp b/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp index edf89af246..2c8b11bd6a 100644 --- a/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp +++ b/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -59,7 +60,7 @@ void WindowObject::initialize_global_object() { Base::initialize_global_object(); - Object::set_prototype(&ensure_web_prototype("EventTarget")); + Object::set_prototype(&ensure_web_prototype("Window")); // FIXME: These should be native accessors, not properties define_direct_property("window", this, JS::Attribute::Enumerable); diff --git a/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h b/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h index 0f193d8bfe..917c188366 100644 --- a/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h +++ b/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h @@ -228,6 +228,8 @@ #include #include #include +#include +#include #include #include #include @@ -238,6 +240,8 @@ #include #include #include +#include +#include #include #include #include @@ -321,6 +325,8 @@ #include #include #include +#include +#include #include #include #include @@ -449,11 +455,13 @@ ADD_WINDOW_OBJECT_INTERFACE(ImageData) \ ADD_WINDOW_OBJECT_INTERFACE(IntersectionObserver) \ ADD_WINDOW_OBJECT_INTERFACE(KeyboardEvent) \ + ADD_WINDOW_OBJECT_INTERFACE(Location) \ ADD_WINDOW_OBJECT_INTERFACE(MediaQueryList) \ ADD_WINDOW_OBJECT_INTERFACE(MediaQueryListEvent) \ ADD_WINDOW_OBJECT_INTERFACE(MessageChannel) \ ADD_WINDOW_OBJECT_INTERFACE(MessageEvent) \ ADD_WINDOW_OBJECT_INTERFACE(MouseEvent) \ + ADD_WINDOW_OBJECT_INTERFACE(Navigator) \ ADD_WINDOW_OBJECT_INTERFACE(Node) \ ADD_WINDOW_OBJECT_INTERFACE(NodeIterator) \ ADD_WINDOW_OBJECT_INTERFACE(NodeList) \ @@ -498,6 +506,7 @@ ADD_WINDOW_OBJECT_INTERFACE(Worker) \ ADD_WINDOW_OBJECT_INTERFACE(XMLHttpRequest) \ ADD_WINDOW_OBJECT_INTERFACE(XMLHttpRequestEventTarget) \ + ADD_WINDOW_OBJECT_INTERFACE(Window) \ ADD_WINDOW_OBJECT_CONSTRUCTOR_AND_PROTOTYPE(Audio, AudioConstructor, HTMLAudioElementPrototype) \ ADD_WINDOW_OBJECT_CONSTRUCTOR_AND_PROTOTYPE(Image, ImageConstructor, HTMLImageElementPrototype) \ ADD_WINDOW_OBJECT_CONSTRUCTOR_AND_PROTOTYPE(Option, OptionConstructor, HTMLOptionElementPrototype) diff --git a/Userland/Libraries/LibWeb/Bindings/WindowPrototype.h b/Userland/Libraries/LibWeb/Bindings/WindowPrototype.h new file mode 100644 index 0000000000..ec57ae2e94 --- /dev/null +++ b/Userland/Libraries/LibWeb/Bindings/WindowPrototype.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2022, the SerenityOS developers. + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include +#include +#include +#include + +namespace Web::Bindings { + +class WindowPrototype final : public JS::Object { + JS_OBJECT(WindowPrototype, JS::Object); + +public: + explicit WindowPrototype(JS::GlobalObject& global_object) + : JS::Object(static_cast(global_object).ensure_web_prototype("EventTarget")) + { + } +}; + +} diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 04abf8ac34..44f28f723e 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -9,11 +9,14 @@ set(SOURCES Bindings/EventWrapperFactory.cpp Bindings/IDLAbstractOperations.cpp Bindings/ImageConstructor.cpp + Bindings/LocationConstructor.cpp Bindings/LocationObject.cpp Bindings/MainThreadVM.cpp + Bindings/NavigatorConstructor.cpp Bindings/NavigatorObject.cpp Bindings/NodeWrapperFactory.cpp Bindings/OptionConstructor.cpp + Bindings/WindowConstructor.cpp Bindings/WindowObject.cpp Bindings/WindowProxy.cpp Bindings/Wrappable.cpp