Fix exception when looking up indexedDB when disabled in Firefox. #798

Closed
wants to merge 2 commits into
from

Projects

None yet

4 participants

@Stebalien

Firefox will sometimes throw an exception when looking up known but
disabled features in the dom. This commit catches exceptions when
looking up properties in testDOMProps.

While this fix could be more specific, putting it in the testDOMProps function will help prevent bugs like this from being introduced in the future.

Stebalien added some commits Jan 27, 2013
@Stebalien Stebalien Catch exceptions when looking up properties in the DOM
Firefox will sometimes throw an exception when looking up known but
disabled features in the dom. This commit catches exceptions when
looking up properties in testDOMProps.
2f3f96b
@Stebalien Stebalien The continue statement in the catch block is unnecessary d72df2c
@paulirish
Member

Can you give me the repro here? Disable indexeddb in about:config and then run !!prefixed("indexedDB", window) ?

In the past we've been averse to try/catching just because someone "broke their warranty" in about:config.

@Stebalien

Sorry, I should have been much clearer in my initial request. I'm working on a cross-browser extension/webapp that I'm currently porting it to Firefox (as an extension). Trying to access window.indexedDB from a Firefox extension throws an exception (same with window.localStorage, etc.).

I understand that Modernizr is not intended to be run inside extensions. When I initially encountered this problem, I mistakenly assumed that it applied to Firefox in general (like bug #92). As it doesn't, I understand if you feel this patch isn't altogether necessary.

@stucox
Member
stucox commented Jan 28, 2013

I think this is what's causing my Modernizr bookmarklet not to work in FF; same goes for a data: URL with a Modernizr build which includes indexeddb, e.g.:

data:text/html,<script src="https://gist.github.com/raw/4654472/f1597530cf8894d5729838f488cff4a62574dfd8/modernizr.custom.07390.js"></script>

Presumably Indexed DB is disabled in FF for bookmarklets (or javascript: URLs in general?) and data: URLs with the same mechanics as disabling it via about:config.

So maybe 3 developer/debug/hack use cases for sticking a try...catch in there.

@mgaert
mgaert commented Jan 28, 2013
@paulirish
Member

try/catch forces a slow path in JS engines. so i'd like to avoid this if neccessary.

especially for all everything. we could do a bypass for FF though.

@stucox stucox was assigned Feb 25, 2013
@stucox
Member
stucox commented Feb 25, 2013

Let's change it to an if (prop[i] in obj ) then.

I'll do this now and wrap up this PR.

@stucox stucox added a commit that closed this pull request Feb 26, 2013
@stucox stucox Changed an existance check to an `in` to avoid exceptions being throw…
…n for disabled features in FF. Fixes #798
f258126
@stucox stucox closed this in f258126 Feb 26, 2013
@SlexAxton SlexAxton added a commit to SlexAxton/Modernizr that referenced this pull request Feb 27, 2013
@SlexAxton SlexAxton Merge branch 'master' of github.com:Modernizr/Modernizr into meta
* 'master' of github.com:Modernizr/Modernizr:
  Remove `pre` from shiv version
  Remove `pre` from printshiv version
  Added detect for <template> HTML tag
  Update HTML5 Shiv to latest version
  Removed dashes from property names corresponding to feature detects.
  Changed an existance check to an `in` to avoid exceptions being thrown for disabled features in FF. Fixes #798
6f97714
@patrickkettner patrickkettner pushed a commit to patrickkettner/Modernizr that referenced this pull request Feb 22, 2015
@stucox stucox Changed an existance check to an `in` to avoid exceptions being throw…
…n for disabled features in FF. Fixes #798
0585f7f
@patrickkettner patrickkettner pushed a commit to patrickkettner/Modernizr that referenced this pull request Feb 22, 2015
@SlexAxton SlexAxton Merge branch 'master' of github.com:Modernizr/Modernizr into meta
* 'master' of github.com:Modernizr/Modernizr:
  Remove `pre` from shiv version
  Remove `pre` from printshiv version
  Added detect for <template> HTML tag
  Update HTML5 Shiv to latest version
  Removed dashes from property names corresponding to feature detects.
  Changed an existance check to an `in` to avoid exceptions being thrown for disabled features in FF. Fixes #798
5ca0ddc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment