MCPcopy
hub / github.com/webpack/webpack / serialize

Method serialize

lib/serialization/PlainObjectSerializer.js:80–101  ·  view source on GitHub ↗

* Serializes this instance into the provided serializer context. * @template {object} T * @param {T} obj plain object * @param {import("./ObjectMiddleware").ObjectSerializerContext<((keyof T)[] | keyof T | null | T[keyof T])[]>} context context

(obj, context)

Source from the content-addressed store, hash-verified

78 * @param {import("./ObjectMiddleware").ObjectSerializerContext<((keyof T)[] | keyof T | null | T[keyof T])[]>} context context
79 */
80 serialize(obj, context) {
81 const keys = /** @type {(keyof T)[]} */ (Object.keys(obj));
82 if (keys.length > 128) {
83 // Objects with so many keys are unlikely to share structure
84 // with other objects
85 context.write(keys);
86 for (const key of keys) {
87 context.write(obj[key]);
88 }
89 } else if (keys.length > 1) {
90 context.write(getCachedKeys(keys, context.write));
91 for (const key of keys) {
92 context.write(obj[key]);
93 }
94 } else if (keys.length === 1) {
95 const key = keys[0];
96 context.write(key);
97 context.write(obj[key]);
98 } else {
99 context.write(null);
100 }
101 }
102
103 /**
104 * Restores this instance from the provided deserializer context.

Callers

nothing calls this directly

Calls 3

getCachedKeysFunction · 0.85
writeMethod · 0.80
keysMethod · 0.65

Tested by

no test coverage detected