Skip to content

Commit 482b220

Browse files
kuriyoshsxa
authored andcommitted
test: validate EventEmitterAsyncResource methods throw on invalid this
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]>
1 parent d6b1a4a commit 482b220

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

test/parallel/test-eventemitter-asyncresource.js

+27
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const {
1010
const {
1111
deepStrictEqual,
1212
strictEqual,
13+
throws,
1314
} = require('assert');
1415

1516
const {
@@ -130,3 +131,29 @@ function makeHook(trackedTypes) {
130131
],
131132
]));
132133
})().then(common.mustCall());
134+
135+
// Member methods ERR_INVALID_THIS
136+
throws(
137+
() => EventEmitterAsyncResource.prototype.emit(),
138+
{ code: 'ERR_INVALID_THIS' }
139+
);
140+
141+
throws(
142+
() => EventEmitterAsyncResource.prototype.emitDestroy(),
143+
{ code: 'ERR_INVALID_THIS' }
144+
);
145+
146+
throws(
147+
() => Reflect.get(EventEmitterAsyncResource.prototype, 'asyncId', {}),
148+
{ code: 'ERR_INVALID_THIS' }
149+
);
150+
151+
throws(
152+
() => Reflect.get(EventEmitterAsyncResource.prototype, 'triggerAsyncId', {}),
153+
{ code: 'ERR_INVALID_THIS' }
154+
);
155+
156+
throws(
157+
() => Reflect.get(EventEmitterAsyncResource.prototype, 'asyncResource', {}),
158+
{ code: 'ERR_INVALID_THIS' }
159+
);

0 commit comments

Comments
 (0)