File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed
Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -66,12 +66,20 @@ define(function(require) {
6666 } else {
6767 s = String ( e ) ;
6868 if ( s === '[object Object]' && typeof JSON !== 'undefined' ) {
69- s = JSON . stringify ( e ) ;
69+ s = tryStringify ( e , s ) ;
7070 }
7171 }
7272
7373 return e instanceof Error ? s : s + ' (WARNING: non-Error used)' ;
74+ }
7475
76+ function tryStringify ( e , defaultValue ) {
77+ try {
78+ return JSON . stringify ( e ) ;
79+ } catch ( e ) {
80+ // Ignore. Cannot JSON.stringify e, stick with String(e)
81+ return defaultValue ;
82+ }
7583 }
7684
7785 function noop ( ) { }
Original file line number Diff line number Diff line change 1+ var buster = typeof window !== 'undefined' ? window . buster : require ( 'buster' ) ;
2+ var unhandledRejection = require ( '../lib/decorators/unhandledRejection' ) ;
3+
4+ buster . testCase ( 'unhandledRejection' , {
5+
6+ 'should not fail if JSON.stringify throws' : function ( done ) {
7+ var fixture = unhandledRejection ( { } , function ( f ) {
8+ setTimeout ( function ( ) {
9+ buster . refute . exception ( f ) ;
10+ done ( ) ;
11+ } ) ;
12+ } ) ;
13+ var circular = { } ;
14+ circular . self = circular ;
15+
16+ fixture . onPotentiallyUnhandledRejection ( { handled : false , value : circular } ) ;
17+ }
18+
19+ } ) ;
You can’t perform that action at this time.
0 commit comments