MCPcopy Index your code
hub / github.com/PrairieLearn/PrairieLearn / serialize

Function serialize

public/javascripts/socket.io.js:2339–2464  ·  view source on GitHub ↗
(property, object, callback, properties, whitespace, indentation, stack)

Source from the content-addressed store, hash-verified

2337 // Internal: Recursively serializes an object. Implements the
2338 // `Str(key, holder)`, `JO(value)`, and `JA(value)` operations.
2339 var serialize = function (property, object, callback, properties, whitespace, indentation, stack) {
2340 var value, className, year, month, date, time, hours, minutes, seconds, milliseconds, results, element, index, length, prefix, result;
2341 try {
2342 // Necessary for host object support.
2343 value = object[property];
2344 } catch (exception) {}
2345 if (typeof value == "object" && value) {
2346 className = getClass.call(value);
2347 if (className == dateClass && !isProperty.call(value, "toJSON")) {
2348 if (value > -1 / 0 && value < 1 / 0) {
2349 // Dates are serialized according to the `Date#toJSON` method
2350 // specified in ES 5.1 section 15.9.5.44. See section 15.9.1.15
2351 // for the ISO 8601 date time string format.
2352 if (getDay) {
2353 // Manually compute the year, month, date, hours, minutes,
2354 // seconds, and milliseconds if the `getUTC*` methods are
2355 // buggy. Adapted from @Yaffle's `date-shim` project.
2356 date = floor(value / 864e5);
2357 for (year = floor(date / 365.2425) + 1970 - 1; getDay(year + 1, 0) <= date; year++);
2358 for (month = floor((date - getDay(year, 0)) / 30.42); getDay(year, month + 1) <= date; month++);
2359 date = 1 + date - getDay(year, month);
2360 // The `time` value specifies the time within the day (see ES
2361 // 5.1 section 15.9.1.2). The formula `(A % B + B) % B` is used
2362 // to compute `A modulo B`, as the `%` operator does not
2363 // correspond to the `modulo` operation for negative numbers.
2364 time = (value % 864e5 + 864e5) % 864e5;
2365 // The hours, minutes, seconds, and milliseconds are obtained by
2366 // decomposing the time within the day. See section 15.9.1.10.
2367 hours = floor(time / 36e5) % 24;
2368 minutes = floor(time / 6e4) % 60;
2369 seconds = floor(time / 1e3) % 60;
2370 milliseconds = time % 1e3;
2371 } else {
2372 year = value.getUTCFullYear();
2373 month = value.getUTCMonth();
2374 date = value.getUTCDate();
2375 hours = value.getUTCHours();
2376 minutes = value.getUTCMinutes();
2377 seconds = value.getUTCSeconds();
2378 milliseconds = value.getUTCMilliseconds();
2379 }
2380 // Serialize extended years correctly.
2381 value = (year <= 0 || year >= 1e4 ? (year < 0 ? "-" : "+") + toPaddedString(6, year < 0 ? -year : year) : toPaddedString(4, year)) +
2382 "-" + toPaddedString(2, month + 1) + "-" + toPaddedString(2, date) +
2383 // Months, dates, hours, minutes, and seconds should have two
2384 // digits; milliseconds should have three.
2385 "T" + toPaddedString(2, hours) + ":" + toPaddedString(2, minutes) + ":" + toPaddedString(2, seconds) +
2386 // Milliseconds are optional in ES 5.0, but required in 5.1.
2387 "." + toPaddedString(3, milliseconds) + "Z";
2388 } else {
2389 value = null;
2390 }
2391 } else if (typeof value.toJSON == "function" && ((className != numberClass && className != stringClass && className != arrayClass) || isProperty.call(value, "toJSON"))) {
2392 // Prototype <= 1.6.1 adds non-standard `toJSON` methods to the
2393 // `Number`, `String`, `Date`, and `Array` prototypes. JSON 3
2394 // ignores all `toJSON` methods on these objects unless they are
2395 // defined directly on an instance.
2396 value = value.toJSON(property);

Callers 1

runInContextFunction · 0.85

Calls 4

getDayFunction · 0.85
toPaddedStringFunction · 0.85
quoteFunction · 0.85
callMethod · 0.80

Tested by

no test coverage detected