- From: Marijn Kruisselbrink <notifications@github.com>
- Date: Wed, 07 Dec 2016 15:19:19 -0800
- To: w3c/FileAPI <FileAPI@noreply.github.com>
- Message-ID: <w3c/FileAPI/issues/10/265605077@github.com>
So I played around with this a bit more myself, trying to figure out what sensible behavior would be for a bunch of situations. And I wrote [some tests](https://gist.github.com/mkruisselbrink/2dbfb08082699fe593d6047491666667) to see what Chrome and Edge currently do. Modulo throwing different types of exceptions Edge at least passes (almost all) those tests. Chrome unfortunately fairs a bit worse, mostly due to bugs in our implementation. But writing those tests also made me realize that no matter how we treat closed Blobs in the various APIs, it's probably never going to be entirely nice and consistent. Naively I would expect things to behave such that any kind of cloning of a blob/passing a blob to some kind of API behaves as if a completely new blob, with a completely new copy of the data was created. As such calling close() on one blob should not effect previously clones of that blob in any way (where clone means structured clone, `new Blob([oldBlob])`, `oldBlob.slice()`, or just passing the blob to any API that accepts a blob). Similarly closing one blob should revoke all URLs made for that specific blob instance, and leave alone all blob URLs that were made for clones of that blob instance. Chrome's current implementation fails pretty badly in this regard in a number of cases, edge seems to mostly get it right. A more tricky question is what various methods should do when a closed Blob is passed to them. For consistency it could make sense to act similarly to how neutered array buffers are treated (for cases where both blobs and array buffers are valid options). That would mean that trying to postMessage a closed Blob would fail with a DataCloneException, but for example trying to pass a closed Blob as body to an XHR.send, or as body for a Response or Request will result in a valid zero-byte body instead (why is that the case for neutered array buffers anyway?) Or maybe a more consistent model would be that any method that takes a Blob should throw if passed a closed blob, as it almost certainly is an error to pass a closed Blob to XHR.send, new Response, etc. Finally there is the question what to do with blobs returned by various methods. XHR.response is documented to return the same Blob every time it is called, so closing that blob would really close the blob. On the other hand what should FormData.get do? Currently that method is seemingly specified to return the same File instance every time it is called (as it just returns the internal state directly), but what should happen if you close that returned instance? So yeah, actually figuring this all out is far from trivial. And I'm sure I missed cases in my tests. Coming back to my current attempt at tests, Edge passes all my tests except that trying to XHR.send a closed blob throws an exception (yet posting a closed blob using fetch(new Request(...)) "works" and just posts zero bytes). Chrome is kind of all over the place... -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/w3c/FileAPI/issues/10#issuecomment-265605077
Received on Wednesday, 7 December 2016 23:20:23 UTC