Skip to content

fix(cddl): fix CDDL syntax for emulation.SetGeolocationOverrideParameters #914

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

christian-bromann
Copy link
Member

@christian-bromann christian-bromann commented May 6, 2025

I find the current definition of emulation.SetGeolocationOverrideParameters somewhat unusual and inconsistent with the style used throughout the rest of the specification.

emulation.SetGeolocationOverrideParameters = {
   (
      (coordinates: emulation.GeolocationCoordinates / null) //
      (error: emulation.GeolocationPositionError)
   ),
   ? contexts: [+browsingContext.BrowsingContext],
   ? userContexts: [+browser.UserContext],
}

Aside from concerns about whether this is valid CDDL syntax—and the fact that some parsers may or may not support it—I recommend refactoring this definition to better align with the established structure used elsewhere in the spec. Specifically, we typically define separate types for success and error cases, then unify them with a top-level choice. For example:

script.EvaluateResult = (
  script.EvaluateResultSuccess /
  script.EvaluateResultException
)

script.EvaluateResultSuccess = {
  type: "success",
  result: script.RemoteValue,
  realm: script.Realm
}

script.EvaluateResultException = {
  type: "exception",
  exceptionDetails: script.ExceptionDetails,
  realm: script.Realm
}

Applying a similar pattern to the emulation namespace would improve readability, tooling compatibility, and consistency across the specification.


Preview | Diff

@christian-bromann christian-bromann changed the title fix(cddl): fix CDDL syntax for emulation.SetGeolocationOverrideParameters fix(cddl): fix CDDL syntax for emulation.SetGeolocationOverrideParameters May 6, 2025
Copy link
Contributor

@whimboo whimboo left a comment

Choose a reason for hiding this comment

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

Thanks @christian-bromann. Personally I definitely like that better. I've just a question that you can find inline.

CC @sadym-chromium and @jgraham

(coordinates: emulation.GeolocationCoordinates / null) //
(error: emulation.GeolocationPositionError)
),
emulation.SetGeolocationOverrideParameters = (
Copy link
Contributor

Choose a reason for hiding this comment

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

AFAICS this can stay as a map, or do I miss something?

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, I think this should stay a map

Copy link
Member Author

Choose a reason for hiding this comment

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

While it is possible to insert a group into a map, e.g.:

foobar = {
  someGroup,
  key: value
}

It is not possible to include group choices, because the map expects a single group, not a group choice expression*.

RFC 8610 (Section 3.5) says:

When a group is used as a member of a map, the entries in the group are included at that location in the map.

But that refers to a group, not a group choice. Group choices (//) are only valid inside a group.

Copy link
Contributor

@OrKoN OrKoN May 8, 2025

Choose a reason for hiding this comment

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

(emulation.SetGeolocationPosition // emulation.GeolocationPositionError) defines a new group (due to ()) so it is valid to put it into a map. We have other places where this works. The current PR version does provide any type for the params key.

Copy link
Member Author

Choose a reason for hiding this comment

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

@OrKoN it is not allowed to have a group choice (//) between two maps ({ ... }). This aligns with other places in the spec, e.g.

  • (browser.ClientWindowNamedState // browser.ClientWindowRectState) (ref) where both browser.ClientWindowNamedState and browser.ClientWindowRectState are groups (( ... ))
  • (network.ContinueWithAuthCredentials // network.ContinueWithAuthNoCredentials) (ref) where also both network.ContinueWithAuthCredentials and network.ContinueWithAuthNoCredentials are groups

The CDDL specification indirectly defines this in RFC 8610 §3.9 — Group-to-Group Composition:

The operator // is used to express a choice between groups. The right-hand side of the operator must be a group.

This means:

  • A // B is only valid if both A and B are groups.
  • A map ({ ... }) is a type, not a group, and therefore cannot be used directly in //.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I am not following: both SetGeolocationPosition and GeolocationPositionError are groups, not maps. SetGeolocationOverrideParameters has to remain a map:

emulation.SetGeolocationOverrideParameters = {
      ? contexts: [+browsingContext.BrowsingContext],
      ? userContexts: [+browser.UserContext],
     (emulation.SetGeolocationPosition // emulation.GeolocationPositionError)
}

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

Successfully merging this pull request may close these issues.

7 participants