Skip to content

Commit

Permalink
create a separate enum for use of other APIs, to accept URLPattern di…
Browse files Browse the repository at this point in the history
…rectly
  • Loading branch information
jeremyroman committed Nov 21, 2023
1 parent 9ce9724 commit b04c982
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ It can be constructed using a string for each component, or from a shorthand str

<xmp class="idl">
typedef (USVString or URLPatternInit) URLPatternInput;
typedef (USVString or URLPatternInit or URLPattern) URLPatternCompatible;

[Exposed=(Window,Worker)]
interface URLPattern {
Expand Down Expand Up @@ -1951,19 +1952,19 @@ JavaScript APIs should accept all of:
* a dictionary-like object which specifies the components required to construct a pattern
* a string (in the constructor string syntax)

To accomplish this, specifications should accept {{URLPatternInput}} 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.
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 for=URLPattern>build a {{URLPattern}} from a WebIDL value</dfn> {{URLPatternInput}} |input| given [=URL=] |baseURL|, perform the following steps:
To <dfn for=URLPattern>build a {{URLPattern}} from a WebIDL value</dfn> {{URLPatternCompatible}} |input| given [=URL=] |baseURL|, perform the following steps:

1. If the [=specific type=] of |input| is {{USVString}}:
1. Return the result of constructing a {{URLPattern/constructor(input, baseURL, options)}} given |input| and the [=URL serializer|serialization=] of |baseURL|.
1. Otherwise:
1. [=Assert=]: the [=specific type=] of |input| is {{URLPatternInit}}.
1. If the [=specific type=] of |input| is {{URLPattern}}:
1. Return |input|.
1. Otherwise, if the [=specific type=] of |input| is {{URLPatternInit}}:
1. If |input|["`baseURL`"] does not [=map/exist=], set it to the [=URL serializer|serialization=] of |baseURL|.
1. Return the result of constructing a {{URLPattern/constructor(input, options)}} given |input|.

<div class=issue>Currently, {{URLPattern}} objects are not handled specially here, but perhaps they should be, since even though {{URLPattern}} has the properties necessary for {{URLPatternInit}}, this loses the {{URLPatternOptions/ignoreCase}} option (which is not exposed on the {{URLPattern}} interface).</div>
1. Otherwise:
1. [=Assert=]: The [=specific type=] of |input| is {{USVString}}:
1. Return the result of constructing a {{URLPattern/constructor(input, baseURL, options)}} given |input| and the [=URL serializer|serialization=] of |baseURL|.
</div>

This allows authors to concisely specify most patterns, and use the {{URLPattern/constructor|constructor}} to access uncommon options if necessary. The implicit use of the base URL is similar to, and consistent with, [[HTML]]'s [=parse a URL=] algorithm.
Expand Down

0 comments on commit b04c982

Please sign in to comment.