{"version":3,"sources":["node_modules/@newrelic/browser-agent/dist/esm/common/util/stringify.js"],"sourcesContent":["/*\n * Copyright 2020 New Relic Corporation. All rights reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { ee } from '../event-emitter/contextual-ee';\n\n/**\n * Returns a function for use as a replacer parameter in JSON.stringify() to handle circular references.\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_object_value MDN - Cyclical object value}\n * @returns {Function} A function that filters out values it has seen before.\n */\nconst getCircularReplacer = () => {\n const seen = new WeakSet();\n return (key, value) => {\n if (typeof value === 'object' && value !== null) {\n if (seen.has(value)) {\n return;\n }\n seen.add(value);\n }\n return value;\n };\n};\n\n/**\n * The native JSON.stringify method augmented with a replacer function to handle circular references.\n * Circular references will be excluded from the JSON output rather than triggering errors.\n * @param {*} val - A value to be converted to a JSON string.\n * @returns {string} A JSON string representation of the value, with circular references handled.\n */\nexport function stringify(val) {\n try {\n return JSON.stringify(val, getCircularReplacer());\n } catch (e) {\n try {\n ee.emit('internal-error', [e]);\n } catch (err) {\n // do nothing\n }\n }\n}"],"mappings":"wCAYA,IAAMA,EAAsB,IAAM,CAChC,IAAMC,EAAO,IAAI,QACjB,MAAO,CAACC,EAAKC,IAAU,CACrB,GAAI,OAAOA,GAAU,UAAYA,IAAU,KAAM,CAC/C,GAAIF,EAAK,IAAIE,CAAK,EAChB,OAEFF,EAAK,IAAIE,CAAK,CAChB,CACA,OAAOA,CACT,CACF,EAQO,SAASC,EAAUC,EAAK,CAC7B,GAAI,CACF,OAAO,KAAK,UAAUA,EAAKL,EAAoB,CAAC,CAClD,OAAS,EAAG,CACV,GAAI,CACFM,EAAG,KAAK,iBAAkB,CAAC,CAAC,CAAC,CAC/B,MAAc,CAEd,CACF,CACF","names":["getCircularReplacer","seen","key","value","stringify","val","globalInstance"],"x_google_ignoreList":[0]}