Browse Source

domain: use camelCase instead of snake_case

While it's true that error objects have a history of getting snake_case
properties attached by the host system, it's a point of confusion to
Node users that comes up a lot.  It's still 'experimental', so best to
change this sooner rather than later.
v0.9.5-release
isaacs 12 years ago
parent
commit
ec8ebaf300
  1. 6
      doc/api/domain.markdown
  2. 4
      lib/domain.js
  3. 4
      lib/events.js
  4. 2
      src/node.js
  5. 4
      test/simple/test-domain-implicit-fs.js
  6. 44
      test/simple/test-domain.js

6
doc/api/domain.markdown

@ -27,11 +27,11 @@ Any time an Error object is routed through a domain, a few extra fields
are added to it. are added to it.
* `error.domain` The domain that first handled the error. * `error.domain` The domain that first handled the error.
* `error.domain_emitter` The event emitter that emitted an 'error' event * `error.domainEmitter` The event emitter that emitted an 'error' event
with the error object. with the error object.
* `error.domain_bound` The callback function which was bound to the * `error.domainBound` The callback function which was bound to the
domain, and passed an error as its first argument. domain, and passed an error as its first argument.
* `error.domain_thrown` A boolean indicating whether the error was * `error.domainThrown` A boolean indicating whether the error was
thrown, emitted, or passed to a bound callback function. thrown, emitted, or passed to a bound callback function.
## Implicit Binding ## Implicit Binding

4
lib/domain.js

@ -140,8 +140,8 @@ Domain.prototype.bind = function(cb, interceptError) {
(arguments[0] instanceof Error)) { (arguments[0] instanceof Error)) {
var er = arguments[0]; var er = arguments[0];
util._extend(er, { util._extend(er, {
domain_bound: cb, domainBound: cb,
domain_thrown: false, domainThrown: false,
domain: self domain: self
}); });
self.emit('error', er); self.emit('error', er);

4
lib/events.js

@ -58,9 +58,9 @@ EventEmitter.prototype.emit = function(type) {
{ {
if (this.domain) { if (this.domain) {
var er = arguments[1]; var er = arguments[1];
er.domain_emitter = this; er.domainEmitter = this;
er.domain = this.domain; er.domain = this.domain;
er.domain_thrown = false; er.domainThrown = false;
this.domain.emit('error', er); this.domain.emit('error', er);
return false; return false;
} }

2
src/node.js

@ -231,7 +231,7 @@
return true; return true;
er.domain = domain; er.domain = domain;
er.domain_thrown = true; er.domainThrown = true;
// wrap this in a try/catch so we don't get infinite throwing // wrap this in a try/catch so we don't get infinite throwing
try { try {
// One of three things will happen here. // One of three things will happen here.

4
test/simple/test-domain-implicit-fs.js

@ -36,8 +36,8 @@ d.on('error', function(er) {
console.error('caught', er); console.error('caught', er);
assert.strictEqual(er.domain, d); assert.strictEqual(er.domain, d);
assert.strictEqual(er.domain_thrown, true); assert.strictEqual(er.domainThrown, true);
assert.ok(!er.domain_emitter); assert.ok(!er.domainEmitter);
assert.strictEqual(er.code, 'ENOENT'); assert.strictEqual(er.code, 'ENOENT');
assert.ok(/\bthis file does not exist\b/i.test(er.path)); assert.ok(/\bthis file does not exist\b/i.test(er.path));
assert.strictEqual(typeof er.errno, 'number'); assert.strictEqual(typeof er.errno, 'number');

44
test/simple/test-domain.js

@ -53,28 +53,28 @@ d.on('error', function(er) {
switch (er_message) { switch (er_message) {
case 'emitted': case 'emitted':
assert.equal(er.domain, d); assert.equal(er.domain, d);
assert.equal(er.domain_emitter, e); assert.equal(er.domainEmitter, e);
assert.equal(er.domain_thrown, false); assert.equal(er.domainThrown, false);
break; break;
case 'bound': case 'bound':
assert.ok(!er.domain_emitter); assert.ok(!er.domainEmitter);
assert.equal(er.domain, d); assert.equal(er.domain, d);
assert.equal(er.domain_bound, fn); assert.equal(er.domainBound, fn);
assert.equal(er.domain_thrown, false); assert.equal(er.domainThrown, false);
break; break;
case 'thrown': case 'thrown':
assert.ok(!er.domain_emitter); assert.ok(!er.domainEmitter);
assert.equal(er.domain, d); assert.equal(er.domain, d);
assert.equal(er.domain_thrown, true); assert.equal(er.domainThrown, true);
break; break;
case "ENOENT, open 'this file does not exist'": case "ENOENT, open 'this file does not exist'":
assert.equal(er.domain, d); assert.equal(er.domain, d);
assert.equal(er.domain_thrown, false); assert.equal(er.domainThrown, false);
assert.equal(typeof er.domain_bound, 'function'); assert.equal(typeof er.domainBound, 'function');
assert.ok(!er.domain_emitter); assert.ok(!er.domainEmitter);
assert.equal(er.code, 'ENOENT'); assert.equal(er.code, 'ENOENT');
assert.equal(er_path, 'this file does not exist'); assert.equal(er_path, 'this file does not exist');
assert.equal(typeof er.errno, 'number'); assert.equal(typeof er.errno, 'number');
@ -85,33 +85,33 @@ d.on('error', function(er) {
assert.equal(er.code, 'ENOENT'); assert.equal(er.code, 'ENOENT');
assert.equal(er_path, 'stream for nonexistent file'); assert.equal(er_path, 'stream for nonexistent file');
assert.equal(er.domain, d); assert.equal(er.domain, d);
assert.equal(er.domain_emitter, fst); assert.equal(er.domainEmitter, fst);
assert.ok(!er.domain_bound); assert.ok(!er.domainBound);
assert.equal(er.domain_thrown, false); assert.equal(er.domainThrown, false);
break; break;
case 'implicit': case 'implicit':
assert.equal(er.domain_emitter, implicit); assert.equal(er.domainEmitter, implicit);
assert.equal(er.domain, d); assert.equal(er.domain, d);
assert.equal(er.domain_thrown, false); assert.equal(er.domainThrown, false);
assert.ok(!er.domain_bound); assert.ok(!er.domainBound);
break; break;
case 'implicit timer': case 'implicit timer':
assert.equal(er.domain, d); assert.equal(er.domain, d);
assert.equal(er.domain_thrown, true); assert.equal(er.domainThrown, true);
assert.ok(!er.domain_emitter); assert.ok(!er.domainEmitter);
assert.ok(!er.domain_bound); assert.ok(!er.domainBound);
break; break;
case 'Cannot call method \'isDirectory\' of undefined': case 'Cannot call method \'isDirectory\' of undefined':
assert.equal(er.domain, d); assert.equal(er.domain, d);
assert.ok(!er.domain_emitter); assert.ok(!er.domainEmitter);
assert.ok(!er.domain_bound); assert.ok(!er.domainBound);
break; break;
default: default:
console.error('unexpected error, throwing %j', er.message || er); console.error('unexpected error, throwing %j', er.message, er);
throw er; throw er;
} }

Loading…
Cancel
Save