MCPcopy Create free account
hub / github.com/awslabs/llrt / parse_node

Function parse_node

libs/llrt_json/src/parse.rs:72–104  ·  view source on GitHub ↗
(ctx: &Ctx<'js>, tape: &[Node], index: usize)

Source from the content-addressed store, hash-verified

70}
71
72fn parse_node<'js>(ctx: &Ctx<'js>, tape: &[Node], index: usize) -> Result<(Value<'js>, usize)> {
73 match tape[index] {
74 Node::String(value) => Ok((value.into_js(ctx)?, index + 1)),
75 Node::Static(node) => Ok((static_node_to_value(ctx, node)?, index + 1)),
76 Node::Object { len, .. } => {
77 let js_object = Object::new(ctx.clone())?;
78 let mut current_index = index + 1;
79
80 for _ in 0..len {
81 if let Node::String(key) = tape[current_index] {
82 current_index += 1;
83 let (value, new_index) = parse_node(ctx, tape, current_index)?;
84 current_index = new_index;
85 js_object.set(key, value)?;
86 }
87 }
88
89 Ok((js_object.into_value(), current_index))
90 },
91 Node::Array { len, .. } => {
92 let js_array = Array::new(ctx.clone())?;
93 let mut current_index = index + 1;
94
95 for i in 0..len {
96 let (value, new_index) = parse_node(ctx, tape, current_index)?;
97 current_index = new_index;
98 js_array.set(i, value)?;
99 }
100
101 Ok((js_array.into_value(), current_index))
102 },
103 }
104}

Callers 1

json_parseFunction · 0.85

Calls 5

static_node_to_valueFunction · 0.85
into_jsMethod · 0.45
cloneMethod · 0.45
setMethod · 0.45
into_valueMethod · 0.45

Tested by

no test coverage detected