@@ -38,7 +38,7 @@ const start = 'Expected values to be strictly deep-equal:';
3838const actExp = '+ actual - expected' ;
3939
4040assert . ok ( a . AssertionError . prototype instanceof Error ,
41- 'a.AssertionError instanceof Error' ) ;
41+ 'a.AssertionError instanceof Error' ) ;
4242
4343assert . throws ( ( ) => a ( false ) , a . AssertionError , 'ok(false)' ) ;
4444assert . throws ( ( ) => a . ok ( false ) , a . AssertionError , 'ok(false)' ) ;
@@ -55,6 +55,52 @@ assert.throws(() => a.ok(false), a.AssertionError, 'ok(false)');
5555 assert . ok ( threw , 'Error: ok(false)' ) ;
5656}
5757
58+ // Throw message if the message is instanceof Error.
59+ {
60+ let threw = false ;
61+ const context = vm . createContext ( ) ;
62+ try {
63+ const errorConstructor = vm . runInContext ( 'Error' , context ) ;
64+ const customError = new errorConstructor ( 'ok(false)' ) ;
65+ assert . ok ( false , customError . message ) ;
66+ } catch ( e ) {
67+ threw = true ;
68+ assert . ok ( e instanceof Error ) ;
69+ }
70+ assert . ok ( threw , 'Error: ok(false)' ) ;
71+ }
72+
73+ // Throw message if the message is instanceof TypeError.
74+ {
75+ let threw = false ;
76+ const context = vm . createContext ( ) ;
77+ context . TypeError = TypeError ;
78+ try {
79+ const TypeErrorConstructor = vm . runInContext ( 'TypeError' , context ) ;
80+ const customTypeError = new TypeErrorConstructor ( 'ok(false)' ) ;
81+ assert . ok ( false , customTypeError ) ;
82+ } catch ( e ) {
83+ threw = true ;
84+ assert . ok ( e instanceof Error ) ;
85+ }
86+ assert . ok ( threw , 'TypeError: ok(false)' ) ;
87+ }
88+
89+ // Throw message if the message is instanceof SyntaxError.
90+ {
91+ let threw = false ;
92+ const context = vm . createContext ( ) ;
93+ context . SyntaxError = SyntaxError ;
94+ try {
95+ const SyntaxErrorConstructor = vm . runInContext ( 'SyntaxError' , context ) ;
96+ const customSyntaxError = new SyntaxErrorConstructor ( 'ok(false)' ) ;
97+ assert . ok ( false , customSyntaxError ) ;
98+ } catch ( e ) {
99+ threw = true ;
100+ assert . ok ( e instanceof Error ) ;
101+ }
102+ assert . ok ( threw , 'SyntaxError: ok(false)' ) ;
103+ }
58104
59105a ( true ) ;
60106a ( 'test' , 'ok(\'test\')' ) ;
0 commit comments