| 200 | |
| 201 | // https://infra.spec.whatwg.org/#serialize-a-javascript-value-to-a-json-string |
| 202 | function serializeJavascriptValueToJSONString (value) { |
| 203 | // 1. Let result be ? Call(%JSON.stringify%, undefined, « value »). |
| 204 | const result = JSON.stringify(value) |
| 205 | |
| 206 | // 2. If result is undefined, then throw a TypeError. |
| 207 | if (result === undefined) { |
| 208 | throw new TypeError('Value is not JSON serializable') |
| 209 | } |
| 210 | |
| 211 | // 3. Assert: result is a string. |
| 212 | assert(typeof result === 'string') |
| 213 | |
| 214 | // 4. Return result. |
| 215 | return result |
| 216 | } |
| 217 | |
| 218 | module.exports = { |
| 219 | collectASequenceOfCodePoints, |