- From: Luca Casonato <notifications@github.com>
- Date: Mon, 26 Aug 2024 02:32:48 -0700
- To: whatwg/fetch <fetch@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/fetch/issues/1291/2309773461@github.com>
We shipped a version of this in the wild as an experiment in node compat, and discovered the following issue that the spec will have to deal with that relates to boxed strings: ```js new Response(new String("hello world")) ``` Currently, boxed strings are cast to `string`, because they don't match any of the interface types (`ReadableStream`, `Blob`, etc). However if the body type becomes `ReadableStream | Blob | BufferSource | DOMString | async iterable<Uint8Array>` as proposed, boxed string (which implements `[Symbol.iterator]`), would be turned into an `async iterable` and then error on the fact that it yields `string` chunks, not `Uint8Array`. This is a web compat issue. I have two proposed solutions: 1. Like how we disallow primitive strings casting to `async iterable`, we also disallow the boxed string being cast to an `async iterable`. We'd do this in WebIDL, and it would mean that no webidl `async iterable` argument would allow boxed strings. This would be the simplest. 2. We add `object` to the body type union instead of `async iterable`, and then handle this case in the spec by: checking whether the value is a boxed string, in which case cast to string, otherwise decoding it with the webidl union `string | async iterable<Uint8Array>` Node does not seem to exhibit this behaviour because Node does not allow `[Symbol.iterable]` bodies, only `[Symbol.asyncIterble]` bodies. -- Reply to this email directly or view it on GitHub: https://github.com/whatwg/fetch/issues/1291#issuecomment-2309773461 You are receiving this because you are subscribed to this thread. Message ID: <whatwg/fetch/issues/1291/2309773461@github.com>
Received on Monday, 26 August 2024 09:32:52 UTC