Skip to content

Commit

Permalink
src: domain should not replace nextTick function
Browse files Browse the repository at this point in the history
Previously if you cached process.nextTick and then require('domain')
subsequent nextTick() calls would not be caught because enqueued
functions were taking the wrong path. This keeps nextTick to a single
function reference and changes the implementation details after domain
has been required.
  • Loading branch information
tjfontaine committed Mar 4, 2014
1 parent 47abdd9 commit 06453a9
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ Handle<Value> UsingDomains(const Arguments& args) {
Local<Function> tdc = tdc_v.As<Function>();
Local<Function> ndt = ndt_v.As<Function>();
process->Set(String::New("_tickCallback"), tdc);
process->Set(String::New("nextTick"), ndt);
process->Set(String::New("_currentTickHandler"), ndt);
process_tickCallback.Dispose(); // Possibly already set by MakeCallback().
process_tickCallback = Persistent<Function>::New(tdc);
return Undefined();
Expand Down
8 changes: 6 additions & 2 deletions src/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,12 @@
var index = 1;
var depth = 2;

process.nextTick = nextTick;
process.nextTick = function nextTick(cb) {
process._currentTickHandler(cb);
};

// needs to be accessible from cc land
process._currentTickHandler = _nextTick;
process._nextDomainTick = _nextDomainTick;
process._tickCallback = _tickCallback;
process._tickDomainCallback = _tickDomainCallback;
Expand Down Expand Up @@ -472,7 +476,7 @@
tickDone(0);
}

function nextTick(callback) {
function _nextTick(callback) {
// on the way out, don't bother. it won't get fired anyway.
if (process._exiting)
return;
Expand Down
2 changes: 2 additions & 0 deletions test/message/max_tick_depth_trace.out
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ tick 12
tick 11
Trace: (node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
at maxTickWarn (node.js:*:*)
at process._nextTick [as _currentTickHandler] (node.js:*:*)
at process.nextTick (node.js:*:*)
at f (*test*message*max_tick_depth_trace.js:*:*)
at process._tickCallback (node.js:*:*)
Expand All @@ -28,6 +29,7 @@ tick 2
tick 1
Trace: (node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
at maxTickWarn (node.js:*:*)
at process._nextTick [as _currentTickHandler] (node.js:*:*)
at process.nextTick (node.js:*:*)
at f (*test*message*max_tick_depth_trace.js:*:*)
at process._tickCallback (node.js:*:*)
Expand Down
29 changes: 29 additions & 0 deletions test/simple/test-next-tick-domain.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

var common = require('../common');
var assert = require('assert');

var origNextTick = process.nextTick;

require('domain');

assert.strictEqual(origNextTick, process.nextTick, 'Requiring domain should not change nextTick');

0 comments on commit 06453a9

Please sign in to comment.