From b8b24648e5716bd4e7f7cb77cb792163e8599149 Mon Sep 17 00:00:00 2001 From: Tsuyoshi Horo Date: Mon, 6 Sep 2021 03:31:07 +0000 Subject: [PATCH] Implement HTMLScriptElement.supports(type) method Bug: 1245528, https://github.com/whatwg/html/issues/6472 Change-Id: I9a902504cf692caa73ae7e49fd65895156bbf197 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3133553 Commit-Queue: Tsuyoshi Horo Reviewed-by: Hiroshige Hayashizaki Cr-Commit-Position: refs/heads/main@{#918474} --- .../renderer/core/html/html_script_element.cc | 19 +++++++ .../renderer/core/html/html_script_element.h | 2 + .../core/html/html_script_element.idl | 3 ++ .../platform/runtime_enabled_features.json5 | 4 ++ .../the-script-element/script-supports.html | 52 +++++++++++++++++++ .../script-supports-importmap.html | 22 ++++++++ .../global-interface-listing-expected.txt | 1 + .../script-supports-speculationrules.html | 21 ++++++++ 8 files changed, 124 insertions(+) create mode 100644 third_party/blink/web_tests/external/wpt/html/semantics/scripting-1/the-script-element/script-supports.html create mode 100644 third_party/blink/web_tests/external/wpt/import-maps/script-supports-importmap.html create mode 100644 third_party/blink/web_tests/wpt_internal/prerender/script-supports-speculationrules.html diff --git a/third_party/blink/renderer/core/html/html_script_element.cc b/third_party/blink/renderer/core/html/html_script_element.cc index b08d20ddca92c3..55c1e4295d0ecd 100644 --- a/third_party/blink/renderer/core/html/html_script_element.cc +++ b/third_party/blink/renderer/core/html/html_script_element.cc @@ -34,6 +34,7 @@ #include "third_party/blink/renderer/core/html_names.h" #include "third_party/blink/renderer/core/script/script_loader.h" #include "third_party/blink/renderer/core/script/script_runner.h" +#include "third_party/blink/renderer/core/script_type_names.h" #include "third_party/blink/renderer/core/trustedtypes/trusted_script.h" #include "third_party/blink/renderer/core/trustedtypes/trusted_types_util.h" #include "third_party/blink/renderer/platform/bindings/exception_state.h" @@ -316,6 +317,24 @@ Element& HTMLScriptElement::CloneWithoutAttributesAndChildren( return *factory.CreateElement(TagQName(), flags, IsValue()); } +// static +bool HTMLScriptElement::supports(ExecutionContext* execution_context, + const AtomicString& type) { + if (type == script_type_names::kClassic) + return true; + if (type == script_type_names::kModule) + return true; + if (type == script_type_names::kImportmap) + return true; + + if ((type == script_type_names::kSpeculationrules) && + RuntimeEnabledFeatures::SpeculationRulesEnabled(execution_context)) { + return true; + } + + return false; +} + void HTMLScriptElement::Trace(Visitor* visitor) const { visitor->Trace(loader_); HTMLElement::Trace(visitor); diff --git a/third_party/blink/renderer/core/html/html_script_element.h b/third_party/blink/renderer/core/html/html_script_element.h index d8f7c0accfc985..fc330e36141e8e 100644 --- a/third_party/blink/renderer/core/html/html_script_element.h +++ b/third_party/blink/renderer/core/html/html_script_element.h @@ -42,6 +42,8 @@ class CORE_EXPORT HTMLScriptElement final : public HTMLElement, DEFINE_WRAPPERTYPEINFO(); public: + static bool supports(ExecutionContext*, const AtomicString&); + HTMLScriptElement(Document&, const CreateElementFlags); // Returns attributes that should be checked against Trusted Types diff --git a/third_party/blink/renderer/core/html/html_script_element.idl b/third_party/blink/renderer/core/html/html_script_element.idl index f92832a7cacc52..952f94e3e2b401 100644 --- a/third_party/blink/renderer/core/html/html_script_element.idl +++ b/third_party/blink/renderer/core/html/html_script_element.idl @@ -43,4 +43,7 @@ // Subresource Integrity // https://w3c.github.io/webappsec-subresource-integrity/#HTMLScriptElement [Reflect] attribute DOMString integrity; + + // https://html.spec.whatwg.org/multipage/scripting.html#dom-script-supports + [RuntimeEnabled=ScriptElementSupports, CallWith=ExecutionContext] static boolean supports(DOMString type); }; diff --git a/third_party/blink/renderer/platform/runtime_enabled_features.json5 b/third_party/blink/renderer/platform/runtime_enabled_features.json5 index 299fd0f8bc4b0d..90c01d8cd1609c 100644 --- a/third_party/blink/renderer/platform/runtime_enabled_features.json5 +++ b/third_party/blink/renderer/platform/runtime_enabled_features.json5 @@ -1942,6 +1942,10 @@ name: "ScriptedSpeechSynthesis", status: "stable", }, + { + name: "ScriptElementSupports", + status: "experimental", + }, { name: "ScrollbarGutter", status: "stable", diff --git a/third_party/blink/web_tests/external/wpt/html/semantics/scripting-1/the-script-element/script-supports.html b/third_party/blink/web_tests/external/wpt/html/semantics/scripting-1/the-script-element/script-supports.html new file mode 100644 index 00000000000000..495056fce9ade1 --- /dev/null +++ b/third_party/blink/web_tests/external/wpt/html/semantics/scripting-1/the-script-element/script-supports.html @@ -0,0 +1,52 @@ + + +HTMLScriptElement.supports + + + + diff --git a/third_party/blink/web_tests/external/wpt/import-maps/script-supports-importmap.html b/third_party/blink/web_tests/external/wpt/import-maps/script-supports-importmap.html new file mode 100644 index 00000000000000..026c052f999ccd --- /dev/null +++ b/third_party/blink/web_tests/external/wpt/import-maps/script-supports-importmap.html @@ -0,0 +1,22 @@ + + +HTMLScriptElement.supports importmap + + + diff --git a/third_party/blink/web_tests/webexposed/global-interface-listing-expected.txt b/third_party/blink/web_tests/webexposed/global-interface-listing-expected.txt index 78e6bc3fb98599..08994cc2c4feb9 100644 --- a/third_party/blink/web_tests/webexposed/global-interface-listing-expected.txt +++ b/third_party/blink/web_tests/webexposed/global-interface-listing-expected.txt @@ -4137,6 +4137,7 @@ interface HTMLQuoteElement : HTMLElement method constructor setter cite interface HTMLScriptElement : HTMLElement + static method supports attribute @@toStringTag getter async getter charset diff --git a/third_party/blink/web_tests/wpt_internal/prerender/script-supports-speculationrules.html b/third_party/blink/web_tests/wpt_internal/prerender/script-supports-speculationrules.html new file mode 100644 index 00000000000000..bd4f3cdb95cf08 --- /dev/null +++ b/third_party/blink/web_tests/wpt_internal/prerender/script-supports-speculationrules.html @@ -0,0 +1,21 @@ + + +HTMLScriptElement.supports speculationrules + + + +