Re: [web-nfc] Define NDEFMessage's, NDEFRecord's and NDEFReadingEvent's constructors normatively (#622)

* NDEFReadingEvent
  * https://dom.spec.whatwg.org/#concept-event-create and https://dom.spec.whatwg.org/#inner-event-creation-steps cover it. The latter has the algorithm to convert an `init`-like dictionary to members. We are implicitly relying on the `NDEFMessageInit` -> `NDEFMessage` conversion, which I'm not sure is very common. I wonder if you could just take an `NDEFMessage` directly without making a backwards-incompatible change?
* NDEFReader
  * While the constructor looks trivial, Web IDL [added](https://github.com/whatwg/webidl/pull/882) language a while ago that simplifies specifying constructor steps, and it does say all constructors need to be specified: https://webidl.spec.whatwg.org/#idl-constructors. See https://dom.spec.whatwg.org/#dom-eventtarget-eventtarget for example. My guess is that saying the constructor must do nothing + specifying the initial values for the internal slots should be fine.
* NDEFRecord/NDEFMessage
  * I don't think the constructor is trivial, as it needs to process `recordInit` somehow, and that includes hooking into "Creating NDEF message" like you said. All I could find so far was https://w3c.github.io/web-nfc/#dom-ndefrecordinit saying _"The NDEFRecordInit dictionary is used to initialize an NDEF record with its record type recordType, and optional record identifier id and payload data data"_. There is nothing saying how this initialization is supposed to take place though. Specifically, if I write `new NDEFRecord(myRecordInit)` there is nothing in the spec saying what must happen (including how to initialize `recordsDepth`).
  * The same applies to `NDEFMessage` and `NDEFMessageInit` in https://w3c.github.io/web-nfc/#the-ndefmessage-interface -- the constructor needs to perform non-trivial steps, and the text just says "The NDEFMessageInit dictionary is used to initialize an NDEF message" without saying how such initialization is supposed to happen (this isn't derived from DOM's `Event` interface, so you need to outline all the initalization steps).
  * With that said, section 9.10 ("Creating NDEF message") has an algorithmic descriptions of both [Create NDEF record](https://w3c.github.io/web-nfc/#creating-ndef-record) and [Creating NDEF Message](https://w3c.github.io/web-nfc/#creating-ndef-message) that pretty much correspond to the construction steps that are missing above. You could try doing something like this for NDEFRecord, for example:
    * Rename the "create NDEF record given record, context, and recordsDepth" operation to "initialize NDEF record given record, recordInit, context and recordsDepth". `record` would be an `NDEFRecord` object that you take as an argument rather than creating here (and the existing `record` argument becomes `recordInit`, which is also clearer).
    * Define e.g. `NDEFRecord`'s construction steps as _"The new NDEFRecord(recordInit) constructor steps are to perform "initialize NDEF record" with this, recordInit, ??? [dunno what the context would be] and 0".
    * Other algorithms that invoke "create NDEF record" directly could be changed to something like "1) Let foo be a [=new=] NDEFRecord 2) Invoke "initialize NDEF record" with foo, recordInit, context, and recordsDepth".
  * Something similar would work for NDEFMessage, but it would also be good to specify what "add NDEFRecord to NDEFMessage" means in [Add ndef to output](https://w3c.github.io/web-nfc/#dfn-create-ndef-message).

-- 
GitHub Notification of comment by rakuco
Please view or discuss this issue at https://github.com/w3c/web-nfc/issues/622#issuecomment-961797173 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Friday, 5 November 2021 10:53:31 UTC