From b338b541ac828113667fdd24c18db97d3e47c282 Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Mon, 8 Jul 2024 21:28:39 +0200 Subject: fix(node/assert): throws not checking error instance (#24466) The implementation for `assert.throws()` from `node:assert` didn't work when the expected value was an `Error` constructor. In this case the thrown error should checked if it's an instance of said constructor. Fixes https://github.com/denoland/deno/issues/24464 --- ext/node/polyfills/assert.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'ext/node/polyfills') diff --git a/ext/node/polyfills/assert.ts b/ext/node/polyfills/assert.ts index 3d7660487..00677e3f7 100644 --- a/ext/node/polyfills/assert.ts +++ b/ext/node/polyfills/assert.ts @@ -17,6 +17,9 @@ import { ERR_MISSING_ARGS, } from "ext:deno_node/internal/errors.ts"; import { isDeepEqual } from "ext:deno_node/internal/util/comparisons.ts"; +import { primordials } from "ext:core/mod.js"; + +const { ObjectPrototypeIsPrototypeOf } = primordials; function innerFail(obj: { actual?: unknown; @@ -744,8 +747,8 @@ function validateThrownError( error = undefined; } if ( - error instanceof Function && error.prototype !== undefined && - error.prototype instanceof Error + typeof error === "function" && + (error === Error || ObjectPrototypeIsPrototypeOf(Error, error)) ) { // error is a constructor if (e instanceof error) { -- cgit v1.2.3