File tree Expand file tree Collapse file tree 4 files changed +68
-3
lines changed Expand file tree Collapse file tree 4 files changed +68
-3
lines changed Original file line number Diff line number Diff line change 1+ var common = require ( '../common.js' ) ;
2+ var domain = require ( 'domain' ) ;
3+
4+ var bench = common . createBenchmark ( main , {
5+ arguments : [ 0 , 1 , 2 , 3 ] ,
6+ n : [ 10 ]
7+ } ) ;
8+
9+ var bdomain = domain . create ( ) ;
10+ var gargs = [ 1 , 2 , 3 ] ;
11+
12+ function main ( conf ) {
13+
14+ var args , ret , n = + conf . n ;
15+ var arguments = gargs . slice ( 0 , conf . arguments ) ;
16+ bench . start ( ) ;
17+
18+ bdomain . enter ( ) ;
19+ for ( var i = 0 ; i < n ; i ++ ) {
20+ if ( arguments . length >= 2 ) {
21+ args = Array . prototype . slice . call ( arguments , 1 ) ;
22+ ret = fn . apply ( this , args ) ;
23+ } else {
24+ ret = fn . call ( this ) ;
25+ }
26+ }
27+ bdomain . exit ( ) ;
28+
29+ bench . end ( n ) ;
30+ }
31+
32+ function fn ( a , b , c ) {
33+ if ( ! a )
34+ a = 1 ;
35+
36+ if ( ! b )
37+ b = 2 ;
38+
39+ if ( ! c )
40+ c = 3 ;
41+
42+ return a + b + c ;
43+ }
Original file line number Diff line number Diff line change @@ -260,13 +260,14 @@ uncaught exceptions to the active Domain object.
260260Domain is a child class of [ EventEmitter] [ ] . To handle the errors that it
261261catches, listen to its ` error ` event.
262262
263- ### domain.run(fn)
263+ ### domain.run(fn[ , arg ] [ , ... ] )
264264
265265* ` fn ` {Function}
266266
267267Run the supplied function in the context of the domain, implicitly
268268binding all event emitters, timers, and lowlevel requests that are
269- created in that context.
269+ created in that context. Optionally, arguments can be passed to
270+ the function.
270271
271272This is the most basic way to use a domain.
272273
Original file line number Diff line number Diff line change @@ -195,9 +195,23 @@ Domain.prototype.remove = function(ee) {
195195Domain . prototype . run = function ( fn ) {
196196 if ( this . _disposed )
197197 return ;
198+
199+ var ret ;
200+
198201 this . enter ( ) ;
199- var ret = fn . call ( this ) ;
202+ if ( arguments . length >= 2 ) {
203+ var len = arguments . length ;
204+ var args = new Array ( len - 1 ) ;
205+
206+ for ( var i = 1 ; i < len ; i ++ )
207+ args [ i - 1 ] = arguments [ i ] ;
208+
209+ ret = fn . apply ( this , args ) ;
210+ } else {
211+ ret = fn . call ( this ) ;
212+ }
200213 this . exit ( ) ;
214+
201215 return ret ;
202216} ;
203217
Original file line number Diff line number Diff line change @@ -258,6 +258,13 @@ var result = d.run(function () {
258258assert . equal ( result , 'return value' ) ;
259259
260260
261+ // check if the executed function take in count the applied parameters
262+ result = d . run ( function ( a , b ) {
263+ return a + ' ' + b ;
264+ } , 'return' , 'value' ) ;
265+ assert . equal ( result , 'return value' ) ;
266+
267+
261268var fst = fs . createReadStream ( 'stream for nonexistent file' )
262269d . add ( fst )
263270expectCaught ++ ;
You can’t perform that action at this time.
0 commit comments