1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-23 15:49:44 -05:00

fix(ext/node): don't call undefined nextTick fn (#20724)

The `process` global is not defined in this file.

Fixes #20441

---------

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This commit is contained in:
Luca Casonato 2023-10-02 21:13:57 +09:00 committed by GitHub
parent 6fd2d08418
commit d5b6c636b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 1 deletions

View file

@ -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,

View file

@ -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;
});

View file

@ -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) {