diff options
author | Luke Wilde <lukew@serenityos.org> | 2021-09-03 21:01:10 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-03 23:11:58 +0200 |
commit | 2f426765a6d7c77956c522bf406e6d75e0b9343e (patch) | |
tree | e56736d846482c8071a82383465f53320d21b347 /Userland | |
parent | ed97ee902bbda9c1a8f62da956fe684371426026 (diff) | |
download | serenity-2f426765a6d7c77956c522bf406e6d75e0b9343e.zip |
LibWeb: Add support HTMLScriptElement.supports
See https://github.com/whatwg/html/commit/33ff054a6caa014f4cce2912c93a19547a2e2717
Diffstat (limited to 'Userland')
3 files changed, 33 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.h b/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.h index 9ba65c259c..827fbcc5dc 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.h @@ -32,6 +32,12 @@ public: virtual void inserted() override; + // https://html.spec.whatwg.org/multipage/scripting.html#dom-script-supports + static bool supports(String const& type) + { + return type.is_one_of("classic", "module"); + } + private: void prepare_script(); void script_became_ready(); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.idl b/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.idl index 370dadd29a..36eb5ccd2e 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.idl +++ b/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.idl @@ -6,6 +6,8 @@ interface HTMLScriptElement : HTMLElement { [Reflect] attribute boolean defer; [Reflect] attribute DOMString integrity; + static boolean supports(DOMString type); + [Reflect] attribute DOMString charset; [Reflect] attribute DOMString event; [Reflect=for] attribute DOMString htmlFor; diff --git a/Userland/Libraries/LibWeb/Tests/HTML/HTMLScriptElement.supports.js b/Userland/Libraries/LibWeb/Tests/HTML/HTMLScriptElement.supports.js new file mode 100644 index 0000000000..e449797d51 --- /dev/null +++ b/Userland/Libraries/LibWeb/Tests/HTML/HTMLScriptElement.supports.js @@ -0,0 +1,25 @@ +describe("HTMLScriptElement.supports", () => { + loadLocalPage("/res/html/misc/blank.html"); + + afterInitialPageLoad(page => { + test("length is 1", () => { + expect(page.HTMLScriptElement.supports).toHaveLength(1); + }); + + test("Basic functionality", () => { + expect(page.HTMLScriptElement.supports("classic")).toBeTrue(); + expect(page.HTMLScriptElement.supports("module")).toBeTrue(); + expect(page.HTMLScriptElement.supports("abc")).toBeFalse(); + + // Is case sensitive. + expect(page.HTMLScriptElement.supports("Classic")).toBeFalse(); + expect(page.HTMLScriptElement.supports("Module")).toBeFalse(); + + // Doesn't strip whitespace. + expect(page.HTMLScriptElement.supports(" classic ")).toBeFalse(); + expect(page.HTMLScriptElement.supports(" module ")).toBeFalse(); + }); + }); + + waitForPageToLoad(); +}); |