summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/tests/integration/node_unit_tests.rs1
-rw-r--r--cli/tests/unit_node/events_test.ts28
-rw-r--r--ext/node/polyfills/_events.mjs3
3 files changed, 31 insertions, 1 deletions
diff --git a/cli/tests/integration/node_unit_tests.rs b/cli/tests/integration/node_unit_tests.rs
index 05aa4c45a..5489a7255 100644
--- a/cli/tests/integration/node_unit_tests.rs
+++ b/cli/tests/integration/node_unit_tests.rs
@@ -58,6 +58,7 @@ util::unit_test_factory!(
crypto_hash_test = crypto / crypto_hash_test,
crypto_key_test = crypto / crypto_key_test,
crypto_sign_test = crypto / crypto_sign_test,
+ events_test,
fs_test,
http_test,
http2_test,
diff --git a/cli/tests/unit_node/events_test.ts b/cli/tests/unit_node/events_test.ts
new file mode 100644
index 000000000..e341a17cb
--- /dev/null
+++ b/cli/tests/unit_node/events_test.ts
@@ -0,0 +1,28 @@
+// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
+
+import { deferred } from "../../../test_util/std/async/deferred.ts";
+import { EventEmitter } from "node:events";
+
+EventEmitter.captureRejections = true;
+
+Deno.test("regression #20441", async () => {
+ const promise = deferred();
+
+ const ee = new EventEmitter();
+
+ ee.on("foo", function () {
+ const p = new Promise((_resolve, reject) => {
+ setTimeout(() => {
+ reject();
+ }, 100);
+ });
+ return p;
+ });
+
+ ee.on("error", function (_) {
+ promise.resolve();
+ });
+
+ ee.emit("foo");
+ await promise;
+});
diff --git a/ext/node/polyfills/_events.mjs b/ext/node/polyfills/_events.mjs
index b6f372723..bd9e92d06 100644
--- a/ext/node/polyfills/_events.mjs
+++ b/ext/node/polyfills/_events.mjs
@@ -42,6 +42,7 @@ import {
validateFunction,
} from "ext:deno_node/internal/validators.mjs";
import { spliceOne } from "ext:deno_node/_utils.ts";
+import { nextTick } from "ext:deno_node/_process/process.ts";
const kCapture = Symbol("kCapture");
const kErrorMonitor = Symbol("events.errorMonitor");
@@ -206,7 +207,7 @@ function addCatch(that, promise, type, args) {
then.call(promise, undefined, function (err) {
// The callback is called with nextTick to avoid a follow-up
// rejection from this promise.
- process.nextTick(emitUnhandledRejectionOrErr, that, err, type, args);
+ nextTick(emitUnhandledRejectionOrErr, that, err, type, args);
});
}
} catch (err) {