11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciconst dc = require('diagnostics_channel'); 51cb0ef41Sopenharmony_ciconst assert = require('assert'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst channel = dc.tracingChannel('test'); 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ciconst expectedResult = { foo: 'bar' }; 101cb0ef41Sopenharmony_ciconst input = { foo: 'bar' }; 111cb0ef41Sopenharmony_ciconst thisArg = { baz: 'buz' }; 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_cifunction check(found) { 141cb0ef41Sopenharmony_ci assert.deepStrictEqual(found, input); 151cb0ef41Sopenharmony_ci} 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ciconst handlers = { 181cb0ef41Sopenharmony_ci start: common.mustCall(check, 2), 191cb0ef41Sopenharmony_ci end: common.mustCall(check, 2), 201cb0ef41Sopenharmony_ci asyncStart: common.mustCall((found) => { 211cb0ef41Sopenharmony_ci check(found); 221cb0ef41Sopenharmony_ci assert.strictEqual(found.error, undefined); 231cb0ef41Sopenharmony_ci assert.deepStrictEqual(found.result, expectedResult); 241cb0ef41Sopenharmony_ci }, 2), 251cb0ef41Sopenharmony_ci asyncEnd: common.mustCall((found) => { 261cb0ef41Sopenharmony_ci check(found); 271cb0ef41Sopenharmony_ci assert.strictEqual(found.error, undefined); 281cb0ef41Sopenharmony_ci assert.deepStrictEqual(found.result, expectedResult); 291cb0ef41Sopenharmony_ci }, 2), 301cb0ef41Sopenharmony_ci error: common.mustNotCall() 311cb0ef41Sopenharmony_ci}; 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_cichannel.subscribe(handlers); 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_cichannel.traceCallback(function(cb, err, res) { 361cb0ef41Sopenharmony_ci assert.deepStrictEqual(this, thisArg); 371cb0ef41Sopenharmony_ci setImmediate(cb, err, res); 381cb0ef41Sopenharmony_ci}, 0, input, thisArg, common.mustCall((err, res) => { 391cb0ef41Sopenharmony_ci assert.strictEqual(err, null); 401cb0ef41Sopenharmony_ci assert.deepStrictEqual(res, expectedResult); 411cb0ef41Sopenharmony_ci}), null, expectedResult); 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_cichannel.tracePromise(function(value) { 441cb0ef41Sopenharmony_ci assert.deepStrictEqual(this, thisArg); 451cb0ef41Sopenharmony_ci return Promise.resolve(value); 461cb0ef41Sopenharmony_ci}, input, thisArg, expectedResult).then( 471cb0ef41Sopenharmony_ci common.mustCall((value) => { 481cb0ef41Sopenharmony_ci assert.deepStrictEqual(value, expectedResult); 491cb0ef41Sopenharmony_ci }), 501cb0ef41Sopenharmony_ci common.mustNotCall() 511cb0ef41Sopenharmony_ci); 521cb0ef41Sopenharmony_ci 531cb0ef41Sopenharmony_cilet failed = false; 541cb0ef41Sopenharmony_citry { 551cb0ef41Sopenharmony_ci channel.traceCallback(common.mustNotCall(), 0, input, thisArg, 1, 2, 3); 561cb0ef41Sopenharmony_ci} catch (err) { 571cb0ef41Sopenharmony_ci assert.ok(/"callback" argument must be of type function/.test(err.message)); 581cb0ef41Sopenharmony_ci failed = true; 591cb0ef41Sopenharmony_ci} 601cb0ef41Sopenharmony_ciassert.strictEqual(failed, true); 61