(obj)
| 118 | |
| 119 | // A utility function to safely escape JSON for embedding in a <script> tag |
| 120 | function safeStringify(obj) { |
| 121 | return JSON.stringify(obj) |
| 122 | .replace(/<\/(script)/ig, '<\\/$1') |
| 123 | .replace(/<!--/g, '<\\!--') |
| 124 | .replace(/\u2028/g, '\\u2028') // Only necessary if interpreting as JS, which we do |
| 125 | .replace(/\u2029/g, '\\u2029') // Ditto |
| 126 | } |