mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2026-04-21 03:10:26 +00:00
LibWeb: Support CSS modules
This adds support for importing CSS stylesheets from CSS files in javascript.
This commit is contained in:
parent
2362a65e3b
commit
f1d3244b22
Notes:
github-actions[bot]
2026-04-03 19:22:27 +00:00
Author: https://github.com/skyz1
Commit: f1d3244b22
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6029
Reviewed-by: https://github.com/AtkinsSJ
Reviewed-by: https://github.com/alimpfard
Reviewed-by: https://github.com/konradekk
Reviewed-by: https://github.com/shannonbooth ✅
21 changed files with 272 additions and 80 deletions
|
|
@ -7,6 +7,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <LibJS/SourceTextModule.h>
|
||||
#include <LibJS/SyntheticModule.h>
|
||||
#include <LibWeb/Export.h>
|
||||
#include <LibWeb/HTML/Scripting/Script.h>
|
||||
|
||||
|
|
@ -18,29 +19,21 @@ struct ParsedProgram;
|
|||
|
||||
namespace Web::HTML {
|
||||
|
||||
// FIXME: Support WebAssembly Module Record
|
||||
using ModuleScriptRecord = Variant<Empty, GC::Ref<JS::SourceTextModule>, GC::Ref<JS::SyntheticModule>>;
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/webappapis.html#module-script
|
||||
class ModuleScript : public Script {
|
||||
class WEB_API ModuleScript : public Script {
|
||||
GC_CELL(ModuleScript, Script);
|
||||
GC_DECLARE_ALLOCATOR(ModuleScript);
|
||||
|
||||
public:
|
||||
virtual ~ModuleScript() override;
|
||||
|
||||
protected:
|
||||
ModuleScript(URL::URL base_url, ByteString filename, JS::Realm&);
|
||||
|
||||
private:
|
||||
virtual bool is_module_script() const final { return true; }
|
||||
};
|
||||
|
||||
class WEB_API JavaScriptModuleScript final : public ModuleScript {
|
||||
GC_CELL(JavaScriptModuleScript, ModuleScript);
|
||||
GC_DECLARE_ALLOCATOR(JavaScriptModuleScript);
|
||||
|
||||
public:
|
||||
virtual ~JavaScriptModuleScript() override;
|
||||
|
||||
static WebIDL::ExceptionOr<GC::Ptr<JavaScriptModuleScript>> create(ByteString const& filename, StringView source, JS::Realm&, URL::URL base_url);
|
||||
static WebIDL::ExceptionOr<GC::Ptr<JavaScriptModuleScript>> create_from_pre_parsed(ByteString const& filename, NonnullRefPtr<JS::SourceCode const> source_code, JS::Realm&, URL::URL base_url, JS::FFI::ParsedProgram* parsed);
|
||||
static WebIDL::ExceptionOr<GC::Ptr<ModuleScript>> create(ByteString const& filename, StringView source, JS::Realm&, URL::URL base_url);
|
||||
static WebIDL::ExceptionOr<GC::Ptr<ModuleScript>> create_from_pre_parsed(ByteString const& filename, NonnullRefPtr<JS::SourceCode const> source_code, JS::Realm&, URL::URL base_url, JS::FFI::ParsedProgram* parsed);
|
||||
static WebIDL::ExceptionOr<GC::Ptr<ModuleScript>> create_a_javascript_module_script(ByteString const& filename, StringView source, JS::Realm&, URL::URL base_url);
|
||||
static WebIDL::ExceptionOr<GC::Ptr<ModuleScript>> create_a_css_module_script(ByteString const& filename, StringView source, JS::Realm&);
|
||||
|
||||
enum class PreventErrorReporting {
|
||||
Yes,
|
||||
|
|
@ -49,28 +42,24 @@ public:
|
|||
|
||||
JS::Promise* run(PreventErrorReporting = PreventErrorReporting::No);
|
||||
|
||||
JS::SourceTextModule const* record() const { return m_record.ptr(); }
|
||||
JS::SourceTextModule* record() { return m_record.ptr(); }
|
||||
ModuleScriptRecord record() const { return m_record; }
|
||||
|
||||
protected:
|
||||
JavaScriptModuleScript(URL::URL base_url, ByteString filename, JS::Realm&);
|
||||
ModuleScript(Optional<URL::URL> base_url, ByteString filename, JS::Realm&);
|
||||
|
||||
private:
|
||||
virtual bool is_javascript_module_script() const final { return true; }
|
||||
virtual bool is_module_script() const final { return true; }
|
||||
virtual void visit_edges(JS::Cell::Visitor&) override;
|
||||
|
||||
GC::Ptr<JS::SourceTextModule> m_record;
|
||||
ModuleScriptRecord m_record;
|
||||
|
||||
size_t m_fetch_internal_request_count { 0 };
|
||||
size_t m_completed_fetch_internal_request_count { 0 };
|
||||
|
||||
Function<void(JavaScriptModuleScript const*)> m_completed_fetch_internal_callback;
|
||||
Function<void(ModuleScript const*)> m_completed_fetch_internal_callback;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
template<>
|
||||
inline bool JS::Script::HostDefined::fast_is<Web::HTML::ModuleScript>() const { return is_module_script(); }
|
||||
|
||||
template<>
|
||||
inline bool JS::Script::HostDefined::fast_is<Web::HTML::JavaScriptModuleScript>() const { return is_javascript_module_script(); }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue