-
Notifications
You must be signed in to change notification settings - Fork 25
Add URLPatternList
#166
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
base: main
Are you sure you want to change the base?
Add URLPatternList
#166
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -815,21 +815,15 @@ To <dfn>compute protocol matches a special scheme flag</dfn> given a [=construct | |
| <xmp class="idl"> | ||
| [Exposed=(Window,Worker)] | ||
| interface URLPatternList { | ||
| constructor(sequence<URLPatternListEntry> entries); | ||
| constructor(sequence<URLPattern> patterns); | ||
|
|
||
| USVString? test(optional URLPatternInput input = {}, optional USVString baseURL); | ||
| boolean 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; | ||
| }; | ||
|
|
||
| dictionary URLPatternListResult { | ||
| URLPatternResult match; | ||
| USVString key; | ||
| dictionary URLPatternListResult : URLPatternResult { | ||
| URLPattern pattern; | ||
| }; | ||
| </xmp> | ||
|
|
||
|
|
@@ -843,17 +837,12 @@ 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: | ||
| The <dfn constructor for=URLPatternList lt="URLPatternList(patterns)">new URLPatternList(|patterns|)</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. [=list/For each=] |pattern| in |patterns|, run the following steps: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't this imply that the pattern list is traversed as an array and is potentially slower? #30 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The iteration steps here and elsewhere don’t appear to be observable, so engines can potentially optimize them however they see fit, right? Spec steps usually aim for the simplest and clearest explanation of observable behaviors, not the most efficient ones (because observable behaviors are the only things they can actually specify, further complexity is noise). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, thanks for the explanation! |
||
| 1. If [=this=]'s [=URLPatternList/pattern list=] [=list/contains=] |pattern|, throw a {{TypeError}}. | ||
| 1. [=list/Append=] the |pattern| to [=this=]'s [=URLPatternList/pattern 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 | ||
|
|
@@ -865,24 +854,20 @@ Each {{URLPatternList}} has an associated <dfn for=URLPatternList>key list</dfn> | |
| <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. | ||
| 1. Return true. | ||
| 1. Return false. | ||
| </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. Let |result| be the result of [=match=] given |pattern|, |input|, and |baseURL| if given. | ||
| 1. If |result| is null, [=continue=]. | ||
| 1. Set |result|'s {{URLPatternListResult/pattern}} to |pattern|. | ||
| 1. Return |result|. | ||
| 1. Return null. | ||
| </div> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how it works internally but shouldn't it contain the match result as well? Since the point is to pick a pattern to match and it's likely doing some work behind the scenes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does — the
: URLPatternResultpart means this dictionary extends URLPatternResult.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aaah i didn’t see it. (Not familiar with this spec language 😂)