From 0839442da5b5bf03a02b295278f996a07c08e57c Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 9 Sep 2021 18:03:01 +0200 Subject: [PATCH] LibWeb: Start working on spec-aligned HTML scripting semantics This patch adds HTML::Script and HTML::ClassicScript (subclass of the former.) --- Userland/Libraries/LibWeb/CMakeLists.txt | 2 ++ .../LibWeb/HTML/Scripting/ClassicScript.cpp | 26 +++++++++++++++++ .../LibWeb/HTML/Scripting/ClassicScript.h | 29 +++++++++++++++++++ .../LibWeb/HTML/Scripting/Script.cpp | 20 +++++++++++++ .../Libraries/LibWeb/HTML/Scripting/Script.h | 28 ++++++++++++++++++ 5 files changed, 105 insertions(+) create mode 100644 Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp create mode 100644 Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.h create mode 100644 Userland/Libraries/LibWeb/HTML/Scripting/Script.cpp create mode 100644 Userland/Libraries/LibWeb/HTML/Scripting/Script.h 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 + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include + +namespace Web::HTML { + +NonnullRefPtr ClassicScript::create(URL base_url, RefPtr script_record) +{ + return adopt_ref(*new ClassicScript(move(base_url), move(script_record))); +} + +ClassicScript::ClassicScript(URL base_url, RefPtr 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 + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include + +namespace Web::HTML { + +// https://html.spec.whatwg.org/multipage/webappapis.html#classic-script +class ClassicScript final : public Script { +public: + ~ClassicScript(); + static NonnullRefPtr create(URL base_url, RefPtr); + + 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); + + RefPtr 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 + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include + +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 + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include + +namespace Web::HTML { + +// https://html.spec.whatwg.org/multipage/webappapis.html#concept-script +class Script : public RefCounted