Skip to content

Commit

Permalink
test: validate EventEmitterAsyncResource methods throw on invalid this
Browse files Browse the repository at this point in the history
PR-URL: #42041
Refs: https://coverage.nodejs.org/coverage-26f9a91cc9b178d3/lib/events.js.html#L156
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Darshan Sen <[email protected]>
Reviewed-By: Mestery <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
  • Loading branch information
kuriyosh authored and sxa committed Mar 7, 2022
1 parent d6b1a4a commit 482b220
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/parallel/test-eventemitter-asyncresource.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {
const {
deepStrictEqual,
strictEqual,
throws,
} = require('assert');

const {
Expand Down Expand Up @@ -130,3 +131,29 @@ function makeHook(trackedTypes) {
],
]));
})().then(common.mustCall());

// Member methods ERR_INVALID_THIS
throws(
() => EventEmitterAsyncResource.prototype.emit(),
{ code: 'ERR_INVALID_THIS' }
);

throws(
() => EventEmitterAsyncResource.prototype.emitDestroy(),
{ code: 'ERR_INVALID_THIS' }
);

throws(
() => Reflect.get(EventEmitterAsyncResource.prototype, 'asyncId', {}),
{ code: 'ERR_INVALID_THIS' }
);

throws(
() => Reflect.get(EventEmitterAsyncResource.prototype, 'triggerAsyncId', {}),
{ code: 'ERR_INVALID_THIS' }
);

throws(
() => Reflect.get(EventEmitterAsyncResource.prototype, 'asyncResource', {}),
{ code: 'ERR_INVALID_THIS' }
);

0 comments on commit 482b220

Please sign in to comment.