diff options
author | Antoine du Hamel <duhamelantoine1995@gmail.com> | 2022-05-02 20:46:24 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-02 20:46:24 +0300 |
commit | 2b41f5980ec8711607901a7303e24f9e8b909ca8 (patch) | |
tree | a64ee488f520f834341ee4d1d574c1bb0cce95c6 | |
parent | 52ba02e874203c1a0d7f97f21e720b88e537731f (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.js | 1 | ||||
-rw-r--r-- | test/parallel/test-assert-fail.js | 6 |
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; |