mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
b3b0c43474
Because the following gives basically no actionable information on its own, neither in the error message nor in the stack trace: (node:3187) [DEP0097] DeprecationWarning: Using a domain property in MakeCallback is deprecated. Use the async_context variant of MakeCallback or the AsyncResource class instead. at emitMakeCallbackDeprecation (domain.js:123:13) at process.topLevelDomainCallback (domain.js:135:5) at process.callbackTrampoline (internal/async_hooks.js:124:14) PR-URL: https://github.com/nodejs/node/pull/36136 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Rich Trott <rtrott@gmail.com>
44 lines
1.2 KiB
JavaScript
44 lines
1.2 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, function someMethod() { setImmediate(cb); });
|
|
}
|
|
|
|
let latestWarning = null;
|
|
process.on('warning', (warning) => {
|
|
latestWarning = warning;
|
|
});
|
|
|
|
const d = domain.create();
|
|
|
|
class Resource {
|
|
constructor(domain) {
|
|
this.domain = domain;
|
|
}
|
|
}
|
|
|
|
// When domain is disabled, no warning will be emitted
|
|
makeCallback(new Resource(d), common.mustCall(() => {
|
|
assert.strictEqual(latestWarning, null);
|
|
|
|
d.run(common.mustCall(() => {
|
|
// No warning will be emitted when no domain property is applied
|
|
makeCallback({}, common.mustCall(() => {
|
|
assert.strictEqual(latestWarning, null);
|
|
|
|
// Warning is emitted when domain property is used and domain is enabled
|
|
makeCallback(new Resource(d), common.mustCall(() => {
|
|
assert.match(latestWarning.message,
|
|
/Triggered by calling someMethod on Resource\./);
|
|
assert.strictEqual(latestWarning.name, 'DeprecationWarning');
|
|
assert.strictEqual(latestWarning.code, 'DEP0097');
|
|
}));
|
|
}));
|
|
}));
|
|
}));
|