* Helper to run a serialization callback with the canonical mode flag * temporarily enabled in the gd.Serializer. Always resets the flag, * even if `callback` throws. * * The flag is global to the gd.Serializer (and to the C++ side), so we must * be careful to reset it: leaving it on would sile
( options: ?SerializationOptions, callback: () => T )
| 25 | * every subsequent serialization (including ones that don't expect it). |
| 26 | */ |
| 27 | function withSerializationOptions<T>( |
| 28 | options: ?SerializationOptions, |
| 29 | callback: () => T |
| 30 | ): T { |
| 31 | const useCanonical = !!(options && options.canonicalEventSerialization); |
| 32 | if (!useCanonical) { |
| 33 | return callback(); |
| 34 | } |
| 35 | |
| 36 | const previous = gd.Serializer.isCanonicalMode(); |
| 37 | gd.Serializer.setCanonicalMode(true); |
| 38 | try { |
| 39 | return callback(); |
| 40 | } finally { |
| 41 | gd.Serializer.setCanonicalMode(previous); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Tool function to save a serializable object to a JS object. |
no test coverage detected