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

Invalid Web IDL loop between NDEFRecordInit and NDEFMessageInit #620

Closed
rakuco opened this issue Aug 31, 2021 · 10 comments · Fixed by #621
Closed

Invalid Web IDL loop between NDEFRecordInit and NDEFMessageInit #620

rakuco opened this issue Aug 31, 2021 · 10 comments · Fixed by #621
Assignees

Comments

@rakuco
Copy link
Member

rakuco commented Aug 31, 2021

https://heycam.github.io/webidl/#idl-dictionaries says:

The type of a dictionary member must not include the dictionary it appears on. A type includes a dictionary D if at least one of the following is true:

  1. the type is D
  2. the type is a dictionary that inherits from D
  3. the type is a nullable type whose inner type includes D
  4. the type is a sequence type or frozen array whose element type includes D
  5. the type is a union type, one of whose member types includes D
  6. the type is a dictionary, one of whose members or inherited members has a type that includes D
  7. the type is record<K, V> where V includes D

#454 introduced a case of 4, 5 and 6, as right now NDEFRecordInit.data can be an NDEFMessageInit, which is a dictionary with a sequence of NDEFRecordInits. This creates a loop that is not allowed by Web IDL and which can cause implementation issues like https://bugs.chromium.org/p/chromium/issues/detail?id=1242274

@kenchris
Copy link
Contributor

kenchris commented Sep 8, 2021

External records allow sub-records, so it does make sense that you can create a record with other records inside it. NFC doesn't define any limit of sub records with sub records, but doing more than one or two would be quite rare.

If web idl doesn't allow this, then I don't know how to spec it

@zolkis
Copy link
Contributor

zolkis commented Sep 9, 2021

If we need to break the structural definition of recursive data, we can define a function in NDEFRecord to init its data from an NDEFMessageInit. A breaking change :).

@kenchris
Copy link
Contributor

kenchris commented Sep 9, 2021

Maybe @littledan or @domenic have ideas here

@reillyeon
Copy link
Member

Prior to #454 the data field used the any type instead. This violates the spirit of the WebIDL specification but would give us the opportunity to add a depth limit to the create NDEF message steps because we get to define when and how that arbitrary value is interpreted as an NDEFMessageInit.

@domenic
Copy link
Contributor

domenic commented Sep 13, 2021

Yes, using any or object and doing the conversion in prose with an additional depth-check step seems like a good solution.

@rakuco
Copy link
Member Author

rakuco commented Sep 14, 2021

My involvement with this spec is very minimal, so it'd be great if someone could make the required changes here. I can help with the implementation changes later.

@beaufortfrancois
Copy link
Collaborator

I'll work on a spec PR in the following days.

@beaufortfrancois
Copy link
Collaborator

I've started a spec PR at #621. Please let me know what you think.

@beaufortfrancois
Copy link
Collaborator

beaufortfrancois commented Sep 17, 2021

@rakuco Spec has been updated. See https://w3c.github.io/web-nfc/#creating-ndef-message and #621

@rakuco
Copy link
Member Author

rakuco commented Sep 17, 2021

Thank you!

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 a pull request may close this issue.

6 participants