11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ci// This tests that AsyncResource throws an error if bad parameters are passed
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_cirequire('../common');
61cb0ef41Sopenharmony_ciconst assert = require('assert');
71cb0ef41Sopenharmony_ciconst async_hooks = require('async_hooks');
81cb0ef41Sopenharmony_ciconst { AsyncResource } = async_hooks;
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci// Setup init hook such parameters are validated
111cb0ef41Sopenharmony_ciasync_hooks.createHook({
121cb0ef41Sopenharmony_ci  init() {}
131cb0ef41Sopenharmony_ci}).enable();
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ciassert.throws(() => {
161cb0ef41Sopenharmony_ci  return new AsyncResource();
171cb0ef41Sopenharmony_ci}, {
181cb0ef41Sopenharmony_ci  code: 'ERR_INVALID_ARG_TYPE',
191cb0ef41Sopenharmony_ci  name: 'TypeError',
201cb0ef41Sopenharmony_ci});
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ciassert.throws(() => {
231cb0ef41Sopenharmony_ci  new AsyncResource('');
241cb0ef41Sopenharmony_ci}, {
251cb0ef41Sopenharmony_ci  code: 'ERR_ASYNC_TYPE',
261cb0ef41Sopenharmony_ci  name: 'TypeError',
271cb0ef41Sopenharmony_ci});
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ciassert.throws(() => {
301cb0ef41Sopenharmony_ci  new AsyncResource('type', -4);
311cb0ef41Sopenharmony_ci}, {
321cb0ef41Sopenharmony_ci  code: 'ERR_INVALID_ASYNC_ID',
331cb0ef41Sopenharmony_ci  name: 'RangeError',
341cb0ef41Sopenharmony_ci});
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ciassert.throws(() => {
371cb0ef41Sopenharmony_ci  new AsyncResource('type', Math.PI);
381cb0ef41Sopenharmony_ci}, {
391cb0ef41Sopenharmony_ci  code: 'ERR_INVALID_ASYNC_ID',
401cb0ef41Sopenharmony_ci  name: 'RangeError',
411cb0ef41Sopenharmony_ci});
42