Re: [File API] Blob URI creation

 Please note that there's one other issue outstanding: both microtasks and
stable states are very closed, but neither may be what this needs.  A
separate hook may be needed.
https://www.w3.org/Bugs/Public/show_bug.cgi?id=16790#c13.

On Tue, Aug 14, 2012 at 4:37 PM, Feras Moussa <ferasm@microsoft.com> wrote:

> In general we are OK with changing it to the autoRevoke behavior below,
> but have some concerns around changing the default behavior.
> Changing the default behavior is a breaking change and any apps which
> expect the URL to work multiple times will now be broken. In Windows 8, we
> also implemented the oneTimeOnly behavior and it was very widely used,
> these consumers will be broken as well.
>
> We would like to support autoRevoke as the default as it helps reduce the
> chance of leaking unintentionally, but  we think developers should have a
> way to feature detect the new change. If a developer can feature detect
> which default behavior is present, then they can reason about what to
> expect from the API.
>

I agree that this needs to be feature detectable.  I don't think this
should be fixed in a special way specific to getObjectURL, because this is
a general issue with the Dictionary pattern, where features are used by
setting a flag in an object.  We need a general way to tell if an API
supports a particular dictionary key in its options dictionary, because
this is going to come up again as dictionaries are used in new APIs.

https://www.w3.org/Bugs/Public/show_bug.cgi?id=16953#c4 suggests using a
property of WebIDL dictionaries to accomplish this: use
Object.defineProperty to detect whether the key's value is read by the API
call:

var hasAutoRevoke = false;
var o = {};
Object.defineProperty(o, "autoRevoke", { get: function() { hasAutoRevoke =
true; return false; } });
URL.createObjectURL(new Blob(), o); // getter will be called if supported

This works (supported dictionary keys are guaranteed to be retrieved
exactly once), but it's fairly cumbersome.  It also requires a close
knowledge of WebIDL details, though maybe it's OK if people copy-and-paste
this code without knowing why it works.

-- 
Glenn Maynard

Received on Tuesday, 14 August 2012 22:01:25 UTC