(property, object, callback, properties, whitespace, indentation, stack)
| 1382 | // Internal: Recursively serializes an object. Implements the |
| 1383 | // `Str(key, holder)`, `JO(value)`, and `JA(value)` operations. |
| 1384 | var serialize = function (property, object, callback, properties, whitespace, indentation, stack) { |
| 1385 | var value, className, year, month, date, time, hours, minutes, seconds, milliseconds, results, element, index, length, prefix, result; |
| 1386 | try { |
| 1387 | // Necessary for host object support. |
| 1388 | value = object[property]; |
| 1389 | } catch (exception) {} |
| 1390 | if (typeof value == "object" && value) { |
| 1391 | className = getClass.call(value); |
| 1392 | if (className == dateClass && !isProperty.call(value, "toJSON")) { |
| 1393 | if (value > -1 / 0 && value < 1 / 0) { |
| 1394 | // Dates are serialized according to the `Date#toJSON` method |
| 1395 | // specified in ES 5.1 section 15.9.5.44. See section 15.9.1.15 |
| 1396 | // for the ISO 8601 date time string format. |
| 1397 | if (getDay) { |
| 1398 | // Manually compute the year, month, date, hours, minutes, |
| 1399 | // seconds, and milliseconds if the `getUTC*` methods are |
| 1400 | // buggy. Adapted from @Yaffle's `date-shim` project. |
| 1401 | date = floor(value / 864e5); |
| 1402 | for (year = floor(date / 365.2425) + 1970 - 1; getDay(year + 1, 0) <= date; year++); |
| 1403 | for (month = floor((date - getDay(year, 0)) / 30.42); getDay(year, month + 1) <= date; month++); |
| 1404 | date = 1 + date - getDay(year, month); |
| 1405 | // The `time` value specifies the time within the day (see ES |
| 1406 | // 5.1 section 15.9.1.2). The formula `(A % B + B) % B` is used |
| 1407 | // to compute `A modulo B`, as the `%` operator does not |
| 1408 | // correspond to the `modulo` operation for negative numbers. |
| 1409 | time = (value % 864e5 + 864e5) % 864e5; |
| 1410 | // The hours, minutes, seconds, and milliseconds are obtained by |
| 1411 | // decomposing the time within the day. See section 15.9.1.10. |
| 1412 | hours = floor(time / 36e5) % 24; |
| 1413 | minutes = floor(time / 6e4) % 60; |
| 1414 | seconds = floor(time / 1e3) % 60; |
| 1415 | milliseconds = time % 1e3; |
| 1416 | } else { |
| 1417 | year = value.getUTCFullYear(); |
| 1418 | month = value.getUTCMonth(); |
| 1419 | date = value.getUTCDate(); |
| 1420 | hours = value.getUTCHours(); |
| 1421 | minutes = value.getUTCMinutes(); |
| 1422 | seconds = value.getUTCSeconds(); |
| 1423 | milliseconds = value.getUTCMilliseconds(); |
| 1424 | } |
| 1425 | // Serialize extended years correctly. |
| 1426 | value = (year <= 0 || year >= 1e4 ? (year < 0 ? "-" : "+") + toPaddedString(6, year < 0 ? -year : year) : toPaddedString(4, year)) + |
| 1427 | "-" + toPaddedString(2, month + 1) + "-" + toPaddedString(2, date) + |
| 1428 | // Months, dates, hours, minutes, and seconds should have two |
| 1429 | // digits; milliseconds should have three. |
| 1430 | "T" + toPaddedString(2, hours) + ":" + toPaddedString(2, minutes) + ":" + toPaddedString(2, seconds) + |
| 1431 | // Milliseconds are optional in ES 5.0, but required in 5.1. |
| 1432 | "." + toPaddedString(3, milliseconds) + "Z"; |
| 1433 | } else { |
| 1434 | value = null; |
| 1435 | } |
| 1436 | } else if (typeof value.toJSON == "function" && ((className != numberClass && className != stringClass && className != arrayClass) || isProperty.call(value, "toJSON"))) { |
| 1437 | // Prototype <= 1.6.1 adds non-standard `toJSON` methods to the |
| 1438 | // `Number`, `String`, `Date`, and `Array` prototypes. JSON 3 |
| 1439 | // ignores all `toJSON` methods on these objects unless they are |
| 1440 | // defined directly on an instance. |
| 1441 | value = value.toJSON(property); |
no test coverage detected