@@ -32,7 +32,7 @@ define(function (require) {
3232} ) ;
3333} ) ( typeof define === 'function' && define . amd ? define : function ( factory ) { module . exports = factory ( require ) ; } ) ;
3434
35- } , { "./Scheduler" :3 , "./env" :5 , "./makePromise" :6 } ] , 3 :[ function ( require , module , exports ) {
35+ } , { "./Scheduler" :3 , "./env" :5 , "./makePromise" :7 } ] , 3 :[ function ( require , module , exports ) {
3636/** @license MIT License (c) copyright 2010-2014 original author or authors */
3737/** @author Brian Cavalier */
3838/** @author John Hann */
@@ -123,6 +123,7 @@ define(function() {
123123define ( function ( require ) {
124124
125125 var setTimer = require ( '../env' ) . setTimer ;
126+ var format = require ( '../format' ) ;
126127
127128 return function unhandledRejection ( Promise ) {
128129 var logError = noop ;
@@ -162,15 +163,15 @@ define(function(require) {
162163 function report ( r ) {
163164 if ( ! r . handled ) {
164165 reported . push ( r ) ;
165- logError ( 'Potentially unhandled rejection [' + r . id + '] ' + formatError ( r . value ) ) ;
166+ logError ( 'Potentially unhandled rejection [' + r . id + '] ' + format . formatError ( r . value ) ) ;
166167 }
167168 }
168169
169170 function unreport ( r ) {
170171 var i = reported . indexOf ( r ) ;
171172 if ( i >= 0 ) {
172173 reported . splice ( i , 1 ) ;
173- logInfo ( 'Handled previous rejection [' + r . id + '] ' + formatObject ( r . value ) ) ;
174+ logInfo ( 'Handled previous rejection [' + r . id + '] ' + format . formatObject ( r . value ) ) ;
174175 }
175176 }
176177
@@ -191,28 +192,6 @@ define(function(require) {
191192 return Promise ;
192193 } ;
193194
194- function formatError ( e ) {
195- var s = typeof e === 'object' && e . stack ? e . stack : formatObject ( e ) ;
196- return e instanceof Error ? s : s + ' (WARNING: non-Error used)' ;
197- }
198-
199- function formatObject ( o ) {
200- var s = String ( o ) ;
201- if ( s === '[object Object]' && typeof JSON !== 'undefined' ) {
202- s = tryStringify ( o , s ) ;
203- }
204- return s ;
205- }
206-
207- function tryStringify ( e , defaultValue ) {
208- try {
209- return JSON . stringify ( e ) ;
210- } catch ( e ) {
211- // Ignore. Cannot JSON.stringify e, stick with String(e)
212- return defaultValue ;
213- }
214- }
215-
216195 function throwit ( e ) {
217196 throw e ;
218197 }
@@ -222,7 +201,7 @@ define(function(require) {
222201} ) ;
223202} ( typeof define === 'function' && define . amd ? define : function ( factory ) { module . exports = factory ( require ) ; } ) ) ;
224203
225- } , { "../env" :5 } ] , 5 :[ function ( require , module , exports ) {
204+ } , { "../env" :5 , "../format" : 6 } ] , 5 :[ function ( require , module , exports ) {
226205/** @license MIT License (c) copyright 2010-2014 original author or authors */
227206/** @author Brian Cavalier */
228207/** @author John Hann */
@@ -302,6 +281,64 @@ define(function(require) {
302281/** @author Brian Cavalier */
303282/** @author John Hann */
304283
284+ ( function ( define ) { 'use strict' ;
285+ define ( function ( ) {
286+
287+ return {
288+ formatError : formatError ,
289+ formatObject : formatObject ,
290+ tryStringify : tryStringify
291+ } ;
292+
293+ /**
294+ * Format an error into a string. If e is an Error and has a stack property,
295+ * it's returned. Otherwise, e is formatted using formatObject, with a
296+ * warning added about e not being a proper Error.
297+ * @param {* } e
298+ * @returns {String } formatted string, suitable for output to developers
299+ */
300+ function formatError ( e ) {
301+ var s = typeof e === 'object' && e !== null && e . stack ? e . stack : formatObject ( e ) ;
302+ return e instanceof Error ? s : s + ' (WARNING: non-Error used)' ;
303+ }
304+
305+ /**
306+ * Format an object, detecting "plain" objects and running them through
307+ * JSON.stringify if possible.
308+ * @param {Object } o
309+ * @returns {string }
310+ */
311+ function formatObject ( o ) {
312+ var s = String ( o ) ;
313+ if ( s === '[object Object]' && typeof JSON !== 'undefined' ) {
314+ s = tryStringify ( o , s ) ;
315+ }
316+ return s ;
317+ }
318+
319+ /**
320+ * Try to return the result of JSON.stringify(x). If that fails, return
321+ * defaultValue
322+ * @param {* } x
323+ * @param {* } defaultValue
324+ * @returns {String|* } JSON.stringify(x) or defaultValue
325+ */
326+ function tryStringify ( x , defaultValue ) {
327+ try {
328+ return JSON . stringify ( x ) ;
329+ } catch ( e ) {
330+ return defaultValue ;
331+ }
332+ }
333+
334+ } ) ;
335+ } ( typeof define === 'function' && define . amd ? define : function ( factory ) { module . exports = factory ( ) ; } ) ) ;
336+
337+ } , { } ] , 7 :[ function ( require , module , exports ) {
338+ /** @license MIT License (c) copyright 2010-2014 original author or authors */
339+ /** @author Brian Cavalier */
340+ /** @author John Hann */
341+
305342( function ( define ) { 'use strict' ;
306343define ( function ( ) {
307344
0 commit comments