From 482b2205b28e90b5105ffe66b69e339f0b307b92 Mon Sep 17 00:00:00 2001 From: Yoshiki Kurihara Date: Wed, 23 Feb 2022 08:55:06 +0900 Subject: [PATCH] test: validate `EventEmitterAsyncResource` methods throw on invalid this PR-URL: https://github.com/nodejs/node/pull/42041 Refs: https://coverage.nodejs.org/coverage-26f9a91cc9b178d3/lib/events.js.html#L156 Reviewed-By: Benjamin Gruenbaum Reviewed-By: James M Snell Reviewed-By: Darshan Sen Reviewed-By: Mestery Reviewed-By: Luigi Pinca Reviewed-By: Antoine du Hamel --- .../test-eventemitter-asyncresource.js | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/parallel/test-eventemitter-asyncresource.js b/test/parallel/test-eventemitter-asyncresource.js index ae86f3608b7ffd..4cd2bc69207219 100644 --- a/test/parallel/test-eventemitter-asyncresource.js +++ b/test/parallel/test-eventemitter-asyncresource.js @@ -10,6 +10,7 @@ const { const { deepStrictEqual, strictEqual, + throws, } = require('assert'); const { @@ -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' } +);