MCPcopy Create free account
hub / github.com/HtmlUnit/htmlunit / str

Function str

src/test/resources/json2.js:222–346  ·  view source on GitHub ↗
(key, holder)

Source from the content-addressed store, hash-verified

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 switch (typeof value) {
251 case 'string':
252 return quote(value);
253
254 case 'number':
255
256// JSON numbers must be finite. Encode non-finite numbers as null.
257
258 return isFinite(value) ? String(value) : 'null';
259
260 case 'boolean':
261 case 'null':
262
263// If the value is a boolean or null, convert it to a string. Note:
264// typeof null does not produce 'null'. The case is included here in
265// the remote chance that this gets fixed someday.
266
267 return String(value);
268
269// If the type is 'object', we might be dealing with an object or an array or
270// null.
271
272 case 'object':
273
274// Due to a specification blunder in ECMAScript, typeof null is 'object',
275// so watch out for that case.
276
277 if (!value) {
278 return 'null';
279 }

Callers 1

json2.jsFile · 0.85

Calls 6

joinMethod · 0.80
quoteFunction · 0.70
toJSONMethod · 0.45
callMethod · 0.45
applyMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected