joyent/node — pull request #6832 by rmg (2014-01-09 07:04:43+00:00)
Title: Make domain.create().exit() safe

Calling `.exit()` on a domain that isn't in the domain stack should not clear the domain stack. It should do nothing.

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();

domain
.create()
.exit(); dumpDomains();

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

Expected output:
```
[ 'a' ]
[ 'a', 'b' ]
[ 'a', 'b', 'c' ]
[ 'a', 'b', 'c' ]
```

Actual output:
```
[ 'a' ]
[ 'a', 'b' ]
[ 'a', 'b', 'c' ]
[]
```

Fixes #6819