domain-browser
Advanced tools
Comparing version 1.1.3 to 1.1.4
56
index.js
/*global define:false require:false */ | ||
module.exports = (function(){ | ||
// Import Events | ||
var events = require('events'); | ||
var events = require('events') | ||
// Export Domain | ||
var domain = {}; | ||
var domain = {} | ||
domain.createDomain = domain.create = function(){ | ||
var d = new events.EventEmitter(); | ||
var d = new events.EventEmitter() | ||
@@ -16,23 +16,53 @@ function emitError(e) { | ||
d.add = function(emitter){ | ||
emitter.on('error', emitError); | ||
emitter.on('error', emitError) | ||
} | ||
d.remove = function(emitter){ | ||
emitter.removeListener('error', emitError); | ||
emitter.removeListener('error', emitError) | ||
} | ||
d.bind = function(fn){ | ||
return function(){ | ||
var args = Array.prototype.slice.call(arguments) | ||
try { | ||
fn.apply(null, args) | ||
} | ||
catch (err){ | ||
emitError(err) | ||
} | ||
} | ||
} | ||
d.intercept = function(fn){ | ||
return function(err){ | ||
if ( err ) { | ||
emitError(err) | ||
} | ||
else { | ||
var args = Array.prototype.slice.call(arguments, 1) | ||
try { | ||
fn.apply(null, args) | ||
} | ||
catch (err){ | ||
emitError(err) | ||
} | ||
} | ||
} | ||
} | ||
d.run = function(fn){ | ||
try { | ||
fn(); | ||
fn() | ||
} | ||
catch (err) { | ||
this.emit('error', err); | ||
emitError(err) | ||
} | ||
return this; | ||
return this | ||
}; | ||
d.dispose = function(){ | ||
this.removeAllListeners(); | ||
return this; | ||
this.removeAllListeners() | ||
return this | ||
}; | ||
return d; | ||
d.enter = d.exit = function(){ | ||
return this | ||
} | ||
return d | ||
}; | ||
return domain; | ||
}).call(this); | ||
return domain | ||
}).call(this) |
{ | ||
"title": "Node's [domain module](http://nodejs.org/api/domain.html) for the web browser", | ||
"name": "domain-browser", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"description": "Note, this is merely an evented try...catch with the same API as node. Nothing more.", | ||
@@ -13,5 +13,6 @@ "homepage": "https://github.com/bevry/domain-browser", | ||
"npm": true, | ||
"npmdownloads": true, | ||
"david": true, | ||
"daviddev": true, | ||
"gittip": "bevry", | ||
"gratipay": "bevry", | ||
"flattr": "344188/balupton-on-Flattr", | ||
@@ -43,2 +44,3 @@ "paypal": "QB8GQPZAH84N6", | ||
"Benjamin Lupton <b@lupton.cc> (https://github.com/balupton)", | ||
"evansolomon (https://github.com/evansolomon)", | ||
"substack (https://github.com/substack)" | ||
@@ -62,5 +64,5 @@ ], | ||
"devDependencies": { | ||
"projectz": "~0.3.2", | ||
"chai": "~1.9.1", | ||
"joe": "~1.4.0", | ||
"projectz": "~0.3.17", | ||
"chai": "~1.10.0", | ||
"joe": "~1.5.0", | ||
"joe-reporter-console": "~1.2.1" | ||
@@ -67,0 +69,0 @@ }, |
@@ -11,11 +11,12 @@ | ||
[![Build Status](http://img.shields.io/travis-ci/bevry/domain-browser.png?branch=master)](http://travis-ci.org/bevry/domain-browser "Check this project's build status on TravisCI") | ||
[![NPM version](http://badge.fury.io/js/domain-browser.png)](https://npmjs.org/package/domain-browser "View this project on NPM") | ||
[![Dependency Status](https://david-dm.org/bevry/domain-browser.png?theme=shields.io)](https://david-dm.org/bevry/domain-browser) | ||
[![Development Dependency Status](https://david-dm.org/bevry/domain-browser/dev-status.png?theme=shields.io)](https://david-dm.org/bevry/domain-browser#info=devDependencies)<br/> | ||
[![Gittip donate button](http://img.shields.io/gittip/bevry.png)](https://www.gittip.com/bevry/ "Donate weekly to this project using Gittip") | ||
[![Flattr donate button](http://img.shields.io/flattr/donate.png?color=yellow)](http://flattr.com/thing/344188/balupton-on-Flattr "Donate monthly to this project using Flattr") | ||
[![PayPayl donate button](http://img.shields.io/paypal/donate.png?color=yellow)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QB8GQPZAH84N6 "Donate once-off to this project using Paypal") | ||
[![BitCoin donate button](http://img.shields.io/bitcoin/donate.png?color=yellow)](https://coinbase.com/checkouts/9ef59f5479eec1d97d63382c9ebcb93a "Donate once-off to this project using BitCoin") | ||
[![Wishlist browse button](http://img.shields.io/wishlist/browse.png?color=yellow)](http://amzn.com/w/2F8TXKSNAFG4V "Buy an item on our wishlist for us") | ||
[![Build Status](https://img.shields.io/travis/bevry/domain-browser/master.svg)](http://travis-ci.org/bevry/domain-browser "Check this project's build status on TravisCI") | ||
[![NPM version](https://img.shields.io/npm/v/domain-browser.svg)](https://npmjs.org/package/domain-browser "View this project on NPM") | ||
[![NPM downloads](https://img.shields.io/npm/dm/domain-browser.svg)](https://npmjs.org/package/domain-browser "View this project on NPM") | ||
[![Dependency Status](https://img.shields.io/david/bevry/domain-browser.svg)](https://david-dm.org/bevry/domain-browser) | ||
[![Dev Dependency Status](https://img.shields.io/david/dev/bevry/domain-browser.svg)](https://david-dm.org/bevry/domain-browser#info=devDependencies)<br/> | ||
[![Gratipay donate button](https://img.shields.io/gratipay/bevry.svg)](https://www.gratipay.com/bevry/ "Donate weekly to this project using Gratipay") | ||
[![Flattr donate button](https://img.shields.io/badge/flattr-donate-yellow.svg)](http://flattr.com/thing/344188/balupton-on-Flattr "Donate monthly to this project using Flattr") | ||
[![PayPayl donate button](https://img.shields.io/badge/paypal-donate-yellow.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QB8GQPZAH84N6 "Donate once-off to this project using Paypal") | ||
[![BitCoin donate button](https://img.shields.io/badge/bitcoin-donate-yellow.svg)](https://coinbase.com/checkouts/9ef59f5479eec1d97d63382c9ebcb93a "Donate once-off to this project using BitCoin") | ||
[![Wishlist browse button](https://img.shields.io/badge/wishlist-donate-yellow.svg)](http://amzn.com/w/2F8TXKSNAFG4V "Buy an item on our wishlist for us") | ||
@@ -43,3 +44,3 @@ <!-- /BADGES --> | ||
- Install: `npm install --save domain-browser` | ||
- CDN URL: `//wzrd.in/bundle/domain-browser@1.1.3` | ||
- CDN URL: `//wzrd.in/bundle/domain-browser@1.1.4` | ||
@@ -75,7 +76,7 @@ ### [Ender](http://ender.jit.su/) | ||
[![Gittip donate button](http://img.shields.io/gittip/bevry.png)](https://www.gittip.com/bevry/ "Donate weekly to this project using Gittip") | ||
[![Flattr donate button](http://img.shields.io/flattr/donate.png?color=yellow)](http://flattr.com/thing/344188/balupton-on-Flattr "Donate monthly to this project using Flattr") | ||
[![PayPayl donate button](http://img.shields.io/paypal/donate.png?color=yellow)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QB8GQPZAH84N6 "Donate once-off to this project using Paypal") | ||
[![BitCoin donate button](http://img.shields.io/bitcoin/donate.png?color=yellow)](https://coinbase.com/checkouts/9ef59f5479eec1d97d63382c9ebcb93a "Donate once-off to this project using BitCoin") | ||
[![Wishlist browse button](http://img.shields.io/wishlist/browse.png?color=yellow)](http://amzn.com/w/2F8TXKSNAFG4V "Buy an item on our wishlist for us") | ||
[![Gratipay donate button](https://img.shields.io/gratipay/bevry.svg)](https://www.gratipay.com/bevry/ "Donate weekly to this project using Gratipay") | ||
[![Flattr donate button](https://img.shields.io/badge/flattr-donate-yellow.svg)](http://flattr.com/thing/344188/balupton-on-Flattr "Donate monthly to this project using Flattr") | ||
[![PayPayl donate button](https://img.shields.io/badge/paypal-donate-yellow.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QB8GQPZAH84N6 "Donate once-off to this project using Paypal") | ||
[![BitCoin donate button](https://img.shields.io/badge/bitcoin-donate-yellow.svg)](https://coinbase.com/checkouts/9ef59f5479eec1d97d63382c9ebcb93a "Donate once-off to this project using BitCoin") | ||
[![Wishlist browse button](https://img.shields.io/badge/wishlist-donate-yellow.svg)](http://amzn.com/w/2F8TXKSNAFG4V "Buy an item on our wishlist for us") | ||
@@ -87,2 +88,3 @@ ### Contributors | ||
- [Benjamin Lupton](https://github.com/balupton) <b@lupton.cc> — [view contributions](https://github.com/bevry/domain-browser/commits?author=balupton) | ||
- [evansolomon](https://github.com/evansolomon) — [view contributions](https://github.com/bevry/domain-browser/commits?author=evansolomon) | ||
- [substack](https://github.com/substack) — [view contributions](https://github.com/bevry/domain-browser/commits?author=substack) | ||
@@ -89,0 +91,0 @@ |
93
test.js
// Import | ||
var events = require('events'); | ||
var expect = require('chai').expect; | ||
var joe = require('joe'); | ||
var domain = require('./'); | ||
var events = require('events') | ||
var expect = require('chai').expect | ||
var joe = require('joe') | ||
var domain = require('./') | ||
@@ -12,34 +12,34 @@ // ===================================== | ||
it('should work on throws', function(done){ | ||
var d = domain.create(); | ||
var d = domain.create() | ||
d.on('error', function(err){ | ||
expect(err && err.message).to.eql('a thrown error'); | ||
done(); | ||
}); | ||
expect(err && err.message).to.eql('a thrown error') | ||
done() | ||
}) | ||
d.run(function(){ | ||
throw new Error('a thrown error'); | ||
}); | ||
}); | ||
throw new Error('a thrown error') | ||
}) | ||
}) | ||
it('should be able to add emitters', function(done){ | ||
var d = domain.create(); | ||
var emitter = new events.EventEmitter(); | ||
var d = domain.create() | ||
var emitter = new events.EventEmitter() | ||
d.add(emitter); | ||
d.add(emitter) | ||
d.on('error', function (err) { | ||
expect(err && err.message).to.eql('an emitted error'); | ||
done(); | ||
}); | ||
expect(err && err.message).to.eql('an emitted error') | ||
done() | ||
}) | ||
emitter.emit('error', new Error('an emitted error')); | ||
}); | ||
emitter.emit('error', new Error('an emitted error')) | ||
}) | ||
it('should be able to remove emitters', function (done){ | ||
var emitter = new events.EventEmitter(); | ||
var d = domain.create(); | ||
var emitter = new events.EventEmitter() | ||
var d = domain.create() | ||
d.add(emitter); | ||
var domainGotError = false; | ||
d.add(emitter) | ||
var domainGotError = false | ||
d.on('error', function (err) { | ||
domainGotError = true | ||
}); | ||
}) | ||
@@ -56,5 +56,44 @@ emitter.on('error', function (err) { | ||
d.remove(emitter); | ||
emitter.emit('error', new Error('This error should not go to the domain')); | ||
d.remove(emitter) | ||
emitter.emit('error', new Error('This error should not go to the domain')) | ||
}) | ||
}); | ||
it('bind should work', function(done){ | ||
var d = domain.create() | ||
d.on('error', function(err){ | ||
expect(err && err.message).to.eql('a thrown error') | ||
done() | ||
}) | ||
d.bind(function(err, a, b){ | ||
expect(err && err.message).to.equal('a passed error') | ||
expect(a).to.equal(2) | ||
expect(b).to.equal(3) | ||
throw new Error('a thrown error') | ||
})(new Error('a passed error'), 2, 3) | ||
}) | ||
it('intercept should work', function(done){ | ||
var d = domain.create() | ||
var count = 0 | ||
d.on('error', function(err){ | ||
if ( count === 0 ) { | ||
expect(err && err.message).to.eql('a thrown error') | ||
} else if ( count === 1 ) { | ||
expect(err && err.message).to.eql('a passed error') | ||
done() | ||
} | ||
count++ | ||
}) | ||
d.intercept(function(a, b){ | ||
expect(a).to.equal(2) | ||
expect(b).to.equal(3) | ||
throw new Error('a thrown error') | ||
})(null, 2, 3) | ||
d.intercept(function(a, b){ | ||
throw new Error('should never reach here') | ||
})(new Error('a passed error'), 2, 3) | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
12174
7
144
104
0