-
Notifications
You must be signed in to change notification settings - Fork 98
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
Meta: export convert an Infra value to a (JSON) JavaScript value #642
Conversation
Also known as convert an Infra value to a JSON-compatible JavaScript value, but that exceeded 72 characters.
I tried to figure out how you're using this, and it seems to not have much to do with JSON. Can't Web IDL handle the conversion from Infra types directly? We already said, e.g., that maps and dictionaries are identified, and that sequences and lists are identified. |
I'm starting from a JSON document. A subset of that JSON document needs to be IDL-validated as per NotificationOptions to ensure things are strings, booleans, etc. The remainder can be dealt with at the Infra level. So https://pr-preview.s3.amazonaws.com/w3c/push-api/pull/385.html#dfn-declarative-push-message-parser goes to Infra values first and then for the subset that needs to be IDL-validated it goes back to JS. It needs to go back because otherwise you cannot apply IDL validation. If I would just treat it as a dictionary I would actually bypass the validation that IDL provides. |
Hmm. You could almost just say "If notificationInput is not a Would you consider instead adding something to Web IDL which converts an Infra value into a dictionary type by removing all the excess keys / applying defaults? I guess that would also have to deal with required dictionary members and throwing on them... which is not fun. OK, I'm basically sold. But a few things to consider:
|
I'm not concerned about the map containing additional keys per se. It's not like "create a notification" would do anything with unknown keys. I am concerned about type coercion and defaulting. I don't want "create a notification" to be invoked with a map that it did not expect, where I think you are correct that other JSON formats might not do type coercion so perhaps I should duplicate the dictionary semantics, modulo some of the type coercion (we'd still do string -> scalar value string though). (Ideally someone solves #159.) However, |
Doing validation by hand does raise some questions that will likely be answered differently across JSON consumers:
|
I would support efforts to make this more uniform, maybe with Infra... I think U+FFFD is generally good, but skipping vs. erroring might need to be format-specific depending on extensibility requirements. |
Yeah same, but I've already done a lot of yak shaving on this particular feature. If you have thoughts on what uniform behavior should be I'm happy to take that into account of course. It sounds like you'd prefer Infra value type checking over IDL dictionary conversion which seems like a reasonable enough change, even though it introduces a fair bit of redundancy. |
Yeah, I think IDL is just not the right tool for JSON usually, thus the discussions in #159. From what I recall of the formats I've had a part in:
Anyway I guess I should approve this because you're right that you'll need it for |
Also known as convert an Infra value to a JSON-compatible JavaScript value, but that exceeded 72 characters.
I use this in w3c/push-api#385.
Preview | Diff