Skip to main content

flatten_depth

Function flatten_depth 

Source
pub(crate) fn flatten_depth(
    items: Vec<Value>,
    depth: f64,
    out: &mut Vec<Value>,
    seen: &mut Vec<ObjRef>,
)
Expand description

再帰的に depth 段だけネスト配列を展開する(arr_flat のヘルパ)。 depth=Infinityarr.flat(Infinity))は定番イディオムだが、depth - 1.0Infinity のままなので、循環参照する配列(a.push(a))に対しては 祖先追跡ガードが無いと無限再帰になり、この no_std 環境ではスタック オーバーフロー(クラッシュ/ハング)に直結し得る(Value::to_js_string で修正済みの「循環参照でスタックオーバーフロー」系と同種のバグ。 2026-07-13 の横断監査で発見)。既に祖先に現れた配列を再訪した時点で、 それ以上展開せずそのまま(配列のまま)結果へ積んで打ち切る。