Ported https://github.com/snichme/smoke.js/commit/563833ba35085b63c70789ccf64f6a6b1a26b678