Skip to content

Commit

Permalink
assert: make assert.fail less affected by prototype tampering
Browse files Browse the repository at this point in the history
PR-URL: #42918
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
  • Loading branch information
aduh95 authored and juanarbol committed May 31, 2022
1 parent f120658 commit c6a814c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/internal/assert/assertion_error.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ class AssertionError extends Error {

this.generatedMessage = !message;
ObjectDefineProperty(this, 'name', {
__proto__: null,
value: 'AssertionError [ERR_ASSERTION]',
enumerable: false,
writable: true,
Expand Down
6 changes: 5 additions & 1 deletion test/parallel/test-assert-fail.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

require('../common');
const common = require('../common');
const assert = require('assert');

// No args
Expand Down Expand Up @@ -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;

0 comments on commit c6a814c

Please sign in to comment.