Actually, I think it would be better to fix this in the JS engine. I filed https://bugzilla.mozilla.org/show_bug.cgi?id=977496.