(
context: &mut StringifyContext<'_, 'js>,
add_comma: bool,
new_value: Option<Value<'js>>,
)
| 201 | } |
| 202 | |
| 203 | fn 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( |
no test coverage detected