@@ -40,39 +40,6 @@ function lazyErrors() {
40
40
41
41
const assert = module . exports = ok ;
42
42
43
- // The AssertionError is defined in assert.
44
- // new assert.AssertionError({ message: message,
45
- // actual: actual,
46
- // expected: expected });
47
-
48
- // TODO(jasnell): Consider moving AssertionError into internal/errors.js
49
- class AssertionError extends Error {
50
- constructor ( options ) {
51
- if ( typeof options !== 'object' || options === null ) {
52
- // Lazy because the errors module itself uses assertions, leading to
53
- // a circular dependency. This can be eliminated by moving this class
54
- // into internal/errors.js
55
- const errors = lazyErrors ( ) ;
56
- throw new errors . TypeError ( 'ERR_INVALID_ARG_TYPE' , 'options' , 'object' ) ;
57
- }
58
- const message = options . message ||
59
- `${ util . inspect ( options . actual ) . slice ( 0 , 128 ) } ` +
60
- `${ options . operator } ` +
61
- util . inspect ( options . expected ) . slice ( 0 , 128 ) ;
62
- super ( message ) ;
63
- this . generatedMessage = ! options . message ;
64
- this . name = 'AssertionError [ERR_ASSERTION]' ;
65
- this . code = 'ERR_ASSERTION' ;
66
- this . actual = options . actual ;
67
- this . expected = options . expected ;
68
- this . operator = options . operator ;
69
- var stackStartFunction = options . stackStartFunction || fail ;
70
- Error . captureStackTrace ( this , stackStartFunction ) ;
71
- }
72
- }
73
-
74
- assert . AssertionError = AssertionError ;
75
-
76
43
// At present only the three keys mentioned above are used and
77
44
// understood by the spec. Implementations or sub modules can pass
78
45
// other keys to the AssertionError's constructor - they will be
@@ -89,7 +56,8 @@ function fail(actual, expected, message, operator, stackStartFunction) {
89
56
message = actual ;
90
57
if ( arguments . length === 2 )
91
58
operator = '!=' ;
92
- throw new AssertionError ( {
59
+ const errors = lazyErrors ( ) ;
60
+ throw new errors . AssertionError ( {
93
61
message : message ,
94
62
actual : actual ,
95
63
expected : expected ,
@@ -101,6 +69,13 @@ function fail(actual, expected, message, operator, stackStartFunction) {
101
69
// EXTENSION! allows for well behaved errors defined elsewhere.
102
70
assert . fail = fail ;
103
71
72
+ // The AssertionError is defined in internal/error.
73
+ // new assert.AssertionError({ message: message,
74
+ // actual: actual,
75
+ // expected: expected });
76
+ assert . AssertionError = lazyErrors ( ) . AssertionError ;
77
+
78
+
104
79
// Pure assertion tests whether a value is truthy, as determined
105
80
// by !!guard.
106
81
// assert.ok(guard, message_opt);
0 commit comments