[w3c/clipboard-apis] Undefined behaviour when handling data promise resolved value (Issue #185)

Consider following example:
```javascript
let object = {
  toString() {
    return "foo";
  }
};
let promise = Promise.resolve(object);
let item = new ClipboardItem({'text/plain': promise});
navigator.clipboard.write([item]);
```

And per steps 3.3.4.1.2 of https://w3c.github.io/clipboard-apis/#dom-clipboard-write
> 1. If representationDataPromise was fulfilled with value v, then:
>    1. If v is a [DOMString](https://webidl.spec.whatwg.org/#idl-DOMString), then follow the below steps:
>  ....
>    2. If v is a [Blob](https://w3c.github.io/FileAPI/#dfn-Blob), then add v to itemList.

The result seems undefined, because `object` isn't a `DOMString` or `Blob`.

But `ClipboardItemData` is defined as `Promise<(DOMString or Blob)>` in idl, see https://w3c.github.io/clipboard-apis/#clipboard-item-interface and `object` actually could be converted to a `DOMString or Blob` per https://webidl.spec.whatwg.org/#dfn-convert-ecmascript-to-idl-value.

Should we convert the value `v` to `DOMString or Blob` idl type first while handling the data promise resolved value, like https://encoding.spec.whatwg.org/#decode-and-enqueue-a-chunk, which should cover above example.




-- 
Reply to this email directly or view it on GitHub:
https://github.com/w3c/clipboard-apis/issues/185
You are receiving this because you are subscribed to this thread.

Message ID: <w3c/clipboard-apis/issues/185@github.com>

Received on Friday, 2 September 2022 11:17:17 UTC