Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

global leaks improvements #783

Merged
merged 3 commits into from
Sep 15, 2013
Merged

Conversation

fool2fish
Copy link
Contributor

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 efficient

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%.

@lepture
Copy link

lepture commented Apr 2, 2013

ping ...

@travisjeffery travisjeffery merged commit 1aac129 into mochajs:master Sep 15, 2013
@fool2fish fool2fish deleted the pr-global-leaks branch September 16, 2013 04:07
aron added a commit to readmill/m.js that referenced this pull request Dec 3, 2013
An implementation detail means they drastically slow the test suite down
in Safari and Phantomjs. JSHint should do most of the work catching
unassigned variables.

See: mochajs/mocha#783
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants