Skip to content

Commit 858415c

Browse files
authored
[cssom-1] Refactor CSSStyleSheet constructor and replaceSync to allow steps to be referenced from HTML spec (w3c#6411)
The CSS module scripts feature is being specified in HTML using several algorithms defined in cssom-1 on the CSSStyleSheet interface. In the review of the CSS module scripts HTML spec PR whatwg/html#4898, there was a concern that referencing the CSSStyleSheet methods directly implies that if these methods were overridden by user script, the UA should call the user script instead. This change pulls the steps for the `CSSStyleSheet` constructor and `replaceSync` method into separate algorithms so that they can be safely referenced from the HTML spec.
1 parent de2301e commit 858415c

1 file changed

Lines changed: 21 additions & 16 deletions

File tree

cssom-1/Overview.bs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -748,21 +748,23 @@ represents a style sheet as defined by the CSS specification. In the CSSOM a
748748
<dl>
749749
<dt><dfn constructor for=CSSStyleSheet>CSSStyleSheet(<var>options</var>)</dfn></dt>
750750
<dd>
751-
When called, execute these steps:
751+
When called, execute the steps to <a>create a constructed CSSStyleSheet</a> given <var>options</var> and return the result.
752+
</dd>
753+
754+
<dt>To <dfn export>create a constructed {{/CSSStyleSheet}}</dfn></dt> given {{CSSStyleSheetInit}} <var>options</var>, run these steps:
755+
<dd>
752756
<ol>
753-
<li>Construct a new {{/CSSStyleSheet}} object <var>sheet</var> with the following properties:
754-
<ul>
755-
<li><a spec=cssom>location</a> set to the <a spec=html>base URL</a> of the <a>associated Document</a> for the <a>current global object</a>.
756-
<li><a>stylesheet base URL</a> set to the {{CSSStyleSheetInit/baseURL}} attribute value from <var>options</var>.
757-
<li>No <a spec=cssom>parent CSS style sheet</a>.
758-
<li>No <a spec=cssom>owner node</a>.
759-
<li>No <a spec=cssom>owner CSS rule</a>.
760-
<li><a spec=cssom>title</a> set to the the empty string.
761-
<li>Unset <a spec=cssom>alternate flag</a>.
762-
<li>Set <a spec=cssom>origin-clean flag</a>.
763-
<li>Set <a>constructed flag</a>.
764-
<li><a>Constructor document</a> set to the <a>associated Document</a> for the <a>current global object</a>.
765-
</ul>
757+
<li>Construct a new {{/CSSStyleSheet}} object <var>sheet</var>.</li>
758+
<li>Set <var>sheet</var>'s <a spec=cssom>location</a> to the <a spec=html>base URL</a> of the <a>associated Document</a> for the <a>current global object</a>.
759+
<li>Set <var>sheet</var>'s <a>stylesheet base URL</a> to the {{CSSStyleSheetInit/baseURL}} attribute value from <var>options</var>.
760+
<li>Set <var>sheet</var>'s <a spec=cssom>parent CSS style sheet</a> to null.
761+
<li>Set <var>sheet</var>'s <a spec=cssom>owner node</a> to null.
762+
<li>Set <var>sheet</var>'s <a spec=cssom>owner CSS rule</a> to null.
763+
<li>Set <var>sheet</var>'s <a spec=cssom>title</a> to the the empty string.
764+
<li>Unset <var>sheet</var>'s <a spec=cssom>alternate flag</a>.
765+
<li>Set <var>sheet</var>'s <a spec=cssom>origin-clean flag</a>.
766+
<li>Set <var>sheet</var>'s <a>constructed flag</a>.
767+
<li>Set <var>sheet</var>'s <a>Constructor document</a> to the <a>associated Document</a> for the <a>current global object</a>.
766768
<li>If the {{CSSStyleSheetInit/media}} attribute of <var>options</var> is a string,
767769
<a>create a MediaList object</a> from the string
768770
and assign it as <var>sheet</var>'s <a spec=cssom>media</a>.
@@ -1027,14 +1029,17 @@ The <dfn method for=CSSStyleSheet>replace(<a for=CSSRule>text</a>)</dfn> method
10271029
<li>Return <var>promise</var>.
10281030
</ol>
10291031

1030-
The <dfn method for=CSSStyleSheet>replaceSync(<a for=CSSRule>text</a>)</dfn> method must run the following steps:
1032+
The <dfn method for=CSSStyleSheet>replaceSync(<a for=CSSRule>text</a>)</dfn> method must run the
1033+
steps to <a>synchronously replace the rules of a CSSStyleSheet</a> on this {{CSSStyleSheet}} given <var>text</var>.
1034+
1035+
To <dfn export>synchronously replace the rules of a CSSStyleSheet</dfn> on <var>sheet</var> given <var>text</var>, run these steps:
10311036
<ol>
10321037
<li>If the <a>constructed flag</a> is not set, or the <a>disallow modification flag</a> is set, throw a {{NotAllowedError}}
10331038
{{DOMException}}.
10341039
<li>Let <var>rules</var> be the result of running <a>parse a list of rules</a> from <var>text</var>. If <var>rules</var> is
10351040
not a list of rules (i.e. an error occurred during parsing), set <var>rules</var> to an empty list.
10361041
<li>If <var>rules</var> contains one or more <a>@import</a> rules, <a lt="remove a CSS rule">remove those rules</a> from <var>rules</var>.
1037-
<li>Set <a>CSS rules</a> to <var>rules</var>.
1042+
<li>Set <var>sheet</var>'s <a>CSS rules</a> to <var>rules</var>.
10381043
</ol>
10391044

10401045
#### Deprecated CSSStyleSheet members #### {#legacy-css-style-sheet-members}

0 commit comments

Comments
 (0)