-
Notifications
You must be signed in to change notification settings - Fork 164
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
Seeking clarification on whether unioning promises and callbacks is allowed #1278
Comments
Promise types are indistinguishable from every type and thus cannot be members of unions, at least as currently specified. This follows from the fact that e.g. This issue about possibly changing the ES→WI conversion of Note that while callback ClipboardCallback = (Blob or DOMString) (); These two “works” cases from above imply errors in Blink’s implementation because these are invalid Web IDL types which don’t have defined conversion behavior:
(I’m assuming that It sounds like you might want something like this? —
|
Yes, I did mean Thanks for the clarifications @bathos! Those explanations all make sense. |
While trying to make some IDL updates to the ClipboardItem constructor in Chromium (https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/modules/clipboard/clipboard_item.idl), we discovered that the Chromium IDL compiler failed to union a promise and callback, or even just multiple promises, together. We tried a few other cases where we unioned promises and/or callbacks with other types, and those seemed to work. Below is a list of what did work and what didn't.
typedef Promise<Blob> ClipboardBlobPromise;
typedef Promise<DOMString> ClipboardStringPromise;
callback ClipboardBlobCallback = Blob();
callback ClipboardStringCallback = DOMString();
typedef (Blob or DOMString) ClipboardItemData; // works
typedef (ClipboardBlobPromise or DOMString) ClipboardItemData; // works
typedef (Blob or ClipboardStringPromise) ClipboardItemData; // works
typedef (ClipboardBlobPromise or ClipboardStringPromise) ClipboardItemData; // does not work
typedef (Blob or ClipboardStringCallback) ClipboardItemData; // works
typedef (ClipboardBlobCallback or DOMString) ClipboardItemData; // works
typedef (ClipboardBlobCallback or ClipboardStringCallback) ClipboardItemData; // works
typedef (ClipboardBlobPromise or ClipboardBlobCallback) ClipboardItemData; // does not work
constructor(record<DOMString, ClipboardItemData> items);
Based on the above examples that do work, as well as reading through the WebIDL spec, it does not look like there should be any limitations on callback function types or promise types participating in unions. Does this sound like a bug in the Chromium WebIDL compiler, or is there anything in the spec that should prevent such cases from working?
cc: @snianu, @anaskim
The text was updated successfully, but these errors were encountered: