visionmedia/mocha — pull request #783 by fool2fish (2013-03-21 03:03:40+00:00)
Title: global leaks improvements

3 improvements

### 1. in ie6,7,8 and opera, insert iframe will cause global leaks

**analysis**

An iframe could be approached by window[iframeIndex].
In ie6,7,8 and opera, iframeIndex is enumerable, this could cause leaks.

**solution**

see: lib/runner.js 540

### 2. in firefox, window.getInterface may cause global leaks

**analysis**

If runner runs in an iframe, this iframe's window.getInterface method not init at first.
It is assigned in some seconds.

**solution**

see: lib/runner.js line536

### 3. in some browsers, mocha.globals([...]) make tests run very slow

**analysis**

- if user specified globals argument, every time a test finished, filterLeaks() will run.
- nested loop is not efficent

**solution**

- see: lib/runner.js line164 ~ 165. I use this.prevGlobalsLength to remember how many global variables are when last test finished. When this test finished, this.prevGlobalsLength will be compared with globals.length, if they are equals, I think this test dose not has global leaks, so filterLeaks() could be jumped.（it is not very strict, if someone delete a global variable, and then create a new one in this test, this won't be found. but if it happened, just let it go). this promotion is huge.

- see: lib/runner.js line531 ~ 547. I moved some code to outer loop from inner loop. this cuts down run time by 50%.