Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntoine du Hamel <duhamelantoine1995@gmail.com>2022-05-02 20:46:24 +0300
committerGitHub <noreply@github.com>2022-05-02 20:46:24 +0300
commit2b41f5980ec8711607901a7303e24f9e8b909ca8 (patch)
treea64ee488f520f834341ee4d1d574c1bb0cce95c6
parent52ba02e874203c1a0d7f97f21e720b88e537731f (diff)
assert: make `assert.fail` less affected by prototype tampering
PR-URL: https://github.com/nodejs/node/pull/42918 Reviewed-By: Michaƫl Zasso <targos@protonmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
-rw-r--r--lib/internal/assert/assertion_error.js1
-rw-r--r--test/parallel/test-assert-fail.js6
2 files changed, 6 insertions, 1 deletions
diff --git a/lib/internal/assert/assertion_error.js b/lib/internal/assert/assertion_error.js
index 837c37b1221..e160d6d7e86 100644
--- a/lib/internal/assert/assertion_error.js
+++ b/lib/internal/assert/assertion_error.js
@@ -441,6 +441,7 @@ class AssertionError extends Error {
this.generatedMessage = !message;
ObjectDefineProperty(this, 'name', {
+ __proto__: null,
value: 'AssertionError [ERR_ASSERTION]',
enumerable: false,
writable: true,
diff --git a/test/parallel/test-assert-fail.js b/test/parallel/test-assert-fail.js
index e2003f2ce91..37e2087a2fd 100644
--- a/test/parallel/test-assert-fail.js
+++ b/test/parallel/test-assert-fail.js
@@ -1,6 +1,6 @@
'use strict';
-require('../common');
+const common = require('../common');
const assert = require('assert');
// No args
@@ -38,3 +38,7 @@ assert.throws(() => {
name: 'TypeError',
message: 'custom message'
});
+
+Object.prototype.get = common.mustNotCall();
+assert.throws(() => assert.fail(''), { code: 'ERR_ASSERTION' });
+delete Object.prototype.get;