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

Add URLPatternList #166

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
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
77 changes: 77 additions & 0 deletions spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,83 @@ To <dfn>compute protocol matches a special scheme flag</dfn> given a [=construct
1. If the result of running [=protocol component matches a special scheme=] given |protocol component| is true, then set |parser|'s [=constructor string parser/protocol matches a special scheme flag=] to true.
</div>

<h2 id=urlpatternlist-class>The {{URLPatternList}} class </h2>

<xmp class="idl">
[Exposed=(Window,Worker)]
interface URLPatternList {
constructor(sequence<URLPatternListEntry> entries);
Copy link
Member

Choose a reason for hiding this comment

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

I think some of the feedback in #30 suggested it would be nice to be able to dynamically mutate the list. So add new entries to the list and possibly delete entries from the list.

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense. I didn't want to add this right away until we figure out the internal sort order a little better.


USVString? test(optional URLPatternInput input = {}, optional USVString baseURL);

URLPatternListResult? exec(optional URLPatternInput input = {}, optional USVString baseURL);
};

dictionary URLPatternListEntry {
required (USVString or URLPattern) pattern;
required USVString key;
lucacasonato marked this conversation as resolved.
Show resolved Hide resolved
};

dictionary URLPatternListResult {
URLPatternResult match;
USVString key;
};
</xmp>

Note: The {{URLPatternList}} is a utility that combines many patterns into one
matcher. This functionality can also be achieved in a naive userland
implementation that iterates over a list of patterns and matches each one
individually. This has the unfortunate effect of not being very fast. With the
built-in {{URLPatternList}} implementers can use a radix tree for matching under
lucacasonato marked this conversation as resolved.
Show resolved Hide resolved
the hood which can drastically improve performance over the naive userland
implementation.

Each {{URLPatternList}} has an associated <dfn for=URLPatternList>pattern list</dfn>, a [=list=] of {{URLPattern}}s.

Each {{URLPatternList}} has an associated <dfn for=URLPatternList>key list</dfn>, a [=list=] of [=string=]s.

<div algorithm>
The <dfn constructor for=URLPatternList lt="URLPatternList(entries)">new URLPattern(|entries|)</dfn> constructor steps are:

1. [=list/For each=] |entry| in |entries|, run the following steps:
1. [=list/Append=] the |entry|'s {{URLPatternListEntry/pattern}} to [=this=]'s [=URLPatternList/pattern list=].
1. Let |key| be |entry|'s {{URLPatternListEntry/key}}.
1. If |key| is the empty string, throw a {{TypeError}}.
1. If [=this=]'s [=URLPatternList/key list=] [=list/contains=] |key|, throw a {{TypeError}}.
1. [=list/Append=] |key| to [=this=]'s [=URLPatternList/key list=].
1. If [=this=]'s [=URLPatternList/pattern list=] is empty, throw a {{TypeError}}.

Issue: The patterns need to be in a "least -> most significant" sort order so
implementers can efficiently use a radix tree under the hood. Enforcing /
sorting the patterns in this order depends on
<a href=https://github.com/WICG/urlpattern/issues/61>https://github.com/WICG/urlpattern/issues/61</a>.
</div>

<div>
The <dfn method for=URLPatternList>test(|input|, |baseURL|)</dfn> method steps are:

1. Let |i| be 0.
1. [=list/For each=] |pattern| in [=this=]'s [=URLPatternList/pattern list=], run the following steps:
1. Let |result| be the result of [=match=] given |pattern|, |input|, and |baseURL| if given.
1. If |result| is null, [=continue=].
1. Return [=this=]'s [=URLPatternList/key list=][|i|].
1. Return null.
</div>

<div>
The <dfn method for=URLPatternList>match(|input|, |baseURL|)</dfn> method steps are:

1. Let |i| be 0.
1. [=list/For each=] |pattern| in [=this=]'s [=URLPatternList/pattern list=], run the following steps:
1. Let |match| be the result of [=match=] given |pattern|, |input|, and |baseURL| if given.
1. If |match| is null, [=continue=].
1. Let |result| be a new {{URLPatternListResult}} dictionary.
1. Set |result|'s {{URLPatternListResult/match}} to |match|.
1. Set |result|'s {{URLPatternListResult/key}} to [=this=]'s [=URLPatternList/key list=][|i|].
1. Return |result|.
1. Return null.
</div>

<h2 id=patterns>Patterns</h2>

A <dfn>pattern string</dfn> is a string that is written to match a set of target strings. A <dfn for="pattern string">well formed</dfn> pattern string conforms to a particular pattern syntax. This pattern syntax is directly based on the syntax used by the popular [path-to-regexp](https://github.com/pillarjs/path-to-regexp) JavaScript library.
Expand Down