MCPcopy
hub / github.com/microsoft/playwright / innerSerialize

Function innerSerialize

packages/isomorphic/utilityScriptSerializers.ts:207–303  ·  view source on GitHub ↗
(value: any, handleSerializer: (value: any) => HandleOrValue, visitorInfo: VisitorInfo)

Source from the content-addressed store, hash-verified

205}
206
207function innerSerialize(value: any, handleSerializer: (value: any) => HandleOrValue, visitorInfo: VisitorInfo): SerializedValue {
208 const result = handleSerializer(value);
209 if ('fallThrough' in result)
210 value = result.fallThrough;
211 else
212 return result;
213
214 if (typeof value === 'symbol')
215 return { v: 'undefined' };
216 if (Object.is(value, undefined))
217 return { v: 'undefined' };
218 if (Object.is(value, null))
219 return { v: 'null' };
220 if (Object.is(value, NaN))
221 return { v: 'NaN' };
222 if (Object.is(value, Infinity))
223 return { v: 'Infinity' };
224 if (Object.is(value, -Infinity))
225 return { v: '-Infinity' };
226 if (Object.is(value, -0))
227 return { v: '-0' };
228
229 if (typeof value === 'boolean')
230 return value;
231 if (typeof value === 'number')
232 return value;
233 if (typeof value === 'string')
234 return value;
235 if (typeof value === 'bigint')
236 return { bi: value.toString() };
237
238 if (isError(value)) {
239 let stack;
240 if (value.stack?.startsWith(value.name + ': ' + value.message)) {
241 // v8
242 stack = value.stack;
243 } else {
244 stack = `${value.name}: ${value.message}\n${value.stack}`;
245 }
246 return { e: { n: value.name, m: value.message, s: stack } };
247 }
248 if (isDate(value))
249 return { d: value.toJSON() };
250 if (isURL(value))
251 return { u: value.toJSON() };
252 if (isRegExp(value))
253 return { r: { p: value.source, f: value.flags } };
254 for (const [k, ctor] of Object.entries(typedArrayConstructors) as [TypedArrayKind, Function][]) {
255 if (isTypedArray(value, ctor))
256 return { ta: { b: typedArrayToBase64(value), k } };
257 }
258 if (isArrayBuffer(value))
259 return { ab: { b: typedArrayToBase64(new Uint8Array(value)) } };
260
261 const id = visitorInfo.visited.get(value);
262 if (id)
263 return { ref: id };
264

Callers 1

serializeFunction · 0.85

Calls 15

isTypedArrayFunction · 0.85
typedArrayToBase64Function · 0.85
isArrayBufferFunction · 0.85
setMethod · 0.80
keysMethod · 0.80
isErrorFunction · 0.70
isDateFunction · 0.70
isURLFunction · 0.70
isRegExpFunction · 0.70
serializeFunction · 0.70
toStringMethod · 0.65
entriesMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…