[IndexedDB] Problems unprefixing IndexedDB

Hello all,

Jonas mentioned earlier on this list that we unprefixed IndexedDB in
Firefox nightlies some time ago.  We ran into a bit of a problem.[0]  Most
of the IndexedDB tutorials (including ours and HTML5 Rocks[1] :-/) tell
authors to deal with prefixing with:

var indexedDB = window.indexedDB || window.webkitIndexedDB ||
window.mozIndexedDB || window.msIndexedDB || ...

This code has a bug when executed at global scope.  Because the properties
are on the prototype chain of the global object, 'var indexedDB' creates a
new property on the global.  Then window.indexedDB finds the new property
(which has the value undefined) instead of the IDBFactory on the prototype
chain.  The result is that all of the pages that do this no longer work
after we unprefix IndexedDB.

Mozilla is the only vendor affected by this at the moment.  In our testing
on IE 10.0.8400.0, both a prefixed and unprefixed version of IndexedDB are
available, so the code above shadows the unprefixed version with the
prefixed version (which has no real effect).  In Chrome, attributes are on
the object itself instead of the prototype, so 'var indexedDB' at global
scope is a no-op.

Our options, as we see them now, are:
1. Make no code changes, and evangelize.
2. Move indexedDB to the global object itself (copy Chrome).
3. Put the prefixed version back temporarily (copy IE).

We'd prefer option 1 of course, if we can make that work.  Any thoughts are
welcome.  We'd especially like to know if IE has plans to drop the prefixed
version, and if Chrome is planning to move attributes to the prototype
anytime soon.

Thoughts?

- Kyle

PS. We're also going to run into this in the future with any other prefixed
DOM APIs we add to the global, probably even if we don't tell people to do
it wrong in our tutorials.  This behavior is a pretty massive footgun.

[0] https://bugzilla.mozilla.org/show_bug.cgi?id=770844
[1] https://bugzilla.mozilla.org/show_bug.cgi?id=770844#c5

Received on Thursday, 9 August 2012 00:06:39 UTC