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

Conversation

yoshisatoyanagisawa
Copy link
Contributor

@yoshisatoyanagisawa yoshisatoyanagisawa commented Feb 16, 2024

To allow the algorithms in the specification to be used outside of JavaScript, we need to remove dependency to JavaScript realm.

This CL make a URLPattern object associated with an underlying URL Pattern struct, and makes algorithms to use it instead.

Fixes #217

  • At least two implementers are interested (and none opposed):
    • Google Chrome
    • n/a (change is simply fixing an issue in a non-controversial way).
  • Tests are written and can be reviewed and commented upon at:
    • n/a (this is a fix to how the spec express this, there is no behavior change, and existing tests cover this behavior)
  • Implementation bugs are filed:
    • Chromium: n/a (no behavior change is required)
    • Gecko: https://bugzilla.mozilla.org/show_bug.cgi?id=1731418 (vendor does not yet implement the spec)
    • WebKit: n/a (no reason to believe a change is required)
    • Deno: n/a (no reason to believe a change is required)
    • kenchris/urlpattern-polyfill: n/a (no reason to believe a change is required)
  • MDN issue is filed: n/a (change is on a spec detail not expressly documented)
  • The top of this comment includes a clear commit message to use.

(See WHATWG Working Mode: Changes for more details.)


Preview | Diff

To allow the algorithms in the specification to be used outside of
JavaScript, we need to remove dependency to JavaScript realm.

This CL make a URLPattern object associated with an underlying URL
Pattern struct, and makes algorithms to use it instead.

Fixes whatwg#217
@yoshisatoyanagisawa
Copy link
Contributor Author

@jeremyroman @sisidovski @domenic Can I ask you to take a look?

spec.bs Outdated Show resolved Hide resolved
spec.bs Outdated Show resolved Hide resolved
spec.bs Outdated Show resolved Hide resolved
spec.bs Outdated Show resolved Hide resolved
spec.bs Outdated Show resolved Hide resolved
spec.bs Outdated Show resolved Hide resolved
- Run -> run
- renamed |this| to |urlPattern|
Copy link
Collaborator

@sisidovski sisidovski left a comment

Choose a reason for hiding this comment

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

To remove JavaScript realm, you also have to update 4.1. Integrating with JavaScript APIs not to accept realm and build URL Pattern with create?

@yoshisatoyanagisawa
Copy link
Contributor Author

To remove JavaScript realm, you also have to update 4.1. Integrating with JavaScript APIs not to accept realm and build URL Pattern with create?

Yes. I tried to update them to eliminate realm dependencies.

Copy link
Collaborator

@sisidovski sisidovski left a comment

Choose a reason for hiding this comment

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

LGTM

@yoshisatoyanagisawa
Copy link
Contributor Author

Thanks for the review, @sisidovski.

@jeremyroman @domenic Will you take a look?

spec.bs Outdated Show resolved Hide resolved
spec.bs Outdated Show resolved Hide resolved
spec.bs Outdated Show resolved Hide resolved
spec.bs Outdated Show resolved Hide resolved
spec.bs Outdated Show resolved Hide resolved
spec.bs Outdated Show resolved Hide resolved
spec.bs Outdated Show resolved Hide resolved
spec.bs Outdated Show resolved Hide resolved
spec.bs Show resolved Hide resolved
- The URLPattern class -> "URL patterns"
  - Introduce an "Introduction" subsection to contain the introductory text
    and examples
  - Introduce a "The URLPattern class" subsection to contain the IDL and
    method definitions
  - Introduce "The URL pattern struct" subsection to contain the struct
    definition
  - Introduce "High-level operations" to contain "create", "match",
    "has regexp groups"
  - Everything else can continue living in "Internals" and "Constructor
    string parsing"
- Rename "Patterns" to "Pattern strings" to be slightly less confusing as
  a sibling of "URL patterns"
@yoshisatoyanagisawa
Copy link
Contributor Author

@domenic Thanks for the review. I have addressed your comments.

spec.bs Outdated Show resolved Hide resolved
spec.bs Outdated Show resolved Hide resolved
spec.bs Outdated Show resolved Hide resolved
@@ -1973,23 +1983,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:
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.

Co-authored-by: Jeremy Roman <jeremy@jeremyroman.com>
Co-authored-by: Jeremy Roman <jeremy@jeremyroman.com>
Copy link
Member

@domenic domenic left a comment

Choose a reason for hiding this comment

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

This is looking really nice; great work.

spec.bs Outdated Show resolved Hide resolved
@@ -1973,23 +1983,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:
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.

spec.bs Outdated Show resolved Hide resolved
spec.bs Outdated Show resolved Hide resolved
spec.bs Outdated Show resolved Hide resolved
spec.bs Outdated Show resolved Hide resolved
Also, fixed the way to call [=create=] because it won't take |pattern|
any more.
I changed like so by mistake.  In this context, we would want to say
that it is not relevant to create a URLPattern object as a JSON input.
We need to say that because unlike JavaScript API, JSON API cannot take
a URLPattern object itself, which has URLPatternOptions.
To allow the API to compare values in the API's attribute with '===',
the way to use |realm| has been introduced.
spec.bs Outdated Show resolved Hide resolved
Co-authored-by: Jeremy Roman <jeremy@jeremyroman.com>
@yoshisatoyanagisawa
Copy link
Contributor Author

Thanks @jeremyroman for the review.
@domenic Will you take another look at the PR?

Copy link
Member

@domenic domenic left a comment

Choose a reason for hiding this comment

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

Amazing work!

spec.bs Outdated Show resolved Hide resolved
Co-authored-by: Domenic Denicola <d@domenic.me>
@yoshisatoyanagisawa
Copy link
Contributor Author

yoshisatoyanagisawa commented Feb 27, 2024

@domenic Thank you for the review!

Will somebody merge this PR?
Thank you in advance.

@sisidovski sisidovski merged commit 69ccf3a into whatwg:main Feb 27, 2024
2 checks passed
@yoshisatoyanagisawa yoshisatoyanagisawa deleted the remove_realm_dependency branch February 27, 2024 07:41
jeremyroman added a commit to jeremyroman/nav-speculation that referenced this pull request Feb 28, 2024
* Fix linking to URL Pattern spec after whatwg/urlpattern#219.
* Fix ambiguous "credentials" link by defaulting it to Fetch.
* Fix RFC 2119 compliance in a note.
jeremyroman added a commit to WICG/nav-speculation that referenced this pull request Feb 29, 2024
Editorial: Various minor fixes

* Fix linking to URL Pattern spec after whatwg/urlpattern#219.
* Fix ambiguous "credentials" link by defaulting it to Fetch.
* Fix RFC 2119 compliance in a note.

Fixes #300.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

The way to integrate the API without depending on ECMAScript realm.
4 participants