(callback, delay)
| 3 | var __nextId = 0; |
| 4 | var __activeTimers = {}; |
| 5 | function setTimeout(callback, delay) { |
| 6 | var start = Date.now(); |
| 7 | var timerId = __nextId++; |
| 8 | |
| 9 | function check() { |
| 10 | if (!__activeTimers[timerId]) { |
| 11 | return; |
| 12 | } |
| 13 | if (Date.now() - start >= delay) { |
| 14 | callback(); |
| 15 | } else { |
| 16 | requestAnimationFrame(check); |
| 17 | } |
| 18 | } |
| 19 | requestAnimationFrame(check); |
| 20 | |
| 21 | __activeTimers[timerId] = true; |
| 22 | return timerId; |
| 23 | } |
| 24 | |
| 25 | function clearTimeout(timerId) { |
| 26 | delete __activeTimers[timerId]; |
no outgoing calls
no test coverage detected