diff options
author | Andreas Kling <kling@serenityos.org> | 2021-09-09 18:03:01 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-09 21:25:10 +0200 |
commit | 0839442da5b5bf03a02b295278f996a07c08e57c (patch) | |
tree | da48571b51bffdb47723f7ac7fb3dd8e4fb324e6 /Userland/Libraries | |
parent | 612a23d6fc1d39ab50e8ecd6dbbd26ca69bc135a (diff) | |
download | serenity-0839442da5b5bf03a02b295278f996a07c08e57c.zip |
LibWeb: Start working on spec-aligned HTML scripting semantics
This patch adds HTML::Script and HTML::ClassicScript (subclass of the
former.)
Diffstat (limited to 'Userland/Libraries')
5 files changed, 105 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index c04837f9b1..1568ef5429 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -157,6 +157,8 @@ set(SOURCES HTML/Parser/HTMLTokenizer.cpp HTML/Parser/ListOfActiveFormattingElements.cpp HTML/Parser/StackOfOpenElements.cpp + HTML/Scripting/ClassicScript.cpp + HTML/Scripting/Script.cpp HTML/SubmitEvent.cpp HTML/SyntaxHighlighter/SyntaxHighlighter.cpp HTML/TagNames.cpp diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp b/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp new file mode 100644 index 0000000000..b43439153c --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2021, Andreas Kling <kling@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include <LibWeb/HTML/Scripting/ClassicScript.h> + +namespace Web::HTML { + +NonnullRefPtr<ClassicScript> ClassicScript::create(URL base_url, RefPtr<JS::Script> script_record) +{ + return adopt_ref(*new ClassicScript(move(base_url), move(script_record))); +} + +ClassicScript::ClassicScript(URL base_url, RefPtr<JS::Script> script_record) + : Script(move(base_url)) + , m_script_record(move(script_record)) +{ +} + +ClassicScript::~ClassicScript() +{ +} + +} diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.h b/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.h new file mode 100644 index 0000000000..2959b308fc --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2021, Andreas Kling <kling@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <LibJS/Script.h> +#include <LibWeb/HTML/Scripting/Script.h> + +namespace Web::HTML { + +// https://html.spec.whatwg.org/multipage/webappapis.html#classic-script +class ClassicScript final : public Script { +public: + ~ClassicScript(); + static NonnullRefPtr<ClassicScript> create(URL base_url, RefPtr<JS::Script>); + + JS::Script* script_record() { return m_script_record; } + JS::Script const* script_record() const { return m_script_record; } + +private: + explicit ClassicScript(URL base_url, RefPtr<JS::Script>); + + RefPtr<JS::Script> m_script_record; +}; + +} diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/Script.cpp b/Userland/Libraries/LibWeb/HTML/Scripting/Script.cpp new file mode 100644 index 0000000000..afd528880f --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/Scripting/Script.cpp @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2021, Andreas Kling <kling@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include <LibWeb/HTML/Scripting/Script.h> + +namespace Web::HTML { + +Script::Script(URL base_url) + : m_base_url(move(base_url)) +{ +} + +Script::~Script() +{ +} + +} diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/Script.h b/Userland/Libraries/LibWeb/HTML/Scripting/Script.h new file mode 100644 index 0000000000..4781a621ad --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/Scripting/Script.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2021, Andreas Kling <kling@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <AK/RefCounted.h> +#include <AK/URL.h> + +namespace Web::HTML { + +// https://html.spec.whatwg.org/multipage/webappapis.html#concept-script +class Script : public RefCounted<Script> { +public: + virtual ~Script(); + + URL const& base_url() const { return m_base_url; } + +protected: + explicit Script(URL base_url); + +private: + URL m_base_url; +}; + +} |