2018-02-08 03:05:45 +08:00
|
|
|
'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) {
|
2020-11-17 00:50:30 +08:00
|
|
|
binding.makeCallback(object, function someMethod() { setImmediate(cb); });
|
2018-02-08 03:05:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
let latestWarning = null;
|
2019-10-26 16:54:18 +08:00
|
|
|
process.on('warning', (warning) => {
|
2018-02-08 03:05:45 +08:00
|
|
|
latestWarning = warning;
|
|
|
|
});
|
|
|
|
|
|
|
|
const d = domain.create();
|
|
|
|
|
2020-11-17 00:50:30 +08:00
|
|
|
class Resource {
|
|
|
|
constructor(domain) {
|
|
|
|
this.domain = domain;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-08 03:05:45 +08:00
|
|
|
// When domain is disabled, no warning will be emitted
|
2020-11-17 00:50:30 +08:00
|
|
|
makeCallback(new Resource(d), common.mustCall(() => {
|
2018-02-08 03:05:45 +08:00
|
|
|
assert.strictEqual(latestWarning, null);
|
|
|
|
|
2019-10-26 16:54:18 +08:00
|
|
|
d.run(common.mustCall(() => {
|
2018-02-08 03:05:45 +08:00
|
|
|
// No warning will be emitted when no domain property is applied
|
2019-10-26 16:54:18 +08:00
|
|
|
makeCallback({}, common.mustCall(() => {
|
2018-02-08 03:05:45 +08:00
|
|
|
assert.strictEqual(latestWarning, null);
|
|
|
|
|
|
|
|
// Warning is emitted when domain property is used and domain is enabled
|
2020-11-17 00:50:30 +08:00
|
|
|
makeCallback(new Resource(d), common.mustCall(() => {
|
|
|
|
assert.match(latestWarning.message,
|
|
|
|
/Triggered by calling someMethod on Resource\./);
|
2018-02-08 03:05:45 +08:00
|
|
|
assert.strictEqual(latestWarning.name, 'DeprecationWarning');
|
|
|
|
assert.strictEqual(latestWarning.code, 'DEP0097');
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
}));
|