Permalink
Browse files

src: domain should not replace nextTick function

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...
1 parent 47abdd9 commit 06453a94a7b06df30be0148e8b1d89932350f677 @tjfontaine tjfontaine committed Mar 4, 2014
Showing with 38 additions and 3 deletions.
  1. +1 −1 src/node.cc
  2. +6 −2 src/node.js
  3. +2 −0 test/message/max_tick_depth_trace.out
  4. +29 −0 test/simple/test-next-tick-domain.js
View
@@ -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();
View
@@ -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;
@@ -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;
@@ -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:*:*)
@@ -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:*:*)
@@ -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.