summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy J Fontaine <tjfontaine@gmail.com>2014-03-03 16:27:58 -0800
committerTimothy J Fontaine <tjfontaine@gmail.com>2014-03-03 16:27:58 -0800
commit06453a94a7b06df30be0148e8b1d89932350f677 (patch)
treeb87a1a4a98787d46e899155486870933fecd703a
parent47abdd9c43ae97ed11cb8cc4c770b43043718308 (diff)
downloadnode-06453a94a7b06df30be0148e8b1d89932350f677.tar.gz
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.
-rw-r--r--src/node.cc2
-rw-r--r--src/node.js8
-rw-r--r--test/message/max_tick_depth_trace.out2
-rw-r--r--test/simple/test-next-tick-domain.js29
4 files changed, 38 insertions, 3 deletions
diff --git a/src/node.cc b/src/node.cc
index a18e0d89d..ac906f0cd 100644
--- a/src/node.cc
+++ b/src/node.cc
@@ -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();
diff --git a/src/node.js b/src/node.js
index bdbe1c5e1..b54ff5175 100644
--- a/src/node.js
+++ b/src/node.js
@@ -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;
diff --git a/test/message/max_tick_depth_trace.out b/test/message/max_tick_depth_trace.out
index 22184a691..c9db2c558 100644
--- a/test/message/max_tick_depth_trace.out
+++ b/test/message/max_tick_depth_trace.out
@@ -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:*:*)
diff --git a/test/simple/test-next-tick-domain.js b/test/simple/test-next-tick-domain.js
new file mode 100644
index 000000000..16f77ed94
--- /dev/null
+++ b/test/simple/test-next-tick-domain.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');