mirror of
https://github.com/nodejs/node.git
synced 2025-05-10 03:12:57 +00:00

AsyncResource previously called emitInitNative. Since AsyncResource is just an abstraction on top of the emitEventScript functions, it should call emitInitScript instead. PR-URL: https://github.com/nodejs/node/pull/14152 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
30 lines
795 B
JavaScript
30 lines
795 B
JavaScript
'use strict';
|
|
require('../common');
|
|
|
|
// This tests that AsyncResource throws an error if bad parameters are passed
|
|
|
|
const assert = require('assert');
|
|
const async_hooks = require('async_hooks');
|
|
const { AsyncResource } = async_hooks;
|
|
|
|
// Setup init hook such parameters are validated
|
|
async_hooks.createHook({
|
|
init() {}
|
|
}).enable();
|
|
|
|
assert.throws(() => {
|
|
return new AsyncResource();
|
|
}, /^TypeError: type must be a string with length > 0$/);
|
|
|
|
assert.throws(() => {
|
|
new AsyncResource('');
|
|
}, /^TypeError: type must be a string with length > 0$/);
|
|
|
|
assert.throws(() => {
|
|
new AsyncResource('type', -4);
|
|
}, /^RangeError: triggerAsyncId must be an unsigned integer$/);
|
|
|
|
assert.throws(() => {
|
|
new AsyncResource('type', Math.PI);
|
|
}, /^RangeError: triggerAsyncId must be an unsigned integer$/);
|