Skip to content

Commit 280cd96

Browse files
addaleaxMylesBorins
authored andcommitted
domain: fix unintentional deprecation warning
646e5a4 changed the way that the domain hook callback is called. Previously, the callback was only used in the case that async_hooks were *not* being used (since domains already integrate with async hooks the way they should), and the corresponding deprecation warning also only emitted in that case. However, that commit didn’t move that condition along when the code was ported from C++ to JS. As a consequence, the domain hook callback was used when it wasn’t necessary to use it, and the deprecation warning emitted accidentally along with it. Refs: 646e5a4#diff-9f21ce1b9d6d46fdd07b969e8a04e140L192 Refs: 646e5a4#diff-e6db408e12db906ead6ddfac3de15a6fR119 Refs: #33801 (comment) PR-URL: #34245 Fixes: #34069 Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com> Reviewed-By: Shelley Vohr <codebytere@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Andrey Pechkurov <apechkurov@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
1 parent 3e3d908 commit 280cd96

6 files changed

+14
-4
lines changed

lib/internal/async_hooks.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,18 @@ function useDomainTrampoline(fn) {
112112
}
113113

114114
function callbackTrampoline(asyncId, cb, ...args) {
115-
if (asyncId && hasHooks(kBefore))
115+
if (asyncId !== 0 && hasHooks(kBefore))
116116
emitBeforeNative(asyncId);
117117

118118
let result;
119-
if (typeof domain_cb === 'function') {
119+
if (asyncId === 0 && typeof domain_cb === 'function') {
120120
ArrayPrototypeUnshift(args, cb);
121121
result = ReflectApply(domain_cb, this, args);
122122
} else {
123123
result = ReflectApply(cb, this, args);
124124
}
125125

126-
if (asyncId && hasHooks(kAfter))
126+
if (asyncId !== 0 && hasHooks(kAfter))
127127
emitAfterNative(asyncId);
128128

129129
return result;

test/parallel/test-domain-http-server.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

2222
'use strict';
23-
require('../common');
23+
const common = require('../common');
2424
const domain = require('domain');
2525
const http = require('http');
2626
const assert = require('assert');
2727
const debug = require('util').debuglog('test');
2828

29+
process.on('warning', common.mustNotCall());
30+
2931
const objects = { foo: 'bar', baz: {}, num: 42, arr: [1, 2, 3] };
3032
objects.baz.asdf = objects;
3133

test/parallel/test-domain-implicit-binding.js

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const domain = require('domain');
66
const fs = require('fs');
77
const isEnumerable = Function.call.bind(Object.prototype.propertyIsEnumerable);
88

9+
process.on('warning', common.mustNotCall());
10+
911
{
1012
const d = new domain.Domain();
1113

test/parallel/test-domain-implicit-fs.js

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ const common = require('../common');
2626
const assert = require('assert');
2727
const domain = require('domain');
2828

29+
process.on('warning', common.mustNotCall());
30+
2931
const d = new domain.Domain();
3032

3133
d.on('error', common.mustCall(function(er) {

test/parallel/test-domain-multi.js

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ const common = require('../common');
2626
const domain = require('domain');
2727
const http = require('http');
2828

29+
process.on('warning', common.mustNotCall());
30+
2931
const a = domain.create();
3032
a.enter(); // This will be our "root" domain
3133

test/parallel/test-domain-promise.js

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ const domain = require('domain');
55
const fs = require('fs');
66
const vm = require('vm');
77

8+
process.on('warning', common.mustNotCall());
9+
810
{
911
const d = domain.create();
1012

0 commit comments

Comments
 (0)