MCPcopy Create free account
hub / github.com/Ray-D-Song/lexe / write_primitive2

Function write_primitive2

libs/llrt_json/src/stringify.rs:203–292  ·  view source on GitHub ↗
(
    context: &mut StringifyContext<'_, 'js>,
    add_comma: bool,
    new_value: Option<Value<'js>>,
)

Source from the content-addressed store, hash-verified

201}
202
203fn write_primitive2<'js>(
204 context: &mut StringifyContext<'_, 'js>,
205 add_comma: bool,
206 new_value: Option<Value<'js>>,
207) -> Result<PrimitiveStatus<'js>> {
208 let key = context.key;
209 let index = context.index;
210 let include_keys_replacer = context.include_keys_replacer;
211 let indentation = context.indentation;
212 let depth = context.depth;
213
214 let value = new_value.as_ref().unwrap_or(context.value);
215
216 let type_of = value.type_of();
217
218 if context.index.is_none()
219 && matches!(
220 type_of,
221 Type::Symbol | Type::Undefined | Type::Function | Type::Constructor
222 )
223 {
224 return Ok(PrimitiveStatus::Ignored);
225 }
226
227 if matches!(type_of, Type::BigInt) {
228 return Err(Exception::throw_type(
229 context.ctx,
230 "Do not know how to serialize a BigInt",
231 ));
232 }
233
234 if let Some(include_keys_replacer) = include_keys_replacer {
235 let key = get_key_or_index(context.itoa_buffer, key, index);
236 if !include_keys_replacer.contains(key) {
237 return Ok(PrimitiveStatus::Ignored);
238 }
239 };
240
241 if let Some(indentation) = indentation {
242 write_indented_separator(context.result, key, add_comma, indentation, depth);
243 } else {
244 write_sep(context.result, add_comma, false);
245 if let Some(key) = key {
246 write_key(context.result, key, false);
247 }
248 }
249
250 match type_of {
251 Type::Null | Type::Undefined => context.result.push_str("null"),
252 Type::Bool => {
253 let bool_str = if unsafe { value.as_bool().unwrap_unchecked() } {
254 "true"
255 } else {
256 "false"
257 };
258 context.result.push_str(bool_str);
259 },
260 Type::Int => context.result.push_str(

Callers 2

run_replacerFunction · 0.85
write_primitiveFunction · 0.85

Calls 10

get_key_or_indexFunction · 0.85
write_indented_separatorFunction · 0.85
write_keyFunction · 0.85
write_stringFunction · 0.85
as_refMethod · 0.80
formatMethod · 0.80
write_sepFunction · 0.70
as_bytesMethod · 0.45
lenMethod · 0.45
to_stringMethod · 0.45

Tested by

no test coverage detected