-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
assert: create internal/assert micro-module
For use in built-in modules that could benefit from `assert()` without having to load the entire module (unless an AssertionError actually occurs): lib/internal/assert.js. PR-URL: #25956 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
- Loading branch information
Showing
3 changed files
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
|
||
function assert(value, message) { | ||
if (!value) { | ||
require('assert')(value, message); | ||
} | ||
} | ||
|
||
module.exports = assert; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Flags: --expose-internals | ||
'use strict'; | ||
|
||
require('../common'); | ||
|
||
const assert = require('assert'); | ||
const internalAssert = require('internal/assert'); | ||
|
||
// Should not throw. | ||
internalAssert(true); | ||
internalAssert(true, 'fhqwhgads'); | ||
|
||
assert.throws(() => { internalAssert(false); }, assert.AssertionError); | ||
assert.throws(() => { internalAssert(false, 'fhqwhgads'); }, | ||
{ code: 'ERR_ASSERTION', message: 'fhqwhgads' }); |