Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove JavaScript realm dependency #219

Merged
merged 26 commits into from
Feb 27, 2024
Merged
Changes from 9 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e2e4725
Remove JavaScript realm dependency
yoshisatoyanagisawa Feb 16, 2024
8fd2654
Omit "struct" after [=URL Pattern=].
yoshisatoyanagisawa Feb 16, 2024
5baf900
Make the create algorithm to avoid breaking the existing callers.
yoshisatoyanagisawa Feb 16, 2024
f2dc8dd
Addressed comments.
yoshisatoyanagisawa Feb 19, 2024
9ef78bf
Remove realm dependencies from other spec integrations
yoshisatoyanagisawa Feb 19, 2024
d188a8d
Update spec.bs
yoshisatoyanagisawa Feb 21, 2024
32acfe3
Rename [=URL Pattern=] to [=URL pattern=]
yoshisatoyanagisawa Feb 21, 2024
52c1032
Another URLPattern to URL pattern rename.
yoshisatoyanagisawa Feb 21, 2024
0d5c24d
Move match as URL pattern's function
yoshisatoyanagisawa Feb 21, 2024
fa9383e
Also updated has regexp groups
yoshisatoyanagisawa Feb 21, 2024
a365f6d
Use associated URL pattern instead of URLPattern itself in algorithms
yoshisatoyanagisawa Feb 22, 2024
46a8a05
Revise [=create=] to return a created [=URL pattern=]
yoshisatoyanagisawa Feb 22, 2024
0914443
Applied the suggested change on URLPattern class.
yoshisatoyanagisawa Feb 22, 2024
e7b873d
Minor fix.
yoshisatoyanagisawa Feb 22, 2024
84f8a34
Make create exported
yoshisatoyanagisawa Feb 22, 2024
6a3c376
Update spec.bs
yoshisatoyanagisawa Feb 26, 2024
29ef4bd
Update spec.bs
yoshisatoyanagisawa Feb 26, 2024
4fa6e48
Omit the beginning "A" from items.
yoshisatoyanagisawa Feb 26, 2024
8075951
Hold on mentioning about {{URLPattern}} in the introduction.
yoshisatoyanagisawa Feb 26, 2024
9311ab2
Remove ", which must be set upon creation."
yoshisatoyanagisawa Feb 26, 2024
d51ad85
Combine three steps.
yoshisatoyanagisawa Feb 26, 2024
17d8a18
Revert the update on {{URLPattern}} to [=URL pattern=]
yoshisatoyanagisawa Feb 26, 2024
4e893ec
Rename from |urlpattern| to |urlPattern|
yoshisatoyanagisawa Feb 26, 2024
bf7a7c0
Implement the algorithm to build {{URLPattern}}
yoshisatoyanagisawa Feb 26, 2024
0699d52
Update spec.bs
yoshisatoyanagisawa Feb 26, 2024
62f5ffa
Update spec.bs
yoshisatoyanagisawa Feb 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 58 additions & 54 deletions spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ spec: URL; urlPrefix: https://url.spec.whatwg.org/

<h2 id=urlpatterns>URL patterns</h2>

<h3 id=introduction>Intrdocution</h3>
<h3 id=introduction>Introduction</h3>

A {{URLPattern}} has an associated [=URL pattern=], which consists of several [=components=], each of which represents a [=/pattern string|pattern=] which could be matched against the corresponding component of a [=/URL=].
A [=URL pattern=] consists of several [=components=], each of which represents a [=/pattern string|pattern=] which could be matched against the corresponding component of a [=/URL=].

It can be constructed using a string for each component, or from a shorthand string. It can optionally be resolved relative to a base URL.

Expand Down Expand Up @@ -416,21 +416,21 @@ Each {{URLPattern}} has an <dfn for="URLPattern">associated URL pattern</dfn>, a

A <dfn>URL pattern</dfn> is a [=struct=] with the following [=struct/items=]:

* A <dfn for="URL pattern">protocol component</dfn>, a [=component=]
* A <dfn for="URL pattern">username component</dfn>, a [=component=]
* A <dfn for="URL pattern">password component</dfn>, a [=component=]
* A <dfn for="URL pattern">hostname component</dfn>, a [=component=]
* A <dfn for="URL pattern">port component</dfn>, a [=component=]
* A <dfn for="URL pattern">pathname component</dfn>, a [=component=]
* A <dfn for="URL pattern">search component</dfn>, a [=component=]
* A <dfn for="URL pattern">hash component</dfn>, a [=component=]
* <dfn for="URL pattern">protocol component</dfn>, a [=component=]
* <dfn for="URL pattern">username component</dfn>, a [=component=]
* <dfn for="URL pattern">password component</dfn>, a [=component=]
* <dfn for="URL pattern">hostname component</dfn>, a [=component=]
* <dfn for="URL pattern">port component</dfn>, a [=component=]
* <dfn for="URL pattern">pathname component</dfn>, a [=component=]
* <dfn for="URL pattern">search component</dfn>, a [=component=]
* <dfn for="URL pattern">hash component</dfn>, a [=component=]

A <dfn>component</dfn> is a [=struct=] with the following [=struct/items=]:

* A <dfn for=component>pattern string</dfn>, a [=pattern string/well formed=] [=/pattern string=], which must be set upon creation.
* A <dfn for=component>regular expression</dfn>, a {{RegExp}}, which must be set upon creation.
* A <dfn for=component>group name list</dfn>, a [=list=] of strings, which must be set upon creation.
* A <dfn for=component>has regexp groups</dfn>, a [=boolean=], which must be set upon creation.
* <dfn for=component>pattern string</dfn>, a [=pattern string/well formed=] [=/pattern string=]
* <dfn for=component>regular expression</dfn>, a {{RegExp}}
* <dfn for=component>group name list</dfn>, a [=list=] of strings
* <dfn for=component>has regexp groups</dfn>, a [=boolean=]

<h3 id=high-level-operations>High-level operations</h3>

Expand Down Expand Up @@ -468,7 +468,7 @@ A <dfn>component</dfn> is a [=struct=] with the following [=struct/items=]:
</div>

<div algorithm>
To perform a <dfn export for="URL pattern">match</dfn> given a [=URL pattern=] |urlpattern|, a {{URLPatternInput}} |input|, and an optional string |baseURLString|:
To perform a <dfn export for="URL pattern">match</dfn> given a [=URL pattern=] |urlPattern|, a {{URLPatternInput}} |input|, and an optional string |baseURLString|:

1. Let |protocol| be the empty string.
1. Let |username| be the empty string.
Expand Down Expand Up @@ -507,39 +507,39 @@ A <dfn>component</dfn> is a [=struct=] with the following [=struct/items=]:
1. Set |pathname| to the result of [=URL path serializing=] |url|.
1. Set |search| to |url|'s [=url/query=] or the empty string if the value is null.
1. Set |hash| to |url|'s [=url/fragment=] or the empty string if the value is null.
1. Let |protocolExecResult| be [$RegExpBuiltinExec$](|urlpattern|'s [=URL pattern/protocol component=]'s [=component/regular expression=], |protocol|).
1. Let |usernameExecResult| be [$RegExpBuiltinExec$](|urlpattern|'s [=URL pattern/username component=]'s [=component/regular expression=], |username|).
1. Let |passwordExecResult| be [$RegExpBuiltinExec$](|urlpattern|'s [=URL pattern/password component=]'s [=component/regular expression=], |password|).
1. Let |hostnameExecResult| be [$RegExpBuiltinExec$](|urlpattern|'s [=URL pattern/hostname component=]'s [=component/regular expression=], |hostname|).
1. Let |portExecResult| be [$RegExpBuiltinExec$](|urlpattern|'s [=URL pattern/port component=]'s [=component/regular expression=], |port|).
1. Let |pathnameExecResult| be [$RegExpBuiltinExec$](|urlpattern|'s [=URL pattern/pathname component=]'s [=component/regular expression=], |pathname|).
1. Let |searchExecResult| be [$RegExpBuiltinExec$](|urlpattern|'s [=URL pattern/search component=]'s [=component/regular expression=], |search|).
1. Let |hashExecResult| be [$RegExpBuiltinExec$](|urlpattern|'s [=URL pattern/hash component=]'s [=component/regular expression=], |hash|).
1. Let |protocolExecResult| be [$RegExpBuiltinExec$](|urlPattern|'s [=URL pattern/protocol component=]'s [=component/regular expression=], |protocol|).
1. Let |usernameExecResult| be [$RegExpBuiltinExec$](|urlPattern|'s [=URL pattern/username component=]'s [=component/regular expression=], |username|).
1. Let |passwordExecResult| be [$RegExpBuiltinExec$](|urlPattern|'s [=URL pattern/password component=]'s [=component/regular expression=], |password|).
1. Let |hostnameExecResult| be [$RegExpBuiltinExec$](|urlPattern|'s [=URL pattern/hostname component=]'s [=component/regular expression=], |hostname|).
1. Let |portExecResult| be [$RegExpBuiltinExec$](|urlPattern|'s [=URL pattern/port component=]'s [=component/regular expression=], |port|).
1. Let |pathnameExecResult| be [$RegExpBuiltinExec$](|urlPattern|'s [=URL pattern/pathname component=]'s [=component/regular expression=], |pathname|).
1. Let |searchExecResult| be [$RegExpBuiltinExec$](|urlPattern|'s [=URL pattern/search component=]'s [=component/regular expression=], |search|).
1. Let |hashExecResult| be [$RegExpBuiltinExec$](|urlPattern|'s [=URL pattern/hash component=]'s [=component/regular expression=], |hash|).
1. If |protocolExecResult|, |usernameExecResult|, |passwordExecResult|, |hostnameExecResult|, |portExecResult|, |pathnameExecResult|, |searchExecResult|, or |hashExecResult| are null then return null.
1. Let |result| be a new {{URLPatternResult}}.
1. Set |result|["{{URLPatternResult/inputs}}"] to |inputs|.
1. Set |result|["{{URLPatternResult/protocol}}"] to the result of [=creating a component match result=] given |urlpattern|'s [=URL pattern/protocol component=], |protocol|, and |protocolExecResult|.
1. Set |result|["{{URLPatternResult/username}}"] to the result of [=creating a component match result=] given |urlpattern|'s [=URL pattern/username component=], |username|, and |usernameExecResult|.
1. Set |result|["{{URLPatternResult/password}}"] to the result of [=creating a component match result=] given |urlpattern|'s [=URL pattern/password component=], |password|, and |passwordExecResult|.
1. Set |result|["{{URLPatternResult/hostname}}"] to the result of [=creating a component match result=] given |urlpattern|'s [=URL pattern/hostname component=], |hostname|, and |hostnameExecResult|.
1. Set |result|["{{URLPatternResult/port}}"] to the result of [=creating a component match result=] given |urlpattern|'s [=URL pattern/port component=], |port|, and |portExecResult|.
1. Set |result|["{{URLPatternResult/pathname}}"] to the result of [=creating a component match result=] given |urlpattern|'s [=URL pattern/pathname component=], |pathname|, and |pathnameExecResult|.
1. Set |result|["{{URLPatternResult/search}}"] to the result of [=creating a component match result=] given |urlpattern|'s [=URL pattern/search component=], |search|, and |searchExecResult|.
1. Set |result|["{{URLPatternResult/hash}}"] to the result of [=creating a component match result=] given |urlpattern|'s [=URL pattern/hash component=], |hash|, and |hashExecResult|.
1. Set |result|["{{URLPatternResult/protocol}}"] to the result of [=creating a component match result=] given |urlPattern|'s [=URL pattern/protocol component=], |protocol|, and |protocolExecResult|.
1. Set |result|["{{URLPatternResult/username}}"] to the result of [=creating a component match result=] given |urlPattern|'s [=URL pattern/username component=], |username|, and |usernameExecResult|.
1. Set |result|["{{URLPatternResult/password}}"] to the result of [=creating a component match result=] given |urlPattern|'s [=URL pattern/password component=], |password|, and |passwordExecResult|.
1. Set |result|["{{URLPatternResult/hostname}}"] to the result of [=creating a component match result=] given |urlPattern|'s [=URL pattern/hostname component=], |hostname|, and |hostnameExecResult|.
1. Set |result|["{{URLPatternResult/port}}"] to the result of [=creating a component match result=] given |urlPattern|'s [=URL pattern/port component=], |port|, and |portExecResult|.
1. Set |result|["{{URLPatternResult/pathname}}"] to the result of [=creating a component match result=] given |urlPattern|'s [=URL pattern/pathname component=], |pathname|, and |pathnameExecResult|.
1. Set |result|["{{URLPatternResult/search}}"] to the result of [=creating a component match result=] given |urlPattern|'s [=URL pattern/search component=], |search|, and |searchExecResult|.
1. Set |result|["{{URLPatternResult/hash}}"] to the result of [=creating a component match result=] given |urlPattern|'s [=URL pattern/hash component=], |hash|, and |hashExecResult|.
1. Return |result|.
</div>

<div algorithm>
A [=URL pattern=] |urlpattern| <dfn export for="URL pattern">has regexp groups</dfn> if the following steps return true:
A [=URL pattern=] |urlPattern| <dfn export for="URL pattern">has regexp groups</dfn> if the following steps return true:

1. If |urlpattern|'s [=URL pattern/protocol component=] [=component/has regexp groups=] is true, then return true.
1. If |urlpattern|'s [=URL pattern/username component=] [=component/has regexp groups=] is true, then return true.
1. If |urlpattern|'s [=URL pattern/password component=] [=component/has regexp groups=] is true, then return true.
1. If |urlpattern|'s [=URL pattern/hostname component=] [=component/has regexp groups=] is true, then return true.
1. If |urlpattern|'s [=URL pattern/port component=] [=component/has regexp groups=] is true, then return true.
1. If |urlpattern|'s [=URL pattern/pathname component=] [=component/has regexp groups=] is true, then return true.
1. If |urlpattern|'s [=URL pattern/search component=] [=component/has regexp groups=] is true, then return true.
1. If |urlpattern|'s [=URL pattern/hash component=] [=component/has regexp groups=] is true, then return true.
1. If |urlPattern|'s [=URL pattern/protocol component=] [=component/has regexp groups=] is true, then return true.
1. If |urlPattern|'s [=URL pattern/username component=] [=component/has regexp groups=] is true, then return true.
1. If |urlPattern|'s [=URL pattern/password component=] [=component/has regexp groups=] is true, then return true.
1. If |urlPattern|'s [=URL pattern/hostname component=] [=component/has regexp groups=] is true, then return true.
1. If |urlPattern|'s [=URL pattern/port component=] [=component/has regexp groups=] is true, then return true.
1. If |urlPattern|'s [=URL pattern/pathname component=] [=component/has regexp groups=] is true, then return true.
1. If |urlPattern|'s [=URL pattern/search component=] [=component/has regexp groups=] is true, then return true.
1. If |urlPattern|'s [=URL pattern/hash component=] [=component/has regexp groups=] is true, then return true.
1. Return false.
</div>

Expand Down Expand Up @@ -1982,6 +1982,17 @@ JavaScript APIs should accept all of:

To accomplish this, specifications should accept {{URLPatternCompatible}} as an argument to an [=operation=] or [=dictionary member=], and process it using the following algorithm, using the appropriate [=environment settings object=]'s [=environment settings object/API base URL=] or equivalent.

<div algorithm>
To <dfn export>build a {{URLPattern}} object from a Web IDL value</dfn> {{URLPatternCompatible}} |input| given [=/URL=] |baseURL| and [=ECMAScript/realm=] |realm|, perform the following steps:

1. If the [=specific type=] of |input| is {{URLPattern}}:
1. Return |input|.
1. Otherwise,
yoshisatoyanagisawa marked this conversation as resolved.
Show resolved Hide resolved
1. Let |pattern| be a [=new=] {{URLPattern}} with |realm|.
1. Set |pattern|'s [=URLPattern/associated URL pattern=] to the result of [=building a URL pattern from a Web IDL value=] given |input| and |baseURL|.
1. Return |pattern|.
</div>

<div algorithm>
To <dfn export>build a [=URL pattern=] from a Web IDL value</dfn> {{URLPatternCompatible}} |input| given [=/URL=] |baseURL|, perform the following steps:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this is a semantic change in the case where a URLPattern is provided -- it creates a second platform object wrapping the same URL pattern, rather than returning the existing one. If it were then exposed back to script (e.g., as the value of an attribute) it would no longer compare equal (===), its expandos would be visibly different, etc.

For the case where the author really does want a platform object because they might show it to script again, do we need to keep this? Should we have two versions of this algorithm, one which returns platform objects (and therefore takes a realm in case it needs to create them) and one which returns URL patterns?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Do we know who the callers would be? I'm not sure the "returns a platform object" version would have any callers, currently.

But if we did have such a caller, then I agree a separate algorithm would be best.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the SW static routing API usage, we actually do not provide the way to see data from JavaScript.
However, I do not have a good reason to block such use case from other APIs.
I tried to implement the algorithm with |realm| in addition.


Expand All @@ -1990,15 +2001,10 @@ To accomplish this, specifications should accept {{URLPatternCompatible}} as an
1. Otherwise, if the [=specific type=] of |input| is {{URLPatternInit}}:
1. Let |init| be a [=map/clone=] of |input|.
1. If |init|["{{URLPatternInit/baseURL}}"] does not [=map/exist=], set it to the [=URL serializer|serialization=] of |baseURL|.
1. Let |pattern| be a new [=URL pattern=].
1. Run [=create=] given |pattern|, |init|, null, and an empty [=map=].
1. Return |pattern|.
1. Return the result of [=creating=] a URL pattern given |init|, null, and an empty [=map=].
1. Otherwise:
1. [=Assert=]: The [=specific type=] of |input| is {{USVString}}.
1. Let |pattern| be a new [=URL pattern=].
1. Run [=create=] given |pattern|, |input|, the [=URL serializer|serialization=] of |baseURL|, and an empty [=map=].
1. Return |pattern|.

1. Return the result of [=creating=] a URL pattern given |input|, the [=URL serializer|serialization=] of |baseURL|, and an empty [=map=].
</div>

This allows authors to concisely specify most patterns, and use the <a constructor for="URLPattern">constructor</a> to access uncommon options if necessary. The implicit use of the base URL is similar to, and consistent with, <cite>HTML</cite>'s [=parse a URL=] algorithm. [[HTML]]
Expand All @@ -2016,11 +2022,10 @@ If a specification has an Infra value (e.g., after using [=parse a JSON string t

1. Let |serializedBaseURL| be the [=URL serializer|serialization=] of |baseURL|.
1. If |rawPattern| is a [=string=], then:
1. Let |pattern| be a new [=URL pattern=].
1. Run [=create=] given |pattern|, |rawPattern|, |serializedBaseURL|, and an empty [=map=].
1. Return the result of [=creating=] a URL pattern given |rawPattern|, |serializedBaseURL|, and an empty [=map=].

<div class="note">It may become necessary in the future to plumb non-empty options here.</div>
1. Return |pattern|.

1. Otherwise, if |rawPattern| is a [=map=], then:
1. Let |init| be «[ "{{URLPatternInit/baseURL}}" → |serializedBaseURL| ]», representing a dictionary of type {{URLPatternInit}}.
1. [=map/For each=] |key| → |value| of |rawPattern|:
Expand All @@ -2029,16 +2034,15 @@ If a specification has an Infra value (e.g., after using [=parse a JSON string t
<div class="note">This will need to be updated if {{URLPatternInit}} gains members of other types.</div>
<div class="note">A future version of this specification might also have a less strict mode, if that proves useful to other specifications.</div>
1. Set |init|[|key|] to |value|.
1. Let |pattern| be a new [=URL pattern=].
1. Run [=create=] given |pattern|, |init|, null, and an empty [=map=].
1. Return the result of [=creating=] a URL pattern given |init|, null, and an empty [=map=].

<div class="note">It may become necessary in the future to plumb non-empty options here.</div>
1. Return |pattern|.

1. Otherwise, return null.

</div>

Specifications may wish to leave room in their formats to accept options for {{URLPatternOptions}}, override the base URL, or similar, since it is not possible to construct a [=URL pattern=] directly in this case, unlike in a JavaScript API. For example, <cite>Speculation Rules</cite> accepts a "`relative_to`" key which can be used to switch to using the [=document base URL=] instead of the JSON resource's URL. [[SPECULATION-RULES]]
Specifications may wish to leave room in their formats to accept options for {{URLPatternOptions}}, override the base URL, or similar, since it is not possible to construct a {{URLPattern}} object directly in this case, unlike in a JavaScript API. For example, <cite>Speculation Rules</cite> accepts a "`relative_to`" key which can be used to switch to using the [=document base URL=] instead of the JSON resource's URL. [[SPECULATION-RULES]]

<h2 id=acknowledgments class=no-num>Acknowledgments</h2>

Expand Down