Re: [IndexedDB] Problems unprefixing IndexedDB

From: Kyle Huey <me@kylehuey.com>
 >
 > 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.

Not according to ECMA-262 Edition 5.1 or conforming implementations of it.

Firefox's JS engine, SpiderMonkey, actually helped get ES5.1 to match JS 
reality and past editions, where ES5 tried to spec what you describe in 
the last paragraph cited above. We found that incompatible, rolled it 
back in

https://bugzilla.mozilla.org/show_bug.cgi?id=632003

and filed an erratum on ES5 which was fixed for ES5.1 (the ISO version 
of ES5).

Unfortunately this bug regressed SpiderMonkey to ES5 status quo ante:

https://bugzilla.mozilla.org/show_bug.cgi?id=722121

I only just noticed, due to the unprefix-indexedDB issue you raise. I filed

https://bugzilla.mozilla.org/show_bug.cgi?id=781739

to get SpiderMonkey fixed.

The takeaway is to never assume a recently modified JS engine matches 
the latest ECMA spec. Sad to report this one involved SpiderMonkey, but 
it hits all evolving engines, and the spec can have bugs too (as 
described above in ES5). The ES5.1 spec is quite clear that the 
prototype chain is checked and no such property found, before a 'var' 
declaration makes a fresh binding with default value undefined.

So no need for WebIDL, IndexedDB, or ES5.1 to change.

/be

Received on Friday, 10 August 2012 06:48:37 UTC