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 5 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
88 changes: 47 additions & 41 deletions spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ spec: URL; urlPrefix: https://url.spec.whatwg.org/

<h2 id=urlpattern-class>The {{URLPattern}} class</h2>
yoshisatoyanagisawa marked this conversation as resolved.
Show resolved Hide resolved

A {{URLPattern}} consists of several [=components=], each of which represents a [=/pattern string|pattern=] which could be matched against the corresponding component of a [=/URL=].
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=].
yoshisatoyanagisawa marked this conversation as resolved.
Show resolved Hide resolved

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 @@ -224,21 +224,21 @@ dictionary URLPatternComponentResult {
};
</xmp>

Each {{URLPattern}} object has an associated <dfn for=URLPattern>protocol component</dfn>, a [=component=], which must be set upon creation.
Each [=URL Pattern=] has an associated <dfn for=URLPattern>protocol component</dfn>, a [=component=], which must be set upon creation.
yoshisatoyanagisawa marked this conversation as resolved.
Show resolved Hide resolved

Each {{URLPattern}} object has an associated <dfn for=URLPattern>username component</dfn>, a [=component=], which must be set upon creation.
Each [=URL Pattern=] has an associated <dfn for=URLPattern>username component</dfn>, a [=component=], which must be set upon creation.

Each {{URLPattern}} object has an associated <dfn for=URLPattern>password component</dfn>, a [=component=], which must be set upon creation.
Each [=URL Pattern=] has an associated <dfn for=URLPattern>password component</dfn>, a [=component=], which must be set upon creation.

Each {{URLPattern}} object has an associated <dfn for=URLPattern>hostname component</dfn>, a [=component=], which must be set upon creation.
Each [=URL Pattern=] has an associated <dfn for=URLPattern>hostname component</dfn>, a [=component=], which must be set upon creation.

Each {{URLPattern}} object has an associated <dfn for=URLPattern>port component</dfn>, a [=component=], which must be set upon creation.
Each [=URL Pattern=] has an associated <dfn for=URLPattern>port component</dfn>, a [=component=], which must be set upon creation.

Each {{URLPattern}} object has an associated <dfn for=URLPattern>pathname component</dfn>, a [=component=], which must be set upon creation.
Each [=URL Pattern=] has an associated <dfn for=URLPattern>pathname component</dfn>, a [=component=], which must be set upon creation.

Each {{URLPattern}} object has an associated <dfn for=URLPattern>search component</dfn>, a [=component=], which must be set upon creation.
Each [=URL Pattern=] has an associated <dfn for=URLPattern>search component</dfn>, a [=component=], which must be set upon creation.

Each {{URLPattern}} object has an associated <dfn for=URLPattern>hash component</dfn>, a [=component=], which must be set upon creation.
Each [=URL Pattern=] has an associated <dfn for=URLPattern>hash component</dfn>, a [=component=], which must be set upon creation.

<dl class="domintro non-normative">
<dt><code>|urlPattern| = new {{URLPattern/constructor(input, baseURL, options)|URLPattern}}(|input|)</code></dt>
Expand Down Expand Up @@ -348,7 +348,11 @@ Each {{URLPattern}} object has an associated <dfn for=URLPattern>hash component<
</div>

<div algorithm>
To <dfn for=URLPattern>initialize</dfn> a {{URLPattern}} given a {{URLPattern}} |this|, {{URLPatternInput}} |input|, string or null |baseURL|, and {{URLPatternOptions}} |options|:
To <dfn for=URLPattern>initialize</dfn> a {{URLPattern}} given a {{URLPattern}} |this|, {{URLPatternInput}} |input|, string or null |baseURL|, and {{URLPatternOptions}} |options|, run [=create=] given |this|'s associated [=URL Pattern=], |input|, |baseURL|, and |options|.
yoshisatoyanagisawa marked this conversation as resolved.
Show resolved Hide resolved
</div>

<div algorithm>
To <dfn for=URLPattern>create</dfn> a [=URL Pattern=] given a [=URL Pattern=] |urlPattern|, {{URLPatternInput}} |input|, string or null |baseURL|, and {{URLPatternOptions}} |options|:

1. Let |init| be null.
1. If |input| is a [=scalar value string=] then:
Expand All @@ -363,19 +367,19 @@ Each {{URLPattern}} object has an associated <dfn for=URLPattern>hash component<
1. [=list/For each=] |componentName| of « "{{URLPatternInit/protocol}}", "{{URLPatternInit/username}}", "{{URLPatternInit/password}}", "{{URLPatternInit/hostname}}", "{{URLPatternInit/port}}", "{{URLPatternInit/pathname}}", "{{URLPatternInit/search}}", "{{URLPatternInit/hash}}" »:
1. If |processedInit|[|componentName|] does not [=map/exist=], then [=map/set=] |processedInit|[|componentName|] to "`*`".
1. If |processedInit|["{{URLPatternInit/protocol}}"] is a [=special scheme=] and |processedInit|["{{URLPatternInit/port}}"] is a string which represents its corresponding [=default port=] in radix-10 using [=ASCII digits=] then set |processedInit|["{{URLPatternInit/port}}"] to the empty string.
1. Set |this|'s [=URLPattern/protocol component=] to the result of [=compiling a component=] given |processedInit|["{{URLPatternInit/protocol}}"], [=canonicalize a protocol=], and [=default options=].
1. Set |this|'s [=URLPattern/username component=] to the result of [=compiling a component=] given |processedInit|["{{URLPatternInit/username}}"], [=canonicalize a username=], and [=default options=].
1. Set |this|'s [=URLPattern/password component=] to the result of [=compiling a component=] given |processedInit|["{{URLPatternInit/password}}"], [=canonicalize a password=], and [=default options=].
1. If the result running [=hostname pattern is an IPv6 address=] given |processedInit|["{{URLPatternInit/hostname}}"] is true, then set |this|'s [=URLPattern/hostname component=] to the result of [=compiling a component=] given |processedInit|["{{URLPatternInit/hostname}}"], [=canonicalize an IPv6 hostname=], and [=hostname options=].
1. Otherwise, set |this|'s [=URLPattern/hostname component=] to the result of [=compiling a component=] given |processedInit|["{{URLPatternInit/hostname}}"], [=canonicalize a hostname=], and [=hostname options=].
1. Set |this|'s [=URLPattern/port component=] to the result of [=compiling a component=] given |processedInit|["{{URLPatternInit/port}}"], [=canonicalize a port=], and [=default options=].
1. Set |urlPattern|'s [=URLPattern/protocol component=] to the result of [=compiling a component=] given |processedInit|["{{URLPatternInit/protocol}}"], [=canonicalize a protocol=], and [=default options=].
1. Set |urlPattern|'s [=URLPattern/username component=] to the result of [=compiling a component=] given |processedInit|["{{URLPatternInit/username}}"], [=canonicalize a username=], and [=default options=].
1. Set |urlPattern|'s [=URLPattern/password component=] to the result of [=compiling a component=] given |processedInit|["{{URLPatternInit/password}}"], [=canonicalize a password=], and [=default options=].
1. If the result running [=hostname pattern is an IPv6 address=] given |processedInit|["{{URLPatternInit/hostname}}"] is true, then set |urlPattern|'s [=URLPattern/hostname component=] to the result of [=compiling a component=] given |processedInit|["{{URLPatternInit/hostname}}"], [=canonicalize an IPv6 hostname=], and [=hostname options=].
1. Otherwise, set |urlPattern|'s [=URLPattern/hostname component=] to the result of [=compiling a component=] given |processedInit|["{{URLPatternInit/hostname}}"], [=canonicalize a hostname=], and [=hostname options=].
1. Set |urlPattern|'s [=URLPattern/port component=] to the result of [=compiling a component=] given |processedInit|["{{URLPatternInit/port}}"], [=canonicalize a port=], and [=default options=].
1. Let |compileOptions| be a copy of the [=default options=] with the [=options/ignore case=] property set to |options|["{{URLPatternOptions/ignoreCase}}"].
1. If the result of running [=protocol component matches a special scheme=] given |this|'s [=URLPattern/protocol component=] is true, then:
1. If the result of running [=protocol component matches a special scheme=] given |urlPattern|'s [=URLPattern/protocol component=] is true, then:
1. Let |pathCompileOptions| be copy of the [=pathname options=] with the [=options/ignore case=] property set to |options|["{{URLPatternOptions/ignoreCase}}"].
1. Set |this|'s [=URLPattern/pathname component=] to the result of [=compiling a component=] given |processedInit|["{{URLPatternInit/pathname}}"], [=canonicalize a pathname=], and |pathCompileOptions|.
1. Otherwise set |this|'s [=URLPattern/pathname component=] to the result of [=compiling a component=] given |processedInit|["{{URLPatternInit/pathname}}"], [=canonicalize an opaque pathname=], and |compileOptions|.
1. Set |this|'s [=URLPattern/search component=] to the result of [=compiling a component=] given |processedInit|["{{URLPatternInit/search}}"], [=canonicalize a search=], and |compileOptions|.
1. Set |this|'s [=URLPattern/hash component=] to the result of [=compiling a component=] given |processedInit|["{{URLPatternInit/hash}}"], [=canonicalize a hash=], and |compileOptions|.
1. Set |urlPattern|'s [=URLPattern/pathname component=] to the result of [=compiling a component=] given |processedInit|["{{URLPatternInit/pathname}}"], [=canonicalize a pathname=], and |pathCompileOptions|.
1. Otherwise set |urlPattern|'s [=URLPattern/pathname component=] to the result of [=compiling a component=] given |processedInit|["{{URLPatternInit/pathname}}"], [=canonicalize an opaque pathname=], and |compileOptions|.
1. Set |urlPattern|'s [=URLPattern/search component=] to the result of [=compiling a component=] given |processedInit|["{{URLPatternInit/search}}"], [=canonicalize a search=], and |compileOptions|.
1. Set |urlPattern|'s [=URLPattern/hash component=] to the result of [=compiling a component=] given |processedInit|["{{URLPatternInit/hash}}"], [=canonicalize a hash=], and |compileOptions|.
</div>

<div algorithm>
yoshisatoyanagisawa marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -436,20 +440,22 @@ Each {{URLPattern}} object has an associated <dfn for=URLPattern>hash component<
<div algorithm>
The <dfn method for="URLPattern">test(|input|, |baseURL|)</dfn> method steps are:

1. Let |result| be the result of [=URLPattern/match=] given [=this=], |input|, and |baseURL| if given.
1. Let |result| be the result of [=URLPattern/match=] given [=this=]'s associated [=URL Pattern=], |input|, and |baseURL| if given.
1. If |result| is null, return false.
1. Return true.
</div>

<div algorithm>
The <dfn method for="URLPattern">exec(|input|, |baseURL|)</dfn> method steps are:

1. Return the result of [=URLPattern/match=] given [=this=], |input|, and |baseURL| if given.
1. Return the result of [=URLPattern/match=] given [=this=]'s associated [=URL Pattern=], |input|, and |baseURL| if given.
</div>

<h3 id=urlpattern-internals>Internals</h3>

A {{URLPattern}} is associated with multiple <dfn>component</dfn> [=structs=].
A {{URLPattern}} has an associated <dfn>URL pattern</dfn> [=structs=].
yoshisatoyanagisawa marked this conversation as resolved.
Show resolved Hide resolved

A [=URL pattern=] is associated with multiple <dfn>component</dfn> [=structs=].

A [=component=] has an associated <dfn for=component>pattern string</dfn>, a [=pattern string/well formed=] [=/pattern string=], which must be set upon creation.

Expand Down Expand Up @@ -477,8 +483,9 @@ A [=component=] has an associated <dfn for=component>has regexp groups</dfn>, a
</div>

<div algorithm>
A {{URLPattern}} |pattern| <dfn export for=URLPattern>has regexp groups</dfn> if the following steps return true:
A {{URLPattern}} |urlpattern| <dfn export for=URLPattern>has regexp groups</dfn> if the following steps return true:
yoshisatoyanagisawa marked this conversation as resolved.
Show resolved Hide resolved

1. Let |pattern| be |urlpattern|'s associated [=URL Pattern=].
1. If |pattern|'s [=URLPattern/protocol component=] [=component/has regexp groups=] is true, then return true.
1. If |pattern|'s [=URLPattern/username component=] [=component/has regexp groups=] is true, then return true.
1. If |pattern|'s [=URLPattern/password component=] [=component/has regexp groups=] is true, then return true.
Expand All @@ -491,7 +498,7 @@ A [=component=] has an associated <dfn for=component>has regexp groups</dfn>, a
</div>

<div algorithm>
To perform a <dfn export for=URLPattern>match</dfn> given a {{URLPattern}} |urlpattern|, a {{URLPatternInput}} |input|, and an optional string |baseURLString|:
To perform a <dfn export for=URLPattern>match</dfn> given a [=URL Pattern=] |urlpattern|, a {{URLPatternInput}} |input|, and an optional string |baseURLString|:
yoshisatoyanagisawa marked this conversation as resolved.
Show resolved Hide resolved
yoshisatoyanagisawa marked this conversation as resolved.
Show resolved Hide resolved

1. Let |protocol| be the empty string.
1. Let |username| be the empty string.
Expand Down Expand Up @@ -1973,23 +1980,22 @@ 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}} from a Web IDL value</dfn> {{URLPatternCompatible}} |input| given [=/URL=] |baseURL| and [=ECMAScript/realm=] |realm|, perform the following steps:
To <dfn export>build a [=URL Pattern=] from a Web IDL value</dfn> {{URLPatternCompatible}} |input| given [=/URL=] |baseURL|, perform the following steps:

1. If the [=specific type=] of |input| is {{URLPattern}}:
1. Return |input|.
1. Return |input|'s associated [=URL Pattern=].
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=] {{URLPattern}} with |realm|.
1. Run [=initialize=] given |pattern|, |init|, null, and an empty [=map=].
1. Let |pattern| be a new [=URL Pattern=].
1. Run [=create=] given |pattern|, |init|, null, and an empty [=map=].
1. Return |pattern|.
yoshisatoyanagisawa marked this conversation as resolved.
Show resolved Hide resolved
1. Otherwise:
1. [=Assert=]: The [=specific type=] of |input| is {{USVString}}.
1. Let |pattern| be a [=new=] {{URLPattern}} with |realm|.
1. Run [=initialize=] given |pattern|, |input|, the [=URL serializer|serialization=] of |baseURL|, and an empty [=map=].
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|.

<p class="XXX">Ideally we wouldn't need a realm here. If we extricate the URL pattern concept from the {{URLPattern}} interface, we won't anymore.</p>
</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 @@ -2003,12 +2009,12 @@ JSON data formats which include URL patterns should mirror the behavior of <a hr
If a specification has an Infra value (e.g., after using [=parse a JSON string to an Infra value=]), use the following algorithm, using the appropriate base URL (by default, the URL of the JSON resource). [[INFRA]]

<div algorithm>
To <dfn export>build a {{URLPattern}} from an Infra value</dfn> |rawPattern| given [=/URL=] |baseURL| and [=ECMAScript/realm=] |realm|, perform the following steps.
To <dfn export>build a [=URL Pattern=] from an Infra value</dfn> |rawPattern| given [=/URL=] |baseURL|, perform the following steps.

1. Let |serializedBaseURL| be the [=URL serializer|serialization=] of |baseURL|.
1. If |rawPattern| is a [=string=], then:
1. Let |pattern| be a [=new=] {{URLPattern}} with |realm|.
1. Run [=initialize=] given |pattern|, |rawPattern|, |serializedBaseURL|, and an empty [=map=].
1. Let |pattern| be a new [=URL Pattern=].
1. Run [=create=] given |pattern|, |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|.
yoshisatoyanagisawa marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -2020,17 +2026,16 @@ 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=] {{URLPattern}} with |realm|.
1. Run [=initialize=] given |pattern|, |init|, null, and an empty [=map=].
1. Let |pattern| be a new [=URL Pattern=].
1. Run [=create=] given |pattern|, |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.

<p class="XXX">Ideally we wouldn't need a realm here. If we extricate the URL pattern concept from the {{URLPattern}} interface, we won't anymore.</p>
</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 {{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]]
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]]

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

Expand Down Expand Up @@ -2069,7 +2074,8 @@ Rajesh Jagannathan,
Ralph Chelala,
Sangwhan Moon,
Sayan Pal,
Victor Costan, and
Victor Costan
yoshisatoyanagisawa marked this conversation as resolved.
Show resolved Hide resolved
Yoshisato Yanagisawa, and
Youenn Fablet
for their contributors to this specification.

Expand Down