Andreas Madsen 14bc3e22f3
domain: runtime deprecate MakeCallback
Users of MakeCallback that adds the domain property to carry context,
should start using the async_context variant of MakeCallback or the
AsyncResource class.

PR-URL: https://github.com/nodejs/node/pull/17417
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2018-02-09 10:38:50 +01:00

36 lines
1.0 KiB
JavaScript

'use strict';
const common = require('../../common');
const assert = require('assert');
const domain = require('domain');
const binding = require(`./build/${common.buildType}/binding`);
function makeCallback(object, cb) {
binding.makeCallback(object, () => setImmediate(cb));
}
let latestWarning = null;
process.on('warning', function(warning) {
latestWarning = warning;
});
const d = domain.create();
// When domain is disabled, no warning will be emitted
makeCallback({ domain: d }, common.mustCall(function() {
assert.strictEqual(latestWarning, null);
d.run(common.mustCall(function() {
// No warning will be emitted when no domain property is applied
makeCallback({}, common.mustCall(function() {
assert.strictEqual(latestWarning, null);
// Warning is emitted when domain property is used and domain is enabled
makeCallback({ domain: d }, common.mustCall(function() {
assert.strictEqual(latestWarning.name, 'DeprecationWarning');
assert.strictEqual(latestWarning.code, 'DEP0097');
}));
}));
}));
}));