forked from nodejs/node-v0.x-archive
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prevent domain.intercept passing 1st arg to cb
GH nodejs#3379
- Loading branch information
Showing
3 changed files
with
21 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,15 +149,16 @@ Domain.prototype.bind = function(cb, interceptError) { | |
var b = function() { | ||
// disposing turns functions into no-ops | ||
if (self._disposed) return; | ||
var args = Array.prototype.slice.call(arguments); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
isaacs
|
||
|
||
if (this instanceof Domain) { | ||
return cb.apply(this, arguments); | ||
return cb.apply(this, args); | ||
} | ||
|
||
// only intercept first-arg errors if explicitly requested. | ||
if (interceptError && arguments[0] && | ||
(arguments[0] instanceof Error)) { | ||
var er = arguments[0]; | ||
if (interceptError && args[0] && | ||
(args[0] instanceof Error)) { | ||
var er = args[0]; | ||
decorate(er, { | ||
domain_bound: cb, | ||
domain_thrown: false, | ||
|
@@ -166,9 +167,11 @@ Domain.prototype.bind = function(cb, interceptError) { | |
self.emit('error', er); | ||
return; | ||
} | ||
// remove first-arg if intercept as assumed to be the error-arg | ||
if (interceptError && args.length) args.shift(); | ||
|
||
self.enter(); | ||
var ret = cb.apply(this, arguments); | ||
var ret = cb.apply(this, args); | ||
self.exit(); | ||
return ret; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is extremely hazardous. I haven't benchmarked it yet, but in my experience in node, calling
Array.prototype.slice.call(arguments)
is an optimization killer.Should be something like this: