joyent/node — pull request #6831 by rmg (2014-01-09 06:45:15+00:00)
Title: Add tests for Domain.enter()/.exit() stack

`Domain.exit()` should pop the given domain off the domain stack as well as the domains after it. Looks like an off-by-one error.

Given:
```javascript
var domain = require('domain');

var a = domain.create(); a.name = 'a';
var b = domain.create(); b.name = 'b';
var c = domain.create(); c.name = 'c';

a.enter(); dumpDomains();
b.enter(); dumpDomains();
c.enter(); dumpDomains();
b.exit(); dumpDomains();

function dumpDomains() {
console.log( domain._stack.map(function(d) { return d.name; }) );
}
```

v0.10.24:
```
[ 'a' ]
[ 'a', 'b' ]
[ 'a', 'b', 'c' ]
[ 'a' ]
```

v0.11.11-pre
```
[ 'a' ]
[ 'a', 'b' ]
[ 'a', 'b', 'c' ]
[ 'a', 'b' ]
```

Possibly introduced in bc39bdd9, found while working on #6819.