msgpackr 1.9.4 → 1.9.5-debug.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1574,8 +1574,13 @@
1574
1574
  if (Array.isArray(value)) {
1575
1575
  packArray(value);
1576
1576
  } else {
1577
- if (value.toJSON) // use this as an alternate mechanism for expressing how to serialize
1578
- return pack(value.toJSON());
1577
+ // use this as an alternate mechanism for expressing how to serialize
1578
+ if (value.toJSON) {
1579
+ const json = value.toJSON();
1580
+ // if for some reason value.toJSON returns itself it'll loop forever
1581
+ if (json !== value)
1582
+ return pack(json)
1583
+ }
1579
1584
 
1580
1585
  // if there is a writeFunction, use it, otherwise just encode as undefined
1581
1586
  if (type === 'function')