Re: [FileAPI] Deterministic release of Blob proposal

On Mon, Mar 5, 2012 at 7:04 PM, Charles Pritchard <chuck@jumis.com> wrote:

>  Do you see old behavior working something like the following?
>

> var blob = new Blob("my new big blob");
> var keepBlob = blob.slice();
> destination.postMessage(blob, '*', [blob]); // is try/catch needed here?
> blob = keepBlob; // keeping a copy of my blob still in thread.
>
Sorry to cover too many angles: if Blob is Transferable, then it'll neuter;
> so if we do want a local copy, we'd use slice ahead of time to keep it.
>

You don't need to do that.  If you don't want postMessage to transfer the
blob, then simply don't include it in the transfer parameter, and it'll
perform a normal structured clone.  postMessage behaves this way in part
for backwards-compatibility: so exactly in cases like this, we can make
Blob implement Transferable without breaking existing code.

See http://dev.w3.org/html5/postmsg/#posting-messages and similar
postMessage APIs.


> And we might have an error on postMessage stashing it in the transfer
> array if it's not a Transferable on an older browser.
>

It'll throw TypeError, which you'll need to handle if you need to support
older browsers.

The new behavior is pretty easy.
> var blob = new Blob("my big blob");
> blob.close(); // My blob has been neutered before it could procreate.
>

Sorry, I'm not really sure what you're trying to say.  This still works
when using the "neutered" concept; it just uses an existing mechanism, and
allows transfers.

-- 
Glenn Maynard

Received on Tuesday, 6 March 2012 01:56:37 UTC