/src/serenity/Userland/Libraries/LibWeb/HTML/Scripting/ModuleScript.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2022, networkException <networkexception@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <LibJS/SourceTextModule.h> |
10 | | #include <LibWeb/HTML/Scripting/Script.h> |
11 | | |
12 | | namespace Web::HTML { |
13 | | |
14 | | // https://html.spec.whatwg.org/multipage/webappapis.html#module-script |
15 | | class ModuleScript : public Script { |
16 | | JS_CELL(ModuleScript, Script); |
17 | | |
18 | | public: |
19 | | virtual ~ModuleScript() override; |
20 | | |
21 | | protected: |
22 | | ModuleScript(URL::URL base_url, ByteString filename, EnvironmentSettingsObject& environment_settings_object); |
23 | | }; |
24 | | |
25 | | class JavaScriptModuleScript final : public ModuleScript { |
26 | | JS_CELL(JavaScriptModuleScript, ModuleScript); |
27 | | JS_DECLARE_ALLOCATOR(JavaScriptModuleScript); |
28 | | |
29 | | public: |
30 | | virtual ~JavaScriptModuleScript() override; |
31 | | |
32 | | static WebIDL::ExceptionOr<JS::GCPtr<JavaScriptModuleScript>> create(ByteString const& filename, StringView source, EnvironmentSettingsObject&, URL::URL base_url); |
33 | | |
34 | | enum class PreventErrorReporting { |
35 | | Yes, |
36 | | No |
37 | | }; |
38 | | |
39 | | JS::Promise* run(PreventErrorReporting = PreventErrorReporting::No); |
40 | | |
41 | 0 | JS::SourceTextModule const* record() const { return m_record.ptr(); } |
42 | 0 | JS::SourceTextModule* record() { return m_record.ptr(); } |
43 | | |
44 | | protected: |
45 | | JavaScriptModuleScript(URL::URL base_url, ByteString filename, EnvironmentSettingsObject& environment_settings_object); |
46 | | |
47 | | private: |
48 | | virtual void visit_edges(JS::Cell::Visitor&) override; |
49 | | |
50 | | JS::GCPtr<JS::SourceTextModule> m_record; |
51 | | |
52 | | size_t m_fetch_internal_request_count { 0 }; |
53 | | size_t m_completed_fetch_internal_request_count { 0 }; |
54 | | |
55 | | Function<void(JavaScriptModuleScript const*)> m_completed_fetch_internal_callback; |
56 | | }; |
57 | | |
58 | | } |