Skip to content

Commit

Permalink
tracing/js: distinguish stack oob error (#219)
Browse files Browse the repository at this point in the history
distinguish the error of stack size out of bound or stake is null.

Signed-off-by: jsvisa <delweng@gmail.com>
  • Loading branch information
jsvisa authored Oct 7, 2024
1 parent 5f3c4b6 commit f9481b9
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/tracing/js/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,20 +429,22 @@ impl StackRef {
fn peek(&self, idx: usize, ctx: &mut Context) -> JsResult<JsValue> {
self.0
.with_inner(|stack| {
let value = stack.peek(idx).map_err(|_| {
JsError::from_native(JsNativeError::typ().with_message(format!(
"tracer accessed out of bound stack: size {}, index {}",
stack.len(),
idx
)))
})?;
to_bigint(value, ctx)
stack
.peek(idx)
.map_err(|_| {
JsError::from_native(JsNativeError::typ().with_message(format!(
"tracer accessed out of bound stack: size {}, index {}",
stack.len(),
idx
)))
})
.and_then(|value| to_bigint(value, ctx))
})
.ok_or_else(|| {
JsError::from_native(JsNativeError::typ().with_message(format!(
"tracer accessed out of bound stack: size 0, index {}",
idx
)))
JsError::from_native(
JsNativeError::typ()
.with_message("tracer accessed stack after it was dropped".to_string()),
)
})?
}

Expand All @@ -465,9 +467,7 @@ impl StackRef {
let idx = idx_f64 as usize;
if len <= idx || idx_f64 < 0. {
return Err(JsError::from_native(JsNativeError::typ().with_message(
format!(
"tracer accessed out of bound stack: size {len}, index {idx_f64}"
),
format!("tracer accessed out of bound stack: size {len}, index {idx}"),
)));
}
stack.peek(idx, ctx)
Expand Down

0 comments on commit f9481b9

Please sign in to comment.