11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../../common');
41cb0ef41Sopenharmony_ciconst assert = require('assert');
51cb0ef41Sopenharmony_ciconst domain = require('domain');
61cb0ef41Sopenharmony_ciconst binding = require(`./build/${common.buildType}/binding`);
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_cifunction makeCallback(object, cb) {
91cb0ef41Sopenharmony_ci  binding.makeCallback(object, function someMethod() { setImmediate(cb); });
101cb0ef41Sopenharmony_ci}
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_cilet latestWarning = null;
131cb0ef41Sopenharmony_ciprocess.on('warning', (warning) => {
141cb0ef41Sopenharmony_ci  latestWarning = warning;
151cb0ef41Sopenharmony_ci});
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ciconst d = domain.create();
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ciclass Resource {
201cb0ef41Sopenharmony_ci  constructor(domain) {
211cb0ef41Sopenharmony_ci    this.domain = domain;
221cb0ef41Sopenharmony_ci  }
231cb0ef41Sopenharmony_ci}
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ci// When domain is disabled, no warning will be emitted
261cb0ef41Sopenharmony_cimakeCallback(new Resource(d), common.mustCall(() => {
271cb0ef41Sopenharmony_ci  assert.strictEqual(latestWarning, null);
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ci  d.run(common.mustCall(() => {
301cb0ef41Sopenharmony_ci    // No warning will be emitted when no domain property is applied
311cb0ef41Sopenharmony_ci    makeCallback({}, common.mustCall(() => {
321cb0ef41Sopenharmony_ci      assert.strictEqual(latestWarning, null);
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_ci      // Warning is emitted when domain property is used and domain is enabled
351cb0ef41Sopenharmony_ci      makeCallback(new Resource(d), common.mustCall(() => {
361cb0ef41Sopenharmony_ci        assert.match(latestWarning.message,
371cb0ef41Sopenharmony_ci                     /Triggered by calling someMethod on Resource\./);
381cb0ef41Sopenharmony_ci        assert.strictEqual(latestWarning.name, 'DeprecationWarning');
391cb0ef41Sopenharmony_ci        assert.strictEqual(latestWarning.code, 'DEP0097');
401cb0ef41Sopenharmony_ci      }));
411cb0ef41Sopenharmony_ci    }));
421cb0ef41Sopenharmony_ci  }));
431cb0ef41Sopenharmony_ci}));
44