11/* global ErrorUtils, __DEV__ */
22
33import { NativeModules } from 'react-native'
4+ import serializeForNativeLayer from './NativeSerializer'
45
56const NativeClient = NativeModules . BugsnagReactNative
67
@@ -159,7 +160,7 @@ export class Client {
159160 NativeClient . leaveBreadcrumb ( {
160161 name,
161162 type,
162- metadata : typedMap ( breadcrumbMetaData )
163+ metadata : serializeForNativeLayer ( breadcrumbMetaData )
163164 } )
164165 }
165166
@@ -353,7 +354,7 @@ export class Report {
353354 errorClass : this . errorClass ,
354355 errorMessage : this . errorMessage ,
355356 groupingHash : this . groupingHash ,
356- metadata : typedMap ( this . metadata ) ,
357+ metadata : serializeForNativeLayer ( this . metadata ) ,
357358 severity : this . severity ,
358359 stacktrace : this . stacktrace ,
359360 user : this . user ,
@@ -363,42 +364,3 @@ export class Report {
363364 }
364365 }
365366}
366-
367- const allowedMapObjectTypes = [ 'string' , 'number' , 'boolean' ]
368-
369- /**
370- * Convert an object into a structure with types suitable for serializing
371- * across to native code.
372- */
373- const typedMap = function ( map , maxDepth = 10 , depth = 0 , seen = new Set ( ) ) {
374- seen . add ( map )
375- const output = { }
376- for ( const key in map ) {
377- if ( ! { } . hasOwnProperty . call ( map , key ) ) continue
378-
379- const value = map [ key ]
380-
381- // Checks for `null`, NaN, and `undefined`.
382- if ( [ undefined , null ] . includes ( value ) || ( typeof value === 'number' && isNaN ( value ) ) ) {
383- output [ key ] = { type : 'string' , value : String ( value ) }
384- } else if ( typeof value === 'object' ) {
385- if ( seen . has ( value ) ) {
386- output [ key ] = { type : 'string' , value : '[circular]' }
387- } else if ( depth === maxDepth ) {
388- output [ key ] = { type : 'string' , value : '[max depth exceeded]' }
389- } else {
390- output [ key ] = { type : 'map' , value : typedMap ( value , maxDepth , depth + 1 , seen ) }
391- }
392- } else {
393- const type = typeof value
394- if ( allowedMapObjectTypes . includes ( type ) ) {
395- output [ key ] = { type : type , value : value }
396- } else {
397- console . warn ( `Could not serialize breadcrumb data for '${ key } ': Invalid type '${ type } '` )
398- }
399- }
400- }
401- return output
402- }
403-
404- export { typedMap }
0 commit comments