| 220 | |
| 221 | |
| 222 | function str(key, holder) { |
| 223 | |
| 224 | // Produce a string from holder[key]. |
| 225 | |
| 226 | var i, // The loop counter. |
| 227 | k, // The member key. |
| 228 | v, // The member value. |
| 229 | length, |
| 230 | mind = gap, |
| 231 | partial, |
| 232 | value = holder[key]; |
| 233 | |
| 234 | // If the value has a toJSON method, call it to obtain a replacement value. |
| 235 | |
| 236 | if (value && typeof value === 'object' && |
| 237 | typeof value.toJSON === 'function') { |
| 238 | value = value.toJSON(key); |
| 239 | } |
| 240 | |
| 241 | // If we were called with a replacer function, then call the replacer to |
| 242 | // obtain a replacement value. |
| 243 | |
| 244 | if (typeof rep === 'function') { |
| 245 | value = rep.call(holder, key, value); |
| 246 | } |
| 247 | |
| 248 | // What happens next depends on the value's type. |
| 249 | |
| 250 | if (value && ((typeof value) === "object")) { |
| 251 | if (value.constructor === String || value.constructor === Number || value.constructor === Boolean) |
| 252 | value = value.valueOf(); |
| 253 | } |
| 254 | |
| 255 | switch (typeof value) { |
| 256 | case 'string': |
| 257 | return quote(value); |
| 258 | |
| 259 | case 'number': |
| 260 | |
| 261 | // JSON numbers must be finite. Encode non-finite numbers as null. |
| 262 | |
| 263 | return isFinite(value) ? String(value) : 'null'; |
| 264 | |
| 265 | case 'boolean': |
| 266 | case 'null': |
| 267 | |
| 268 | // If the value is a boolean or null, convert it to a string. Note: |
| 269 | // typeof null does not produce 'null'. The case is included here in |
| 270 | // the remote chance that this gets fixed someday. |
| 271 | |
| 272 | return String(value); |
| 273 | |
| 274 | // If the type is 'object', we might be dealing with an object or an array or |
| 275 | // null. |
| 276 | |
| 277 | case 'object': |
| 278 | |
| 279 | // Due to a specification blunder in ECMAScript, typeof null is 'object', |